private async Task <bool> SaveLogViews(IEnumerable <LogView> logViewsToSave, bool showConfAndWaitDialogs = true) { var editedLogViewNames = string.Empty; foreach (var logView in logViewsToSave) { editedLogViewNames += $"{logView.Name},{Environment.NewLine}"; } if (!string.IsNullOrWhiteSpace(editedLogViewNames)) { var dialogSettings = new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", FirstAuxiliaryButtonText = "Cancel", DefaultButtonFocus = MessageDialogResult.Affirmative, }; editedLogViewNames = editedLogViewNames.Substring(0, editedLogViewNames.Length - 3); var dialogResult = !showConfAndWaitDialogs ? MessageDialogResult.Affirmative : await _dialogCoordinator.ShowMessageAsync(this, "Save Log Views", $"Would you like to save changes to the following log views?{Environment.NewLine + Environment.NewLine + editedLogViewNames}", MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, dialogSettings); if (dialogResult == MessageDialogResult.Affirmative) { var minWaitTime = !showConfAndWaitDialogs ? 0 : 300; var progressController = !showConfAndWaitDialogs ? null : await _dialogCoordinator.ShowProgressAsync(this, "Saving Log Views", "Preparing..."); progressController?.SetIndeterminate(); var failedLogViews = string.Empty; await Task.Run(async() => { foreach (var logView in logViewsToSave) { try { progressController?.SetMessage($"Saving log view \"{logView.Name}\"..."); await Task.WhenAll(SettingsService.AddOrUpdateLogView(logView), Task.Delay(minWaitTime)); logView.IsEdited = false; } catch { failedLogViews += logView.Name + $",{Environment.NewLine}"; } } SettingsService.SaveSettings(); }); if (progressController != null) { await progressController.CloseAsync(); } if (!string.IsNullOrWhiteSpace(failedLogViews)) { await _dialogCoordinator.ShowMessageAsync(this, "Save Failed", $"{AppInfo.BaseAppInfo.AppName} failed to save the following log views:{Environment.NewLine + Environment.NewLine + failedLogViews}"); } } else if (dialogResult == MessageDialogResult.Negative) { //If user declines to save log views, reload them to discard in-memory changes var tasks = new List <Task <ServiceOperationResult> >(); foreach (var logView in logViewsToSave) { tasks.Add(SettingsService.ReloadLogView(logView)); } await Task.WhenAll(tasks); } else if (dialogResult == MessageDialogResult.FirstAuxiliary) { return(false); } } return(true); }