From 001c2621584b61b74f4edc0f5694096aa4faf18c Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 7 Feb 2018 13:25:49 +0100 Subject: [PATCH] SEBWIN-219: Extracted text dependency from user interface factory methods. --- .../AboutNotificationControllerTests.cs | 14 ++-- .../LogNotificationControllerTests.cs | 15 ++-- .../Behaviour/Operations/TaskbarOperation.cs | 3 +- SafeExamBrowser.Client/CompositionRoot.cs | 3 +- .../AboutNotificationController.cs | 6 +- .../LogNotificationController.cs | 6 +- .../Notifications/LogNotificationInfo.cs | 9 ++- SafeExamBrowser.Contracts/I18n/TextKey.cs | 2 + .../UserInterface/IMessageBox.cs | 7 ++ .../UserInterface/IUserInterfaceFactory.cs | 9 ++- .../Operations/OperationSequenceTests.cs | 2 +- SafeExamBrowser.Core/I18n/Text.xml | 6 ++ .../Behaviour/RuntimeController.cs | 69 +++++++++---------- SafeExamBrowser.Runtime/CompositionRoot.cs | 4 +- .../UserInterfaceFactory.cs | 20 ++++-- .../UserInterfaceFactory.cs | 20 ++++-- 16 files changed, 110 insertions(+), 85 deletions(-) diff --git a/SafeExamBrowser.Client.UnitTests/Notifications/AboutNotificationControllerTests.cs b/SafeExamBrowser.Client.UnitTests/Notifications/AboutNotificationControllerTests.cs index dac9c8bf..01573744 100644 --- a/SafeExamBrowser.Client.UnitTests/Notifications/AboutNotificationControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Notifications/AboutNotificationControllerTests.cs @@ -19,14 +19,12 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications public class AboutNotificationControllerTests { private Mock runtimeInfoMock; - private Mock textMock; private Mock uiFactoryMock; [TestInitialize] public void Initialize() { runtimeInfoMock = new Mock(); - textMock = new Mock(); uiFactoryMock = new Mock(); } @@ -35,9 +33,9 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications { var button = new NotificationButtonMock(); var window = new Mock(); - var sut = new AboutNotificationController(runtimeInfoMock.Object, textMock.Object, uiFactoryMock.Object); + var sut = new AboutNotificationController(runtimeInfoMock.Object, uiFactoryMock.Object); - uiFactoryMock.Setup(u => u.CreateAboutWindow(It.IsAny(), It.IsAny())).Returns(window.Object); + uiFactoryMock.Setup(u => u.CreateAboutWindow(It.IsAny())).Returns(window.Object); sut.RegisterNotification(button); button.Click(); sut.Terminate(); @@ -50,9 +48,9 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications { var button = new NotificationButtonMock(); var window = new Mock(); - var sut = new AboutNotificationController(runtimeInfoMock.Object, textMock.Object, uiFactoryMock.Object); + var sut = new AboutNotificationController(runtimeInfoMock.Object, uiFactoryMock.Object); - uiFactoryMock.Setup(u => u.CreateAboutWindow(It.IsAny(), It.IsAny())).Returns(window.Object); + uiFactoryMock.Setup(u => u.CreateAboutWindow(It.IsAny())).Returns(window.Object); sut.RegisterNotification(button); button.Click(); button.Click(); @@ -60,7 +58,7 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications button.Click(); button.Click(); - uiFactoryMock.Verify(u => u.CreateAboutWindow(It.IsAny(), It.IsAny()), Times.Once); + uiFactoryMock.Verify(u => u.CreateAboutWindow(It.IsAny()), Times.Once); window.Verify(u => u.Show(), Times.Once); window.Verify(u => u.BringToForeground(), Times.Exactly(4)); } @@ -69,7 +67,7 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications public void MustSubscribeToClickEvent() { var button = new NotificationButtonMock(); - var sut = new AboutNotificationController(runtimeInfoMock.Object, textMock.Object, uiFactoryMock.Object); + var sut = new AboutNotificationController(runtimeInfoMock.Object, uiFactoryMock.Object); sut.RegisterNotification(button); diff --git a/SafeExamBrowser.Client.UnitTests/Notifications/LogNotificationControllerTests.cs b/SafeExamBrowser.Client.UnitTests/Notifications/LogNotificationControllerTests.cs index c7f446b4..2559f852 100644 --- a/SafeExamBrowser.Client.UnitTests/Notifications/LogNotificationControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Notifications/LogNotificationControllerTests.cs @@ -9,7 +9,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Notifications; -using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; @@ -19,14 +18,12 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications public class LogNotificationControllerTests { private Mock loggerMock; - private Mock textMock; private Mock uiFactoryMock; [TestInitialize] public void Initialize() { loggerMock = new Mock(); - textMock = new Mock(); uiFactoryMock = new Mock(); } @@ -35,9 +32,9 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications { var button = new NotificationButtonMock(); var window = new Mock(); - var sut = new LogNotificationController(loggerMock.Object, textMock.Object, uiFactoryMock.Object); + var sut = new LogNotificationController(loggerMock.Object, uiFactoryMock.Object); - uiFactoryMock.Setup(u => u.CreateLogWindow(It.IsAny(), It.IsAny())).Returns(window.Object); + uiFactoryMock.Setup(u => u.CreateLogWindow(It.IsAny())).Returns(window.Object); sut.RegisterNotification(button); button.Click(); sut.Terminate(); @@ -50,9 +47,9 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications { var button = new NotificationButtonMock(); var window = new Mock(); - var sut = new LogNotificationController(loggerMock.Object, textMock.Object, uiFactoryMock.Object); + var sut = new LogNotificationController(loggerMock.Object, uiFactoryMock.Object); - uiFactoryMock.Setup(u => u.CreateLogWindow(It.IsAny(), It.IsAny())).Returns(window.Object); + uiFactoryMock.Setup(u => u.CreateLogWindow(It.IsAny())).Returns(window.Object); sut.RegisterNotification(button); button.Click(); button.Click(); @@ -60,7 +57,7 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications button.Click(); button.Click(); - uiFactoryMock.Verify(u => u.CreateLogWindow(It.IsAny(), It.IsAny()), Times.Once); + uiFactoryMock.Verify(u => u.CreateLogWindow(It.IsAny()), Times.Once); window.Verify(u => u.Show(), Times.Once); window.Verify(u => u.BringToForeground(), Times.Exactly(4)); } @@ -69,7 +66,7 @@ namespace SafeExamBrowser.Client.UnitTests.Notifications public void MustSubscribeToClickEvent() { var button = new NotificationButtonMock(); - var sut = new LogNotificationController(loggerMock.Object, textMock.Object, uiFactoryMock.Object); + var sut = new LogNotificationController(loggerMock.Object, uiFactoryMock.Object); sut.RegisterNotification(button); diff --git a/SafeExamBrowser.Client/Behaviour/Operations/TaskbarOperation.cs b/SafeExamBrowser.Client/Behaviour/Operations/TaskbarOperation.cs index 06cbc4ec..29d1f1a2 100644 --- a/SafeExamBrowser.Client/Behaviour/Operations/TaskbarOperation.cs +++ b/SafeExamBrowser.Client/Behaviour/Operations/TaskbarOperation.cs @@ -140,10 +140,11 @@ namespace SafeExamBrowser.Client.Behaviour.Operations private void CreateLogNotification() { + // TODO: Resolve dependencies -> CompositionRoot! var logInfo = new LogNotificationInfo(text); var logNotification = uiFactory.CreateNotification(logInfo); - logController = new LogNotificationController(logger, text, uiFactory); + logController = new LogNotificationController(logger, uiFactory); logController.RegisterNotification(logNotification); taskbar.AddNotification(logNotification); diff --git a/SafeExamBrowser.Client/CompositionRoot.cs b/SafeExamBrowser.Client/CompositionRoot.cs index 35f94a47..b654effc 100644 --- a/SafeExamBrowser.Client/CompositionRoot.cs +++ b/SafeExamBrowser.Client/CompositionRoot.cs @@ -9,7 +9,6 @@ using System.Collections.Generic; using SafeExamBrowser.Browser; using SafeExamBrowser.Configuration; -using SafeExamBrowser.Configuration.Settings; using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Behaviour.Operations; using SafeExamBrowser.Contracts.Configuration; @@ -60,11 +59,11 @@ namespace SafeExamBrowser.Client nativeMethods = new NativeMethods(); settings = new ConfigurationRepository().LoadDefaultSettings(); systemInfo = new SystemInfo(); - uiFactory = new UserInterfaceFactory(); InitializeLogging(); text = new Text(logger); + uiFactory = new UserInterfaceFactory(text); // TODO //Taskbar = new Taskbar(new ModuleLogger(logger, typeof(Taskbar))); //browserController = new BrowserApplicationController(settings.Browser, text, uiFactory); diff --git a/SafeExamBrowser.Client/Notifications/AboutNotificationController.cs b/SafeExamBrowser.Client/Notifications/AboutNotificationController.cs index 4af39041..d7795634 100644 --- a/SafeExamBrowser.Client/Notifications/AboutNotificationController.cs +++ b/SafeExamBrowser.Client/Notifications/AboutNotificationController.cs @@ -18,14 +18,12 @@ namespace SafeExamBrowser.Client.Notifications { private INotificationButton notification; private IRuntimeInfo runtimeInfo; - private IText text; private IUserInterfaceFactory uiFactory; private IWindow window; - public AboutNotificationController(IRuntimeInfo runtimeInfo, IText text, IUserInterfaceFactory uiFactory) + public AboutNotificationController(IRuntimeInfo runtimeInfo, IUserInterfaceFactory uiFactory) { this.runtimeInfo = runtimeInfo; - this.text = text; this.uiFactory = uiFactory; } @@ -45,7 +43,7 @@ namespace SafeExamBrowser.Client.Notifications { if (window == null) { - window = uiFactory.CreateAboutWindow(runtimeInfo, text); + window = uiFactory.CreateAboutWindow(runtimeInfo); window.Closing += () => window = null; window.Show(); diff --git a/SafeExamBrowser.Client/Notifications/LogNotificationController.cs b/SafeExamBrowser.Client/Notifications/LogNotificationController.cs index a77c079c..d55f7cf8 100644 --- a/SafeExamBrowser.Client/Notifications/LogNotificationController.cs +++ b/SafeExamBrowser.Client/Notifications/LogNotificationController.cs @@ -18,14 +18,12 @@ namespace SafeExamBrowser.Client.Notifications { private INotificationButton notification; private ILogger logger; - private IText text; private IUserInterfaceFactory uiFactory; private IWindow window; - public LogNotificationController(ILogger logger, IText text, IUserInterfaceFactory uiFactory) + public LogNotificationController(ILogger logger, IUserInterfaceFactory uiFactory) { this.logger = logger; - this.text = text; this.uiFactory = uiFactory; } @@ -45,7 +43,7 @@ namespace SafeExamBrowser.Client.Notifications { if (window == null) { - window = uiFactory.CreateLogWindow(logger, text); + window = uiFactory.CreateLogWindow(logger); window.Closing += () => window = null; window.Show(); diff --git a/SafeExamBrowser.Client/Notifications/LogNotificationInfo.cs b/SafeExamBrowser.Client/Notifications/LogNotificationInfo.cs index f854cd81..d35e28aa 100644 --- a/SafeExamBrowser.Client/Notifications/LogNotificationInfo.cs +++ b/SafeExamBrowser.Client/Notifications/LogNotificationInfo.cs @@ -13,14 +13,13 @@ namespace SafeExamBrowser.Client.Notifications { internal class LogNotificationInfo : INotificationInfo { - private IText text; - - public string Tooltip => text.Get(TextKey.Notification_LogTooltip); - public IIconResource IconResource { get; } = new LogNotificationIconResource(); + public string Tooltip { get; private set; } + public IIconResource IconResource { get; private set; } public LogNotificationInfo(IText text) { - this.text = text; + Tooltip = text.Get(TextKey.Notification_LogTooltip); + IconResource = new LogNotificationIconResource(); } } } diff --git a/SafeExamBrowser.Contracts/I18n/TextKey.cs b/SafeExamBrowser.Contracts/I18n/TextKey.cs index 6b4e74f5..73c09d35 100644 --- a/SafeExamBrowser.Contracts/I18n/TextKey.cs +++ b/SafeExamBrowser.Contracts/I18n/TextKey.cs @@ -17,6 +17,8 @@ namespace SafeExamBrowser.Contracts.I18n LogWindow_Title, MessageBox_ConfigureClientSuccess, MessageBox_ConfigureClientSuccessTitle, + MessageBox_SessionStartError, + MessageBox_SessionStartErrorTitle, MessageBox_ShutdownError, MessageBox_ShutdownErrorTitle, MessageBox_SingleInstance, diff --git a/SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs b/SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs index 8a6b15ac..5a932882 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs +++ b/SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs @@ -6,6 +6,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using SafeExamBrowser.Contracts.I18n; + namespace SafeExamBrowser.Contracts.UserInterface { public interface IMessageBox @@ -14,5 +16,10 @@ namespace SafeExamBrowser.Contracts.UserInterface /// Shows a message box according to the specified parameters and returns the result chosen by the user. /// MessageBoxResult Show(string message, string title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information); + + /// + /// Shows a message box according to the specified parameters and returns the result chosen by the user. + /// + MessageBoxResult Show(TextKey message, TextKey title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information); } } diff --git a/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs b/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs index c5ce81f3..b5c0f141 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs +++ b/SafeExamBrowser.Contracts/UserInterface/IUserInterfaceFactory.cs @@ -8,7 +8,6 @@ using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Configuration.Settings; -using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface.Taskbar; @@ -19,7 +18,7 @@ namespace SafeExamBrowser.Contracts.UserInterface /// /// Creates a new about window displaying information about the currently running application version. /// - IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo, IText text); + IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo); /// /// Creates a taskbar button, initialized with the given application information. @@ -34,7 +33,7 @@ namespace SafeExamBrowser.Contracts.UserInterface /// /// Creates a new log window which runs on its own thread. /// - IWindow CreateLogWindow(ILogger logger, IText text); + IWindow CreateLogWindow(ILogger logger); /// /// Creates a taskbar notification, initialized with the given notification information. @@ -55,12 +54,12 @@ namespace SafeExamBrowser.Contracts.UserInterface /// Creates a new runtime window which runs on its own thread. /// /// - IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo, IText text); + IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo); /// /// Creates a new splash screen which runs on its own thread. /// - ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo, IText text); + ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo); /// /// Creates a system control which allows to change the wireless network connection of the computer. diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/OperationSequenceTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/OperationSequenceTests.cs index e496af26..9add7677 100644 --- a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/OperationSequenceTests.cs +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/OperationSequenceTests.cs @@ -531,7 +531,7 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations var sut = new OperationSequence(loggerMock.Object, new Queue()); var indicatorMock = new Mock(); - indicatorMock.Setup(i => i.SetMaxValue(It.IsAny())).Throws(); + indicatorMock.Setup(i => i.SetIndeterminate()).Throws(); sut.ProgressIndicator = indicatorMock.Object; var success = sut.TryRevert(); diff --git a/SafeExamBrowser.Core/I18n/Text.xml b/SafeExamBrowser.Core/I18n/Text.xml index 2d553a04..c5737c30 100644 --- a/SafeExamBrowser.Core/I18n/Text.xml +++ b/SafeExamBrowser.Core/I18n/Text.xml @@ -12,6 +12,12 @@ Configuration Successful + + The application failed to start a new session. Please consult the application log for more information... + + + Session Start Error + An unexpected error occurred during the shutdown procedure! Please consult the application log for more information... diff --git a/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs b/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs index cd8374aa..e1414dd3 100644 --- a/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs +++ b/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs @@ -32,7 +32,6 @@ namespace SafeExamBrowser.Runtime.Behaviour private IServiceProxy serviceProxy; private ISplashScreen splashScreen; private Action shutdown; - private IText text; private IUserInterfaceFactory uiFactory; public RuntimeController( @@ -44,7 +43,6 @@ namespace SafeExamBrowser.Runtime.Behaviour IRuntimeInfo runtimeInfo, IServiceProxy serviceProxy, Action shutdown, - IText text, IUserInterfaceFactory uiFactory) { this.configuration = configuration; @@ -55,7 +53,6 @@ namespace SafeExamBrowser.Runtime.Behaviour this.runtimeInfo = runtimeInfo; this.serviceProxy = serviceProxy; this.shutdown = shutdown; - this.text = text; this.uiFactory = uiFactory; } @@ -63,11 +60,13 @@ namespace SafeExamBrowser.Runtime.Behaviour { logger.Info("--- Initiating startup procedure ---"); - runtimeWindow = uiFactory.CreateRuntimeWindow(runtimeInfo, text); - splashScreen = uiFactory.CreateSplashScreen(runtimeInfo, text); - splashScreen.Show(); + runtimeWindow = uiFactory.CreateRuntimeWindow(runtimeInfo); + splashScreen = uiFactory.CreateSplashScreen(runtimeInfo); bootstrapSequence.ProgressIndicator = splashScreen; + sessionSequence.ProgressIndicator = runtimeWindow; + + splashScreen.Show(); initialized = bootstrapSequence.TryPerform(); @@ -117,10 +116,12 @@ namespace SafeExamBrowser.Runtime.Behaviour if (success) { logger.Info("--- Application successfully finalized! ---"); + logger.Log(string.Empty); } else { logger.Info("--- Shutdown procedure failed! ---"); + logger.Log(string.Empty); } splashScreen?.Close(); @@ -129,44 +130,43 @@ namespace SafeExamBrowser.Runtime.Behaviour private void StartSession(bool initial = false) { logger.Info("Starting new session..."); + runtimeWindow.UpdateText(TextKey.RuntimeWindow_StartSession, true); runtimeWindow.Show(); - sessionSequence.ProgressIndicator = runtimeWindow; - - // TODO: - // - Initialize configuration - // - Initialize kiosk mode - // - Initialize session data - // - Create and connect to client - // - Initialize session with service - // - Verify session integrity and start event handling var success = initial ? sessionSequence.TryPerform() : sessionSequence.TryRepeat(); if (success) { - // TODO + // TODO: + // - Initialize session data + // - Create and connect to client + // - Initialize session with service + // - Verify session integrity and start event handling + + + + runtimeWindow.HideProgressBar(); + runtimeWindow.UpdateText(TextKey.RuntimeWindow_ApplicationRunning); + + if (configuration.CurrentSettings.KioskMode == KioskMode.DisableExplorerShell) + { + runtimeWindow.Hide(); + } } else { - // TODO + uiFactory.Show(TextKey.MessageBox_SessionStartError, TextKey.MessageBox_SessionStartErrorTitle, icon: MessageBoxIcon.Error); + + if (initial) + { + initialized = false; + } + else + { + shutdown(); + } } - - // TODO: Remove! - System.Threading.Thread.Sleep(5000); - - runtimeWindow.HideProgressBar(); - runtimeWindow.UpdateText(TextKey.RuntimeWindow_ApplicationRunning); - - if (configuration.CurrentSettings.KioskMode == KioskMode.DisableExplorerShell) - { - runtimeWindow.Hide(); - } - - // TODO: Remove! - System.Threading.Thread.Sleep(5000); - - shutdown.Invoke(); } private void StopSession() @@ -183,9 +183,6 @@ namespace SafeExamBrowser.Runtime.Behaviour // - Stop event handling and close session var success = sessionSequence.TryRevert(); - // TODO: Remove! - System.Threading.Thread.Sleep(5000); - if (success) { // TODO diff --git a/SafeExamBrowser.Runtime/CompositionRoot.cs b/SafeExamBrowser.Runtime/CompositionRoot.cs index 23319ed0..cf04ca40 100644 --- a/SafeExamBrowser.Runtime/CompositionRoot.cs +++ b/SafeExamBrowser.Runtime/CompositionRoot.cs @@ -41,7 +41,6 @@ namespace SafeExamBrowser.Runtime var sessionOperations = new Queue(); var nativeMethods = new NativeMethods(); var configuration = new ConfigurationRepository(); - var uiFactory = new UserInterfaceFactory(); logger = new Logger(); runtimeInfo = configuration.RuntimeInfo; @@ -50,6 +49,7 @@ namespace SafeExamBrowser.Runtime InitializeLogging(); var text = new Text(logger); + var uiFactory = new UserInterfaceFactory(text); var runtimeHost = new RuntimeHost(runtimeInfo.RuntimeAddress, new ModuleLogger(logger, typeof(RuntimeHost))); var serviceProxy = new ServiceProxy(runtimeInfo.ServiceAddress, new ModuleLogger(logger, typeof(ServiceProxy))); @@ -63,7 +63,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, Application.Current.Shutdown, text, uiFactory); + RuntimeController = new RuntimeController(configuration, logger, boostrapSequence, sessionSequence, runtimeHost, runtimeInfo, serviceProxy, Application.Current.Shutdown, uiFactory); } internal void LogStartupInformation() diff --git a/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs b/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs index ae3863fd..1d40e0e0 100644 --- a/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs +++ b/SafeExamBrowser.UserInterface.Classic/UserInterfaceFactory.cs @@ -22,7 +22,14 @@ namespace SafeExamBrowser.UserInterface.Classic { public class UserInterfaceFactory : IUserInterfaceFactory { - public IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo, IText text) + private IText text; + + public UserInterfaceFactory(IText text) + { + this.text = text; + } + + public IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo) { return new AboutWindow(runtimeInfo, text); } @@ -37,7 +44,7 @@ namespace SafeExamBrowser.UserInterface.Classic return new BrowserWindow(control, settings); } - public IWindow CreateLogWindow(ILogger logger, IText text) + public IWindow CreateLogWindow(ILogger logger) { LogWindow logWindow = null; var logWindowReadyEvent = new AutoResetEvent(false); @@ -77,7 +84,7 @@ namespace SafeExamBrowser.UserInterface.Classic return new PowerSupplyControl(); } - public IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo, IText text) + public IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo) { RuntimeWindow runtimeWindow = null; var windowReadyEvent = new AutoResetEvent(false); @@ -101,7 +108,7 @@ namespace SafeExamBrowser.UserInterface.Classic return runtimeWindow; } - public ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo, IText text) + public ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo) { SplashScreen splashScreen = null; var splashReadyEvent = new AutoResetEvent(false); @@ -140,6 +147,11 @@ namespace SafeExamBrowser.UserInterface.Classic 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) diff --git a/SafeExamBrowser.UserInterface.Windows10/UserInterfaceFactory.cs b/SafeExamBrowser.UserInterface.Windows10/UserInterfaceFactory.cs index ae4ceae9..dd9b58d6 100644 --- a/SafeExamBrowser.UserInterface.Windows10/UserInterfaceFactory.cs +++ b/SafeExamBrowser.UserInterface.Windows10/UserInterfaceFactory.cs @@ -21,7 +21,14 @@ namespace SafeExamBrowser.UserInterface.Windows10 { public class UserInterfaceFactory : IUserInterfaceFactory { - public IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo, IText text) + private IText text; + + public UserInterfaceFactory(IText text) + { + this.text = text; + } + + public IWindow CreateAboutWindow(IRuntimeInfo runtimeInfo) { return new AboutWindow(runtimeInfo, text); } @@ -36,7 +43,7 @@ namespace SafeExamBrowser.UserInterface.Windows10 return new BrowserWindow(control, settings); } - public IWindow CreateLogWindow(ILogger logger, IText text) + public IWindow CreateLogWindow(ILogger logger) { LogWindow logWindow = null; var logWindowReadyEvent = new AutoResetEvent(false); @@ -77,13 +84,13 @@ namespace SafeExamBrowser.UserInterface.Windows10 return new PowerSupplyControl(); } - public IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo, IText text) + public IRuntimeWindow CreateRuntimeWindow(IRuntimeInfo runtimeInfo) { // TODO throw new System.NotImplementedException(); } - public ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo, IText text) + public ISplashScreen CreateSplashScreen(IRuntimeInfo runtimeInfo) { SplashScreen splashScreen = null; var splashReadyEvent = new AutoResetEvent(false); @@ -123,6 +130,11 @@ namespace SafeExamBrowser.UserInterface.Windows10 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)