private ImportStats DoImport(Profile profile) { var stats = new ImportStats(); AddProtocol($"profile {profile.Name}"); foreach (var file in Files) { try { if (Importer.CancellationPending) { return(stats); } if (checkBoxOnlyAfterLastImport.Checked && file.LastWriteTime < OnlyAfter) { stats.Skipped++; } else if (FileHandlers[file.Extension](file)) { stats.Copied++; } else { stats.Skipped++; } } catch (Exception exception) { AddProtocol($"failed - {file.FullName}"); AddProtocol($" {exception.Message}"); stats.Failed++; } Invoke((MethodInvoker) delegate { progressBar.Value++; }); } return(stats); }
private void CompletedImport(ImportStats stats, bool canceled, Exception exception) { progressBar.Visible = false; buttonImport.Text = "&Import"; if (stats != null) { var results = new List <string>(); if (stats.Copied > 0) { results.Add($"{stats.Copied:#,##0} copied"); } if (stats.Skipped > 0) { results.Add($"{stats.Skipped:#,##0} skipped"); } if (stats.Failed > 0) { results.Add($"{stats.Failed:#,##0} failed"); } var result = string.Join(", ", results); if (result.NotEmpty()) { AddProtocol($"result - {result}"); } } if (canceled) { AddProtocol("import aborted."); } else if (exception != null) { AddProtocol($"import failed - {exception.Message}"); } else { var state = new ImportState { Timestamp = DateTime.Now, Overwrite = checkBoxOverwrite.Checked, OnlyAfterLastImport = checkBoxOnlyAfterLastImport.Checked, ProfileName = Profile.Name }; if (state.Save(textBoxSource.Text)) { AddProtocol("state saved"); } AddProtocol($"import completed"); } textBoxSource.Enabled = buttonSelect.Enabled = buttonEdit.Enabled = comboBoxProfiles.Enabled = checkBoxOverwrite.Enabled = buttonImport.Enabled = true; }