Example #1
0
        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);
            }
        }
Example #2
0
        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);
        }