SEBWIN-219: Changed startup procedure for runtime component in order to be able to re-configure during application execution.
This commit is contained in:
parent
c56b4a0251
commit
7d5c6a1b0b
17 changed files with 91 additions and 144 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
using SafeExamBrowser.Contracts.Behaviour;
|
||||
using SafeExamBrowser.Contracts.Client;
|
||||
using SafeExamBrowser.Contracts.I18n;
|
||||
using SafeExamBrowser.Contracts.Logging;
|
||||
using SafeExamBrowser.Contracts.UserInterface;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
{
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Wires up and starts the application event handling.
|
||||
/// Reverts any changes performed during the startup or runtime and releases all used resources.
|
||||
/// </summary>
|
||||
void Start();
|
||||
|
||||
/// <summary>
|
||||
/// Stops the event handling and removes all event subscriptions.
|
||||
/// </summary>
|
||||
void Stop();
|
||||
void FinalizeApplication();
|
||||
}
|
||||
}
|
|
@ -54,16 +54,16 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Behaviour\IApplicationController.cs" />
|
||||
<Compile Include="Behaviour\IRuntimeController.cs" />
|
||||
<Compile Include="Communication\ICommunicationHost.cs" />
|
||||
<Compile Include="Communication\Messages\IMessage.cs" />
|
||||
<Compile Include="Communication\Responses\IResponse.cs" />
|
||||
<Compile Include="Communication\Responses\IConnectResponse.cs" />
|
||||
<Compile Include="Configuration\IRuntimeInfo.cs" />
|
||||
<Compile Include="Configuration\Settings\ConfigurationMode.cs" />
|
||||
<Compile Include="Runtime\IRuntimeController.cs" />
|
||||
<Compile Include="Behaviour\INotificationController.cs" />
|
||||
<Compile Include="Behaviour\IOperation.cs" />
|
||||
<Compile Include="Client\IClientController.cs" />
|
||||
<Compile Include="Behaviour\IClientController.cs" />
|
||||
<Compile Include="Configuration\IIconResource.cs" />
|
||||
<Compile Include="Configuration\IApplicationInfo.cs" />
|
||||
<Compile Include="Configuration\IApplicationInstance.cs" />
|
||||
|
@ -122,6 +122,8 @@
|
|||
<Compile Include="WindowsApi\IBounds.cs" />
|
||||
<Compile Include="WindowsApi\INativeMethods.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Folder Include="Client\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -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<ILogger> loggerMock;
|
||||
private Mock<IRuntimeController> runtimeControllerMock;
|
||||
private Mock<ISplashScreen> splashScreenMock;
|
||||
|
||||
private RuntimeControllerOperation sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
loggerMock = new Mock<ILogger>();
|
||||
runtimeControllerMock = new Mock<IRuntimeController>();
|
||||
splashScreenMock = new Mock<ISplashScreen>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations
|
|||
[TestMethod]
|
||||
public void Test()
|
||||
{
|
||||
// TODO
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -81,8 +81,8 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Behaviour\Operations\ConfigurationOperationTests.cs" />
|
||||
<Compile Include="Behaviour\Operations\RuntimeControllerOperationTests.cs" />
|
||||
<Compile Include="Behaviour\Operations\ServiceOperationTests.cs" />
|
||||
<Compile Include="Behaviour\RuntimeControllerTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -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<IOperation>(instances.StartupOperations.Reverse());
|
||||
|
||||
MainWindow.Hide();
|
||||
instances.ShutdownController.FinalizeApplication(operations);
|
||||
instances.RuntimeController.FinalizeApplication();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<IOperation> 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<IOperation>();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
public bool TryInitializeApplication(Queue<IOperation> operations)
|
||||
{
|
||||
// TODO
|
||||
operations = new Queue<IOperation>(operations);
|
||||
|
||||
var success = startupController.TryInitializeApplication(operations);
|
||||
|
||||
if (success)
|
||||
{
|
||||
Start();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
public void FinalizeApplication()
|
||||
{
|
||||
// TODO
|
||||
Stop();
|
||||
shutdownController.FinalizeApplication(new Queue<IOperation>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<IOperation> 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<IOperation>();
|
||||
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()
|
||||
|
|
|
@ -88,7 +88,6 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="App.cs" />
|
||||
<Compile Include="Behaviour\Operations\ConfigurationOperation.cs" />
|
||||
<Compile Include="Behaviour\Operations\RuntimeControllerOperation.cs" />
|
||||
<Compile Include="Behaviour\Operations\ServiceOperation.cs" />
|
||||
<Compile Include="CompositionRoot.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
|
|
Loading…
Reference in a new issue