public void Restore(BitnamiRedmineStack stack, BackupConfiguration configuration, string path, IProgress <ProgressReportsModel> progress = null) { if (!Directory.Exists(path)) { throw new DirectoryNotFoundException($"{path} は存在しません。"); } var databaseName = Resources.Word_Database; var pluginName = Resources.Word_Plugin; var themeName = Resources.Word_Theme; var attachedFileName = Resources.Word_AttachedFile; var report = new ProgressReportsModel(this._DispatcherService, new[] { new ProgressItemModel { Key = databaseName, Progress = ProgressState.NotStart }, new ProgressItemModel { Key = pluginName, Progress = ProgressState.NotStart }, new ProgressItemModel { Key = themeName, Progress = ProgressState.NotStart }, new ProgressItemModel { Key = attachedFileName, Progress = ProgressState.NotStart }, }); // データベースの復元 if (configuration.Database) { report.UpdateProgress(databaseName, ProgressState.InProgress); progress?.Report(report); var databaseConfigurations = this._DatabaseConfigurationService.GetDatabaseConfiguration(stack).ToArray(); foreach (var databaseConfiguration in databaseConfigurations) { var sqlFileName = $"{databaseConfiguration.Mode}.sql"; var sqlFilePath = Path.Combine(path, sqlFileName); if (!File.Exists(sqlFilePath)) { continue; } this._DatabaseService.Restore(stack, databaseConfiguration, sqlFilePath); } report.UpdateProgress(databaseName, ProgressState.Complete); progress?.Report(report); report.AddErrorMessage(databaseName, Resources.Msg_RestoreComplete); } else { report.UpdateProgress(databaseName, ProgressState.NotRequire); report.AddErrorMessage(databaseName, Resources.Msg_RestoreSkip); this._LogService.Info("Database is skipped"); } // プラグイン、テーマ、添付ファイルの復元 var rules = new[] { new { Condition = configuration.Plugins, Target = BackupConfiguration.PluginsPath, Source = PluginsDirectoryName, CheckAction = new Action <ProgressState>(state => { report.UpdateProgress(pluginName, state); progress?.Report(report); switch (state) { case ProgressState.Complete: report.AddErrorMessage(databaseName, Resources.Msg_RestoreComplete); break; case ProgressState.NotRequire: report.AddErrorMessage(databaseName, Resources.Msg_RestoreSkip); break; case ProgressState.Failed: report.AddErrorMessage(databaseName, Resources.Msg_RestoreFailed); break; } }) }, new { Condition = configuration.Themes, Target = BackupConfiguration.ThemesePath, Source = ThemeseDirectoryName, CheckAction = new Action <ProgressState>(state => { report.UpdateProgress(themeName, state); progress?.Report(report); switch (state) { case ProgressState.Complete: report.AddErrorMessage(databaseName, Resources.Msg_RestoreComplete); break; case ProgressState.NotRequire: report.AddErrorMessage(databaseName, Resources.Msg_RestoreSkip); break; case ProgressState.Failed: report.AddErrorMessage(databaseName, Resources.Msg_RestoreFailed); break; } }) }, new { Condition = configuration.Files, Target = BackupConfiguration.FilesPath, Source = FilesDirectoryName, CheckAction = new Action <ProgressState>(state => { report.UpdateProgress(attachedFileName, state); progress?.Report(report); switch (state) { case ProgressState.Complete: report.AddErrorMessage(databaseName, Resources.Msg_RestoreComplete); break; case ProgressState.NotRequire: report.AddErrorMessage(databaseName, Resources.Msg_RestoreSkip); break; case ProgressState.Failed: report.AddErrorMessage(databaseName, Resources.Msg_RestoreFailed); break; } }) } }; foreach (var rule in rules) { if (!rule.Condition) { rule.CheckAction(ProgressState.NotRequire); continue; } var sourceDir = Path.Combine(path, rule.Source); var targetDir = Path.Combine(stack.InstallLocation, rule.Target); var condition = Directory.Exists(sourceDir); if (!condition) { rule.CheckAction(ProgressState.Failed); continue; } rule.CheckAction(ProgressState.InProgress); this.CopyDirectory(sourceDir, targetDir); rule.CheckAction(ProgressState.Complete); } }
public BackupConfiguration CheckRestoreFolder(BitnamiRedmineStack stack, string path) { var configuration = new BackupConfiguration(); // データベース var databaseConfigurations = this._DatabaseConfigurationService.GetDatabaseConfiguration(stack).ToArray(); foreach (var databaseConfiguration in databaseConfigurations) { var sqlFileName = string.Format("{0}.sql", databaseConfiguration.Mode); var sqlFilePath = Path.Combine(path, sqlFileName); if (!File.Exists(sqlFilePath)) { continue; } configuration.Database = true; break; } // プラグイン、テーマ、添付ファイル var rules = new[] { new { Target = BackupConfiguration.PluginsPath, Source = PluginsDirectoryName, CheckAction = new Action(() => { configuration.Plugins = true; }) }, new { Target = BackupConfiguration.ThemesePath, Source = ThemeseDirectoryName, CheckAction = new Action(() => { configuration.Themes = true; }) }, new { Target = BackupConfiguration.FilesPath, Source = FilesDirectoryName, CheckAction = new Action(() => { configuration.Files = true; }) } }; foreach (var rule in rules) { var sourceDir = Path.Combine(path, rule.Source); var condition = Directory.Exists(sourceDir); if (!condition) { continue; } rule.CheckAction(); } return(configuration); }