Make import notifications fail when any imports fail

This commit is contained in:
Dean Herbert 2018-03-19 20:15:17 +09:00
parent 4e4f3fc039
commit 18368d2446
1 changed files with 6 additions and 4 deletions

View File

@ -88,7 +88,8 @@ public void Import(params string[] paths)
List<TModel> imported = new List<TModel>();
int i = 0;
int success = 0;
int errors = 0;
foreach (string path in paths)
{
if (notification.State == ProgressNotificationState.Cancelled)
@ -97,11 +98,11 @@ public void Import(params string[] paths)
try
{
notification.Text = $"Importing ({i} of {paths.Length})\n{Path.GetFileName(path)}";
notification.Text = $"Importing ({success} of {paths.Length})\n{Path.GetFileName(path)}";
using (ArchiveReader reader = getReaderFrom(path))
imported.Add(Import(reader));
notification.Progress = (float)++i / paths.Length;
notification.Progress = (float)++success / paths.Length;
// We may or may not want to delete the file depending on where it is stored.
// e.g. reconstructing/repairing database with items from default storage.
@ -121,10 +122,11 @@ public void Import(params string[] paths)
{
e = e.InnerException ?? e;
Logger.Error(e, $@"Could not import ({Path.GetFileName(path)})");
errors++;
}
}
notification.State = ProgressNotificationState.Completed;
notification.State = errors == 0 ? ProgressNotificationState.Completed : ProgressNotificationState.Cancelled;
}
/// <summary>