private void ImportSnaphotFiles(List<SnapshotFile> Files, CancellationToken CancelToken)
{
// Number of snapshots we have processed
int processed = 0;
// Do Work
foreach (SnapshotFile SnapshotFile in Files)
{
// If we have a cancelation request
if (CancelToken.IsCancellationRequested)
break;
// Make sure we arent processing twice
if (SnapshotFile.IsProcessed)
continue;
// Process the snapshot
try
{
// Update status and run snapshot
TaskForm.Progress.Report(new TaskProgressUpdate(String.Format("Processing: \"{0}\"", SnapshotFile)));
Snapshot Snapshot = new Snapshot(File.ReadAllText(SnapshotFile.FilePath));
// Avoid processing exception
if (Snapshot.IsProcessed)
continue;
else // Do snapshot
Snapshot.ProcessData();
// Move the Temp snapshot to the Processed folder
File.Move(
Path.Combine(Paths.SnapshotTempPath, SnapshotFile.FileName),
Path.Combine(Paths.SnapshotProcPath, SnapshotFile.FileName)
);
}
catch (Exception E)
{
using (ExceptionForm Form = new ExceptionForm(E, true))
{
Form.Message = "An exception was thrown while trying to import the snapshot."
+ "If you click Continue, the application will continue proccessing the remaining "
+ "snapshot files. If you click Quit, the operation will be aborted.";
DialogResult Result = Form.ShowDialog();
// User Abort
if (Result == DialogResult.Abort)
break;
}
}
// Whether we failed or succeeded, we are finished with this step
// and should move the progress bar 1 step
TaskForm.Progress.Report(new TaskProgressUpdate(++processed));
}
// Let progress bar update to 100%
TaskForm.Progress.Report(new TaskProgressUpdate("Done! Cleaning up..."));
Thread.Sleep(250);
}