private async void DeleteHistoryExecute(BackupHistorySetting historySetting) { if (historySetting == null) { return; } var result = await this._DialogService.ShowMessage(MessageBoxButton.YesNo, Resources.Msg_DeleteHistory, null); if (result == MessageBoxResult.No) { return; } var item = this._ApplicationSettingService.BackupHistories.FirstOrDefault( setting => setting.OutputDirectory.Equals(historySetting.OutputDirectory)); if (item != null) { this._ApplicationSettingService.BackupHistories.Remove(item); } RedmineSetting redmineSetting; var applicationSetting = this.GetApplicationSetting(out redmineSetting); item = applicationSetting.BackupHistories.FirstOrDefault( setting => setting.OutputDirectory.Equals(historySetting.OutputDirectory)); if (item != null) { applicationSetting.BackupHistories.Remove(item); } this.UpdateRedmineSetting(applicationSetting); }
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); }