From 955ae3545e2c60f4ba24e26d1cd3cee7baf6ecc4 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Fri, 20 Dec 2019 10:03:47 +0100 Subject: [PATCH] Refactored configuration data mapping. --- .../DataMapper.ConfigurationFile.cs | 25 -- .../ConfigurationData/DataMapper.cs | 277 ++---------------- .../ApplicationDataMapper.cs} | 17 +- .../AudioDataMapper.cs} | 20 +- .../DataMapping/BaseDataMapper.cs | 19 ++ .../BrowserDataMapper.cs} | 101 ++++++- .../ConfigurationFileDataMapper.cs | 46 +++ .../GeneralDataMapper.cs} | 33 +-- .../InputDataMapper.cs} | 71 ++++- .../SecurityDataMapper.cs} | 41 ++- .../UserInterfaceDataMapper.cs} | 29 +- .../ConfigurationData/Keys.cs | 1 + .../SafeExamBrowser.Configuration.csproj | 34 +-- 13 files changed, 374 insertions(+), 340 deletions(-) delete mode 100644 SafeExamBrowser.Configuration/ConfigurationData/DataMapper.ConfigurationFile.cs rename SafeExamBrowser.Configuration/ConfigurationData/{DataMapper.Applications.cs => DataMapping/ApplicationDataMapper.cs} (91%) rename SafeExamBrowser.Configuration/ConfigurationData/{DataMapper.Audio.cs => DataMapping/AudioDataMapper.cs} (61%) create mode 100644 SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BaseDataMapper.cs rename SafeExamBrowser.Configuration/ConfigurationData/{DataMapper.Browser.cs => DataMapping/BrowserDataMapper.cs} (82%) create mode 100644 SafeExamBrowser.Configuration/ConfigurationData/DataMapping/ConfigurationFileDataMapper.cs rename SafeExamBrowser.Configuration/ConfigurationData/{DataMapper.General.cs => DataMapping/GeneralDataMapper.cs} (70%) rename SafeExamBrowser.Configuration/ConfigurationData/{DataMapper.Input.cs => DataMapping/InputDataMapper.cs} (64%) rename SafeExamBrowser.Configuration/ConfigurationData/{DataMapper.Security.cs => DataMapping/SecurityDataMapper.cs} (60%) rename SafeExamBrowser.Configuration/ConfigurationData/{DataMapper.UserInterface.cs => DataMapping/UserInterfaceDataMapper.cs} (65%) diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.ConfigurationFile.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.ConfigurationFile.cs deleted file mode 100644 index f758051b..00000000 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.ConfigurationFile.cs +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -using SafeExamBrowser.Settings; - -namespace SafeExamBrowser.Configuration.ConfigurationData -{ - internal partial class DataMapper - { - private void MapConfigurationMode(AppSettings settings, object value) - { - const int CONFIGURE_CLIENT = 1; - - if (value is int mode) - { - settings.ConfigurationMode = mode == CONFIGURE_CLIENT ? ConfigurationMode.ConfigureClient : ConfigurationMode.Exam; - } - } - } -} diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs index e17fcef3..8689a552 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs @@ -7,277 +7,38 @@ */ using System.Collections.Generic; +using SafeExamBrowser.Configuration.ConfigurationData.DataMapping; using SafeExamBrowser.Settings; namespace SafeExamBrowser.Configuration.ConfigurationData { internal partial class DataMapper { + private BaseDataMapper[] mappers = + { + new ApplicationDataMapper(), + new AudioDataMapper(), + new BrowserDataMapper(), + new ConfigurationFileDataMapper(), + new GeneralDataMapper(), + new InputDataMapper(), + new SecurityDataMapper(), + new UserInterfaceDataMapper() + }; + internal void MapRawDataToSettings(IDictionary rawData, AppSettings settings) { foreach (var item in rawData) { - MapApplicationSettings(item.Key, item.Value, settings); - MapAudioSettings(item.Key, item.Value, settings); - MapBrowserSettings(item.Key, item.Value, settings); - MapConfigurationFileSettings(item.Key, item.Value, settings); - MapGeneralSettings(item.Key, item.Value, settings); - MapKeyboardSettings(item.Key, item.Value, settings); - MapMouseSettings(item.Key, item.Value, settings); - MapSecuritySettings(item.Key, item.Value, settings); - MapUserInterfaceSettings(item.Key, item.Value, settings); + foreach (var mapper in mappers) + { + mapper.Map(item.Key, item.Value, settings); + } } - MapApplicationLogAccess(rawData, settings); - MapKioskMode(rawData, settings); - MapPopupPolicy(rawData, settings); - MapRequestFilter(rawData, settings); - MapUserAgentMode(rawData, settings); - } - - private void MapApplicationSettings(string key, object value, AppSettings settings) - { - switch (key) + foreach (var mapper in mappers) { - case Keys.Applications.Blacklist: - MapApplicationBlacklist(settings, value); - break; - case Keys.Applications.Whitelist: - MapApplicationWhitelist(settings, value); - break; - } - } - - private void MapAudioSettings(string key, object value, AppSettings settings) - { - switch (key) - { - case Keys.Audio.InitialVolumeLevel: - MapInitialVolumeLevel(settings, value); - break; - case Keys.Audio.MuteAudio: - MapMuteAudio(settings, value); - break; - case Keys.Audio.SetInitialVolumeLevel: - MapSetInitialVolumeLevel(settings, value); - break; - } - } - - private void MapBrowserSettings(string key, object value, AppSettings settings) - { - switch (key) - { - case Keys.Browser.AllowConfigurationDownloads: - MapAllowConfigurationDownloads(settings, value); - break; - case Keys.Browser.AllowDeveloperConsole: - MapAllowDeveloperConsole(settings, value); - break; - case Keys.Browser.AllowDownloads: - MapAllowDownloads(settings, value); - break; - case Keys.Browser.AllowPageZoom: - MapAllowPageZoom(settings, value); - break; - case Keys.Browser.AdditionalWindow.AllowAddressBar: - MapAllowAddressBarAdditionalWindow(settings, value); - break; - case Keys.Browser.AdditionalWindow.AllowNavigation: - MapAllowNavigationAdditionalWindow(settings, value); - break; - case Keys.Browser.AdditionalWindow.AllowReload: - MapAllowReloadAdditionalWindow(settings, value); - break; - case Keys.Browser.AdditionalWindow.ShowReloadWarning: - MapShowReloadWarningAdditionalWindow(settings, value); - break; - case Keys.Browser.AdditionalWindow.WindowHeight: - MapWindowHeightAdditionalWindow(settings, value); - break; - case Keys.Browser.AdditionalWindow.WindowPosition: - MapWindowPositionAdditionalWindow(settings, value); - break; - case Keys.Browser.AdditionalWindow.WindowWidth: - MapWindowWidthAdditionalWindow(settings, value); - break; - case Keys.Browser.Filter.FilterRules: - MapFilterRules(settings, value); - break; - case Keys.Browser.MainWindow.AllowAddressBar: - MapAllowAddressBar(settings, value); - break; - case Keys.Browser.MainWindow.AllowNavigation: - MapAllowNavigation(settings, value); - break; - case Keys.Browser.MainWindow.AllowReload: - MapAllowReload(settings, value); - break; - case Keys.Browser.MainWindow.ShowReloadWarning: - MapShowReloadWarning(settings, value); - break; - case Keys.Browser.MainWindow.WindowHeight: - MapWindowHeightMainWindow(settings, value); - break; - case Keys.Browser.MainWindow.WindowMode: - MapMainWindowMode(settings, value); - break; - case Keys.Browser.MainWindow.WindowPosition: - MapWindowPositionMainWindow(settings, value); - break; - case Keys.Browser.MainWindow.WindowWidth: - MapWindowWidthMainWindow(settings, value); - break; - case Keys.Browser.Proxy.Policy: - MapProxyPolicy(settings, value); - break; - case Keys.Browser.Proxy.Settings: - MapProxySettings(settings, value); - break; - case Keys.Browser.QuitUrl: - MapQuitUrl(settings, value); - break; - case Keys.Browser.QuitUrlConfirmation: - MapQuitUrlConfirmation(settings, value); - break; - case Keys.Browser.StartUrl: - MapStartUrl(settings, value); - break; - } - } - - private void MapConfigurationFileSettings(string key, object value, AppSettings settings) - { - switch (key) - { - case Keys.ConfigurationFile.AdminPasswordHash: - MapAdminPasswordHash(settings, value); - break; - case Keys.ConfigurationFile.ConfigurationPurpose: - MapConfigurationMode(settings, value); - break; - } - } - - private void MapGeneralSettings(string key, object value, AppSettings settings) - { - switch (key) - { - case Keys.General.LogLevel: - MapLogLevel(settings, value); - break; - } - } - - private void MapKeyboardSettings(string key, object value, AppSettings settings) - { - switch (key) - { - case Keys.Keyboard.EnableAltEsc: - MapEnableAltEsc(settings, value); - break; - case Keys.Keyboard.EnableAltF4: - MapEnableAltF4(settings, value); - break; - case Keys.Keyboard.EnableAltTab: - MapEnableAltTab(settings, value); - break; - case Keys.Keyboard.EnableCtrlEsc: - MapEnableCtrlEsc(settings, value); - break; - case Keys.Keyboard.EnableEsc: - MapEnableEsc(settings, value); - break; - case Keys.Keyboard.EnableF1: - MapEnableF1(settings, value); - break; - case Keys.Keyboard.EnableF2: - MapEnableF2(settings, value); - break; - case Keys.Keyboard.EnableF3: - MapEnableF3(settings, value); - break; - case Keys.Keyboard.EnableF4: - MapEnableF4(settings, value); - break; - case Keys.Keyboard.EnableF5: - MapEnableF5(settings, value); - break; - case Keys.Keyboard.EnableF6: - MapEnableF6(settings, value); - break; - case Keys.Keyboard.EnableF7: - MapEnableF7(settings, value); - break; - case Keys.Keyboard.EnableF8: - MapEnableF8(settings, value); - break; - case Keys.Keyboard.EnableF9: - MapEnableF9(settings, value); - break; - case Keys.Keyboard.EnableF10: - MapEnableF10(settings, value); - break; - case Keys.Keyboard.EnableF11: - MapEnableF11(settings, value); - break; - case Keys.Keyboard.EnableF12: - MapEnableF12(settings, value); - break; - case Keys.Keyboard.EnablePrintScreen: - MapEnablePrintScreen(settings, value); - break; - case Keys.Keyboard.EnableSystemKey: - MapEnableSystemKey(settings, value); - break; - } - } - - private void MapMouseSettings(string key, object value, AppSettings settings) - { - switch (key) - { - case Keys.Mouse.EnableRightMouse: - MapEnableRightMouse(settings, value); - break; - } - } - - private void MapSecuritySettings(string key, object value, AppSettings settings) - { - switch (key) - { - case Keys.Security.QuitPasswordHash: - MapQuitPasswordHash(settings, value); - break; - case Keys.Security.ServicePolicy: - MapServicePolicy(settings, value); - break; - } - } - - private void MapUserInterfaceSettings(string key, object value, AppSettings settings) - { - switch (key) - { - case Keys.UserInterface.ShowAudio: - MapAudio(settings, value); - break; - case Keys.UserInterface.ShowKeyboardLayout: - MapKeyboardLayout(settings, value); - break; - case Keys.UserInterface.ShowWirelessNetwork: - MapWirelessNetwork(settings, value); - break; - case Keys.UserInterface.ShowClock: - MapClock(settings, value); - break; - case Keys.UserInterface.UserInterfaceMode: - MapUserInterfaceMode(settings, value); - break; - case Keys.UserInterface.Taskbar.ShowApplicationLog: - MapApplicationLogButton(settings, value); - break; + mapper.MapGlobal(rawData, settings); } } } diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Applications.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/ApplicationDataMapper.cs similarity index 91% rename from SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Applications.cs rename to SafeExamBrowser.Configuration/ConfigurationData/DataMapping/ApplicationDataMapper.cs index d8497452..3e2d5beb 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Applications.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/ApplicationDataMapper.cs @@ -10,10 +10,23 @@ using System.Collections.Generic; using SafeExamBrowser.Settings; using SafeExamBrowser.Settings.Applications; -namespace SafeExamBrowser.Configuration.ConfigurationData +namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping { - internal partial class DataMapper + internal class ApplicationDataMapper : BaseDataMapper { + internal override void Map(string key, object value, AppSettings settings) + { + switch (key) + { + case Keys.Applications.Blacklist: + MapApplicationBlacklist(settings, value); + break; + case Keys.Applications.Whitelist: + MapApplicationWhitelist(settings, value); + break; + } + } + private void MapApplicationBlacklist(AppSettings settings, object value) { if (value is IList applications) diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Audio.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/AudioDataMapper.cs similarity index 61% rename from SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Audio.cs rename to SafeExamBrowser.Configuration/ConfigurationData/DataMapping/AudioDataMapper.cs index 2bebbc5d..7a8b7862 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Audio.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/AudioDataMapper.cs @@ -8,10 +8,26 @@ using SafeExamBrowser.Settings; -namespace SafeExamBrowser.Configuration.ConfigurationData +namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping { - internal partial class DataMapper + internal class AudioDataMapper : BaseDataMapper { + internal override void Map(string key, object value, AppSettings settings) + { + switch (key) + { + case Keys.Audio.InitialVolumeLevel: + MapInitialVolumeLevel(settings, value); + break; + case Keys.Audio.MuteAudio: + MapMuteAudio(settings, value); + break; + case Keys.Audio.SetInitialVolumeLevel: + MapSetInitialVolumeLevel(settings, value); + break; + } + } + private void MapInitialVolumeLevel(AppSettings settings, object value) { if (value is int volume) diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BaseDataMapper.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BaseDataMapper.cs new file mode 100644 index 00000000..ca8cb4bc --- /dev/null +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BaseDataMapper.cs @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using System.Collections.Generic; +using SafeExamBrowser.Settings; + +namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping +{ + internal abstract class BaseDataMapper + { + internal abstract void Map(string key, object value, AppSettings settings); + internal virtual void MapGlobal(IDictionary rawData, AppSettings settings) { } + } +} diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs similarity index 82% rename from SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs rename to SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs index 4fc92648..a990e586 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs @@ -13,10 +13,99 @@ using SafeExamBrowser.Settings.Browser.Filter; using SafeExamBrowser.Settings.Browser.Proxy; using SafeExamBrowser.Settings.UserInterface; -namespace SafeExamBrowser.Configuration.ConfigurationData +namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping { - internal partial class DataMapper + internal class BrowserDataMapper : BaseDataMapper { + internal override void Map(string key, object value, AppSettings settings) + { + switch (key) + { + case Keys.Browser.AllowConfigurationDownloads: + MapAllowConfigurationDownloads(settings, value); + break; + case Keys.Browser.AllowDeveloperConsole: + MapAllowDeveloperConsole(settings, value); + break; + case Keys.Browser.AllowDownloads: + MapAllowDownloads(settings, value); + break; + case Keys.Browser.AllowPageZoom: + MapAllowPageZoom(settings, value); + break; + case Keys.Browser.AdditionalWindow.AllowAddressBar: + MapAllowAddressBarAdditionalWindow(settings, value); + break; + case Keys.Browser.AdditionalWindow.AllowNavigation: + MapAllowNavigationAdditionalWindow(settings, value); + break; + case Keys.Browser.AdditionalWindow.AllowReload: + MapAllowReloadAdditionalWindow(settings, value); + break; + case Keys.Browser.AdditionalWindow.ShowReloadWarning: + MapShowReloadWarningAdditionalWindow(settings, value); + break; + case Keys.Browser.AdditionalWindow.WindowHeight: + MapWindowHeightAdditionalWindow(settings, value); + break; + case Keys.Browser.AdditionalWindow.WindowPosition: + MapWindowPositionAdditionalWindow(settings, value); + break; + case Keys.Browser.AdditionalWindow.WindowWidth: + MapWindowWidthAdditionalWindow(settings, value); + break; + case Keys.Browser.Filter.FilterRules: + MapFilterRules(settings, value); + break; + case Keys.Browser.MainWindow.AllowAddressBar: + MapAllowAddressBar(settings, value); + break; + case Keys.Browser.MainWindow.AllowNavigation: + MapAllowNavigation(settings, value); + break; + case Keys.Browser.MainWindow.AllowReload: + MapAllowReload(settings, value); + break; + case Keys.Browser.MainWindow.ShowReloadWarning: + MapShowReloadWarning(settings, value); + break; + case Keys.Browser.MainWindow.WindowHeight: + MapWindowHeightMainWindow(settings, value); + break; + case Keys.Browser.MainWindow.WindowMode: + MapMainWindowMode(settings, value); + break; + case Keys.Browser.MainWindow.WindowPosition: + MapWindowPositionMainWindow(settings, value); + break; + case Keys.Browser.MainWindow.WindowWidth: + MapWindowWidthMainWindow(settings, value); + break; + case Keys.Browser.Proxy.Policy: + MapProxyPolicy(settings, value); + break; + case Keys.Browser.Proxy.Settings: + MapProxySettings(settings, value); + break; + case Keys.Browser.QuitUrl: + MapQuitUrl(settings, value); + break; + case Keys.Browser.QuitUrlConfirmation: + MapQuitUrlConfirmation(settings, value); + break; + case Keys.Browser.StartUrl: + MapStartUrl(settings, value); + break; + } + } + + internal override void MapGlobal(IDictionary rawData, AppSettings settings) + { + MapPopupPolicy(rawData, settings); + MapRequestFilter(rawData, settings); + MapUserAgentMode(rawData, settings); + } + private void MapAllowAddressBar(AppSettings settings, object value) { if (value is bool allow) @@ -174,6 +263,14 @@ namespace SafeExamBrowser.Configuration.ConfigurationData } } + private void MapStartUrl(AppSettings settings, object value) + { + if (value is string url) + { + settings.Browser.StartUrl = url; + } + } + private void MapUserAgentMode(IDictionary rawData, AppSettings settings) { const int DEFAULT = 0; diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/ConfigurationFileDataMapper.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/ConfigurationFileDataMapper.cs new file mode 100644 index 00000000..486fe61e --- /dev/null +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/ConfigurationFileDataMapper.cs @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using SafeExamBrowser.Settings; + +namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping +{ + internal class ConfigurationFileDataMapper : BaseDataMapper + { + internal override void Map(string key, object value, AppSettings settings) + { + switch (key) + { + case Keys.ConfigurationFile.AdminPasswordHash: + MapAdminPasswordHash(settings, value); + break; + case Keys.ConfigurationFile.ConfigurationPurpose: + MapConfigurationMode(settings, value); + break; + } + } + + private void MapAdminPasswordHash(AppSettings settings, object value) + { + if (value is string hash) + { + settings.AdminPasswordHash = hash; + } + } + + private void MapConfigurationMode(AppSettings settings, object value) + { + const int CONFIGURE_CLIENT = 1; + + if (value is int mode) + { + settings.ConfigurationMode = mode == CONFIGURE_CLIENT ? ConfigurationMode.ConfigureClient : ConfigurationMode.Exam; + } + } + } +} diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.General.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/GeneralDataMapper.cs similarity index 70% rename from SafeExamBrowser.Configuration/ConfigurationData/DataMapper.General.cs rename to SafeExamBrowser.Configuration/ConfigurationData/DataMapping/GeneralDataMapper.cs index 6a3a088f..d98a2ff1 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.General.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/GeneralDataMapper.cs @@ -10,18 +10,25 @@ using System.Collections.Generic; using SafeExamBrowser.Settings; using SafeExamBrowser.Settings.Logging; -namespace SafeExamBrowser.Configuration.ConfigurationData +namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping { - internal partial class DataMapper + internal class GeneralDataMapper : BaseDataMapper { - private void MapAdminPasswordHash(AppSettings settings, object value) + internal override void Map(string key, object value, AppSettings settings) { - if (value is string hash) + switch (key) { - settings.AdminPasswordHash = hash; + case Keys.General.LogLevel: + MapLogLevel(settings, value); + break; } } + internal override void MapGlobal(IDictionary rawData, AppSettings settings) + { + MapApplicationLogAccess(rawData, settings); + } + private void MapApplicationLogAccess(IDictionary rawData, AppSettings settings) { var hasValue = rawData.TryGetValue(Keys.General.AllowApplicationLog, out var value); @@ -51,21 +58,5 @@ namespace SafeExamBrowser.Configuration.ConfigurationData settings.LogLevel = level == ERROR ? LogLevel.Error : (level == WARNING ? LogLevel.Warning : (level == INFO ? LogLevel.Info : LogLevel.Debug)); } } - - private void MapQuitPasswordHash(AppSettings settings, object value) - { - if (value is string hash) - { - settings.QuitPasswordHash = hash; - } - } - - private void MapStartUrl(AppSettings settings, object value) - { - if (value is string url) - { - settings.Browser.StartUrl = url; - } - } } } diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Input.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/InputDataMapper.cs similarity index 64% rename from SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Input.cs rename to SafeExamBrowser.Configuration/ConfigurationData/DataMapping/InputDataMapper.cs index 7b34dfe2..20b0fe2d 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Input.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/InputDataMapper.cs @@ -8,10 +8,77 @@ using SafeExamBrowser.Settings; -namespace SafeExamBrowser.Configuration.ConfigurationData +namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping { - internal partial class DataMapper + internal class InputDataMapper : BaseDataMapper { + internal override void Map(string key, object value, AppSettings settings) + { + switch (key) + { + case Keys.Keyboard.EnableAltEsc: + MapEnableAltEsc(settings, value); + break; + case Keys.Keyboard.EnableAltF4: + MapEnableAltF4(settings, value); + break; + case Keys.Keyboard.EnableAltTab: + MapEnableAltTab(settings, value); + break; + case Keys.Keyboard.EnableCtrlEsc: + MapEnableCtrlEsc(settings, value); + break; + case Keys.Keyboard.EnableEsc: + MapEnableEsc(settings, value); + break; + case Keys.Keyboard.EnableF1: + MapEnableF1(settings, value); + break; + case Keys.Keyboard.EnableF2: + MapEnableF2(settings, value); + break; + case Keys.Keyboard.EnableF3: + MapEnableF3(settings, value); + break; + case Keys.Keyboard.EnableF4: + MapEnableF4(settings, value); + break; + case Keys.Keyboard.EnableF5: + MapEnableF5(settings, value); + break; + case Keys.Keyboard.EnableF6: + MapEnableF6(settings, value); + break; + case Keys.Keyboard.EnableF7: + MapEnableF7(settings, value); + break; + case Keys.Keyboard.EnableF8: + MapEnableF8(settings, value); + break; + case Keys.Keyboard.EnableF9: + MapEnableF9(settings, value); + break; + case Keys.Keyboard.EnableF10: + MapEnableF10(settings, value); + break; + case Keys.Keyboard.EnableF11: + MapEnableF11(settings, value); + break; + case Keys.Keyboard.EnableF12: + MapEnableF12(settings, value); + break; + case Keys.Keyboard.EnablePrintScreen: + MapEnablePrintScreen(settings, value); + break; + case Keys.Keyboard.EnableSystemKey: + MapEnableSystemKey(settings, value); + break; + case Keys.Mouse.EnableRightMouse: + MapEnableRightMouse(settings, value); + break; + } + } + private void MapEnableAltEsc(AppSettings settings, object value) { if (value is bool enabled) diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Security.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/SecurityDataMapper.cs similarity index 60% rename from SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Security.cs rename to SafeExamBrowser.Configuration/ConfigurationData/DataMapping/SecurityDataMapper.cs index e27b7dd4..0e27c5ad 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Security.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/SecurityDataMapper.cs @@ -10,10 +10,31 @@ using System.Collections.Generic; using SafeExamBrowser.Settings; using SafeExamBrowser.Settings.Service; -namespace SafeExamBrowser.Configuration.ConfigurationData +namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping { - internal partial class DataMapper + internal class SecurityDataMapper : BaseDataMapper { + internal override void Map(string key, object value, AppSettings settings) + { + switch (key) + { + case Keys.Security.AllowVirtualMachine: + MapVirtualMachinePolicy(settings, value); + break; + case Keys.Security.QuitPasswordHash: + MapQuitPasswordHash(settings, value); + break; + case Keys.Security.ServicePolicy: + MapServicePolicy(settings, value); + break; + } + } + + internal override void MapGlobal(IDictionary rawData, AppSettings settings) + { + MapKioskMode(rawData, settings); + } + private void MapKioskMode(IDictionary rawData, AppSettings settings) { var hasCreateNewDesktop = rawData.TryGetValue(Keys.Security.KioskModeCreateNewDesktop, out var createNewDesktop); @@ -35,6 +56,14 @@ namespace SafeExamBrowser.Configuration.ConfigurationData } } + private void MapQuitPasswordHash(AppSettings settings, object value) + { + if (value is string hash) + { + settings.QuitPasswordHash = hash; + } + } + private void MapServicePolicy(AppSettings settings, object value) { const int WARN = 1; @@ -45,5 +74,13 @@ namespace SafeExamBrowser.Configuration.ConfigurationData settings.Service.Policy = policy == FORCE ? ServicePolicy.Mandatory : (policy == WARN ? ServicePolicy.Warn : ServicePolicy.Optional); } } + + private void MapVirtualMachinePolicy(AppSettings settings, object value) + { + if (value is bool allow) + { + // TODO NEXT: settings.Security.VirtualMachinePolicy = ; + } + } } } diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.UserInterface.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/UserInterfaceDataMapper.cs similarity index 65% rename from SafeExamBrowser.Configuration/ConfigurationData/DataMapper.UserInterface.cs rename to SafeExamBrowser.Configuration/ConfigurationData/DataMapping/UserInterfaceDataMapper.cs index 06b3741f..0cb4dd99 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.UserInterface.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/UserInterfaceDataMapper.cs @@ -9,10 +9,35 @@ using SafeExamBrowser.Settings; using SafeExamBrowser.Settings.UserInterface; -namespace SafeExamBrowser.Configuration.ConfigurationData +namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping { - internal partial class DataMapper + internal class UserInterfaceDataMapper : BaseDataMapper { + internal override void Map(string key, object value, AppSettings settings) + { + switch (key) + { + case Keys.UserInterface.ShowAudio: + MapAudio(settings, value); + break; + case Keys.UserInterface.ShowKeyboardLayout: + MapKeyboardLayout(settings, value); + break; + case Keys.UserInterface.ShowWirelessNetwork: + MapWirelessNetwork(settings, value); + break; + case Keys.UserInterface.ShowClock: + MapClock(settings, value); + break; + case Keys.UserInterface.UserInterfaceMode: + MapUserInterfaceMode(settings, value); + break; + case Keys.UserInterface.Taskbar.ShowApplicationLog: + MapApplicationLogButton(settings, value); + break; + } + } + private void MapApplicationLogButton(AppSettings settings, object value) { if (value is bool show) diff --git a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs index 7a8f6ff5..6dd3b198 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs @@ -193,6 +193,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData internal static class Security { + internal const string AllowVirtualMachine = "allowVirtualMachine"; internal const string KioskModeCreateNewDesktop = "createNewDesktop"; internal const string KioskModeDisableExplorerShell = "killExplorerShell"; internal const string QuitPasswordHash = "hashedQuitPassword"; diff --git a/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj b/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj index ee62e858..e687322d 100644 --- a/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj +++ b/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj @@ -56,6 +56,15 @@ + + + + + + + + + @@ -67,30 +76,6 @@ - - DataMapper.cs - - - DataMapper.cs - - - DataMapper.cs - - - DataMapper.cs - - - DataMapper.cs - - - DataMapper.cs - - - DataMapper.cs - - - DataMapper.cs - @@ -116,5 +101,6 @@ SafeExamBrowser.Settings + \ No newline at end of file