protected override async void Execute() { var configuration = new BackupConfiguration { Database = this.HasDatabase && this.Database, Files = this.HasFile && this.Files, Plugins = this.HasPlugin && this.Plugins, Themes = this.HasTheme && this.Themes }; // リストア処理の実行 string message = null; try { var progressDialogService = new ProgressDialogService { IsAutoClose = true }; var engine = new RestoreEngine(this._BitnamiRedmineService, this._BackupService, this._DispatcherService, this._LogService, configuration, this.Stack, this.Directory); var report = engine.PrepareRestore(); progressDialogService.Action = () => { engine.ExecuteRestore(); }; progressDialogService.Report = report; await progressDialogService.ShowMessage(null, null); if (progressDialogService.Result == MessageBoxResult.Cancel) { message = Resources.Msg_RestoreCancel; } else { message = Resources.Msg_RestoreComplete; } } catch (Exception ex) { message = $"Exception is thown. Reason is {ex.Message}"; this._LogService.Error(message); message = $"StackTrace is {ex.StackTrace}"; this._LogService.Error(message); message = Resources.Msg_BackupFailed; } finally { await this._DialogService.ShowMessage(MessageBoxButton.OK, message, null); } }
/// <summary> /// Асинхронная смена сценария /// </summary> /// <returns></returns> private async Task ChangeScenarioAsync(string fileName, bool isQuickLoad) { if (isQuickLoad) { mFileName = fileName; await ProgressDialogService.ExecuteAsync(LoadAsync).ConfigureAwait(false); } else { await TaskExtension.Delay(1).ConfigureAwait(false); var dialog = new OpenFileDialog { Filter = "Файл с описанием сценария (xmlinfo)|*.xmlinfo" }; if (!string.IsNullOrEmpty(DataHolder.Instance.FullFolderPath)) { dialog.InitialDirectory = DataHolder.Instance.FullFolderPath; dialog.FileName = Path.Combine(DataHolder.Instance.FullFolderPath, Constants.cScenarioDescriptor); } if (dialog.ShowDialog() == true) { mFileName = dialog.FileName; await ProgressDialogService.ExecuteAsync(LoadAsync).ConfigureAwait(false); } } }
protected override void InitializeShell() { base.InitializeShell(); DialogService dialogService = new DialogService("MessageDialogHost"); ProgressDialogService progressDialogService = new ProgressDialogService("ProgressDialogHost"); UserDataAddDialogService userDataAddDialogService = new UserDataAddDialogService("UserDataAddDialogHost"); Shell shell = Shell as Shell; App.Current.MainWindow = shell; shell.DataContext = new ShellViewModel(dialogService, progressDialogService, userDataAddDialogService); shell.Show(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); MainWindow window = new MainWindow(); IDialogService mProgressService = new ProgressDialogService(window); MainWindowViewModel mainViewModel = new MainWindowViewModel(mProgressService); // Allow all controls in the window to // bind to the ViewModel by setting the // DataContext, which propagates down // the element tree. window.DataContext = mainViewModel; window.Show(); }
public MenuViewModel(IDataService dataService, IProjectService projectService, ProgressDialogService progressDialogService) { _dataService = dataService; _projectService = projectService; _progressDialogService = progressDialogService; OpenCommand = new RelayCommand(DoOpenCommand); OpenProjectCommand = new RelayCommand(DoOpenProjectCommand); SaveCommand = new RelayCommand(DoSaveCommand); SaveProjectCommand = new RelayCommand(DoSaveProjectCommand); AddCarCommand = new RelayCommand(DoAddCarCommand); AboutCommand = new RelayCommand(DoAboutCommand); CanOpen = true; this.MessengerInstance.Register <ProjectMessage>(this, HandleProjectMessage); }
protected override async void Execute() { string message; var path = this.OutputDirectory; DirectoryInfo directory; // 出力先ディレクトリのディレクトリ名の検証 try { directory = System.IO.Directory.CreateDirectory(path); } catch (Exception) { await this._DialogService.ShowMessage(MessageBoxButton.OK, Resources.Msg_BackupFailed, null); return; } // 空かどうか検証 if (!this.IsOutputDirectoryEmpty(directory.FullName)) { var result = await this._DialogService.ShowMessage(MessageBoxButton.YesNo, Resources.Msg_DirectoryIsNotEmpty, null); if (result == MessageBoxResult.No) { return; } } var configuration = new BackupConfiguration { Database = this.Database, Files = this.Files, Plugins = this.Plugins, Themes = this.Themes }; try { var progressDialogService = new ProgressDialogService { IsAutoClose = true }; var engine = new BackupEngine(this._BitnamiRedmineService, this._BackupService, this._DispatcherService, this._LogService, configuration, this.Stack, this._OutputDirectory); var report = engine.PrepareBackup(); progressDialogService.Action = () => { engine.ExecuteBackup(); }; progressDialogService.Report = report; await progressDialogService.ShowMessage(null, null); if (progressDialogService.Result == MessageBoxResult.Cancel) { message = Resources.Msg_BackupCancel; await this._DialogService.ShowMessage(MessageBoxButton.OK, message, null); return; } else { message = Resources.Msg_BackupComplete; } } catch (Exception ex) { message = $"Exception is thown. Reason is {ex.Message}"; this._LogService.Error(message); message = $"StackTrace is {ex.StackTrace}"; this._LogService.Error(message); message = Resources.Msg_BackupFailed; await this._DialogService.ShowMessage(MessageBoxButton.OK, message, null); return; } // Update Setting RedmineSetting redmineSetting; var applicationSetting = this.GetApplicationSetting(out redmineSetting); redmineSetting.Backup.Database = configuration.Database; redmineSetting.Backup.Files = configuration.Files; redmineSetting.Backup.Plugins = configuration.Plugins; redmineSetting.Backup.Themes = configuration.Themes; redmineSetting.Backup.BaseDirectory = this.Directory; redmineSetting.Backup.DirectoryName = this.DirectoryName; var history = new BackupHistorySetting { DisplayVersion = this.Stack.DisplayVersion, DateTime = DateTime.UtcNow, OutputDirectory = path }; this._ApplicationSettingService.BackupHistories.Add(history); applicationSetting.BackupHistories.Add(history); this._ApplicationSettingService.UpdateApplicationSetting(applicationSetting); await this._DialogService.ShowMessage(MessageBoxButton.OK, message, null); }
/// <summary> /// Асинхронное сохранение сценария /// </summary> /// <returns></returns> private async Task SaveScenarioHandlerAsync(object param) { if (IndicatorSave.IsEqual(Indicators.Accept.GetColor())) { if (!DataHolder.Instance.SlideDataHolders.Any(x => (x as ISaveValidator).With(valid => valid.OwnScenarioTypes.Contains(DataHolder.Instance.ScenarioProperties.ScenarioType) && !valid.IsValid))) { var dialog = new FolderBrowserDialog { SelectedPath = DataHolder.Instance.FullFolderPath }; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { await DataHolder.Instance.ReleaseMedia(true, null, new CancellationToken()); string directoryName = dialog.SelectedPath; IEnumerable <string> scenarioInfos = Directory.GetFiles(directoryName) .ToList() .Where(x => x.Contains(".xmlinfo")) .Select(Path.GetFileName) .ToList(); if (!scenarioInfos.Any()) { await ProgressDialogService.ExecuteAsync((cancellation, progress) => UploadScenarioAsync(dialog.SelectedPath, cancellation, progress)).ConfigureAwait(false); } else if (scenarioInfos.Any(x => x == Constants.cScenarioDescriptor)) { switch (MessageBox.Show(Application.Current.MainWindow, Constants.cInsureRewriteScenario, "Сохранение сценария", MessageBoxButton.YesNo)) { case MessageBoxResult.Yes: await ProgressDialogService.ExecuteAsync(async (cancellation, progress) => await UploadScenarioAsync(dialog.SelectedPath, cancellation, progress)).ConfigureAwait(false); break; case MessageBoxResult.No: await TaskExtension.Delay(1); return; } } else { await ProgressDialogService.ExecuteAsync((cancellation, progress) => UploadScenarioAsync(dialog.SelectedPath, cancellation, progress)).ConfigureAwait(false); } } } else { MessageBox.Show(string.Format("Данный Сценарий нельзя сохранить. Проверьте правильность запонения следующих вкладок для корректного сохранения \n{0}", DataHolder.Instance.SlideDataHolders.Where(x => (x as ISaveValidator).With(valid => valid.OwnScenarioTypes.Contains(DataHolder.Instance.ScenarioProperties.ScenarioType) && !valid.IsValid)).Select(x => x.Name).EnumerableToString("{0}\n")), Constants.cScenarioEditorTitle, MessageBoxButton.OK, MessageBoxImage.Error); } } else { throw new NotImplementedException("ScenarioEditor.ViewModel.ViewModels.StartPageViewModelsSaveScenarioHandlerAsync"); } await TaskExtension.Delay(1); CommandManager.InvalidateRequerySuggested(); }