From 10202a807f167efefb7f4b79e50024ddfe480942 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Mon, 12 Feb 2018 12:21:55 +0100 Subject: [PATCH] SEBWIN-219: Adapted startup procedure for client component by introducing the DelayedInitializationOperation. --- .../ClientControllerOperationTests.cs | 50 ------ .../ClientControllerTests.cs | 19 +- .../SafeExamBrowser.Client.UnitTests.csproj | 1 - SafeExamBrowser.Client/App.cs | 31 ++-- .../Behaviour/ClientController.cs | 22 ++- .../Operations/ClientControllerOperation.cs | 52 ------ .../Operations/ConfigurationOperation.cs | 66 +++++++ .../Operations/RuntimeConnectionOperation.cs | 81 +++++++++ .../Communication/ClientHost.cs | 42 +++++ SafeExamBrowser.Client/CompositionRoot.cs | 162 ++++++++++++------ .../SafeExamBrowser.Client.csproj | 4 +- .../ClientConfiguration.cs | 22 +++ .../ConfigurationRepository.cs | 10 ++ .../SafeExamBrowser.Configuration.csproj | 1 + .../Behaviour/IClientController.cs | 9 +- .../Behaviour/IRuntimeController.cs | 1 + .../Communication/IClientHost.cs | 15 ++ .../Communication/IRuntimeHost.cs | 2 +- .../Communication/IRuntimeProxy.cs | 14 ++ .../Configuration/IClientConfiguration.cs | 30 ++++ .../Configuration/IConfigurationRepository.cs | 5 + SafeExamBrowser.Contracts/I18n/TextKey.cs | 2 + .../SafeExamBrowser.Contracts.csproj | 2 + .../DelayedInitializationOperationTests.cs | 22 +++ .../SafeExamBrowser.Core.UnitTests.csproj | 1 + .../DelayedInitializationOperation.cs | 51 ++++++ .../Communication/RuntimeProxy.cs | 41 +++++ SafeExamBrowser.Core/I18n/Text.xml | 6 + .../SafeExamBrowser.Core.csproj | 2 + ....cs => ServiceConnectionOperationTests.cs} | 6 +- .../SafeExamBrowser.Runtime.UnitTests.csproj | 2 +- ...ation.cs => ServiceConnectionOperation.cs} | 23 ++- .../Operations/SessionSequenceOperation.cs | 8 +- SafeExamBrowser.Runtime/CompositionRoot.cs | 2 +- .../SafeExamBrowser.Runtime.csproj | 2 +- 35 files changed, 591 insertions(+), 218 deletions(-) delete mode 100644 SafeExamBrowser.Client.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs delete mode 100644 SafeExamBrowser.Client/Behaviour/Operations/ClientControllerOperation.cs create mode 100644 SafeExamBrowser.Client/Behaviour/Operations/ConfigurationOperation.cs create mode 100644 SafeExamBrowser.Client/Behaviour/Operations/RuntimeConnectionOperation.cs create mode 100644 SafeExamBrowser.Client/Communication/ClientHost.cs create mode 100644 SafeExamBrowser.Configuration/ClientConfiguration.cs create mode 100644 SafeExamBrowser.Contracts/Communication/IClientHost.cs create mode 100644 SafeExamBrowser.Contracts/Configuration/IClientConfiguration.cs create mode 100644 SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DelayedInitializationOperationTests.cs create mode 100644 SafeExamBrowser.Core/Behaviour/Operations/DelayedInitializationOperation.cs create mode 100644 SafeExamBrowser.Core/Communication/RuntimeProxy.cs rename SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/{ServiceOperationTests.cs => ServiceConnectionOperationTests.cs} (96%) rename SafeExamBrowser.Runtime/Behaviour/Operations/{ServiceOperation.cs => ServiceConnectionOperation.cs} (72%) diff --git a/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs deleted file mode 100644 index 862b79d8..00000000 --- a/SafeExamBrowser.Client.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs +++ /dev/null @@ -1,50 +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.Client.Behaviour.Operations; -using SafeExamBrowser.Contracts.Behaviour; -using SafeExamBrowser.Contracts.Logging; - -namespace SafeExamBrowser.Client.UnitTests.Behaviour.Operations -{ - [TestClass] - public class ClientControllerOperationTests - { - private Mock loggerMock; - private Mock clientControllerMock; - - private ClientControllerOperation sut; - - [TestInitialize] - public void Initialize() - { - loggerMock = new Mock(); - clientControllerMock = new Mock(); - - sut = new ClientControllerOperation(clientControllerMock.Object, loggerMock.Object); - } - - [TestMethod] - public void MustPerformCorrectly() - { - sut.Perform(); - - clientControllerMock.Verify(r => r.Start(), Times.Once); - } - - [TestMethod] - public void MustRevertCorrectly() - { - sut.Revert(); - - clientControllerMock.Verify(r => r.Stop(), Times.Once); - } - } -} diff --git a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs index dcf71857..94f5fe32 100644 --- a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs @@ -9,7 +9,6 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using SafeExamBrowser.Client.Behaviour; using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.Monitoring; @@ -37,14 +36,16 @@ namespace SafeExamBrowser.Client.UnitTests taskbarMock = new Mock(); windowMonitorMock= new Mock(); - sut = new ClientController( - displayMonitorMock.Object, - loggerMock.Object, - processMonitorMock.Object, - taskbarMock.Object, - windowMonitorMock.Object); + // TODO - sut.Start(); + //sut = new ClientController( + // displayMonitorMock.Object, + // loggerMock.Object, + // processMonitorMock.Object, + // taskbarMock.Object, + // windowMonitorMock.Object); + + // sut.Start(); } [TestMethod] @@ -151,7 +152,7 @@ namespace SafeExamBrowser.Client.UnitTests [TestCleanup] public void Cleanup() { - sut.Stop(); + // TODO sut.Stop(); } } } diff --git a/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj b/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj index e3aa1723..1d8d954f 100644 --- a/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj +++ b/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj @@ -79,7 +79,6 @@ - diff --git a/SafeExamBrowser.Client/App.cs b/SafeExamBrowser.Client/App.cs index 6addc121..c4cf75e4 100644 --- a/SafeExamBrowser.Client/App.cs +++ b/SafeExamBrowser.Client/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.Operations; namespace SafeExamBrowser.Client { @@ -61,26 +58,24 @@ namespace SafeExamBrowser.Client instances.BuildObjectGraph(); - //var success = instances.StartupController.TryInitializeApplication(instances.StartupOperations); + var success = instances.ClientController.TryStart(); - //if (success) - //{ - // MainWindow = instances.Taskbar; - // MainWindow.Closing += MainWindow_Closing; - // MainWindow.Show(); - //} - //else - //{ - // Shutdown(); - //} + if (success) + { + MainWindow = instances.Taskbar; + MainWindow.Closing += MainWindow_Closing; + MainWindow.Show(); + } + else + { + Shutdown(); + } } private void MainWindow_Closing(object sender, CancelEventArgs e) { - var operations = new Queue(instances.StartupOperations.Reverse()); - - MainWindow.Hide(); - //instances.ShutdownController.FinalizeApplication(operations); + MainWindow?.Hide(); + instances.ClientController.Terminate(); } } } diff --git a/SafeExamBrowser.Client/Behaviour/ClientController.cs b/SafeExamBrowser.Client/Behaviour/ClientController.cs index eda5a1c1..73f6d78d 100644 --- a/SafeExamBrowser.Client/Behaviour/ClientController.cs +++ b/SafeExamBrowser.Client/Behaviour/ClientController.cs @@ -8,6 +8,7 @@ using System; using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Contracts.Behaviour.Operations; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.Monitoring; using SafeExamBrowser.Contracts.UserInterface.Taskbar; @@ -18,6 +19,7 @@ namespace SafeExamBrowser.Client.Behaviour { private IDisplayMonitor displayMonitor; private ILogger logger; + private IOperationSequence operations; private IProcessMonitor processMonitor; private ITaskbar taskbar; private IWindowMonitor windowMonitor; @@ -25,31 +27,35 @@ namespace SafeExamBrowser.Client.Behaviour public ClientController( IDisplayMonitor displayMonitor, ILogger logger, + IOperationSequence operations, IProcessMonitor processMonitor, ITaskbar taskbar, IWindowMonitor windowMonitor) { this.displayMonitor = displayMonitor; this.logger = logger; + this.operations = operations; this.processMonitor = processMonitor; this.taskbar = taskbar; this.windowMonitor = windowMonitor; } - public void Start() - { - displayMonitor.DisplayChanged += DisplayMonitor_DisplaySettingsChanged; - processMonitor.ExplorerStarted += ProcessMonitor_ExplorerStarted; - windowMonitor.WindowChanged += WindowMonitor_WindowChanged; - } - - public void Stop() + public void Terminate() { displayMonitor.DisplayChanged -= DisplayMonitor_DisplaySettingsChanged; processMonitor.ExplorerStarted -= ProcessMonitor_ExplorerStarted; windowMonitor.WindowChanged -= WindowMonitor_WindowChanged; } + public bool TryStart() + { + displayMonitor.DisplayChanged += DisplayMonitor_DisplaySettingsChanged; + processMonitor.ExplorerStarted += ProcessMonitor_ExplorerStarted; + windowMonitor.WindowChanged += WindowMonitor_WindowChanged; + + return true; + } + private void DisplayMonitor_DisplaySettingsChanged() { logger.Info("Reinitializing working area..."); diff --git a/SafeExamBrowser.Client/Behaviour/Operations/ClientControllerOperation.cs b/SafeExamBrowser.Client/Behaviour/Operations/ClientControllerOperation.cs deleted file mode 100644 index a6d223b2..00000000 --- a/SafeExamBrowser.Client/Behaviour/Operations/ClientControllerOperation.cs +++ /dev/null @@ -1,52 +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.Behaviour.Operations; -using SafeExamBrowser.Contracts.I18n; -using SafeExamBrowser.Contracts.Logging; -using SafeExamBrowser.Contracts.UserInterface; - -namespace SafeExamBrowser.Client.Behaviour.Operations -{ - internal class ClientControllerOperation : IOperation - { - private ILogger logger; - private IClientController controller; - - public bool Abort { get; private set; } - public IProgressIndicator ProgressIndicator { private get; set; } - - public ClientControllerOperation(IClientController controller, ILogger logger) - { - this.controller = controller; - this.logger = logger; - } - - public void Perform() - { - logger.Info("Starting event handling..."); - ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_StartEventHandling); - - controller.Start(); - } - - public void Repeat() - { - // Nothing to do here... - } - - public void Revert() - { - logger.Info("Stopping event handling..."); - ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_StopEventHandling); - - controller.Stop(); - } - } -} diff --git a/SafeExamBrowser.Client/Behaviour/Operations/ConfigurationOperation.cs b/SafeExamBrowser.Client/Behaviour/Operations/ConfigurationOperation.cs new file mode 100644 index 00000000..886df7c0 --- /dev/null +++ b/SafeExamBrowser.Client/Behaviour/Operations/ConfigurationOperation.cs @@ -0,0 +1,66 @@ +/* + * 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; +using SafeExamBrowser.Contracts.Behaviour.Operations; +using SafeExamBrowser.Contracts.Communication; +using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.I18n; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.UserInterface; + +namespace SafeExamBrowser.Client.Behaviour.Operations +{ + internal class ConfigurationOperation : IOperation + { + private IClientConfiguration configuration; + private ILogger logger; + private IRuntimeProxy runtime; + + public bool Abort { get; private set; } + public IProgressIndicator ProgressIndicator { private get; set; } + + public ConfigurationOperation(IClientConfiguration configuration, ILogger logger, IRuntimeProxy runtime) + { + this.configuration = configuration; + this.logger = logger; + this.runtime = runtime; + } + + public void Perform() + { + logger.Info("Initializing application configuration..."); + ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_InitializeConfiguration); + + try + { + var config = runtime.GetConfiguration(); + + configuration.RuntimeInfo = config.RuntimeInfo; + configuration.SessionData = config.SessionData; + configuration.Settings = config.Settings; + + logger.Info("Successfully retrieved the application configuration from the runtime."); + } + catch (Exception e) + { + logger.Error("An unexpected error occurred while trying to retrieve the application configuration!", e); + } + } + + public void Repeat() + { + // Nothing to do here... + } + + public void Revert() + { + // Nothing to do here... + } + } +} diff --git a/SafeExamBrowser.Client/Behaviour/Operations/RuntimeConnectionOperation.cs b/SafeExamBrowser.Client/Behaviour/Operations/RuntimeConnectionOperation.cs new file mode 100644 index 00000000..37904411 --- /dev/null +++ b/SafeExamBrowser.Client/Behaviour/Operations/RuntimeConnectionOperation.cs @@ -0,0 +1,81 @@ +/* + * 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; +using SafeExamBrowser.Contracts.Behaviour.Operations; +using SafeExamBrowser.Contracts.Communication; +using SafeExamBrowser.Contracts.I18n; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.UserInterface; + +namespace SafeExamBrowser.Client.Behaviour.Operations +{ + internal class RuntimeConnectionOperation : IOperation + { + private bool connected; + private ILogger logger; + private IRuntimeProxy runtime; + private Guid token; + + public bool Abort { get; private set; } + public IProgressIndicator ProgressIndicator { private get; set; } + + public RuntimeConnectionOperation(ILogger logger, IRuntimeProxy runtime, Guid token) + { + this.logger = logger; + this.runtime = runtime; + this.token = token; + } + + public void Perform() + { + logger.Info("Initializing runtime connection..."); + ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_InitializeRuntimeConnection); + + try + { + connected = runtime.Connect(token); + + logger.Info("Successfully connected to the runtime host."); + } + catch (Exception e) + { + logger.Error("An unexpected error occurred while trying to connect to the runtime host!", e); + } + + if (!connected) + { + Abort = true; + logger.Info("Failed to connect to the runtime. Aborting startup..."); + } + } + + public void Repeat() + { + // Nothing to do here... + } + + public void Revert() + { + logger.Info("Closing runtime connection..."); + ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_CloseRuntimeConnection); + + if (connected) + { + try + { + runtime.Disconnect(); + } + catch (Exception e) + { + logger.Error("Failed to disconnect from runtime host!", e); + } + } + } + } +} diff --git a/SafeExamBrowser.Client/Communication/ClientHost.cs b/SafeExamBrowser.Client/Communication/ClientHost.cs new file mode 100644 index 00000000..0db76b9d --- /dev/null +++ b/SafeExamBrowser.Client/Communication/ClientHost.cs @@ -0,0 +1,42 @@ +/* + * 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; +using SafeExamBrowser.Contracts.Communication; +using SafeExamBrowser.Contracts.Communication.Messages; +using SafeExamBrowser.Contracts.Communication.Responses; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Core.Communication; + +namespace SafeExamBrowser.Client.Communication +{ + internal class ClientHost : BaseHost, IClientHost + { + public ClientHost(string address, ILogger logger) : base(address, logger) + { + } + + protected override IConnectResponse OnConnect(Guid? token) + { + // TODO + throw new NotImplementedException(); + } + + protected override void OnDisconnect(IMessage message) + { + // TODO + throw new NotImplementedException(); + } + + protected override IResponse OnReceive(IMessage message) + { + // TODO + throw new NotImplementedException(); + } + } +} diff --git a/SafeExamBrowser.Client/CompositionRoot.cs b/SafeExamBrowser.Client/CompositionRoot.cs index b654effc..5cb033f0 100644 --- a/SafeExamBrowser.Client/CompositionRoot.cs +++ b/SafeExamBrowser.Client/CompositionRoot.cs @@ -6,22 +6,30 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using System.Collections.Generic; using SafeExamBrowser.Browser; +using SafeExamBrowser.Client.Behaviour; +using SafeExamBrowser.Client.Behaviour.Operations; +using SafeExamBrowser.Client.Communication; using SafeExamBrowser.Configuration; using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Behaviour.Operations; using SafeExamBrowser.Contracts.Configuration; -using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; -using SafeExamBrowser.Contracts.Monitoring; -using SafeExamBrowser.Contracts.SystemComponents; using SafeExamBrowser.Contracts.UserInterface; -using SafeExamBrowser.Contracts.UserInterface.Taskbar; using SafeExamBrowser.Contracts.WindowsApi; +using SafeExamBrowser.Core.Behaviour.Operations; +using SafeExamBrowser.Core.Communication; using SafeExamBrowser.Core.I18n; using SafeExamBrowser.Core.Logging; +using SafeExamBrowser.Monitoring.Display; +using SafeExamBrowser.Monitoring.Keyboard; +using SafeExamBrowser.Monitoring.Mouse; +using SafeExamBrowser.Monitoring.Processes; +using SafeExamBrowser.Monitoring.Windows; +using SafeExamBrowser.SystemComponents; using SafeExamBrowser.UserInterface.Classic; using SafeExamBrowser.WindowsApi; @@ -29,77 +37,127 @@ namespace SafeExamBrowser.Client { internal class CompositionRoot { - private IApplicationController browserController; - private IApplicationInfo browserInfo; - private IClientController clientController; - private IDisplayMonitor displayMonitor; - private IKeyboardInterceptor keyboardInterceptor; + private IClientConfiguration configuration; private ILogger logger; - private IMouseInterceptor mouseInterceptor; - private IProcessMonitor processMonitor; private INativeMethods nativeMethods; - private ISettings settings; - private ISystemComponent keyboardLayout; - private ISystemComponent powerSupply; - private ISystemComponent wirelessNetwork; private ISystemInfo systemInfo; private IText text; private IUserInterfaceFactory uiFactory; - private IWindowMonitor windowMonitor; - //internal IShutdownController ShutdownController { get; private set; } - //internal IStartupController StartupController { get; private set; } - internal Queue StartupOperations { get; private set; } + internal IClientController ClientController { get; private set; } internal Taskbar Taskbar { get; private set; } internal void BuildObjectGraph() { - browserInfo = new BrowserApplicationInfo(); + var args = Environment.GetCommandLineArgs(); + + Validate(args); + + configuration = new ClientConfiguration(); logger = new Logger(); nativeMethods = new NativeMethods(); - settings = new ConfigurationRepository().LoadDefaultSettings(); systemInfo = new SystemInfo(); - InitializeLogging(); + InitializeLogging(args[1]); text = new Text(logger); uiFactory = new UserInterfaceFactory(text); - // TODO - //Taskbar = new Taskbar(new ModuleLogger(logger, typeof(Taskbar))); - //browserController = new BrowserApplicationController(settings.Browser, text, uiFactory); - //displayMonitor = new DisplayMonitor(new ModuleLogger(logger, typeof(DisplayMonitor)), nativeMethods); - //keyboardInterceptor = new KeyboardInterceptor(settings.Keyboard, new ModuleLogger(logger, typeof(KeyboardInterceptor))); - //keyboardLayout = new KeyboardLayout(new ModuleLogger(logger, typeof(KeyboardLayout)), text); - //mouseInterceptor = new MouseInterceptor(new ModuleLogger(logger, typeof(MouseInterceptor)), settings.Mouse); - //powerSupply = new PowerSupply(new ModuleLogger(logger, typeof(PowerSupply)), text); - //processMonitor = new ProcessMonitor(new ModuleLogger(logger, typeof(ProcessMonitor)), nativeMethods); - //windowMonitor = new WindowMonitor(new ModuleLogger(logger, typeof(WindowMonitor)), nativeMethods); - //wirelessNetwork = new WirelessNetwork(new ModuleLogger(logger, typeof(WirelessNetwork)), text); - //clientController = new ClientController(displayMonitor, new ModuleLogger(logger, typeof(ClientController)), processMonitor, Taskbar, windowMonitor); - //ShutdownController = new ShutdownController(logger, settings, text, uiFactory); - //StartupController = new StartupController(logger, settings, systemInfo, text, uiFactory); + var runtimeProxy = new RuntimeProxy(args[2], new ModuleLogger(logger, typeof(RuntimeProxy))); + var displayMonitor = new DisplayMonitor(new ModuleLogger(logger, typeof(DisplayMonitor)), nativeMethods); + var processMonitor = new ProcessMonitor(new ModuleLogger(logger, typeof(ProcessMonitor)), nativeMethods); + var windowMonitor = new WindowMonitor(new ModuleLogger(logger, typeof(WindowMonitor)), nativeMethods); - //StartupOperations = new Queue(); - //StartupOperations.Enqueue(new I18nOperation(logger, text)); - //StartupOperations.Enqueue(new KeyboardInterceptorOperation(keyboardInterceptor, logger, nativeMethods)); - //StartupOperations.Enqueue(new WindowMonitorOperation(logger, windowMonitor)); - //StartupOperations.Enqueue(new ProcessMonitorOperation(logger, processMonitor)); - //StartupOperations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, Taskbar)); - //StartupOperations.Enqueue(new TaskbarOperation(logger, settings.Taskbar, keyboardLayout, powerSupply, wirelessNetwork, systemInfo, Taskbar, text, uiFactory)); - //StartupOperations.Enqueue(new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory)); - //StartupOperations.Enqueue(new ClientControllerOperation(clientController, logger)); - //StartupOperations.Enqueue(new ClipboardOperation(logger, nativeMethods)); - //StartupOperations.Enqueue(new MouseInterceptorOperation(logger, mouseInterceptor, nativeMethods)); + Taskbar = new Taskbar(new ModuleLogger(logger, typeof(Taskbar))); + + var operations = new Queue(); + + operations.Enqueue(new I18nOperation(logger, text)); + operations.Enqueue(new RuntimeConnectionOperation(logger, runtimeProxy, Guid.Parse(args[3]))); + operations.Enqueue(new ConfigurationOperation(configuration, logger, runtimeProxy)); + operations.Enqueue(new DelayedInitializationOperation(BuildCommunicationHostOperation)); + operations.Enqueue(new DelayedInitializationOperation(BuildKeyboardInterceptorOperation)); + operations.Enqueue(new WindowMonitorOperation(logger, windowMonitor)); + operations.Enqueue(new ProcessMonitorOperation(logger, processMonitor)); + operations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, Taskbar)); + operations.Enqueue(new DelayedInitializationOperation(BuildTaskbarOperation)); + operations.Enqueue(new DelayedInitializationOperation(BuildBrowserOperation)); + operations.Enqueue(new ClipboardOperation(logger, nativeMethods)); + operations.Enqueue(new DelayedInitializationOperation(BuildMouseInterceptorOperation)); + + var sequence = new OperationSequence(logger, operations); + + ClientController = new ClientController(displayMonitor, logger, sequence, processMonitor, Taskbar, windowMonitor); } - private void InitializeLogging() + private void Validate(string[] args) { - // TODO - //var logFileWriter = new LogFileWriter(new DefaultLogFormatter(), settings.Logging.ClientLogFile); + var hasFourParameters = args?.Length == 4; - //logFileWriter.Initialize(); - //logger.Subscribe(logFileWriter); + if (hasFourParameters) + { + var hasLogfilePath = Uri.TryCreate(args?[1], UriKind.Absolute, out Uri filePath) && filePath.IsFile; + var hasHostUri = Uri.TryCreate(args?[2], UriKind.Absolute, out Uri hostUri) && hostUri.IsWellFormedOriginalString(); + var hasToken = Guid.TryParse(args?[3], out Guid token); + + if (hasLogfilePath && hasHostUri && hasToken) + { + return; + } + } + + throw new ArgumentException("Invalid parameters! Required: SafeExamBrowser.Client.exe "); + } + + private void InitializeLogging(string filePath) + { + var logFileWriter = new LogFileWriter(new DefaultLogFormatter(), filePath); + + logFileWriter.Initialize(); + logger.Subscribe(logFileWriter); + } + + private IOperation BuildBrowserOperation() + { + var browserController = new BrowserApplicationController(configuration.Settings.Browser, configuration.RuntimeInfo, text, uiFactory); + var browserInfo = new BrowserApplicationInfo(); + var operation = new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory); + + return operation; + } + + private IOperation BuildCommunicationHostOperation() + { + var host = new ClientHost(configuration.RuntimeInfo.ClientAddress, new ModuleLogger(logger, typeof(ClientHost))); + var operation = new CommunicationOperation(host, logger); + + return operation; + } + + private IOperation BuildKeyboardInterceptorOperation() + { + var keyboardInterceptor = new KeyboardInterceptor(configuration.Settings.Keyboard, new ModuleLogger(logger, typeof(KeyboardInterceptor))); + var operation = new KeyboardInterceptorOperation(keyboardInterceptor, logger, nativeMethods); + + return operation; + } + + private IOperation BuildMouseInterceptorOperation() + { + var mouseInterceptor = new MouseInterceptor(new ModuleLogger(logger, typeof(MouseInterceptor)), configuration.Settings.Mouse); + var operation = new MouseInterceptorOperation(logger, mouseInterceptor, nativeMethods); + + return operation; + } + + private IOperation BuildTaskbarOperation() + { + var keyboardLayout = new KeyboardLayout(new ModuleLogger(logger, typeof(KeyboardLayout)), text); + var powerSupply = new PowerSupply(new ModuleLogger(logger, typeof(PowerSupply)), text); + var wirelessNetwork = new WirelessNetwork(new ModuleLogger(logger, typeof(WirelessNetwork)), text); + var operation = new TaskbarOperation(logger, configuration.Settings.Taskbar, keyboardLayout, powerSupply, wirelessNetwork, systemInfo, Taskbar, text, uiFactory); + + return operation; } } } diff --git a/SafeExamBrowser.Client/SafeExamBrowser.Client.csproj b/SafeExamBrowser.Client/SafeExamBrowser.Client.csproj index 982814d9..c54da209 100644 --- a/SafeExamBrowser.Client/SafeExamBrowser.Client.csproj +++ b/SafeExamBrowser.Client/SafeExamBrowser.Client.csproj @@ -70,6 +70,9 @@ + + + @@ -78,7 +81,6 @@ - diff --git a/SafeExamBrowser.Configuration/ClientConfiguration.cs b/SafeExamBrowser.Configuration/ClientConfiguration.cs new file mode 100644 index 00000000..95731ab6 --- /dev/null +++ b/SafeExamBrowser.Configuration/ClientConfiguration.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 System; +using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Configuration.Settings; + +namespace SafeExamBrowser.Configuration +{ + [Serializable] + public class ClientConfiguration : IClientConfiguration + { + public ISessionData SessionData { get; set; } + public ISettings Settings { get; set; } + public IRuntimeInfo RuntimeInfo { get; set; } + } +} diff --git a/SafeExamBrowser.Configuration/ConfigurationRepository.cs b/SafeExamBrowser.Configuration/ConfigurationRepository.cs index ece6003e..15d2e8da 100644 --- a/SafeExamBrowser.Configuration/ConfigurationRepository.cs +++ b/SafeExamBrowser.Configuration/ConfigurationRepository.cs @@ -45,6 +45,16 @@ namespace SafeExamBrowser.Configuration return sessionData; } + public IClientConfiguration BuildClientConfiguration() + { + return new ClientConfiguration + { + RuntimeInfo = RuntimeInfo, + SessionData = CurrentSessionData, + Settings = CurrentSettings + }; + } + public ISettings LoadSettings(Uri path) { // TODO diff --git a/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj b/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj index 770e8af2..bb05983f 100644 --- a/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj +++ b/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj @@ -53,6 +53,7 @@ + diff --git a/SafeExamBrowser.Contracts/Behaviour/IClientController.cs b/SafeExamBrowser.Contracts/Behaviour/IClientController.cs index 52efcfe9..02a10bd2 100644 --- a/SafeExamBrowser.Contracts/Behaviour/IClientController.cs +++ b/SafeExamBrowser.Contracts/Behaviour/IClientController.cs @@ -8,16 +8,17 @@ namespace SafeExamBrowser.Contracts.Behaviour { + // TODO: Interface really needed?! public interface IClientController { /// - /// Wires up and starts the application event handling. + /// Reverts any changes, releases all used resources and terminates the client. /// - void Start(); + void Terminate(); /// - /// Stops the event handling and removes all event subscriptions. + /// Tries to start the client. Returns true if successful, otherwise false. /// - void Stop(); + bool TryStart(); } } diff --git a/SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs b/SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs index 500f38b0..aaaf1a13 100644 --- a/SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs +++ b/SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs @@ -9,6 +9,7 @@ namespace SafeExamBrowser.Contracts.Behaviour { + // TODO: Interface really needed?! public interface IRuntimeController { /// diff --git a/SafeExamBrowser.Contracts/Communication/IClientHost.cs b/SafeExamBrowser.Contracts/Communication/IClientHost.cs new file mode 100644 index 00000000..8ff6a50c --- /dev/null +++ b/SafeExamBrowser.Contracts/Communication/IClientHost.cs @@ -0,0 +1,15 @@ +/* + * 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.Communication +{ + public interface IClientHost : ICommunicationHost + { + // TODO: Necessary? + } +} diff --git a/SafeExamBrowser.Contracts/Communication/IRuntimeHost.cs b/SafeExamBrowser.Contracts/Communication/IRuntimeHost.cs index dbcb1463..0c3e0e00 100644 --- a/SafeExamBrowser.Contracts/Communication/IRuntimeHost.cs +++ b/SafeExamBrowser.Contracts/Communication/IRuntimeHost.cs @@ -10,6 +10,6 @@ namespace SafeExamBrowser.Contracts.Communication { public interface IRuntimeHost : ICommunicationHost { - + // TODO: Necessary? } } diff --git a/SafeExamBrowser.Contracts/Communication/IRuntimeProxy.cs b/SafeExamBrowser.Contracts/Communication/IRuntimeProxy.cs index 13e9ccbd..510eb0c5 100644 --- a/SafeExamBrowser.Contracts/Communication/IRuntimeProxy.cs +++ b/SafeExamBrowser.Contracts/Communication/IRuntimeProxy.cs @@ -7,11 +7,25 @@ */ using System; +using SafeExamBrowser.Contracts.Configuration; namespace SafeExamBrowser.Contracts.Communication { public interface IRuntimeProxy { + /// + /// Tries to establish a connection with the runtime host, utilizing the specified authentication token. + /// bool Connect(Guid token); + + /// + /// Disconnects from the runtime host. + /// + void Disconnect(); + + /// + /// Retrieves the application configuration from the runtime host. + /// + IClientConfiguration GetConfiguration(); } } diff --git a/SafeExamBrowser.Contracts/Configuration/IClientConfiguration.cs b/SafeExamBrowser.Contracts/Configuration/IClientConfiguration.cs new file mode 100644 index 00000000..1036b7a2 --- /dev/null +++ b/SafeExamBrowser.Contracts/Configuration/IClientConfiguration.cs @@ -0,0 +1,30 @@ +/* + * 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.Configuration.Settings; + +namespace SafeExamBrowser.Contracts.Configuration +{ + public interface IClientConfiguration + { + /// + /// The session data to be used by the client. + /// + ISessionData SessionData { get; set; } + + /// + /// The application settings to be used by the client. + /// + ISettings Settings { get; set; } + + /// + /// The information about the current runtime. + /// + IRuntimeInfo RuntimeInfo { get; set; } + } +} diff --git a/SafeExamBrowser.Contracts/Configuration/IConfigurationRepository.cs b/SafeExamBrowser.Contracts/Configuration/IConfigurationRepository.cs index 69e85199..e0ee6615 100644 --- a/SafeExamBrowser.Contracts/Configuration/IConfigurationRepository.cs +++ b/SafeExamBrowser.Contracts/Configuration/IConfigurationRepository.cs @@ -30,6 +30,11 @@ namespace SafeExamBrowser.Contracts.Configuration /// IRuntimeInfo RuntimeInfo { get; } + /// + /// Builds a configuration for the client component, given the currently loaded settings, session data and runtime information. + /// + IClientConfiguration BuildClientConfiguration(); + /// /// Initializes all relevant data for a new session. /// diff --git a/SafeExamBrowser.Contracts/I18n/TextKey.cs b/SafeExamBrowser.Contracts/I18n/TextKey.cs index 27f5a142..65e43f21 100644 --- a/SafeExamBrowser.Contracts/I18n/TextKey.cs +++ b/SafeExamBrowser.Contracts/I18n/TextKey.cs @@ -27,12 +27,14 @@ namespace SafeExamBrowser.Contracts.I18n MessageBox_StartupErrorTitle, Notification_AboutTooltip, Notification_LogTooltip, + ProgressIndicator_CloseRuntimeConnection, ProgressIndicator_CloseServiceConnection, ProgressIndicator_EmptyClipboard, ProgressIndicator_InitializeBrowser, ProgressIndicator_InitializeConfiguration, ProgressIndicator_InitializeKioskMode, ProgressIndicator_InitializeProcessMonitoring, + ProgressIndicator_InitializeRuntimeConnection, ProgressIndicator_InitializeServiceConnection, ProgressIndicator_InitializeTaskbar, ProgressIndicator_InitializeWindowMonitoring, diff --git a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj index d41c12c2..f905bc5f 100644 --- a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj +++ b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj @@ -56,6 +56,7 @@ + @@ -65,6 +66,7 @@ + diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DelayedInitializationOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DelayedInitializationOperationTests.cs new file mode 100644 index 00000000..cb65cb9f --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/DelayedInitializationOperationTests.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.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class DelayedInitializationOperationTests + { + [TestMethod] + public void Todo() + { + Assert.Fail(); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj b/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj index 5a0df3b5..16cb0ade 100644 --- a/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj +++ b/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj @@ -79,6 +79,7 @@ + diff --git a/SafeExamBrowser.Core/Behaviour/Operations/DelayedInitializationOperation.cs b/SafeExamBrowser.Core/Behaviour/Operations/DelayedInitializationOperation.cs new file mode 100644 index 00000000..3a193c8e --- /dev/null +++ b/SafeExamBrowser.Core/Behaviour/Operations/DelayedInitializationOperation.cs @@ -0,0 +1,51 @@ +/* + * 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; +using SafeExamBrowser.Contracts.Behaviour.Operations; +using SafeExamBrowser.Contracts.UserInterface; + +namespace SafeExamBrowser.Core.Behaviour.Operations +{ + public class DelayedInitializationOperation : IOperation + { + private Func initialize; + private IOperation operation; + + public bool Abort { get; set; } + public IProgressIndicator ProgressIndicator { get; set; } + + public DelayedInitializationOperation(Func initialize) + { + this.initialize = initialize; + } + + public void Perform() + { + operation = initialize.Invoke(); + operation.ProgressIndicator = ProgressIndicator; + operation.Perform(); + + Abort = operation.Abort; + } + + public void Repeat() + { + operation.ProgressIndicator = ProgressIndicator; + operation.Repeat(); + + Abort = operation.Abort; + } + + public void Revert() + { + operation.ProgressIndicator = ProgressIndicator; + operation.Revert(); + } + } +} diff --git a/SafeExamBrowser.Core/Communication/RuntimeProxy.cs b/SafeExamBrowser.Core/Communication/RuntimeProxy.cs new file mode 100644 index 00000000..e96fb83d --- /dev/null +++ b/SafeExamBrowser.Core/Communication/RuntimeProxy.cs @@ -0,0 +1,41 @@ +/* + * 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; +using SafeExamBrowser.Contracts.Communication; +using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Core.Communication.Messages; + +namespace SafeExamBrowser.Core.Communication +{ + public class RuntimeProxy : BaseProxy, IRuntimeProxy + { + public RuntimeProxy(string address, ILogger logger) : base(address, logger) + { + } + + public bool Connect(Guid token) + { + return base.Connect(token).ConnectionEstablished; + } + + public void Disconnect() + { + FailIfNotConnected(nameof(Disconnect)); + + base.Disconnect(new Message { CommunicationToken = CommunicationToken.Value }); + } + + public IClientConfiguration GetConfiguration() + { + // TODO + throw new NotImplementedException(); + } + } +} diff --git a/SafeExamBrowser.Core/I18n/Text.xml b/SafeExamBrowser.Core/I18n/Text.xml index f3b1262a..a370bd33 100644 --- a/SafeExamBrowser.Core/I18n/Text.xml +++ b/SafeExamBrowser.Core/I18n/Text.xml @@ -36,6 +36,9 @@ Application Log + + Closing runtime connection + Closing service connection @@ -54,6 +57,9 @@ Initializing process monitoring + + Initializing runtime connection + Initializing service connection diff --git a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj index 31e04463..1a1944ed 100644 --- a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj +++ b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj @@ -56,11 +56,13 @@ + + diff --git a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceOperationTests.cs b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceConnectionOperationTests.cs similarity index 96% rename from SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceOperationTests.cs rename to SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceConnectionOperationTests.cs index 4b5a925e..fb4c1644 100644 --- a/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceOperationTests.cs +++ b/SafeExamBrowser.Runtime.UnitTests/Behaviour/Operations/ServiceConnectionOperationTests.cs @@ -20,14 +20,14 @@ using SafeExamBrowser.Runtime.Behaviour.Operations; namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations { [TestClass] - public class ServiceOperationTests + public class ServiceConnectionOperationTests { private Mock logger; private Mock service; private Mock configuration; private Mock progressIndicator; private Mock text; - private ServiceOperation sut; + private ServiceConnectionOperation sut; [TestInitialize] public void Initialize() @@ -38,7 +38,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations progressIndicator = new Mock(); text = new Mock(); - sut = new ServiceOperation(configuration.Object, logger.Object, service.Object, text.Object); + sut = new ServiceConnectionOperation(configuration.Object, logger.Object, service.Object, text.Object); } [TestMethod] diff --git a/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj b/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj index c2150a67..0e881f6e 100644 --- a/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj +++ b/SafeExamBrowser.Runtime.UnitTests/SafeExamBrowser.Runtime.UnitTests.csproj @@ -82,7 +82,7 @@ - + diff --git a/SafeExamBrowser.Runtime/Behaviour/Operations/ServiceOperation.cs b/SafeExamBrowser.Runtime/Behaviour/Operations/ServiceConnectionOperation.cs similarity index 72% rename from SafeExamBrowser.Runtime/Behaviour/Operations/ServiceOperation.cs rename to SafeExamBrowser.Runtime/Behaviour/Operations/ServiceConnectionOperation.cs index 22a3f0a9..db916801 100644 --- a/SafeExamBrowser.Runtime/Behaviour/Operations/ServiceOperation.cs +++ b/SafeExamBrowser.Runtime/Behaviour/Operations/ServiceConnectionOperation.cs @@ -17,10 +17,9 @@ using SafeExamBrowser.Contracts.UserInterface; namespace SafeExamBrowser.Runtime.Behaviour.Operations { - internal class ServiceOperation : IOperation + internal class ServiceConnectionOperation : IOperation { - private bool serviceAvailable; - private bool serviceMandatory; + private bool connected, mandatory; private IConfigurationRepository configuration; private ILogger logger; private IServiceProxy service; @@ -29,7 +28,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations public bool Abort { get; private set; } public IProgressIndicator ProgressIndicator { private get; set; } - public ServiceOperation(IConfigurationRepository configuration, ILogger logger, IServiceProxy service, IText text) + public ServiceConnectionOperation(IConfigurationRepository configuration, ILogger logger, IServiceProxy service, IText text) { this.configuration = configuration; this.service = service; @@ -44,23 +43,23 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations try { - serviceMandatory = configuration.CurrentSettings.ServicePolicy == ServicePolicy.Mandatory; - serviceAvailable = service.Connect(); + mandatory = configuration.CurrentSettings.ServicePolicy == ServicePolicy.Mandatory; + connected = service.Connect(); } catch (Exception e) { LogException(e); } - if (serviceMandatory && !serviceAvailable) + if (mandatory && !connected) { Abort = true; logger.Info("Aborting startup because the service is mandatory but not available!"); } else { - service.Ignore = !serviceAvailable; - logger.Info($"The service is {(serviceMandatory ? "mandatory" : "optional")} and {(serviceAvailable ? "available." : "not available. All service-related operations will be ignored!")}"); + service.Ignore = !connected; + logger.Info($"The service is {(mandatory ? "mandatory" : "optional")} and {(connected ? "available." : "not available. All service-related operations will be ignored!")}"); } } @@ -74,7 +73,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations logger.Info("Closing service connection..."); ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_CloseServiceConnection); - if (serviceAvailable) + if (connected) { try { @@ -82,7 +81,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations } catch (Exception e) { - logger.Error("Failed to disconnect from service component!", e); + logger.Error("Failed to disconnect from service host!", e); } } } @@ -91,7 +90,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations { var message = "Failed to connect to the service component!"; - if (serviceMandatory) + if (mandatory) { logger.Error(message, e); } diff --git a/SafeExamBrowser.Runtime/Behaviour/Operations/SessionSequenceOperation.cs b/SafeExamBrowser.Runtime/Behaviour/Operations/SessionSequenceOperation.cs index 4236270a..d137f552 100644 --- a/SafeExamBrowser.Runtime/Behaviour/Operations/SessionSequenceOperation.cs +++ b/SafeExamBrowser.Runtime/Behaviour/Operations/SessionSequenceOperation.cs @@ -17,7 +17,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations { internal abstract class SessionSequenceOperation : IOperation { - private bool sessionInitialized; + private bool sessionRunning; private IConfigurationRepository configuration; private ILogger logger; private IServiceProxy serviceProxy; @@ -50,13 +50,13 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations // - Verify session integrity and start event handling -> in runtime controller? System.Threading.Thread.Sleep(5000); - sessionInitialized = true; + sessionRunning = true; logger.Info($"Successfully started new session with identifier '{sessionData.Id}'."); } protected void StopSession() { - if (sessionInitialized) + if (sessionRunning) { logger.Info($"Stopping session with identifier '{sessionData.Id}'..."); ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_StopSession, true); @@ -68,7 +68,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations // - Stop event handling and verify session termination -> in runtime controller? System.Threading.Thread.Sleep(5000); - sessionInitialized = false; + sessionRunning = false; logger.Info($"Successfully stopped session with identifier '{sessionData.Id}'."); } } diff --git a/SafeExamBrowser.Runtime/CompositionRoot.cs b/SafeExamBrowser.Runtime/CompositionRoot.cs index 7d5efe0a..e938161b 100644 --- a/SafeExamBrowser.Runtime/CompositionRoot.cs +++ b/SafeExamBrowser.Runtime/CompositionRoot.cs @@ -59,7 +59,7 @@ namespace SafeExamBrowser.Runtime sessionOperations.Enqueue(new SessionSequenceStartOperation(configuration, logger, serviceProxy)); sessionOperations.Enqueue(new ConfigurationOperation(configuration, logger, runtimeInfo, text, uiFactory, args)); - sessionOperations.Enqueue(new ServiceOperation(configuration, logger, serviceProxy, text)); + sessionOperations.Enqueue(new ServiceConnectionOperation(configuration, logger, serviceProxy, text)); sessionOperations.Enqueue(new KioskModeOperation(logger, configuration)); sessionOperations.Enqueue(new SessionSequenceEndOperation(configuration, logger, serviceProxy)); diff --git a/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj b/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj index 050d4535..6f9e793d 100644 --- a/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj +++ b/SafeExamBrowser.Runtime/SafeExamBrowser.Runtime.csproj @@ -89,7 +89,7 @@ - +