private void CloseTab(object p) { if (!(p is MainEditorViewModel)) { return; } var removeView = _regionManager.Regions[Names.MainContentRegion].Views.Cast <FrameworkElement>().FirstOrDefault(v => v.DataContext == p); if (removeView == null) { return; } var needSave = ((MainEditorViewModel)p).IsNeedSave; if (needSave) { var result = DialogCoordinator.ShowMessageAsync(this, "Close", "Save project before closing?", MessageDialogStyle.AffirmativeAndNegative, ServiceLocator.GetInstance <MetroDialogSettings>()); result.Wait(); if (result.Result == MessageDialogResult.Affirmative) { SaveProject(); } } removeView.DataContext = null; _regionManager.Regions[Names.MainContentRegion].Remove(removeView); ((MainEditorViewModel)p).Dispose(); }
private void VerifyIfPlayerWonGame() { if (_numberOfLeftPawns == 0) { DialogCoordinator.ShowMessageAsync(this, "Congratulations", "You won game !!!"); } }
private async void CloseTab(object p) { var model = p as ICloseable; if (model == null) { return; } var removeView = RegionManager.Regions[Names.MainContentRegion].Views.Cast <FrameworkElement>().FirstOrDefault(v => v.DataContext == p); if (removeView == null) { return; } var needSave = model.IsNeedSave; if (needSave) { var result = await DialogCoordinator.ShowMessageAsync(this, "Close", "Save project before closing?", MessageDialogStyle.AffirmativeAndNegative, Container.GetInstance <MetroDialogSettings>()); if (result == MessageDialogResult.Affirmative) { SaveProject(); } } removeView.DataContext = null; RegionManager.Regions[Names.MainContentRegion].Remove(removeView); model.Close(); }
/// <summary> /// Show dialog with error message /// </summary> /// <param name="message">Message</param> protected void ShowErrorMessage(string message) { DialogCoordinator.ShowMessageAsync(this, "Error", message, MessageDialogStyle.Affirmative, new MetroDialogSettings { AnimateHide = false, AnimateShow = false }); }
private async void RestetGame(object obj) { var progressDialogController = DialogCoordinator.ShowMessageAsync(this, "Restart", "Restart game..."); LoadGameSettings(); ResetSettings(); await progressDialogController; }
protected async Task <MessageDialogResult> ConfirmAsync(string title, string description, CancellationToken ct = default) { var result = await DialogCoordinator.ShowMessageAsync(DialogContext, title, description, MessageDialogStyle.AffirmativeAndNegative, CreateDialog(ct)); return(result); }
public async void ChangeViewModel(object param) { if (param != null) { if (StaticSourcesViewModel.SourceChanged) { if (await(_dialogCoordinator.ShowMessageAsync(this, "Advertencia", "Hay cambios sin guardar, ¿Seguro que desea salir sin guardar?", MahApps.Metro.Controls.Dialogs.MessageDialogStyle.AffirmativeAndNegative)) == MahApps.Metro.Controls.Dialogs.MessageDialogResult.Affirmative) { StaticSourcesViewModel.SourceChanged = false; } else { return; } } var params1 = (object[])param; var model = Type.GetType((params1[0]).ToString()); var view = Type.GetType((params1[1]).ToString()); if (model == null || view == null) { return; } object vistamodelo = null; switch (model.Name) { case "CatAlmacenViewModel": case "CatProducto_CategoriaViewModel": case "CatProducto_SubCategoriaViewModel": case "CatProducto_TipoViewModel": case "CatProductoViewModel": case "CapturaOCViewModel": case "CalendarizacionViewModel": case "EntradasAlmacenesViewModel": case "RegistroTraspasosExternosViewModel": case "RequisicionExtraordinariaPrincipalViewModel": //var controller = await _dialogCoordinator.ShowProgressAsync(this, "Por favor espere un momento", string.Empty); StaticSourcesViewModel.ShowProgressLoading(); await Task.Factory.StartNew(() => { vistamodelo = Activator.CreateInstance(model, new object[] { DialogCoordinator.Instance, Usuario }); }); StaticSourcesViewModel.CloseProgressLoading(); ContentControlBag = new ContentControlBag(Activator.CreateInstance(view), vistamodelo); break; default: StaticSourcesViewModel.ShowProgressLoading(); await Task.Factory.StartNew(() => { vistamodelo = Activator.CreateInstance(model, new object[] { DialogCoordinator.Instance }); }); StaticSourcesViewModel.CloseProgressLoading(); ContentControlBag = new ContentControlBag(Activator.CreateInstance(view), vistamodelo); break; } } }
private async void SaveSettings(object obj) { var controller = DialogCoordinator.ShowMessageAsync(this, "Saving", "Saving"); GameSettings.SelectedPawn = _chessPawnFactory.CreatePawn(_selectedPawn + 1); GameSettings.GameType = _gameTypeFactory.CreateGameType(SelectedGameType, TimeMax, NumberOfMistakes, IsTipsEnabled); SettingsService.Save(GameSettings); Chessboard.ClearChessboard(); await controller; }
private async void StartBackup() { if (SavesToCompressedFile && CompressedFileUsesPassword && string.IsNullOrWhiteSpace(Utilities.SecureStringToString(Password))) { await DialogCoordinator.ShowMessageAsync(this, "Error!", "Your password cannot be blank", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "OK", ColorScheme = MetroDialogColorScheme.Theme } ); } else if (SavesToCompressedFile && CompressedFileUsesPassword && Utilities.SecureStringToString(Password) != Utilities.SecureStringToString(ConfirmPassword)) { await DialogCoordinator.ShowMessageAsync(this, "Error!", "Password and confirm password do not match", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "OK", ColorScheme = MetroDialogColorScheme.Theme } ); } else { bool canProceed = true; if (SavesToCompressedFile && CompressedFileUsesPassword) { var result = await DialogCoordinator.ShowMessageAsync(this, "Warning!", "This backup will be encrypted. " + "The backup cannot be recovered if you forget your password. " + "Are you sure you want to proceed? ", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", ColorScheme = MetroDialogColorScheme.Theme } ); if (result != MessageDialogResult.Affirmative) { canProceed = false; } } if (canProceed) { PushViewModel(new BackupInProgressViewModel(ViewModelChanger, Items.ToList(), BackupLocation, SavesToCompressedFile, CompressedFileUsesPassword ? Password : null)); } } }
public static async Task<MessageDialogResult> GetUserConfirmationOnClosing(DialogCoordinator dialogCoordinator, ScreenBase tab) { MetroDialogSettings settings = new MetroDialogSettings() { AffirmativeButtonText = " Save and close ", NegativeButtonText = " Close without saving ", FirstAuxiliaryButtonText = "Cancel" }; MessageDialogResult result = await dialogCoordinator. ShowMessageAsync(tab, "There are some unsaved changes. What do you want to do?", "", MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, settings); return result; }
public static async Task<MessageDialogResult> GetUserConfirmation(DialogCoordinator dialogCoordinator, ScreenBase tab) { MetroDialogSettings settings = new MetroDialogSettings() { AffirmativeButtonText = "Save", NegativeButtonText = "Discard", FirstAuxiliaryButtonText = "Cancel" }; MessageDialogResult result = await dialogCoordinator. ShowMessageAsync(tab, "What do you want to do with your changes?", "", MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, settings); return result; }
public static async Task <MessageDialogResult> GetUserConfirmationOnClosing(DialogCoordinator dialogCoordinator, ScreenBase tab) { MetroDialogSettings settings = new MetroDialogSettings() { AffirmativeButtonText = " Save and close ", NegativeButtonText = " Close without saving ", FirstAuxiliaryButtonText = "Cancel" }; MessageDialogResult result = await dialogCoordinator. ShowMessageAsync(tab, "There are some unsaved changes. What do you want to do?", "", MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, settings); return(result); }
public static async Task <MessageDialogResult> GetUserConfirmation(DialogCoordinator dialogCoordinator, ScreenBase tab) { MetroDialogSettings settings = new MetroDialogSettings() { AffirmativeButtonText = "Save", NegativeButtonText = "Discard", FirstAuxiliaryButtonText = "Cancel" }; MessageDialogResult result = await dialogCoordinator. ShowMessageAsync(tab, "What do you want to do with your changes?", "", MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, settings); return(result); }
public async Task <bool> ShowMessageConfirm(object context, string title, string message) { IDialogCoordinator dialogCoodinator = new DialogCoordinator(); var mySettings = new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No" }; MessageDialogResult result = await dialogCoodinator.ShowMessageAsync(context, title, message, MessageDialogStyle.AffirmativeAndNegative, mySettings); return(result == MessageDialogResult.Affirmative); }
private void VerifyIfPlayerLoseGame() { if (!_isGameStarted) { return; } if (!_timerService.IsCountingFinished && TimeLimit != Timer && NumberOfPossibleMistakes >= NumberOfMistakes) { return; } DialogCoordinator.ShowMessageAsync(this, "Lose", "You lose game!!!"); _isGameStarted = false; _timerService.Reset(); }
private async void CheckAndRemoveAllItems() { var result = await DialogCoordinator.ShowMessageAsync(this, "Warning!", "Are you sure you want to remove all items?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", ColorScheme = MetroDialogColorScheme.Theme } ); if (result == MessageDialogResult.Affirmative) { Items.Clear(); } }
private void CreateCommands() { Add = ReactiveCommand.Create(ExecuteAdd); //get existing jobs and tags/instruments Load = ReactiveCommand.CreateFromTask(async _ => { var dataUpdateJobs = _client.GetaDataUpdateJobs(); var econReleaseUpdateJobs = _client.GetEconomicReleaseUpdateJobs(); var dividendUpdateJobs = _client.GetDividendUpdateJobs(); var earningsUpdateJobs = _client.GetEarningsUpdateJobs(); var tags = _client.GetTags(); var instruments = _client.GetInstruments(); var econReleaseSources = _client.GetEconomicReleaseDataSources(); var dividendSources = _client.GetDividendDataSources(); var earningsSources = _client.GetEarningsDataSources(); await Task.WhenAll(dataUpdateJobs, econReleaseUpdateJobs, dividendUpdateJobs, tags, instruments, econReleaseSources, dividendSources, earningsUpdateJobs, earningsSources).ConfigureAwait(false); var responses = new ApiResponse[] { dataUpdateJobs.Result, econReleaseUpdateJobs.Result, dividendUpdateJobs.Result, tags.Result, instruments.Result, econReleaseSources.Result, dividendSources.Result, earningsUpdateJobs.Result, earningsSources.Result }; if (await responses.DisplayErrors(this, DialogCoordinator).ConfigureAwait(true)) { return(null); } Tags.AddRange(tags.Result.Result); Instruments.AddRange(instruments.Result.Result); EconomicReleaseDataSources.AddRange(econReleaseSources.Result.Result); DividendDataSources.AddRange(dividendSources.Result.Result); EarningsDataSources.AddRange(earningsSources.Result.Result); var jobs = new List <IJobSettings>(); jobs.AddRange(dataUpdateJobs.Result.Result); jobs.AddRange(econReleaseUpdateJobs.Result.Result); jobs.AddRange(dividendUpdateJobs.Result.Result); jobs.AddRange(earningsUpdateJobs.Result.Result); return(jobs); }); Load.Subscribe(jobs => { if (jobs == null) { return; } foreach (var job in jobs) { Jobs.Add(GetJobViewModel(job)); } }); //Delete job var deleteCanExecute = this .WhenAnyValue(x => x.SelectedJob) .Select(x => x != null && !string.IsNullOrEmpty(x.PreChangeName)); Delete = ReactiveCommand.CreateFromTask(async _ => { //Give a dialog to confirm the deletion MessageDialogResult dialogResult = await DialogCoordinator.ShowMessageAsync(this, "Delete Job", string.Format("Are you sure you want to delete {0}?", SelectedJob.Name), MessageDialogStyle.AffirmativeAndNegative); if (dialogResult != MessageDialogResult.Affirmative) { return; } //If the name has changed but hasn't been saved, we change it back to be in sync with the server SelectedJob.Name = SelectedJob.PreChangeName; //Request deletion var response = await SelectedJob.Delete.Execute(); if (await response.DisplayErrors(this, DialogCoordinator)) { return; } //if it was successful, remove the VM from the list Jobs.Remove(SelectedJob); SelectedJob = null; }, deleteCanExecute); }
/// **************************************************************************************************** /// メソッド定義 /// **************************************************************************************************** /// <summary> /// メッセージダイアログを表示します。 /// </summary> /// <param name="title">タイトル</param> /// <param name="message">メッセージ</param> /// <param name="style">ダイアログスタイル</param> /// <param name="settings">設定情報</param> /// <returns><code>MessageDialogResult</code></returns> public async Task <MessageDialogResult> ShowMessageAsync(string title, string message, MessageDialogStyle style = MessageDialogStyle.Affirmative, MetroDialogSettings settings = null) { return(await DialogCoordinator.ShowMessageAsync(this, title, message, style, settings)); }
private async void EditFeed(RoutedEventArgs e) { if (_selectedNode == null) { return; } SimpleTreeNodeViewModel tvm = (SimpleTreeNodeViewModel)_selectedNode; Model.Feed selectedFeed = null; if (tvm.Node is Model.Feed) { selectedFeed = (Model.Feed)tvm.Node; } else { if (tvm.Node is Model.Host) { try { Model.Host selectedHost = (Model.Host)tvm.Node; IsBrowserVisible = false; RaisePropertyChanged("IsBrowserVisible"); MetroDialogSettings diagSettings = new MetroDialogSettings(); diagSettings.DefaultText = selectedHost.Zoom.ToString(); var ZoomLevel = await _dialogCoordinator.ShowInputAsync(this, "Set Zoom Level", "Enter the desired zoom level for this host: ", diagSettings); int prevZoom = selectedHost.Zoom; selectedHost.Zoom = Int32.Parse(ZoomLevel.ToString()); Data.Host dh = new Data.Host(selectedHost); dh.Save(); if (prevZoom != selectedHost.Zoom) { var msg = new SendSetZoomMessage(selectedHost.Zoom); msg.SetImmediately = true; Messenger.Default.Send <SendSetZoomMessage>(msg); } } catch (Exception ex) { await _dialogCoordinator.ShowMessageAsync(this, "Set Zoom Level", "Unable to set zoom: " + ex.Message); } finally { IsBrowserVisible = true; RaisePropertyChanged("IsBrowserVisible"); } } return; } // Hides browser otherwise dialog gets behind it IsBrowserVisible = false; RaisePropertyChanged("IsBrowserVisible"); MetroDialogSettings dialogSettings = new MetroDialogSettings(); dialogSettings.DefaultText = selectedFeed.Location.ToString(); var FeedText = await _dialogCoordinator.ShowInputAsync(this, "Edit feed", "Enter the URL of the feed:", dialogSettings); if (FeedText != null) { string errMsg = null; try { Uri feedUri = new Uri(FeedText); Data.Feed f = new Data.Feed(selectedFeed); f.Location = feedUri; f.UpdateFromUri(true, RetentionDays); f.Save(true); InitializeData(true); } catch (Exception ex) { errMsg = ex.Message; } if (errMsg != null) { await _dialogCoordinator.ShowMessageAsync(this, "Edit Feed", "Unable to edit feed with the supplied URL: " + errMsg); } } IsBrowserVisible = true; RaisePropertyChanged("IsBrowserVisible"); }
private async void OpenLogView(LogView logView) { logView.Open(); AdjustOpenLogViewCount(1); RequestSetSelectedLogView(logView); logView.IsLoading = true; RequestToggleLaunchViewIsOpen(); await Task.Delay(500); if (!logView.IsNew && LogViewToOpenDocumentIn == null) { OpenableObjectService.SaveOpenableObject(logView); } var tasks = new List <Task <ServiceOperationResult> >(); foreach (var logFilePath in logView.LogFilePaths) { var logFile = LogFilesSourceCache.Lookup(logFilePath); if (logFile.HasValue) { logFile.Value.Open(); OpenableObjectService.SaveOpenableObject(logFile.Value); tasks.Add(LogFileService.LoadLogEntriesIntoSourceCacheAsync(logFile.Value, LogEntriesSourceCache)); } } foreach (var databaseName in logView.DatabaseNames) { var database = DatabasesSourceCache.Lookup(databaseName); if (database.HasValue) { database.Value.Open(); OpenableObjectService.SaveOpenableObject(database.Value); tasks.Add(DatabaseService.LoadLogEntriesIntoSourceCache(database.Value, LogEntriesSourceCache)); } } var results = await Task.WhenAll(tasks); var failedLogFilesString = string.Empty; var failedDatabasesString = string.Empty; var errorMessage = string.Empty; await Task.Run(() => { for (int i = 0; i < results.Length - logView.DatabaseNames.Count; i++) { var result = results[i]; if (result.OperationFailed && logView.LogFilePaths.Count > i) { failedLogFilesString += logView.LogFilePaths[i] + "," + Environment.NewLine; } } if (failedLogFilesString.Length > 2) { failedLogFilesString = failedLogFilesString.Substring(0, failedLogFilesString.Length - 3); } for (int i = logView.LogFilePaths.Count; i < results.Length; i++) { var result = results[i]; if (result.OperationFailed) { failedDatabasesString += logView.DatabaseNames[i - logView.LogFilePaths.Count] + "," + Environment.NewLine; } } if (failedDatabasesString.Length > 2) { failedDatabasesString = failedDatabasesString.Substring(0, failedDatabasesString.Length - 3); } if (!string.IsNullOrWhiteSpace(failedLogFilesString)) { errorMessage += $"Failed to load log entries for the following log files:{Environment.NewLine + failedLogFilesString}"; if (!string.IsNullOrWhiteSpace(failedDatabasesString)) { errorMessage += $"{Environment.NewLine + Environment.NewLine}Failed to load log entries for the following databases:{Environment.NewLine + failedDatabasesString}"; } } else if (!string.IsNullOrWhiteSpace(failedDatabasesString)) { errorMessage += $"Failed to load log entries for the following databases:{Environment.NewLine + failedDatabasesString}"; } }); if (!string.IsNullOrWhiteSpace(errorMessage)) { //TODO: I'm getting this summary error message and individual error messages. Have to disable the error message for each individual log source. await DialogCoordinator.ShowMessageAsync(this, "Failed to Load Log Entries", errorMessage); } //Notify the LogViewManagementViewModel that the AutoRefreshSetting changed so that it can tell databases and log files Mediator.NotifyColleagues(MediatorMessages.AutoRefreshSettingChanged, logView.Settings.AutoRefresh); logView.IsLoading = false; }
public void ShowMessage(object context, string title, string message) { IDialogCoordinator dialogCoodinator = new DialogCoordinator(); dialogCoodinator.ShowMessageAsync(context, title, message); }
private async void CheckForUpdates() { await Task.Delay(3000); while (!DialogCoordinatorRegistered) { await Task.Delay(25); } if (await _updateHandler.IsUpdateAvailable()) { IsUpdating = true; var result = await DialogCoordinator.ShowMessageAsync(this, "Update available", $"An update is available.{Environment.NewLine}{Environment.NewLine}Current installed version: {_updateHandler.LocalVersion}.{Environment.NewLine}Available version: {_updateHandler.RemoteVersion}{Environment.NewLine}{Environment.NewLine}Do you want to install this update now?", MessageDialogStyle.AffirmativeAndNegative); if (result == MessageDialogResult.Affirmative) { _updateHandler.UpdateDownloadProgressChanged += (sender, args) => { _progressController.SetProgress(args.ProgressPercentage / 100.0); _progressController.SetMessage($"Downloading...{Environment.NewLine}Received: {args.MegabytesReceived} MB{Environment.NewLine}Total Size: {args.MegabytesToReceive} MB"); }; _updateHandler.UpdateDownloadCompleted += async(sender, args) => { if (args.Aborted) { _progressController?.SetMessage("Failed to download update"); } else { _progressController?.SetMessage("Completed!"); _progressController?.SetIndeterminate(); } await Task.Delay(3000); try { await _progressController?.CloseAsync(); } catch (Exception) { // ignored } IsUpdating = false; }; var task = _updateHandler.DownloadUpdate(); _progressController = await DialogCoordinator.ShowProgressAsync(this, "Downloading update", "", true); _progressController.Canceled += (sender, args) => { _progressController.CloseAsync(); _updateHandler.CancelDownload(); IsUpdating = false; }; } else { IsUpdating = false; } } }
protected async Task ErrorAccrued(Exception ex) { await DialogCoordinator.ShowMessageAsync(DialogContext, Error, ex.Message); }
protected async Task ShowInfoMessageAsync(string title, string description, CancellationToken ct = default) { await DialogCoordinator.ShowMessageAsync(DialogContext, title, description, settings : CreateDialog(ct)); }