From 7d5c6a1b0b29724c53aff0fb8873349d81a2adee Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 24 Jan 2018 07:46:22 +0100 Subject: [PATCH] SEBWIN-219: Changed startup procedure for runtime component in order to be able to re-configure during application execution. --- .../ClientControllerOperationTests.cs | 2 +- .../ClientControllerTests.cs | 2 +- .../Behaviour/ClientController.cs | 2 +- .../Operations/ClientControllerOperation.cs | 1 - SafeExamBrowser.Client/CompositionRoot.cs | 1 - .../IClientController.cs | 2 +- .../IRuntimeController.cs | 15 ++--- .../SafeExamBrowser.Contracts.csproj | 8 ++- .../RuntimeControllerOperationTests.cs | 56 ------------------- .../Operations/ServiceOperationTests.cs | 2 +- .../Behaviour/RuntimeControllerTests.cs | 22 ++++++++ .../SafeExamBrowser.Runtime.UnitTests.csproj | 2 +- SafeExamBrowser.Runtime/App.cs | 9 +-- .../Operations/RuntimeControllerOperation.cs | 47 ---------------- .../Behaviour/RuntimeController.cs | 53 ++++++++++++++++-- SafeExamBrowser.Runtime/CompositionRoot.cs | 10 ++-- .../SafeExamBrowser.Runtime.csproj | 1 - 17 files changed, 91 insertions(+), 144 deletions(-) rename SafeExamBrowser.Contracts/{Client => Behaviour}/IClientController.cs (92%) rename SafeExamBrowser.Contracts/{Runtime => Behaviour}/IRuntimeController.cs (54%) delete mode 100644 SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs create mode 100644 SafeExamBrowser.Runtime.UnitTests/Behaviour/RuntimeControllerTests.cs delete mode 100644 SafeExamBrowser.Runtime/Behaviour/Operations/RuntimeControllerOperation.cs diff --git a/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs index 41970c76..ebffe149 100644 --- a/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs @@ -9,7 +9,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Behaviour.Operations; -using SafeExamBrowser.Contracts.Client; +using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; diff --git a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs index 6755d3cd..dcf71857 100644 --- a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs @@ -10,7 +10,7 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Behaviour; -using SafeExamBrowser.Contracts.Client; +using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.Monitoring; using SafeExamBrowser.Contracts.UserInterface.Taskbar; diff --git a/SafeExamBrowser.Client/Behaviour/ClientController.cs b/SafeExamBrowser.Client/Behaviour/ClientController.cs index c54f430b..eda5a1c1 100644 --- a/SafeExamBrowser.Client/Behaviour/ClientController.cs +++ b/SafeExamBrowser.Client/Behaviour/ClientController.cs @@ -7,7 +7,7 @@ */ using System; -using SafeExamBrowser.Contracts.Client; +using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.Monitoring; using SafeExamBrowser.Contracts.UserInterface.Taskbar; diff --git a/SafeExamBrowser.Client/Behaviour/Operations/ClientControllerOperation.cs b/SafeExamBrowser.Client/Behaviour/Operations/ClientControllerOperation.cs index bbd34ceb..b48984cb 100644 --- a/SafeExamBrowser.Client/Behaviour/Operations/ClientControllerOperation.cs +++ b/SafeExamBrowser.Client/Behaviour/Operations/ClientControllerOperation.cs @@ -7,7 +7,6 @@ */ using SafeExamBrowser.Contracts.Behaviour; -using SafeExamBrowser.Contracts.Client; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; diff --git a/SafeExamBrowser.Client/CompositionRoot.cs b/SafeExamBrowser.Client/CompositionRoot.cs index 6ace1af4..c81d5985 100644 --- a/SafeExamBrowser.Client/CompositionRoot.cs +++ b/SafeExamBrowser.Client/CompositionRoot.cs @@ -11,7 +11,6 @@ using SafeExamBrowser.Browser; using SafeExamBrowser.Configuration; using SafeExamBrowser.Configuration.Settings; using SafeExamBrowser.Contracts.Behaviour; -using SafeExamBrowser.Contracts.Client; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; diff --git a/SafeExamBrowser.Contracts/Client/IClientController.cs b/SafeExamBrowser.Contracts/Behaviour/IClientController.cs similarity index 92% rename from SafeExamBrowser.Contracts/Client/IClientController.cs rename to SafeExamBrowser.Contracts/Behaviour/IClientController.cs index 1b828385..52efcfe9 100644 --- a/SafeExamBrowser.Contracts/Client/IClientController.cs +++ b/SafeExamBrowser.Contracts/Behaviour/IClientController.cs @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -namespace SafeExamBrowser.Contracts.Client +namespace SafeExamBrowser.Contracts.Behaviour { public interface IClientController { diff --git a/SafeExamBrowser.Contracts/Runtime/IRuntimeController.cs b/SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs similarity index 54% rename from SafeExamBrowser.Contracts/Runtime/IRuntimeController.cs rename to SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs index c6452974..675b1776 100644 --- a/SafeExamBrowser.Contracts/Runtime/IRuntimeController.cs +++ b/SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs @@ -1,23 +1,18 @@ /* * 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/. */ -namespace SafeExamBrowser.Contracts.Runtime +namespace SafeExamBrowser.Contracts.Behaviour { - public interface IRuntimeController + public interface IRuntimeController : IStartupController { /// - /// Wires up and starts the application event handling. + /// Reverts any changes performed during the startup or runtime and releases all used resources. /// - void Start(); - - /// - /// Stops the event handling and removes all event subscriptions. - /// - void Stop(); + void FinalizeApplication(); } } diff --git a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj index 3b391f27..c8f5181c 100644 --- a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj +++ b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj @@ -54,16 +54,16 @@ + - - + @@ -122,6 +122,8 @@ - + + + \ No newline at end of file diff --git a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs deleted file mode 100644 index f6db421b..00000000 --- a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using SafeExamBrowser.Contracts.Logging; -using SafeExamBrowser.Contracts.Runtime; -using SafeExamBrowser.Contracts.UserInterface; -using SafeExamBrowser.Runtime.Behaviour.Operations; - -namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations -{ - [TestClass] - public class RuntimeControllerOperationTests - { - private Mock loggerMock; - private Mock runtimeControllerMock; - private Mock splashScreenMock; - - private RuntimeControllerOperation sut; - - [TestInitialize] - public void Initialize() - { - loggerMock = new Mock(); - runtimeControllerMock = new Mock(); - splashScreenMock = new Mock(); - - sut = new RuntimeControllerOperation(runtimeControllerMock.Object, loggerMock.Object) - { - SplashScreen = splashScreenMock.Object - }; - } - - [TestMethod] - public void MustPerformCorrectly() - { - sut.Perform(); - - runtimeControllerMock.Verify(r => r.Start(), Times.Once); - } - - [TestMethod] - public void MustRevertCorrectly() - { - sut.Revert(); - - runtimeControllerMock.Verify(r => r.Stop(), Times.Once); - } - } -} diff --git a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceOperationTests.cs index 10d4df4b..499af334 100644 --- a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceOperationTests.cs +++ b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceOperationTests.cs @@ -16,7 +16,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations [TestMethod] public void Test() { - // TODO + Assert.Fail(); } } } diff --git a/SafeExamBrowser.Runtime.UnitTests/Behaviour/RuntimeControllerTests.cs b/SafeExamBrowser.Runtime.UnitTests/Behaviour/RuntimeControllerTests.cs new file mode 100644 index 00000000..91bd5b3d --- /dev/null +++ b/SafeExamBrowser.Runtime.UnitTests/Behaviour/RuntimeControllerTests.cs @@ -0,0 +1,22 @@ +/* + * 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 Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SafeExamBrowser.Runtime.UnitTests.Behaviour +{ + [TestClass] + public class RuntimeControllerTests + { + [TestMethod] + public void Test() + { + Assert.Fail(); + } + } +} diff --git a/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj b/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj index e3b1a600..2b314531 100644 --- a/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj +++ b/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj @@ -81,8 +81,8 @@ - + diff --git a/SafeExamBrowser.Runtime/App.cs b/SafeExamBrowser.Runtime/App.cs index f7118da0..b4a8d348 100644 --- a/SafeExamBrowser.Runtime/App.cs +++ b/SafeExamBrowser.Runtime/App.cs @@ -7,12 +7,9 @@ */ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; using System.Threading; using System.Windows; -using SafeExamBrowser.Contracts.Behaviour; namespace SafeExamBrowser.Runtime { @@ -62,7 +59,7 @@ namespace SafeExamBrowser.Runtime instances.BuildObjectGraph(); instances.LogStartupInformation(); - var success = instances.StartupController.TryInitializeApplication(instances.StartupOperations); + var success = instances.RuntimeController.TryInitializeApplication(instances.StartupOperations); if (success) { @@ -86,10 +83,8 @@ namespace SafeExamBrowser.Runtime private void MainWindow_Closing(object sender, CancelEventArgs e) { - var operations = new Queue(instances.StartupOperations.Reverse()); - MainWindow.Hide(); - instances.ShutdownController.FinalizeApplication(operations); + instances.RuntimeController.FinalizeApplication(); } } } diff --git a/SafeExamBrowser.Runtime/Behaviour/Operations/RuntimeControllerOperation.cs b/SafeExamBrowser.Runtime/Behaviour/Operations/RuntimeControllerOperation.cs deleted file mode 100644 index 49c80c60..00000000 --- a/SafeExamBrowser.Runtime/Behaviour/Operations/RuntimeControllerOperation.cs +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 SafeExamBrowser.Contracts.Behaviour; -using SafeExamBrowser.Contracts.I18n; -using SafeExamBrowser.Contracts.Logging; -using SafeExamBrowser.Contracts.Runtime; -using SafeExamBrowser.Contracts.UserInterface; - -namespace SafeExamBrowser.Runtime.Behaviour.Operations -{ - internal class RuntimeControllerOperation : IOperation - { - private ILogger logger; - private IRuntimeController controller; - - public bool AbortStartup { get; private set; } - public ISplashScreen SplashScreen { private get; set; } - - public RuntimeControllerOperation(IRuntimeController controller, ILogger logger) - { - this.controller = controller; - this.logger = logger; - } - - public void Perform() - { - logger.Info("Starting event handling..."); - SplashScreen.UpdateText(TextKey.SplashScreen_StartEventHandling); - - controller.Start(); - } - - public void Revert() - { - logger.Info("Stopping event handling..."); - SplashScreen.UpdateText(TextKey.SplashScreen_StopEventHandling); - - controller.Stop(); - } - } -} diff --git a/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs b/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs index c6d89845..f040316e 100644 --- a/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs +++ b/SafeExamBrowser.Runtime/Behaviour/RuntimeController.cs @@ -6,31 +6,72 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System.Collections.Generic; +using System.Linq; +using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Contracts.Communication; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.Logging; -using SafeExamBrowser.Contracts.Runtime; namespace SafeExamBrowser.Runtime.Behaviour { internal class RuntimeController : IRuntimeController { + private ICommunicationHost serviceProxy; + private Queue operations; private ILogger logger; + private ISettingsRepository settingsRepository; + private IShutdownController shutdownController; + private IStartupController startupController; public ISettings Settings { private get; set; } - public RuntimeController(ILogger logger) + public RuntimeController( + ICommunicationHost serviceProxy, + ILogger logger, + ISettingsRepository settingsRepository, + IShutdownController shutdownController, + IStartupController startupController) { + this.serviceProxy = serviceProxy; this.logger = logger; + this.settingsRepository = settingsRepository; + this.shutdownController = shutdownController; + this.startupController = startupController; + + operations = new Queue(); } - public void Start() + public bool TryInitializeApplication(Queue operations) { - // TODO + operations = new Queue(operations); + + var success = startupController.TryInitializeApplication(operations); + + if (success) + { + Start(); + } + + return success; } - public void Stop() + public void FinalizeApplication() { - // TODO + Stop(); + shutdownController.FinalizeApplication(new Queue(operations.Reverse())); + } + + private void Start() + { + logger.Info("Starting event handling..."); + // TODO SplashScreen.UpdateText(TextKey.SplashScreen_StartEventHandling); + } + + private void Stop() + { + logger.Info("Stopping event handling..."); + // TODO SplashScreen.UpdateText(TextKey.SplashScreen_StopEventHandling); } } } diff --git a/SafeExamBrowser.Runtime/CompositionRoot.cs b/SafeExamBrowser.Runtime/CompositionRoot.cs index 02ed3b77..d667158b 100644 --- a/SafeExamBrowser.Runtime/CompositionRoot.cs +++ b/SafeExamBrowser.Runtime/CompositionRoot.cs @@ -33,8 +33,7 @@ namespace SafeExamBrowser.Runtime private RuntimeInfo runtimeInfo; private ISystemInfo systemInfo; - internal IShutdownController ShutdownController { get; private set; } - internal IStartupController StartupController { get; private set; } + internal IRuntimeController RuntimeController { get; private set; } internal Queue StartupOperations { get; private set; } internal void BuildObjectGraph() @@ -52,18 +51,17 @@ namespace SafeExamBrowser.Runtime InitializeLogging(); var text = new Text(logger); - var runtimeController = new RuntimeController(new ModuleLogger(logger, typeof(RuntimeController))); var serviceProxy = new CommunicationHostProxy(new ModuleLogger(logger, typeof(CommunicationHostProxy)), "net.pipe://localhost/safeexambrowser/service"); + var shutdownController = new ShutdownController(logger, runtimeInfo, text, uiFactory); + var startupController = new StartupController(logger, runtimeInfo, systemInfo, text, uiFactory); - ShutdownController = new ShutdownController(logger, runtimeInfo, text, uiFactory); - StartupController = new StartupController(logger, runtimeInfo, systemInfo, text, uiFactory); + RuntimeController = new RuntimeController(serviceProxy, new ModuleLogger(logger, typeof(RuntimeController)), settingsRepository, shutdownController, startupController); StartupOperations = new Queue(); StartupOperations.Enqueue(new I18nOperation(logger, text)); StartupOperations.Enqueue(new ConfigurationOperation(logger, runtimeInfo, settingsRepository, text, uiFactory, args)); StartupOperations.Enqueue(new ServiceOperation(serviceProxy, logger, settingsRepository)); //StartupOperations.Enqueue(new KioskModeOperation()); - StartupOperations.Enqueue(new RuntimeControllerOperation(runtimeController, logger)); } internal void LogStartupInformation() diff --git a/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj b/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj index 2b04d1f4..8a5d9433 100644 --- a/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj +++ b/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj @@ -88,7 +88,6 @@ -