From 86a3e9ce3c5cee7f7762b106a64ce6542f98718b Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 17 Jul 2019 16:17:20 +0200 Subject: [PATCH] SEBWIN-320: Implemented restore functionality for reset utility. --- .../CompositionRoot.cs | 30 +++- SafeExamBrowser.ResetUtility/Context.cs | 7 + .../Procedure/{ShowLog.cs => Log.cs} | 4 +- .../Procedure/MainMenu.cs | 79 +--------- .../Procedure/MainMenuOption.cs | 16 ++ .../Procedure/MenuOption.cs | 21 +++ .../Procedure/ProcedureStep.cs | 79 +++++++++- .../Procedure/Reset.cs | 6 +- .../Procedure/Restore.cs | 138 +++++++++++++++++- .../Procedure/{ShowVersion.cs => Version.cs} | 4 +- .../SafeExamBrowser.ResetUtility.csproj | 6 +- 11 files changed, 297 insertions(+), 93 deletions(-) rename SafeExamBrowser.ResetUtility/Procedure/{ShowLog.cs => Log.cs} (97%) create mode 100644 SafeExamBrowser.ResetUtility/Procedure/MainMenuOption.cs create mode 100644 SafeExamBrowser.ResetUtility/Procedure/MenuOption.cs rename SafeExamBrowser.ResetUtility/Procedure/{ShowVersion.cs => Version.cs} (93%) diff --git a/SafeExamBrowser.ResetUtility/CompositionRoot.cs b/SafeExamBrowser.ResetUtility/CompositionRoot.cs index 9dd21e7d..bfdcb408 100644 --- a/SafeExamBrowser.ResetUtility/CompositionRoot.cs +++ b/SafeExamBrowser.ResetUtility/CompositionRoot.cs @@ -7,8 +7,11 @@ */ using System; +using System.Collections.Generic; using System.IO; +using SafeExamBrowser.Contracts.Lockdown; using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Lockdown; using SafeExamBrowser.Logging; using SafeExamBrowser.ResetUtility.Procedure; @@ -23,12 +26,14 @@ namespace SafeExamBrowser.ResetUtility internal void BuildObjectGraph() { + var context = new Context(); + InitializeLogging(); - var context = new Context - { - Logger = logger, - }; + context.CreateBackup = CreateBackup; + context.Logger = logger; + context.MainMenu = BuildMainMenu(context); + context.Update = new SystemConfigurationUpdate(new ModuleLogger(logger, nameof(SystemConfigurationUpdate))); InitialStep = new Initialization(context); NativeMethods = new NativeMethods(); @@ -46,6 +51,23 @@ namespace SafeExamBrowser.ResetUtility logger?.Log($"# Application terminated at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}"); } + private IList BuildMainMenu(Context context) + { + return new List + { + new MainMenuOption { IsSelected = true, NextStep = new Restore(context), Result = ProcedureStepResult.Continue, Text = "Restore system configuration via backup mechanism" }, + new MainMenuOption { NextStep = new Reset(context), Result = ProcedureStepResult.Continue, Text = "Reset system configuration to default values" }, + new MainMenuOption { NextStep = new Procedure.Version(context), Result = ProcedureStepResult.Continue, Text = "Show version information" }, + new MainMenuOption { NextStep = new Log(context), Result = ProcedureStepResult.Continue, Text = "Show application log" }, + new MainMenuOption { Result = ProcedureStepResult.Terminate, Text = "Exit" } + }; + } + + private IFeatureConfigurationBackup CreateBackup(string filePath) + { + return new FeatureConfigurationBackup(filePath, new ModuleLogger(logger, nameof(FeatureConfigurationBackup))); + } + private void InitializeLogging() { var appDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), nameof(SafeExamBrowser)); diff --git a/SafeExamBrowser.ResetUtility/Context.cs b/SafeExamBrowser.ResetUtility/Context.cs index d472de97..c18da8ce 100644 --- a/SafeExamBrowser.ResetUtility/Context.cs +++ b/SafeExamBrowser.ResetUtility/Context.cs @@ -6,12 +6,19 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; +using System.Collections.Generic; +using SafeExamBrowser.Contracts.Lockdown; using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.ResetUtility.Procedure; namespace SafeExamBrowser.ResetUtility { internal class Context { + internal Func CreateBackup { get; set; } internal ILogger Logger { get; set; } + internal IList MainMenu { get; set; } + internal ISystemConfigurationUpdate Update { get; set; } } } diff --git a/SafeExamBrowser.ResetUtility/Procedure/ShowLog.cs b/SafeExamBrowser.ResetUtility/Procedure/Log.cs similarity index 97% rename from SafeExamBrowser.ResetUtility/Procedure/ShowLog.cs rename to SafeExamBrowser.ResetUtility/Procedure/Log.cs index 1fc702c5..53431734 100644 --- a/SafeExamBrowser.ResetUtility/Procedure/ShowLog.cs +++ b/SafeExamBrowser.ResetUtility/Procedure/Log.cs @@ -12,9 +12,9 @@ using SafeExamBrowser.Contracts.Logging; namespace SafeExamBrowser.ResetUtility.Procedure { - internal class ShowLog : ProcedureStep + internal class Log : ProcedureStep { - public ShowLog(Context context) : base(context) + public Log(Context context) : base(context) { } diff --git a/SafeExamBrowser.ResetUtility/Procedure/MainMenu.cs b/SafeExamBrowser.ResetUtility/Procedure/MainMenu.cs index 7a130815..c8ea2938 100644 --- a/SafeExamBrowser.ResetUtility/Procedure/MainMenu.cs +++ b/SafeExamBrowser.ResetUtility/Procedure/MainMenu.cs @@ -6,98 +6,27 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using System; -using System.Collections.Generic; using System.Linq; namespace SafeExamBrowser.ResetUtility.Procedure { internal class MainMenu : ProcedureStep { - private IList