Skip to content

Commit 31679f3

Browse files
committed
Minor fix to Staging Tester if trying to load invalid file.
1 parent 16a4a58 commit 31679f3

File tree

1 file changed

+46
-21
lines changed
  • TNMStagingCSharp/TNMStaging_StagingViewerApp

1 file changed

+46
-21
lines changed

TNMStagingCSharp/TNMStaging_StagingViewerApp/FrmMain.cs

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,10 @@ private void cmbAlgorithms_SelectedIndexChanged(object sender, EventArgs e)
149149

150150
Refresh();
151151

152+
mStaging = null;
153+
152154
string sName = (string)cmbAlgorithms.Items[cmbAlgorithms.SelectedIndex];
153155
LoadAlgorithm(sName);
154-
155-
tabControl.Enabled = true;
156-
157-
// unselect listbox selections
158-
//panel1.Refresh();
159-
//cmbSchemaSelect.SelectedItem = -1;
160-
//cmbSchemaSelect.SelectedText = "";
161-
//Refresh();
162156
}
163157
}
164158

@@ -206,6 +200,7 @@ void ClearStagingResults()
206200

207201
public async void LoadAlgorithm(string sFilename)
208202
{
203+
bool bFailure = false;
209204
const int WAIT_AMT = 300;
210205
UpdateProgress(0);
211206
pbLoad.Visible = true;
@@ -222,24 +217,54 @@ public async void LoadAlgorithm(string sFilename)
222217
{
223218
await Task.Delay(WAIT_AMT);
224219

225-
FileStream SourceStream = File.Open(sFullFilename, FileMode.Open);
226-
await Task.Delay(WAIT_AMT);
227-
mProvider = new ExternalStagingFileDataProvider(SourceStream);
228-
await Task.Delay(WAIT_AMT);
229-
mStaging = Staging.getInstance(mProvider);
220+
FileStream SourceStream = null;
221+
222+
try
223+
{
224+
SourceStream = File.Open(sFullFilename, FileMode.Open);
225+
await Task.Delay(WAIT_AMT);
226+
mProvider = new ExternalStagingFileDataProvider(SourceStream);
227+
await Task.Delay(WAIT_AMT);
228+
mStaging = Staging.getInstance(mProvider);
229+
}
230+
catch (Exception e)
231+
{
232+
bFailure = true;
233+
MessageBox.Show("Unable to load the algorithm " + sFilename + ".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
234+
tabControl.Enabled = false;
235+
pbLoad.Visible = false;
236+
tmrLoad.Enabled = false;
237+
}
238+
239+
if (!bFailure)
240+
{
241+
UpdateProgress(100);
242+
await Task.Delay(WAIT_AMT);
243+
}
230244

245+
SourceStream.Close();
246+
if (!bFailure)
247+
{
248+
UpdateAlgorithmHeaderValues();
249+
LoadSchemas();
250+
SetupStageTesterTab();
251+
}
252+
}
253+
if (!bFailure)
254+
{
255+
pbLoad.Visible = false;
256+
tmrLoad.Enabled = false;
231257
UpdateProgress(100);
232258
await Task.Delay(WAIT_AMT);
233259

234-
SourceStream.Close();
235-
UpdateAlgorithmHeaderValues();
236-
LoadSchemas();
237-
SetupStageTesterTab();
260+
261+
tabControl.Enabled = true;
262+
263+
// unselect listbox selections
264+
cmbSchemaSelect.SelectedItem = -1;
265+
cmbSchemaSelect.SelectedText = "";
266+
Refresh();
238267
}
239-
pbLoad.Visible = false;
240-
tmrLoad.Enabled = false;
241-
UpdateProgress(100);
242-
await Task.Delay(WAIT_AMT);
243268
}
244269

245270
private void UpdateProgress(int iNewValue)

0 commit comments

Comments
 (0)