From 49d9b03d7ad383aa11bcb4dd04f659289e172fff Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 14 Mar 2018 12:07:20 +0100 Subject: [PATCH] SEBWIN-219: Extracted message box from UI factory and tidied up user interface contracts. --- .../BrowserApplicationController.cs | 10 ++- .../BrowserApplicationInstance.cs | 2 + SafeExamBrowser.Browser/BrowserControl.cs | 2 +- .../AboutNotificationControllerTests.cs | 2 +- .../LogNotificationControllerTests.cs | 1 + .../Behaviour/ClientController.cs | 11 ++- SafeExamBrowser.Client/CompositionRoot.cs | 7 +- .../AboutNotificationController.cs | 2 +- .../LogNotificationController.cs | 2 +- .../Configuration/IApplicationInstance.cs | 1 + .../SafeExamBrowser.Contracts.csproj | 18 ++-- .../{ => Browser}/IBrowserControl.cs | 2 +- .../{ => Browser}/IBrowserWindow.cs | 4 +- .../UserInterface/IUserInterfaceFactory.cs | 4 +- .../{ => MessageBox}/IMessageBox.cs | 2 +- .../{ => MessageBox}/MessageBoxAction.cs | 2 +- .../{ => MessageBox}/MessageBoxIcon.cs | 2 +- .../{ => MessageBox}/MessageBoxResult.cs | 2 +- .../{ => Windows}/IRuntimeWindow.cs | 2 +- .../{ => Windows}/ISplashScreen.cs | 2 +- .../UserInterface/{ => Windows}/IWindow.cs | 2 +- .../Operations/ConfigurationOperationTests.cs | 29 +++---- .../Operations/ConfigurationOperation.cs | 9 +- .../Behaviour/RuntimeController.cs | 21 +++-- SafeExamBrowser.Runtime/CompositionRoot.cs | 5 +- .../AboutWindow.xaml.cs | 2 +- .../BrowserWindow.xaml.cs | 3 +- .../LogWindow.xaml.cs | 2 +- .../MessageBox.cs | 82 +++++++++++++++++++ .../RuntimeWindow.xaml.cs | 2 +- ...feExamBrowser.UserInterface.Classic.csproj | 1 + .../SplashScreen.xaml.cs | 2 +- .../UserInterfaceFactory.cs | 61 +------------- .../AboutWindow.xaml.cs | 2 +- .../LogWindow.xaml.cs | 2 +- .../SplashScreen.xaml.cs | 2 +- .../UserInterfaceFactory.cs | 61 +------------- 37 files changed, 183 insertions(+), 185 deletions(-) rename SafeExamBrowser.Contracts/UserInterface/{ => Browser}/IBrowserControl.cs (96%) rename SafeExamBrowser.Contracts/UserInterface/{ => Browser}/IBrowserWindow.cs (93%) rename SafeExamBrowser.Contracts/UserInterface/{ => MessageBox}/IMessageBox.cs (94%) rename SafeExamBrowser.Contracts/UserInterface/{ => MessageBox}/MessageBoxAction.cs (87%) rename SafeExamBrowser.Contracts/UserInterface/{ => MessageBox}/MessageBoxIcon.cs (88%) rename SafeExamBrowser.Contracts/UserInterface/{ => MessageBox}/MessageBoxResult.cs (88%) rename SafeExamBrowser.Contracts/UserInterface/{ => Windows}/IRuntimeWindow.cs (94%) rename SafeExamBrowser.Contracts/UserInterface/{ => Windows}/ISplashScreen.cs (92%) rename SafeExamBrowser.Contracts/UserInterface/{ => Windows}/IWindow.cs (94%) create mode 100644 SafeExamBrowser.UserInterface.Classic/MessageBox.cs diff --git a/SafeExamBrowser.Browser/BrowserApplicationController.cs b/SafeExamBrowser.Browser/BrowserApplicationController.cs index e092307e..4e4325fe 100644 --- a/SafeExamBrowser.Browser/BrowserApplicationController.cs +++ b/SafeExamBrowser.Browser/BrowserApplicationController.cs @@ -18,6 +18,7 @@ using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.MessageBox; using SafeExamBrowser.Contracts.UserInterface.Taskbar; using BrowserSettings = SafeExamBrowser.Contracts.Configuration.Settings.BrowserSettings; @@ -29,6 +30,7 @@ namespace SafeExamBrowser.Browser private IList instances = new List(); private BrowserSettings settings; private ILogger logger; + private IMessageBox messageBox; private IRuntimeProxy runtime; private RuntimeInfo runtimeInfo; private IUserInterfaceFactory uiFactory; @@ -38,11 +40,13 @@ namespace SafeExamBrowser.Browser BrowserSettings settings, RuntimeInfo runtimeInfo, ILogger logger, + IMessageBox messageBox, IRuntimeProxy runtime, IText text, IUserInterfaceFactory uiFactory) { this.logger = logger; + this.messageBox = messageBox; this.runtime = runtime; this.runtimeInfo = runtimeInfo; this.settings = settings; @@ -122,7 +126,7 @@ namespace SafeExamBrowser.Browser private void Instance_ConfigurationDetected(string url, CancelEventArgs args) { - var result = uiFactory.Show(TextKey.MessageBox_ReconfigurationQuestion, TextKey.MessageBox_ReconfigurationQuestionTitle, MessageBoxAction.YesNo, MessageBoxIcon.Question); + var result = messageBox.Show(TextKey.MessageBox_ReconfigurationQuestion, TextKey.MessageBox_ReconfigurationQuestionTitle, MessageBoxAction.YesNo, MessageBoxIcon.Question); var reconfigure = result == MessageBoxResult.Yes; var allowed = false; @@ -137,13 +141,13 @@ namespace SafeExamBrowser.Browser if (!allowed) { - uiFactory.Show(TextKey.MessageBox_ReconfigurationDenied, TextKey.MessageBox_ReconfigurationDeniedTitle); + messageBox.Show(TextKey.MessageBox_ReconfigurationDenied, TextKey.MessageBox_ReconfigurationDeniedTitle); } } catch (Exception e) { logger.Error("Failed to communicate the reconfiguration request to the runtime!", e); - uiFactory.Show(TextKey.MessageBox_ReconfigurationError, TextKey.MessageBox_ReconfigurationErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_ReconfigurationError, TextKey.MessageBox_ReconfigurationErrorTitle, icon: MessageBoxIcon.Error); } } diff --git a/SafeExamBrowser.Browser/BrowserApplicationInstance.cs b/SafeExamBrowser.Browser/BrowserApplicationInstance.cs index a442945f..7a686ca9 100644 --- a/SafeExamBrowser.Browser/BrowserApplicationInstance.cs +++ b/SafeExamBrowser.Browser/BrowserApplicationInstance.cs @@ -12,6 +12,8 @@ using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Browser; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.Browser { diff --git a/SafeExamBrowser.Browser/BrowserControl.cs b/SafeExamBrowser.Browser/BrowserControl.cs index bc8233c6..37fc0153 100644 --- a/SafeExamBrowser.Browser/BrowserControl.cs +++ b/SafeExamBrowser.Browser/BrowserControl.cs @@ -10,7 +10,7 @@ using System; using CefSharp.WinForms; using SafeExamBrowser.Browser.Handlers; using SafeExamBrowser.Contracts.I18n; -using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Browser; using BrowserSettings = SafeExamBrowser.Contracts.Configuration.Settings.BrowserSettings; namespace SafeExamBrowser.Browser diff --git a/SafeExamBrowser.Client.UnitTests/Notifications/AboutNotificationControllerTests.cs b/SafeExamBrowser.Client.UnitTests/Notifications/AboutNotificationControllerTests.cs index 8020ffeb..01a6871f 100644 --- a/SafeExamBrowser.Client.UnitTests/Notifications/AboutNotificationControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Notifications/AboutNotificationControllerTests.cs @@ -10,8 +10,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Notifications; using SafeExamBrowser.Contracts.Configuration; -using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.Client.UnitTests.Notifications { diff --git a/SafeExamBrowser.Client.UnitTests/Notifications/LogNotificationControllerTests.cs b/SafeExamBrowser.Client.UnitTests/Notifications/LogNotificationControllerTests.cs index 2559f852..577a3aee 100644 --- a/SafeExamBrowser.Client.UnitTests/Notifications/LogNotificationControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Notifications/LogNotificationControllerTests.cs @@ -11,6 +11,7 @@ using Moq; using SafeExamBrowser.Client.Notifications; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.Client.UnitTests.Notifications { diff --git a/SafeExamBrowser.Client/Behaviour/ClientController.cs b/SafeExamBrowser.Client/Behaviour/ClientController.cs index a007db12..bb418bbd 100644 --- a/SafeExamBrowser.Client/Behaviour/ClientController.cs +++ b/SafeExamBrowser.Client/Behaviour/ClientController.cs @@ -16,7 +16,9 @@ using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.Monitoring; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.MessageBox; using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.Client.Behaviour { @@ -24,6 +26,7 @@ namespace SafeExamBrowser.Client.Behaviour { private IDisplayMonitor displayMonitor; private ILogger logger; + private IMessageBox messageBox; private IOperationSequence operations; private IProcessMonitor processMonitor; private IRuntimeProxy runtime; @@ -54,6 +57,7 @@ namespace SafeExamBrowser.Client.Behaviour public ClientController( IDisplayMonitor displayMonitor, ILogger logger, + IMessageBox messageBox, IOperationSequence operations, IProcessMonitor processMonitor, IRuntimeProxy runtime, @@ -64,6 +68,7 @@ namespace SafeExamBrowser.Client.Behaviour { this.displayMonitor = displayMonitor; this.logger = logger; + this.messageBox = messageBox; this.operations = operations; this.processMonitor = processMonitor; this.runtime = runtime; @@ -186,7 +191,7 @@ namespace SafeExamBrowser.Client.Behaviour private void Runtime_ConnectionLost() { logger.Error("Lost connection to the runtime!"); - uiFactory.Show(TextKey.MessageBox_ApplicationError, TextKey.MessageBox_ApplicationErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_ApplicationError, TextKey.MessageBox_ApplicationErrorTitle, icon: MessageBoxIcon.Error); taskbar.Close(); shutdown.Invoke(); @@ -194,7 +199,7 @@ namespace SafeExamBrowser.Client.Behaviour private void Taskbar_QuitButtonClicked() { - var result = uiFactory.Show(TextKey.MessageBox_Quit, TextKey.MessageBox_QuitTitle, MessageBoxAction.YesNo, MessageBoxIcon.Question); + var result = messageBox.Show(TextKey.MessageBox_Quit, TextKey.MessageBox_QuitTitle, MessageBoxAction.YesNo, MessageBoxIcon.Question); if (result == MessageBoxResult.Yes) { @@ -205,7 +210,7 @@ namespace SafeExamBrowser.Client.Behaviour catch (Exception e) { logger.Error("Failed to communicate shutdown request to the runtime!", e); - uiFactory.Show(TextKey.MessageBox_QuitError, TextKey.MessageBox_QuitErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_QuitError, TextKey.MessageBox_QuitErrorTitle, icon: MessageBoxIcon.Error); } } } diff --git a/SafeExamBrowser.Client/CompositionRoot.cs b/SafeExamBrowser.Client/CompositionRoot.cs index a93f3fad..c40522de 100644 --- a/SafeExamBrowser.Client/CompositionRoot.cs +++ b/SafeExamBrowser.Client/CompositionRoot.cs @@ -22,6 +22,7 @@ using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.MessageBox; using SafeExamBrowser.Contracts.WindowsApi; using SafeExamBrowser.Core.Behaviour.OperationModel; using SafeExamBrowser.Core.Communication; @@ -47,6 +48,7 @@ namespace SafeExamBrowser.Client private ClientConfiguration configuration; private IClientHost clientHost; private ILogger logger; + private IMessageBox messageBox; private INativeMethods nativeMethods; private IRuntimeProxy runtimeProxy; private ISystemInfo systemInfo; @@ -68,6 +70,7 @@ namespace SafeExamBrowser.Client InitializeLogging(); text = new Text(logger); + messageBox = new MessageBox(text); uiFactory = new UserInterfaceFactory(text); runtimeProxy = new RuntimeProxy(runtimeHostUri, new ModuleLogger(logger, typeof(RuntimeProxy))); @@ -96,7 +99,7 @@ namespace SafeExamBrowser.Client var sequence = new OperationSequence(logger, operations); - ClientController = new ClientController(displayMonitor, logger, sequence, processMonitor, runtimeProxy, shutdown, Taskbar, uiFactory, windowMonitor); + ClientController = new ClientController(displayMonitor, logger, messageBox, sequence, processMonitor, runtimeProxy, shutdown, Taskbar, uiFactory, windowMonitor); } internal void LogStartupInformation() @@ -145,7 +148,7 @@ namespace SafeExamBrowser.Client private IOperation BuildBrowserOperation() { var moduleLogger = new ModuleLogger(logger, typeof(BrowserApplicationController)); - var browserController = new BrowserApplicationController(configuration.Settings.Browser, configuration.RuntimeInfo, moduleLogger, runtimeProxy, text, uiFactory); + var browserController = new BrowserApplicationController(configuration.Settings.Browser, configuration.RuntimeInfo, moduleLogger, messageBox, runtimeProxy, text, uiFactory); var browserInfo = new BrowserApplicationInfo(); var operation = new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory); diff --git a/SafeExamBrowser.Client/Notifications/AboutNotificationController.cs b/SafeExamBrowser.Client/Notifications/AboutNotificationController.cs index 7523b8d5..f921701e 100644 --- a/SafeExamBrowser.Client/Notifications/AboutNotificationController.cs +++ b/SafeExamBrowser.Client/Notifications/AboutNotificationController.cs @@ -8,9 +8,9 @@ using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Configuration; -using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.UserInterface; using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.Client.Notifications { diff --git a/SafeExamBrowser.Client/Notifications/LogNotificationController.cs b/SafeExamBrowser.Client/Notifications/LogNotificationController.cs index d55f7cf8..6cc4b1a4 100644 --- a/SafeExamBrowser.Client/Notifications/LogNotificationController.cs +++ b/SafeExamBrowser.Client/Notifications/LogNotificationController.cs @@ -7,10 +7,10 @@ */ using SafeExamBrowser.Contracts.Behaviour; -using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.Client.Notifications { diff --git a/SafeExamBrowser.Contracts/Configuration/IApplicationInstance.cs b/SafeExamBrowser.Contracts/Configuration/IApplicationInstance.cs index bef8a4e8..ee8d6178 100644 --- a/SafeExamBrowser.Contracts/Configuration/IApplicationInstance.cs +++ b/SafeExamBrowser.Contracts/Configuration/IApplicationInstance.cs @@ -8,6 +8,7 @@ using System; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.Contracts.Configuration { diff --git a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj index e1e16adc..29ab4299 100644 --- a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj +++ b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj @@ -123,14 +123,14 @@ - - - + + + - - + + - + @@ -140,9 +140,9 @@ - - - + + + diff --git a/SafeExamBrowser.Contracts/UserInterface/IBrowserControl.cs b/SafeExamBrowser.Contracts/UserInterface/Browser/IBrowserControl.cs similarity index 96% rename from SafeExamBrowser.Contracts/UserInterface/IBrowserControl.cs rename to SafeExamBrowser.Contracts/UserInterface/Browser/IBrowserControl.cs index 23fae85c..c79c27ff 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IBrowserControl.cs +++ b/SafeExamBrowser.Contracts/UserInterface/Browser/IBrowserControl.cs @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -namespace SafeExamBrowser.Contracts.UserInterface +namespace SafeExamBrowser.Contracts.UserInterface.Browser { public delegate void AddressChangedEventHandler(string address); public delegate void LoadingStateChangedEventHandler(bool isLoading); diff --git a/SafeExamBrowser.Contracts/UserInterface/IBrowserWindow.cs b/SafeExamBrowser.Contracts/UserInterface/Browser/IBrowserWindow.cs similarity index 93% rename from SafeExamBrowser.Contracts/UserInterface/IBrowserWindow.cs rename to SafeExamBrowser.Contracts/UserInterface/Browser/IBrowserWindow.cs index ef9c3973..f1e29e1a 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IBrowserWindow.cs +++ b/SafeExamBrowser.Contracts/UserInterface/Browser/IBrowserWindow.cs @@ -6,7 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -namespace SafeExamBrowser.Contracts.UserInterface +using SafeExamBrowser.Contracts.UserInterface.Windows; + +namespace SafeExamBrowser.Contracts.UserInterface.Browser { public delegate void ActionRequestedEventHandler(); diff --git a/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs b/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs index 7e93efb9..16a6fe7c 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs +++ b/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs @@ -9,7 +9,9 @@ using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.UserInterface.Browser; using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.Contracts.UserInterface { @@ -18,7 +20,7 @@ namespace SafeExamBrowser.Contracts.UserInterface /// from the particular user interface framework in use, all dynamically generated user interface elements must be generated by this /// factory. /// - public interface IUserInterfaceFactory : IMessageBox + public interface IUserInterfaceFactory { /// /// Creates a new about window displaying information about the currently running application version. diff --git a/SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs b/SafeExamBrowser.Contracts/UserInterface/MessageBox/IMessageBox.cs similarity index 94% rename from SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs rename to SafeExamBrowser.Contracts/UserInterface/MessageBox/IMessageBox.cs index ed2ba72c..6103b19a 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs +++ b/SafeExamBrowser.Contracts/UserInterface/MessageBox/IMessageBox.cs @@ -8,7 +8,7 @@ using SafeExamBrowser.Contracts.I18n; -namespace SafeExamBrowser.Contracts.UserInterface +namespace SafeExamBrowser.Contracts.UserInterface.MessageBox { /// /// Defines the API for message boxes. diff --git a/SafeExamBrowser.Contracts/UserInterface/MessageBoxAction.cs b/SafeExamBrowser.Contracts/UserInterface/MessageBox/MessageBoxAction.cs similarity index 87% rename from SafeExamBrowser.Contracts/UserInterface/MessageBoxAction.cs rename to SafeExamBrowser.Contracts/UserInterface/MessageBox/MessageBoxAction.cs index 5290f1f8..92bb42ab 100644 --- a/SafeExamBrowser.Contracts/UserInterface/MessageBoxAction.cs +++ b/SafeExamBrowser.Contracts/UserInterface/MessageBox/MessageBoxAction.cs @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -namespace SafeExamBrowser.Contracts.UserInterface +namespace SafeExamBrowser.Contracts.UserInterface.MessageBox { /// /// Defines all actions available for a message box. diff --git a/SafeExamBrowser.Contracts/UserInterface/MessageBoxIcon.cs b/SafeExamBrowser.Contracts/UserInterface/MessageBox/MessageBoxIcon.cs similarity index 88% rename from SafeExamBrowser.Contracts/UserInterface/MessageBoxIcon.cs rename to SafeExamBrowser.Contracts/UserInterface/MessageBox/MessageBoxIcon.cs index 264eb834..aa5c06ff 100644 --- a/SafeExamBrowser.Contracts/UserInterface/MessageBoxIcon.cs +++ b/SafeExamBrowser.Contracts/UserInterface/MessageBox/MessageBoxIcon.cs @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -namespace SafeExamBrowser.Contracts.UserInterface +namespace SafeExamBrowser.Contracts.UserInterface.MessageBox { /// /// Defines all icons available in a message box. diff --git a/SafeExamBrowser.Contracts/UserInterface/MessageBoxResult.cs b/SafeExamBrowser.Contracts/UserInterface/MessageBox/MessageBoxResult.cs similarity index 88% rename from SafeExamBrowser.Contracts/UserInterface/MessageBoxResult.cs rename to SafeExamBrowser.Contracts/UserInterface/MessageBox/MessageBoxResult.cs index 8d90c5cf..02109395 100644 --- a/SafeExamBrowser.Contracts/UserInterface/MessageBoxResult.cs +++ b/SafeExamBrowser.Contracts/UserInterface/MessageBox/MessageBoxResult.cs @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -namespace SafeExamBrowser.Contracts.UserInterface +namespace SafeExamBrowser.Contracts.UserInterface.MessageBox { /// /// Defines all possible results of a message box. diff --git a/SafeExamBrowser.Contracts/UserInterface/IRuntimeWindow.cs b/SafeExamBrowser.Contracts/UserInterface/Windows/IRuntimeWindow.cs similarity index 94% rename from SafeExamBrowser.Contracts/UserInterface/IRuntimeWindow.cs rename to SafeExamBrowser.Contracts/UserInterface/Windows/IRuntimeWindow.cs index d8b87004..4ed09a9c 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IRuntimeWindow.cs +++ b/SafeExamBrowser.Contracts/UserInterface/Windows/IRuntimeWindow.cs @@ -8,7 +8,7 @@ using SafeExamBrowser.Contracts.Logging; -namespace SafeExamBrowser.Contracts.UserInterface +namespace SafeExamBrowser.Contracts.UserInterface.Windows { /// /// The main window of the runtime application component. It is controlled by the and serves diff --git a/SafeExamBrowser.Contracts/UserInterface/ISplashScreen.cs b/SafeExamBrowser.Contracts/UserInterface/Windows/ISplashScreen.cs similarity index 92% rename from SafeExamBrowser.Contracts/UserInterface/ISplashScreen.cs rename to SafeExamBrowser.Contracts/UserInterface/Windows/ISplashScreen.cs index 40bae391..bf62ed3c 100644 --- a/SafeExamBrowser.Contracts/UserInterface/ISplashScreen.cs +++ b/SafeExamBrowser.Contracts/UserInterface/Windows/ISplashScreen.cs @@ -8,7 +8,7 @@ using SafeExamBrowser.Contracts.Configuration; -namespace SafeExamBrowser.Contracts.UserInterface +namespace SafeExamBrowser.Contracts.UserInterface.Windows { /// /// Defines the functionality of a splash screen. diff --git a/SafeExamBrowser.Contracts/UserInterface/IWindow.cs b/SafeExamBrowser.Contracts/UserInterface/Windows/IWindow.cs similarity index 94% rename from SafeExamBrowser.Contracts/UserInterface/IWindow.cs rename to SafeExamBrowser.Contracts/UserInterface/Windows/IWindow.cs index c12f1156..9dfd8d79 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IWindow.cs +++ b/SafeExamBrowser.Contracts/UserInterface/Windows/IWindow.cs @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -namespace SafeExamBrowser.Contracts.UserInterface +namespace SafeExamBrowser.Contracts.UserInterface.Windows { public delegate void WindowClosingEventHandler(); diff --git a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs index 3e1c3bff..94f361d4 100644 --- a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs +++ b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ConfigurationOperationTests.cs @@ -16,6 +16,7 @@ using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.MessageBox; using SafeExamBrowser.Runtime.Behaviour.Operations; namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations @@ -24,22 +25,22 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations public class ConfigurationOperationTests { private Mock logger; + private Mock messageBox; private RuntimeInfo info; private Mock repository; private Settings settings; private Mock text; - private Mock uiFactory; private ConfigurationOperation sut; [TestInitialize] public void Initialize() { - logger = new Mock(); info = new RuntimeInfo(); + logger = new Mock(); + messageBox = new Mock(); repository = new Mock(); settings = new Settings(); text = new Mock(); - uiFactory = new Mock(); info.AppDataFolder = @"C:\Not\Really\AppData"; info.DefaultSettingsFileName = "SettingsDummy.txt"; @@ -53,11 +54,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations { repository.Setup(r => r.LoadDefaultSettings()); - sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); sut.Perform(); - sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, new string[] { }); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new string[] { }); sut.Perform(); @@ -69,7 +70,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations { var path = @"an/invalid\path.'*%yolo/()"; - sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, new [] { "blubb.exe", path }); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new [] { "blubb.exe", path }); sut.Perform(); } @@ -83,7 +84,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations info.ProgramDataFolder = location; info.AppDataFolder = location; - sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, new[] { "blubb.exe", path }); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, new[] { "blubb.exe", path }); sut.Perform(); @@ -98,7 +99,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations info.ProgramDataFolder = location; info.AppDataFolder = $@"{location}\WRONG"; - sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); sut.Perform(); @@ -112,7 +113,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations info.AppDataFolder = location; - sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); sut.Perform(); @@ -122,7 +123,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations [TestMethod] public void MustFallbackToDefaultsAsLastPrio() { - sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); sut.Perform(); @@ -133,9 +134,9 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations public void MustAbortIfWishedByUser() { info.ProgramDataFolder = Path.GetDirectoryName(GetType().Assembly.Location); - uiFactory.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.Yes); + messageBox.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.Yes); - sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); var result = sut.Perform(); @@ -145,9 +146,9 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations [TestMethod] public void MustNotAbortIfNotWishedByUser() { - uiFactory.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.No); + messageBox.Setup(u => u.Show(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(MessageBoxResult.No); - sut = new ConfigurationOperation(repository.Object, logger.Object, info, text.Object, uiFactory.Object, null); + sut = new ConfigurationOperation(repository.Object, logger.Object, messageBox.Object, info, text.Object, null); var result = sut.Perform(); diff --git a/SafeExamBrowser.Runtime/Behaviour/Operations/ConfigurationOperation.cs b/SafeExamBrowser.Runtime/Behaviour/Operations/ConfigurationOperation.cs index 7fe37d6e..38f7c091 100644 --- a/SafeExamBrowser.Runtime/Behaviour/Operations/ConfigurationOperation.cs +++ b/SafeExamBrowser.Runtime/Behaviour/Operations/ConfigurationOperation.cs @@ -14,6 +14,7 @@ using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.MessageBox; namespace SafeExamBrowser.Runtime.Behaviour.Operations { @@ -21,9 +22,9 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations { private IConfigurationRepository repository; private ILogger logger; + private IMessageBox messageBox; private RuntimeInfo runtimeInfo; private IText text; - private IUserInterfaceFactory uiFactory; private string[] commandLineArgs; public IProgressIndicator ProgressIndicator { private get; set; } @@ -31,17 +32,17 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations public ConfigurationOperation( IConfigurationRepository repository, ILogger logger, + IMessageBox messageBox, RuntimeInfo runtimeInfo, IText text, - IUserInterfaceFactory uiFactory, string[] commandLineArgs) { this.repository = repository; this.logger = logger; + this.messageBox = messageBox; this.commandLineArgs = commandLineArgs; this.runtimeInfo = runtimeInfo; this.text = text; - this.uiFactory = uiFactory; } public OperationResult Perform() @@ -129,7 +130,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations { var message = text.Get(TextKey.MessageBox_ClientConfigurationQuestion); var title = text.Get(TextKey.MessageBox_ClientConfigurationQuestionTitle); - var abort = uiFactory.Show(message, title, MessageBoxAction.YesNo, MessageBoxIcon.Question); + var abort = messageBox.Show(message, title, MessageBoxAction.YesNo, MessageBoxIcon.Question); return abort == MessageBoxResult.Yes; } diff --git a/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs b/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs index 63ee08e5..06ec364b 100644 --- a/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs +++ b/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs @@ -15,6 +15,8 @@ using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.MessageBox; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.Runtime.Behaviour { @@ -24,6 +26,7 @@ namespace SafeExamBrowser.Runtime.Behaviour private IConfigurationRepository configuration; private ILogger logger; + private IMessageBox messageBox; private IOperationSequence bootstrapSequence; private IOperationSequence sessionSequence; private IRuntimeHost runtimeHost; @@ -37,6 +40,7 @@ namespace SafeExamBrowser.Runtime.Behaviour public RuntimeController( IConfigurationRepository configuration, ILogger logger, + IMessageBox messageBox, IOperationSequence bootstrapSequence, IOperationSequence sessionSequence, IRuntimeHost runtimeHost, @@ -46,11 +50,12 @@ namespace SafeExamBrowser.Runtime.Behaviour IUserInterfaceFactory uiFactory) { this.configuration = configuration; - this.logger = logger; this.bootstrapSequence = bootstrapSequence; - this.sessionSequence = sessionSequence; + this.logger = logger; + this.messageBox = messageBox; this.runtimeHost = runtimeHost; this.runtimeInfo = runtimeInfo; + this.sessionSequence = sessionSequence; this.service = service; this.shutdown = shutdown; this.uiFactory = uiFactory; @@ -86,7 +91,7 @@ namespace SafeExamBrowser.Runtime.Behaviour logger.Info("--- Application startup aborted! ---"); logger.Log(string.Empty); - uiFactory.Show(TextKey.MessageBox_StartupError, TextKey.MessageBox_StartupErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_StartupError, TextKey.MessageBox_StartupErrorTitle, icon: MessageBoxIcon.Error); } return initialized && sessionRunning; @@ -121,7 +126,7 @@ namespace SafeExamBrowser.Runtime.Behaviour logger.Info("--- Shutdown procedure failed! ---"); logger.Log(string.Empty); - uiFactory.Show(TextKey.MessageBox_ShutdownError, TextKey.MessageBox_ShutdownErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_ShutdownError, TextKey.MessageBox_ShutdownErrorTitle, icon: MessageBoxIcon.Error); } splashScreen?.Close(); @@ -163,7 +168,7 @@ namespace SafeExamBrowser.Runtime.Behaviour if (result == OperationResult.Failed) { - uiFactory.Show(TextKey.MessageBox_SessionStartError, TextKey.MessageBox_SessionStartErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_SessionStartError, TextKey.MessageBox_SessionStartErrorTitle, icon: MessageBoxIcon.Error); } if (!initial) @@ -193,7 +198,7 @@ namespace SafeExamBrowser.Runtime.Behaviour else { logger.Info(">>>--- Session reversion was erroneous! ---<<<"); - uiFactory.Show(TextKey.MessageBox_SessionStopError, TextKey.MessageBox_SessionStopErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_SessionStopError, TextKey.MessageBox_SessionStopErrorTitle, icon: MessageBoxIcon.Error); } } @@ -225,7 +230,7 @@ namespace SafeExamBrowser.Runtime.Behaviour { logger.Error($"Client application has unexpectedly terminated with exit code {exitCode}!"); // TODO: Check if message box is rendered on new desktop as well -> otherwise shutdown is blocked! - uiFactory.Show(TextKey.MessageBox_ApplicationError, TextKey.MessageBox_ApplicationErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_ApplicationError, TextKey.MessageBox_ApplicationErrorTitle, icon: MessageBoxIcon.Error); shutdown.Invoke(); } @@ -234,7 +239,7 @@ namespace SafeExamBrowser.Runtime.Behaviour { logger.Error("Lost connection to the client application!"); // TODO: Check if message box is rendered on new desktop as well -> otherwise shutdown is blocked! - uiFactory.Show(TextKey.MessageBox_ApplicationError, TextKey.MessageBox_ApplicationErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_ApplicationError, TextKey.MessageBox_ApplicationErrorTitle, icon: MessageBoxIcon.Error); shutdown.Invoke(); } diff --git a/SafeExamBrowser.Runtime/CompositionRoot.cs b/SafeExamBrowser.Runtime/CompositionRoot.cs index 5887fac9..a9b9cff8 100644 --- a/SafeExamBrowser.Runtime/CompositionRoot.cs +++ b/SafeExamBrowser.Runtime/CompositionRoot.cs @@ -46,6 +46,7 @@ namespace SafeExamBrowser.Runtime InitializeLogging(); var text = new Text(logger); + var messageBox = new MessageBox(text); var uiFactory = new UserInterfaceFactory(text); var desktop = new Desktop(new ModuleLogger(logger, typeof(Desktop))); var processFactory = new ProcessFactory(desktop, new ModuleLogger(logger, typeof(ProcessFactory))); @@ -61,7 +62,7 @@ namespace SafeExamBrowser.Runtime bootstrapOperations.Enqueue(new CommunicationOperation(runtimeHost, logger)); sessionOperations.Enqueue(new SessionSequenceStartOperation(sessionController)); - sessionOperations.Enqueue(new ConfigurationOperation(configuration, logger, runtimeInfo, text, uiFactory, args)); + sessionOperations.Enqueue(new ConfigurationOperation(configuration, logger, messageBox, runtimeInfo, text, args)); sessionOperations.Enqueue(new ServiceConnectionOperation(configuration, logger, serviceProxy, text)); sessionOperations.Enqueue(new KioskModeOperation(logger, configuration)); sessionOperations.Enqueue(new SessionSequenceEndOperation(sessionController)); @@ -69,7 +70,7 @@ namespace SafeExamBrowser.Runtime var boostrapSequence = new OperationSequence(logger, bootstrapOperations); var sessionSequence = new OperationSequence(logger, sessionOperations); - RuntimeController = new RuntimeController(configuration, logger, boostrapSequence, sessionSequence, runtimeHost, runtimeInfo, serviceProxy, shutdown, uiFactory); + RuntimeController = new RuntimeController(configuration, logger, messageBox, boostrapSequence, sessionSequence, runtimeHost, runtimeInfo, serviceProxy, shutdown, uiFactory); } internal void LogStartupInformation() diff --git a/SafeExamBrowser.UserInterface.Classic/AboutWindow.xaml.cs b/SafeExamBrowser.UserInterface.Classic/AboutWindow.xaml.cs index 15cb9ad1..0a6d2f5c 100644 --- a/SafeExamBrowser.UserInterface.Classic/AboutWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Classic/AboutWindow.xaml.cs @@ -10,7 +10,7 @@ using System.Windows; using System.Windows.Documents; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.I18n; -using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.UserInterface.Classic { diff --git a/SafeExamBrowser.UserInterface.Classic/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Classic/BrowserWindow.xaml.cs index 00eaaec4..850547a8 100644 --- a/SafeExamBrowser.UserInterface.Classic/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Classic/BrowserWindow.xaml.cs @@ -10,7 +10,8 @@ using System; using System.Windows; using System.Windows.Input; using SafeExamBrowser.Contracts.Configuration.Settings; -using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Browser; +using SafeExamBrowser.Contracts.UserInterface.Windows; using SafeExamBrowser.UserInterface.Classic.Utilities; namespace SafeExamBrowser.UserInterface.Classic diff --git a/SafeExamBrowser.UserInterface.Classic/LogWindow.xaml.cs b/SafeExamBrowser.UserInterface.Classic/LogWindow.xaml.cs index 49d3f9a4..dfb781ac 100644 --- a/SafeExamBrowser.UserInterface.Classic/LogWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Classic/LogWindow.xaml.cs @@ -10,7 +10,7 @@ using System.ComponentModel; using System.Windows; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; -using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Windows; using SafeExamBrowser.UserInterface.Classic.ViewModels; namespace SafeExamBrowser.UserInterface.Classic diff --git a/SafeExamBrowser.UserInterface.Classic/MessageBox.cs b/SafeExamBrowser.UserInterface.Classic/MessageBox.cs new file mode 100644 index 00000000..ba6b9992 --- /dev/null +++ b/SafeExamBrowser.UserInterface.Classic/MessageBox.cs @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2018 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.Windows; +using SafeExamBrowser.Contracts.I18n; +using SafeExamBrowser.Contracts.UserInterface.MessageBox; +using MessageBoxResult = SafeExamBrowser.Contracts.UserInterface.MessageBox.MessageBoxResult; + +namespace SafeExamBrowser.UserInterface.Classic +{ + public class MessageBox : IMessageBox + { + private IText text; + + public MessageBox(IText text) + { + this.text = text; + } + + public MessageBoxResult Show(string message, string title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information) + { + // The last two parameters are an unfortunate necessity, since e.g. splash screens are displayed topmost while running in their + // own thread / dispatcher, and would thus conceal the message box... + var result = System.Windows.MessageBox.Show(message, title, ToButton(action), ToImage(icon), System.Windows.MessageBoxResult.None, MessageBoxOptions.ServiceNotification); + + return ToResult(result); + } + + public MessageBoxResult Show(TextKey message, TextKey title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information) + { + return Show(text.Get(message), text.Get(title), action, icon); + } + + private MessageBoxButton ToButton(MessageBoxAction action) + { + switch (action) + { + case MessageBoxAction.YesNo: + return MessageBoxButton.YesNo; + default: + return MessageBoxButton.OK; + } + } + + private MessageBoxImage ToImage(MessageBoxIcon icon) + { + switch (icon) + { + case MessageBoxIcon.Error: + return MessageBoxImage.Error; + case MessageBoxIcon.Question: + return MessageBoxImage.Question; + case MessageBoxIcon.Warning: + return MessageBoxImage.Warning; + default: + return MessageBoxImage.Information; + } + } + + private MessageBoxResult ToResult(System.Windows.MessageBoxResult result) + { + switch (result) + { + case System.Windows.MessageBoxResult.Cancel: + return MessageBoxResult.Cancel; + case System.Windows.MessageBoxResult.No: + return MessageBoxResult.No; + case System.Windows.MessageBoxResult.OK: + return MessageBoxResult.Ok; + case System.Windows.MessageBoxResult.Yes: + return MessageBoxResult.Yes; + default: + return MessageBoxResult.None; + } + } + } +} diff --git a/SafeExamBrowser.UserInterface.Classic/RuntimeWindow.xaml.cs b/SafeExamBrowser.UserInterface.Classic/RuntimeWindow.xaml.cs index 74f4c481..bd9343e6 100644 --- a/SafeExamBrowser.UserInterface.Classic/RuntimeWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Classic/RuntimeWindow.xaml.cs @@ -12,7 +12,7 @@ using System.Windows.Documents; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; -using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Windows; using SafeExamBrowser.UserInterface.Classic.ViewModels; namespace SafeExamBrowser.UserInterface.Classic diff --git a/SafeExamBrowser.UserInterface.Classic/SafeExamBrowser.UserInterface.Classic.csproj b/SafeExamBrowser.UserInterface.Classic/SafeExamBrowser.UserInterface.Classic.csproj index 677b263b..8af616a1 100644 --- a/SafeExamBrowser.UserInterface.Classic/SafeExamBrowser.UserInterface.Classic.csproj +++ b/SafeExamBrowser.UserInterface.Classic/SafeExamBrowser.UserInterface.Classic.csproj @@ -105,6 +105,7 @@ LogWindow.xaml + RuntimeWindow.xaml diff --git a/SafeExamBrowser.UserInterface.Classic/SplashScreen.xaml.cs b/SafeExamBrowser.UserInterface.Classic/SplashScreen.xaml.cs index d97542ab..25fbba24 100644 --- a/SafeExamBrowser.UserInterface.Classic/SplashScreen.xaml.cs +++ b/SafeExamBrowser.UserInterface.Classic/SplashScreen.xaml.cs @@ -10,7 +10,7 @@ using System.Windows; using System.Windows.Documents; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.I18n; -using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Windows; using SafeExamBrowser.UserInterface.Classic.ViewModels; namespace SafeExamBrowser.UserInterface.Classic diff --git a/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs b/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs index 2ae94533..5b057bbe 100644 --- a/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs +++ b/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs @@ -7,16 +7,16 @@ */ using System.Threading; -using System.Windows; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Browser; using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using SafeExamBrowser.Contracts.UserInterface.Windows; using SafeExamBrowser.UserInterface.Classic.Controls; using SafeExamBrowser.UserInterface.Classic.Utilities; -using MessageBoxResult = SafeExamBrowser.Contracts.UserInterface.MessageBoxResult; namespace SafeExamBrowser.UserInterface.Classic { @@ -137,62 +137,5 @@ namespace SafeExamBrowser.UserInterface.Classic { return new WirelessNetworkControl(); } - - public MessageBoxResult Show(string message, string title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information) - { - // The last two parameters are an unfortunate necessity, since e.g. splash screens are displayed topmost while running in their - // own thread / dispatcher, and would thus conceal the message box... - var result = MessageBox.Show(message, title, ToButton(action), ToImage(icon), System.Windows.MessageBoxResult.None, MessageBoxOptions.ServiceNotification); - - return ToResult(result); - } - - public MessageBoxResult Show(TextKey message, TextKey title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information) - { - return Show(text.Get(message), text.Get(title), action, icon); - } - - private MessageBoxButton ToButton(MessageBoxAction action) - { - switch (action) - { - case MessageBoxAction.YesNo: - return MessageBoxButton.YesNo; - default: - return MessageBoxButton.OK; - } - } - - private MessageBoxImage ToImage(MessageBoxIcon icon) - { - switch (icon) - { - case MessageBoxIcon.Error: - return MessageBoxImage.Error; - case MessageBoxIcon.Question: - return MessageBoxImage.Question; - case MessageBoxIcon.Warning: - return MessageBoxImage.Warning; - default: - return MessageBoxImage.Information; - } - } - - private MessageBoxResult ToResult(System.Windows.MessageBoxResult result) - { - switch (result) - { - case System.Windows.MessageBoxResult.Cancel: - return MessageBoxResult.Cancel; - case System.Windows.MessageBoxResult.No: - return MessageBoxResult.No; - case System.Windows.MessageBoxResult.OK: - return MessageBoxResult.Ok; - case System.Windows.MessageBoxResult.Yes: - return MessageBoxResult.Yes; - default: - return MessageBoxResult.None; - } - } } } diff --git a/SafeExamBrowser.UserInterface.Windows10/AboutWindow.xaml.cs b/SafeExamBrowser.UserInterface.Windows10/AboutWindow.xaml.cs index edce6581..235aa8bb 100644 --- a/SafeExamBrowser.UserInterface.Windows10/AboutWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Windows10/AboutWindow.xaml.cs @@ -10,7 +10,7 @@ using System.Windows; using System.Windows.Documents; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.I18n; -using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Windows; namespace SafeExamBrowser.UserInterface.Windows10 { diff --git a/SafeExamBrowser.UserInterface.Windows10/LogWindow.xaml.cs b/SafeExamBrowser.UserInterface.Windows10/LogWindow.xaml.cs index d2530f17..c8cad60d 100644 --- a/SafeExamBrowser.UserInterface.Windows10/LogWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Windows10/LogWindow.xaml.cs @@ -10,7 +10,7 @@ using System.ComponentModel; using System.Windows; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; -using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Windows; using SafeExamBrowser.UserInterface.Windows10.ViewModels; namespace SafeExamBrowser.UserInterface.Windows10 diff --git a/SafeExamBrowser.UserInterface.Windows10/SplashScreen.xaml.cs b/SafeExamBrowser.UserInterface.Windows10/SplashScreen.xaml.cs index 865e797c..aa57e34d 100644 --- a/SafeExamBrowser.UserInterface.Windows10/SplashScreen.xaml.cs +++ b/SafeExamBrowser.UserInterface.Windows10/SplashScreen.xaml.cs @@ -10,7 +10,7 @@ using System.Windows; using System.Windows.Documents; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.I18n; -using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Windows; using SafeExamBrowser.UserInterface.Windows10.ViewModels; namespace SafeExamBrowser.UserInterface.Windows10 diff --git a/SafeExamBrowser.UserInterface.Windows10/UserInterfaceFactory.cs b/SafeExamBrowser.UserInterface.Windows10/UserInterfaceFactory.cs index 3933934e..7db00aeb 100644 --- a/SafeExamBrowser.UserInterface.Windows10/UserInterfaceFactory.cs +++ b/SafeExamBrowser.UserInterface.Windows10/UserInterfaceFactory.cs @@ -7,15 +7,15 @@ */ using System.Threading; -using System.Windows; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Browser; using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using SafeExamBrowser.Contracts.UserInterface.Windows; using SafeExamBrowser.UserInterface.Windows10.Controls; -using MessageBoxResult = SafeExamBrowser.Contracts.UserInterface.MessageBoxResult; namespace SafeExamBrowser.UserInterface.Windows10 { @@ -122,62 +122,5 @@ namespace SafeExamBrowser.UserInterface.Windows10 // TODO throw new System.NotImplementedException(); } - - public MessageBoxResult Show(string message, string title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information) - { - // The last two parameters are an unfortunate necessity, since e.g. splash screens are displayed topmost while running in their - // own thread / dispatcher, and would thus conceal the message box... - var result = MessageBox.Show(message, title, ToButton(action), ToImage(icon), System.Windows.MessageBoxResult.None, MessageBoxOptions.ServiceNotification); - - return ToResult(result); - } - - public MessageBoxResult Show(TextKey message, TextKey title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information) - { - return Show(text.Get(message), text.Get(title), action, icon); - } - - private MessageBoxButton ToButton(MessageBoxAction action) - { - switch (action) - { - case MessageBoxAction.YesNo: - return MessageBoxButton.YesNo; - default: - return MessageBoxButton.OK; - } - } - - private MessageBoxImage ToImage(MessageBoxIcon icon) - { - switch (icon) - { - case MessageBoxIcon.Error: - return MessageBoxImage.Error; - case MessageBoxIcon.Question: - return MessageBoxImage.Question; - case MessageBoxIcon.Warning: - return MessageBoxImage.Warning; - default: - return MessageBoxImage.Information; - } - } - - private MessageBoxResult ToResult(System.Windows.MessageBoxResult result) - { - switch (result) - { - case System.Windows.MessageBoxResult.Cancel: - return MessageBoxResult.Cancel; - case System.Windows.MessageBoxResult.No: - return MessageBoxResult.No; - case System.Windows.MessageBoxResult.OK: - return MessageBoxResult.Ok; - case System.Windows.MessageBoxResult.Yes: - return MessageBoxResult.Yes; - default: - return MessageBoxResult.None; - } - } } }