SEBWIN-219: Adapted startup procedure for client component by introducing the DelayedInitializationOperation.
This commit is contained in:
		
							parent
							
								
									66e9078a4c
								
							
						
					
					
						commit
						10202a807f
					
				
					 35 changed files with 591 additions and 218 deletions
				
			
		|  | @ -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<ILogger> loggerMock; |  | ||||||
| 		private Mock<IClientController> clientControllerMock; |  | ||||||
| 
 |  | ||||||
| 		private ClientControllerOperation sut; |  | ||||||
| 
 |  | ||||||
| 		[TestInitialize] |  | ||||||
| 		public void Initialize() |  | ||||||
| 		{ |  | ||||||
| 			loggerMock = new Mock<ILogger>(); |  | ||||||
| 			clientControllerMock = new Mock<IClientController>(); |  | ||||||
| 
 |  | ||||||
| 			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); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  | @ -9,7 +9,6 @@ | ||||||
| using System; | using System; | ||||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | using Microsoft.VisualStudio.TestTools.UnitTesting; | ||||||
| using Moq; | using Moq; | ||||||
| using SafeExamBrowser.Client.Behaviour; |  | ||||||
| using SafeExamBrowser.Contracts.Behaviour; | using SafeExamBrowser.Contracts.Behaviour; | ||||||
| using SafeExamBrowser.Contracts.Logging; | using SafeExamBrowser.Contracts.Logging; | ||||||
| using SafeExamBrowser.Contracts.Monitoring; | using SafeExamBrowser.Contracts.Monitoring; | ||||||
|  | @ -37,14 +36,16 @@ namespace SafeExamBrowser.Client.UnitTests | ||||||
| 			taskbarMock = new Mock<ITaskbar>(); | 			taskbarMock = new Mock<ITaskbar>(); | ||||||
| 			windowMonitorMock= new Mock<IWindowMonitor>(); | 			windowMonitorMock= new Mock<IWindowMonitor>(); | ||||||
| 
 | 
 | ||||||
| 			sut = new ClientController( | 			// TODO | ||||||
| 				displayMonitorMock.Object, |  | ||||||
| 				loggerMock.Object, |  | ||||||
| 				processMonitorMock.Object, |  | ||||||
| 				taskbarMock.Object, |  | ||||||
| 				windowMonitorMock.Object); |  | ||||||
| 
 | 
 | ||||||
| 			sut.Start(); | 			//sut = new ClientController( | ||||||
|  | 			//	displayMonitorMock.Object, | ||||||
|  | 			//	loggerMock.Object, | ||||||
|  | 			//	processMonitorMock.Object, | ||||||
|  | 			//	taskbarMock.Object, | ||||||
|  | 			//	windowMonitorMock.Object); | ||||||
|  | 
 | ||||||
|  | 			// sut.Start(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
|  | @ -151,7 +152,7 @@ namespace SafeExamBrowser.Client.UnitTests | ||||||
| 		[TestCleanup] | 		[TestCleanup] | ||||||
| 		public void Cleanup() | 		public void Cleanup() | ||||||
| 		{ | 		{ | ||||||
| 			sut.Stop(); | 			// TODO sut.Stop(); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -79,7 +79,6 @@ | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <Compile Include="Behaviour\Operations\BrowserOperationTests.cs" /> |     <Compile Include="Behaviour\Operations\BrowserOperationTests.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\ClientControllerOperationTests.cs" /> |  | ||||||
|     <Compile Include="Behaviour\Operations\ClipboardOperationTests.cs" /> |     <Compile Include="Behaviour\Operations\ClipboardOperationTests.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\DisplayMonitorOperationTests.cs" /> |     <Compile Include="Behaviour\Operations\DisplayMonitorOperationTests.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\KeyboardInterceptorOperationTests.cs" /> |     <Compile Include="Behaviour\Operations\KeyboardInterceptorOperationTests.cs" /> | ||||||
|  |  | ||||||
|  | @ -7,12 +7,9 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| using System; | using System; | ||||||
| using System.Collections.Generic; |  | ||||||
| using System.ComponentModel; | using System.ComponentModel; | ||||||
| using System.Linq; |  | ||||||
| using System.Threading; | using System.Threading; | ||||||
| using System.Windows; | using System.Windows; | ||||||
| using SafeExamBrowser.Contracts.Behaviour.Operations; |  | ||||||
| 
 | 
 | ||||||
| namespace SafeExamBrowser.Client | namespace SafeExamBrowser.Client | ||||||
| { | { | ||||||
|  | @ -61,26 +58,24 @@ namespace SafeExamBrowser.Client | ||||||
| 
 | 
 | ||||||
| 			instances.BuildObjectGraph(); | 			instances.BuildObjectGraph(); | ||||||
| 
 | 
 | ||||||
| 			//var success = instances.StartupController.TryInitializeApplication(instances.StartupOperations); | 			var success = instances.ClientController.TryStart(); | ||||||
| 
 | 
 | ||||||
| 			//if (success) | 			if (success) | ||||||
| 			//{ | 			{ | ||||||
| 			//	MainWindow = instances.Taskbar; | 				MainWindow = instances.Taskbar; | ||||||
| 			//	MainWindow.Closing += MainWindow_Closing; | 				MainWindow.Closing += MainWindow_Closing; | ||||||
| 			//	MainWindow.Show(); | 				MainWindow.Show(); | ||||||
| 			//} | 			} | ||||||
| 			//else | 			else | ||||||
| 			//{ | 			{ | ||||||
| 			//	Shutdown(); | 				Shutdown(); | ||||||
| 			//} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		private void MainWindow_Closing(object sender, CancelEventArgs e) | 		private void MainWindow_Closing(object sender, CancelEventArgs e) | ||||||
| 		{ | 		{ | ||||||
| 			var operations = new Queue<IOperation>(instances.StartupOperations.Reverse()); | 			MainWindow?.Hide(); | ||||||
| 
 | 			instances.ClientController.Terminate(); | ||||||
| 			MainWindow.Hide(); |  | ||||||
| 			//instances.ShutdownController.FinalizeApplication(operations); |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -8,6 +8,7 @@ | ||||||
| 
 | 
 | ||||||
| using System; | using System; | ||||||
| using SafeExamBrowser.Contracts.Behaviour; | using SafeExamBrowser.Contracts.Behaviour; | ||||||
|  | using SafeExamBrowser.Contracts.Behaviour.Operations; | ||||||
| using SafeExamBrowser.Contracts.Logging; | using SafeExamBrowser.Contracts.Logging; | ||||||
| using SafeExamBrowser.Contracts.Monitoring; | using SafeExamBrowser.Contracts.Monitoring; | ||||||
| using SafeExamBrowser.Contracts.UserInterface.Taskbar; | using SafeExamBrowser.Contracts.UserInterface.Taskbar; | ||||||
|  | @ -18,6 +19,7 @@ namespace SafeExamBrowser.Client.Behaviour | ||||||
| 	{ | 	{ | ||||||
| 		private IDisplayMonitor displayMonitor; | 		private IDisplayMonitor displayMonitor; | ||||||
| 		private ILogger logger; | 		private ILogger logger; | ||||||
|  | 		private IOperationSequence operations; | ||||||
| 		private IProcessMonitor processMonitor; | 		private IProcessMonitor processMonitor; | ||||||
| 		private ITaskbar taskbar; | 		private ITaskbar taskbar; | ||||||
| 		private IWindowMonitor windowMonitor; | 		private IWindowMonitor windowMonitor; | ||||||
|  | @ -25,31 +27,35 @@ namespace SafeExamBrowser.Client.Behaviour | ||||||
| 		public ClientController( | 		public ClientController( | ||||||
| 			IDisplayMonitor displayMonitor, | 			IDisplayMonitor displayMonitor, | ||||||
| 			ILogger logger, | 			ILogger logger, | ||||||
|  | 			IOperationSequence operations, | ||||||
| 			IProcessMonitor processMonitor, | 			IProcessMonitor processMonitor, | ||||||
| 			ITaskbar taskbar, | 			ITaskbar taskbar, | ||||||
| 			IWindowMonitor windowMonitor) | 			IWindowMonitor windowMonitor) | ||||||
| 		{ | 		{ | ||||||
| 			this.displayMonitor = displayMonitor; | 			this.displayMonitor = displayMonitor; | ||||||
| 			this.logger = logger; | 			this.logger = logger; | ||||||
|  | 			this.operations = operations; | ||||||
| 			this.processMonitor = processMonitor; | 			this.processMonitor = processMonitor; | ||||||
| 			this.taskbar = taskbar; | 			this.taskbar = taskbar; | ||||||
| 			this.windowMonitor = windowMonitor; | 			this.windowMonitor = windowMonitor; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		public void Start() | 		public void Terminate() | ||||||
| 		{ |  | ||||||
| 			displayMonitor.DisplayChanged += DisplayMonitor_DisplaySettingsChanged; |  | ||||||
| 			processMonitor.ExplorerStarted += ProcessMonitor_ExplorerStarted; |  | ||||||
| 			windowMonitor.WindowChanged += WindowMonitor_WindowChanged; |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		public void Stop() |  | ||||||
| 		{ | 		{ | ||||||
| 			displayMonitor.DisplayChanged -= DisplayMonitor_DisplaySettingsChanged; | 			displayMonitor.DisplayChanged -= DisplayMonitor_DisplaySettingsChanged; | ||||||
| 			processMonitor.ExplorerStarted -= ProcessMonitor_ExplorerStarted; | 			processMonitor.ExplorerStarted -= ProcessMonitor_ExplorerStarted; | ||||||
| 			windowMonitor.WindowChanged -= WindowMonitor_WindowChanged; | 			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() | 		private void DisplayMonitor_DisplaySettingsChanged() | ||||||
| 		{ | 		{ | ||||||
| 			logger.Info("Reinitializing working area..."); | 			logger.Info("Reinitializing working area..."); | ||||||
|  |  | ||||||
|  | @ -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(); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  | @ -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... | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | @ -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); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										42
									
								
								SafeExamBrowser.Client/Communication/ClientHost.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								SafeExamBrowser.Client/Communication/ClientHost.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -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(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | @ -6,22 +6,30 @@ | ||||||
|  * file, You can obtain one at http://mozilla.org/MPL/2.0/. |  * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using SafeExamBrowser.Browser; | using SafeExamBrowser.Browser; | ||||||
|  | using SafeExamBrowser.Client.Behaviour; | ||||||
|  | using SafeExamBrowser.Client.Behaviour.Operations; | ||||||
|  | using SafeExamBrowser.Client.Communication; | ||||||
| using SafeExamBrowser.Configuration; | using SafeExamBrowser.Configuration; | ||||||
| using SafeExamBrowser.Contracts.Behaviour; | using SafeExamBrowser.Contracts.Behaviour; | ||||||
| using SafeExamBrowser.Contracts.Behaviour.Operations; | using SafeExamBrowser.Contracts.Behaviour.Operations; | ||||||
| using SafeExamBrowser.Contracts.Configuration; | using SafeExamBrowser.Contracts.Configuration; | ||||||
| using SafeExamBrowser.Contracts.Configuration.Settings; |  | ||||||
| using SafeExamBrowser.Contracts.I18n; | using SafeExamBrowser.Contracts.I18n; | ||||||
| using SafeExamBrowser.Contracts.Logging; | using SafeExamBrowser.Contracts.Logging; | ||||||
| using SafeExamBrowser.Contracts.Monitoring; |  | ||||||
| using SafeExamBrowser.Contracts.SystemComponents; |  | ||||||
| using SafeExamBrowser.Contracts.UserInterface; | using SafeExamBrowser.Contracts.UserInterface; | ||||||
| using SafeExamBrowser.Contracts.UserInterface.Taskbar; |  | ||||||
| using SafeExamBrowser.Contracts.WindowsApi; | using SafeExamBrowser.Contracts.WindowsApi; | ||||||
|  | using SafeExamBrowser.Core.Behaviour.Operations; | ||||||
|  | using SafeExamBrowser.Core.Communication; | ||||||
| using SafeExamBrowser.Core.I18n; | using SafeExamBrowser.Core.I18n; | ||||||
| using SafeExamBrowser.Core.Logging; | 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.UserInterface.Classic; | ||||||
| using SafeExamBrowser.WindowsApi; | using SafeExamBrowser.WindowsApi; | ||||||
| 
 | 
 | ||||||
|  | @ -29,77 +37,127 @@ namespace SafeExamBrowser.Client | ||||||
| { | { | ||||||
| 	internal class CompositionRoot | 	internal class CompositionRoot | ||||||
| 	{ | 	{ | ||||||
| 		private IApplicationController browserController; | 		private IClientConfiguration configuration; | ||||||
| 		private IApplicationInfo browserInfo; |  | ||||||
| 		private IClientController clientController; |  | ||||||
| 		private IDisplayMonitor displayMonitor; |  | ||||||
| 		private IKeyboardInterceptor keyboardInterceptor; |  | ||||||
| 		private ILogger logger; | 		private ILogger logger; | ||||||
| 		private IMouseInterceptor mouseInterceptor; |  | ||||||
| 		private IProcessMonitor processMonitor; |  | ||||||
| 		private INativeMethods nativeMethods; | 		private INativeMethods nativeMethods; | ||||||
| 		private ISettings settings; |  | ||||||
| 		private ISystemComponent<ISystemKeyboardLayoutControl> keyboardLayout; |  | ||||||
| 		private ISystemComponent<ISystemPowerSupplyControl> powerSupply; |  | ||||||
| 		private ISystemComponent<ISystemWirelessNetworkControl> wirelessNetwork; |  | ||||||
| 		private ISystemInfo systemInfo; | 		private ISystemInfo systemInfo; | ||||||
| 		private IText text; | 		private IText text; | ||||||
| 		private IUserInterfaceFactory uiFactory; | 		private IUserInterfaceFactory uiFactory; | ||||||
| 		private IWindowMonitor windowMonitor; |  | ||||||
| 
 | 
 | ||||||
| 		//internal IShutdownController ShutdownController { get; private set; } | 		internal IClientController ClientController { get; private set; } | ||||||
| 		//internal IStartupController StartupController { get; private set; } |  | ||||||
| 		internal Queue<IOperation> StartupOperations { get; private set; } |  | ||||||
| 		internal Taskbar Taskbar { get; private set; } | 		internal Taskbar Taskbar { get; private set; } | ||||||
| 
 | 
 | ||||||
| 		internal void BuildObjectGraph() | 		internal void BuildObjectGraph() | ||||||
| 		{ | 		{ | ||||||
| 			browserInfo = new BrowserApplicationInfo(); | 			var args = Environment.GetCommandLineArgs(); | ||||||
|  | 
 | ||||||
|  | 			Validate(args); | ||||||
|  | 
 | ||||||
|  | 			configuration = new ClientConfiguration(); | ||||||
| 			logger = new Logger(); | 			logger = new Logger(); | ||||||
| 			nativeMethods = new NativeMethods(); | 			nativeMethods = new NativeMethods(); | ||||||
| 			settings = new ConfigurationRepository().LoadDefaultSettings(); |  | ||||||
| 			systemInfo = new SystemInfo(); | 			systemInfo = new SystemInfo(); | ||||||
| 
 | 
 | ||||||
| 			InitializeLogging(); | 			InitializeLogging(args[1]); | ||||||
| 
 | 
 | ||||||
| 			text = new Text(logger); | 			text = new Text(logger); | ||||||
| 			uiFactory = new UserInterfaceFactory(text); | 			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); | 			var runtimeProxy = new RuntimeProxy(args[2], new ModuleLogger(logger, typeof(RuntimeProxy))); | ||||||
| 			//ShutdownController = new ShutdownController(logger, settings, text, uiFactory); | 			var displayMonitor = new DisplayMonitor(new ModuleLogger(logger, typeof(DisplayMonitor)), nativeMethods); | ||||||
| 			//StartupController = new StartupController(logger, settings, systemInfo, text, uiFactory); | 			var processMonitor = new ProcessMonitor(new ModuleLogger(logger, typeof(ProcessMonitor)), nativeMethods); | ||||||
|  | 			var windowMonitor = new WindowMonitor(new ModuleLogger(logger, typeof(WindowMonitor)), nativeMethods); | ||||||
| 
 | 
 | ||||||
| 			//StartupOperations = new Queue<IOperation>(); | 			Taskbar = new Taskbar(new ModuleLogger(logger, typeof(Taskbar))); | ||||||
| 			//StartupOperations.Enqueue(new I18nOperation(logger, text)); | 
 | ||||||
| 			//StartupOperations.Enqueue(new KeyboardInterceptorOperation(keyboardInterceptor, logger, nativeMethods)); | 			var operations = new Queue<IOperation>(); | ||||||
| 			//StartupOperations.Enqueue(new WindowMonitorOperation(logger, windowMonitor)); | 
 | ||||||
| 			//StartupOperations.Enqueue(new ProcessMonitorOperation(logger, processMonitor)); | 			operations.Enqueue(new I18nOperation(logger, text)); | ||||||
| 			//StartupOperations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, Taskbar)); | 			operations.Enqueue(new RuntimeConnectionOperation(logger, runtimeProxy, Guid.Parse(args[3]))); | ||||||
| 			//StartupOperations.Enqueue(new TaskbarOperation(logger, settings.Taskbar, keyboardLayout, powerSupply, wirelessNetwork, systemInfo, Taskbar, text, uiFactory)); | 			operations.Enqueue(new ConfigurationOperation(configuration, logger, runtimeProxy)); | ||||||
| 			//StartupOperations.Enqueue(new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory)); | 			operations.Enqueue(new DelayedInitializationOperation(BuildCommunicationHostOperation)); | ||||||
| 			//StartupOperations.Enqueue(new ClientControllerOperation(clientController, logger)); | 			operations.Enqueue(new DelayedInitializationOperation(BuildKeyboardInterceptorOperation)); | ||||||
| 			//StartupOperations.Enqueue(new ClipboardOperation(logger, nativeMethods)); | 			operations.Enqueue(new WindowMonitorOperation(logger, windowMonitor)); | ||||||
| 			//StartupOperations.Enqueue(new MouseInterceptorOperation(logger, mouseInterceptor, nativeMethods)); | 			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 hasFourParameters = args?.Length == 4; | ||||||
| 			//var logFileWriter = new LogFileWriter(new DefaultLogFormatter(), settings.Logging.ClientLogFile); |  | ||||||
| 
 | 
 | ||||||
| 			//logFileWriter.Initialize(); | 			if (hasFourParameters) | ||||||
| 			//logger.Subscribe(logFileWriter); | 			{ | ||||||
|  | 				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 <logfile path> <host URI> <token>"); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		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; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -70,6 +70,9 @@ | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <Compile Include="App.cs" /> |     <Compile Include="App.cs" /> | ||||||
|     <Compile Include="Behaviour\ClientController.cs" /> |     <Compile Include="Behaviour\ClientController.cs" /> | ||||||
|  |     <Compile Include="Behaviour\Operations\ConfigurationOperation.cs" /> | ||||||
|  |     <Compile Include="Behaviour\Operations\RuntimeConnectionOperation.cs" /> | ||||||
|  |     <Compile Include="Communication\ClientHost.cs" /> | ||||||
|     <Compile Include="CompositionRoot.cs" /> |     <Compile Include="CompositionRoot.cs" /> | ||||||
|     <Compile Include="Notifications\AboutNotificationController.cs" /> |     <Compile Include="Notifications\AboutNotificationController.cs" /> | ||||||
|     <Compile Include="Notifications\AboutNotificationIconResource.cs" /> |     <Compile Include="Notifications\AboutNotificationIconResource.cs" /> | ||||||
|  | @ -78,7 +81,6 @@ | ||||||
|     <Compile Include="Notifications\LogNotificationIconResource.cs" /> |     <Compile Include="Notifications\LogNotificationIconResource.cs" /> | ||||||
|     <Compile Include="Notifications\LogNotificationInfo.cs" /> |     <Compile Include="Notifications\LogNotificationInfo.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\BrowserOperation.cs" /> |     <Compile Include="Behaviour\Operations\BrowserOperation.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\ClientControllerOperation.cs" /> |  | ||||||
|     <Compile Include="Behaviour\Operations\ClipboardOperation.cs" /> |     <Compile Include="Behaviour\Operations\ClipboardOperation.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\DisplayMonitorOperation.cs" /> |     <Compile Include="Behaviour\Operations\DisplayMonitorOperation.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\KeyboardInterceptorOperation.cs" /> |     <Compile Include="Behaviour\Operations\KeyboardInterceptorOperation.cs" /> | ||||||
|  |  | ||||||
							
								
								
									
										22
									
								
								SafeExamBrowser.Configuration/ClientConfiguration.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								SafeExamBrowser.Configuration/ClientConfiguration.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; } | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | @ -45,6 +45,16 @@ namespace SafeExamBrowser.Configuration | ||||||
| 			return sessionData; | 			return sessionData; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		public IClientConfiguration BuildClientConfiguration() | ||||||
|  | 		{ | ||||||
|  | 			return new ClientConfiguration | ||||||
|  | 			{ | ||||||
|  | 				RuntimeInfo = RuntimeInfo, | ||||||
|  | 				SessionData = CurrentSessionData, | ||||||
|  | 				Settings = CurrentSettings | ||||||
|  | 			}; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		public ISettings LoadSettings(Uri path) | 		public ISettings LoadSettings(Uri path) | ||||||
| 		{ | 		{ | ||||||
| 			// TODO | 			// TODO | ||||||
|  |  | ||||||
|  | @ -53,6 +53,7 @@ | ||||||
|     <Reference Include="Microsoft.CSharp" /> |     <Reference Include="Microsoft.CSharp" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|  |     <Compile Include="ClientConfiguration.cs" /> | ||||||
|     <Compile Include="RuntimeInfo.cs" /> |     <Compile Include="RuntimeInfo.cs" /> | ||||||
|     <Compile Include="SessionData.cs" /> |     <Compile Include="SessionData.cs" /> | ||||||
|     <Compile Include="Settings\BrowserSettings.cs" /> |     <Compile Include="Settings\BrowserSettings.cs" /> | ||||||
|  |  | ||||||
|  | @ -8,16 +8,17 @@ | ||||||
| 
 | 
 | ||||||
| namespace SafeExamBrowser.Contracts.Behaviour | namespace SafeExamBrowser.Contracts.Behaviour | ||||||
| { | { | ||||||
|  | 	// TODO: Interface really needed?! | ||||||
| 	public interface IClientController | 	public interface IClientController | ||||||
| 	{ | 	{ | ||||||
| 		/// <summary> | 		/// <summary> | ||||||
| 		/// Wires up and starts the application event handling. | 		/// Reverts any changes, releases all used resources and terminates the client. | ||||||
| 		/// </summary> | 		/// </summary> | ||||||
| 		void Start(); | 		void Terminate(); | ||||||
| 
 | 
 | ||||||
| 		/// <summary> | 		/// <summary> | ||||||
| 		/// Stops the event handling and removes all event subscriptions. | 		/// Tries to start the client. Returns <c>true</c> if successful, otherwise <c>false</c>. | ||||||
| 		/// </summary> | 		/// </summary> | ||||||
| 		void Stop(); | 		bool TryStart(); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace SafeExamBrowser.Contracts.Behaviour | namespace SafeExamBrowser.Contracts.Behaviour | ||||||
| { | { | ||||||
|  | 	// TODO: Interface really needed?! | ||||||
| 	public interface IRuntimeController | 	public interface IRuntimeController | ||||||
| 	{ | 	{ | ||||||
| 		/// <summary> | 		/// <summary> | ||||||
|  |  | ||||||
							
								
								
									
										15
									
								
								SafeExamBrowser.Contracts/Communication/IClientHost.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								SafeExamBrowser.Contracts/Communication/IClientHost.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -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? | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | @ -10,6 +10,6 @@ namespace SafeExamBrowser.Contracts.Communication | ||||||
| { | { | ||||||
| 	public interface IRuntimeHost : ICommunicationHost | 	public interface IRuntimeHost : ICommunicationHost | ||||||
| 	{ | 	{ | ||||||
| 
 | 		// TODO: Necessary? | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,11 +7,25 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| using System; | using System; | ||||||
|  | using SafeExamBrowser.Contracts.Configuration; | ||||||
| 
 | 
 | ||||||
| namespace SafeExamBrowser.Contracts.Communication | namespace SafeExamBrowser.Contracts.Communication | ||||||
| { | { | ||||||
| 	public interface IRuntimeProxy | 	public interface IRuntimeProxy | ||||||
| 	{ | 	{ | ||||||
|  | 		/// <summary> | ||||||
|  | 		/// Tries to establish a connection with the runtime host, utilizing the specified authentication token. | ||||||
|  | 		/// </summary> | ||||||
| 		bool Connect(Guid token); | 		bool Connect(Guid token); | ||||||
|  | 
 | ||||||
|  | 		/// <summary> | ||||||
|  | 		/// Disconnects from the runtime host. | ||||||
|  | 		/// </summary> | ||||||
|  | 		void Disconnect(); | ||||||
|  | 
 | ||||||
|  | 		/// <summary> | ||||||
|  | 		/// Retrieves the application configuration from the runtime host. | ||||||
|  | 		/// </summary> | ||||||
|  | 		IClientConfiguration GetConfiguration(); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -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 | ||||||
|  | 	{ | ||||||
|  | 		/// <summary> | ||||||
|  | 		/// The session data to be used by the client. | ||||||
|  | 		/// </summary> | ||||||
|  | 		ISessionData SessionData { get; set; } | ||||||
|  | 
 | ||||||
|  | 		/// <summary> | ||||||
|  | 		/// The application settings to be used by the client. | ||||||
|  | 		/// </summary> | ||||||
|  | 		ISettings Settings { get; set; } | ||||||
|  | 
 | ||||||
|  | 		/// <summary> | ||||||
|  | 		/// The information about the current runtime. | ||||||
|  | 		/// </summary> | ||||||
|  | 		IRuntimeInfo RuntimeInfo { get; set; } | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | @ -30,6 +30,11 @@ namespace SafeExamBrowser.Contracts.Configuration | ||||||
| 		/// </summary> | 		/// </summary> | ||||||
| 		IRuntimeInfo RuntimeInfo { get; } | 		IRuntimeInfo RuntimeInfo { get; } | ||||||
| 
 | 
 | ||||||
|  | 		/// <summary> | ||||||
|  | 		/// Builds a configuration for the client component, given the currently loaded settings, session data and runtime information. | ||||||
|  | 		/// </summary> | ||||||
|  | 		IClientConfiguration BuildClientConfiguration(); | ||||||
|  | 
 | ||||||
| 		/// <summary> | 		/// <summary> | ||||||
| 		/// Initializes all relevant data for a new session. | 		/// Initializes all relevant data for a new session. | ||||||
| 		/// </summary> | 		/// </summary> | ||||||
|  |  | ||||||
|  | @ -27,12 +27,14 @@ namespace SafeExamBrowser.Contracts.I18n | ||||||
| 		MessageBox_StartupErrorTitle, | 		MessageBox_StartupErrorTitle, | ||||||
| 		Notification_AboutTooltip, | 		Notification_AboutTooltip, | ||||||
| 		Notification_LogTooltip, | 		Notification_LogTooltip, | ||||||
|  | 		ProgressIndicator_CloseRuntimeConnection, | ||||||
| 		ProgressIndicator_CloseServiceConnection, | 		ProgressIndicator_CloseServiceConnection, | ||||||
| 		ProgressIndicator_EmptyClipboard, | 		ProgressIndicator_EmptyClipboard, | ||||||
| 		ProgressIndicator_InitializeBrowser, | 		ProgressIndicator_InitializeBrowser, | ||||||
| 		ProgressIndicator_InitializeConfiguration, | 		ProgressIndicator_InitializeConfiguration, | ||||||
| 		ProgressIndicator_InitializeKioskMode, | 		ProgressIndicator_InitializeKioskMode, | ||||||
| 		ProgressIndicator_InitializeProcessMonitoring, | 		ProgressIndicator_InitializeProcessMonitoring, | ||||||
|  | 		ProgressIndicator_InitializeRuntimeConnection, | ||||||
| 		ProgressIndicator_InitializeServiceConnection, | 		ProgressIndicator_InitializeServiceConnection, | ||||||
| 		ProgressIndicator_InitializeTaskbar, | 		ProgressIndicator_InitializeTaskbar, | ||||||
| 		ProgressIndicator_InitializeWindowMonitoring, | 		ProgressIndicator_InitializeWindowMonitoring, | ||||||
|  |  | ||||||
|  | @ -56,6 +56,7 @@ | ||||||
|     <Compile Include="Behaviour\IApplicationController.cs" /> |     <Compile Include="Behaviour\IApplicationController.cs" /> | ||||||
|     <Compile Include="Behaviour\IRuntimeController.cs" /> |     <Compile Include="Behaviour\IRuntimeController.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\IOperationSequence.cs" /> |     <Compile Include="Behaviour\Operations\IOperationSequence.cs" /> | ||||||
|  |     <Compile Include="Communication\IClientHost.cs" /> | ||||||
|     <Compile Include="Communication\ICommunication.cs" /> |     <Compile Include="Communication\ICommunication.cs" /> | ||||||
|     <Compile Include="Communication\IClientProxy.cs" /> |     <Compile Include="Communication\IClientProxy.cs" /> | ||||||
|     <Compile Include="Communication\ICommunicationHost.cs" /> |     <Compile Include="Communication\ICommunicationHost.cs" /> | ||||||
|  | @ -65,6 +66,7 @@ | ||||||
|     <Compile Include="Communication\Messages\IMessage.cs" /> |     <Compile Include="Communication\Messages\IMessage.cs" /> | ||||||
|     <Compile Include="Communication\Responses\IResponse.cs" /> |     <Compile Include="Communication\Responses\IResponse.cs" /> | ||||||
|     <Compile Include="Communication\Responses\IConnectResponse.cs" /> |     <Compile Include="Communication\Responses\IConnectResponse.cs" /> | ||||||
|  |     <Compile Include="Configuration\IClientConfiguration.cs" /> | ||||||
|     <Compile Include="Configuration\IRuntimeInfo.cs" /> |     <Compile Include="Configuration\IRuntimeInfo.cs" /> | ||||||
|     <Compile Include="Configuration\ISessionData.cs" /> |     <Compile Include="Configuration\ISessionData.cs" /> | ||||||
|     <Compile Include="Configuration\Settings\ConfigurationMode.cs" /> |     <Compile Include="Configuration\Settings\ConfigurationMode.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(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | @ -79,6 +79,7 @@ | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <Compile Include="Behaviour\Operations\CommunicationOperationTests.cs" /> |     <Compile Include="Behaviour\Operations\CommunicationOperationTests.cs" /> | ||||||
|  |     <Compile Include="Behaviour\Operations\DelayedInitializationOperationTests.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\I18nOperationTests.cs" /> |     <Compile Include="Behaviour\Operations\I18nOperationTests.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\OperationSequenceTests.cs" /> |     <Compile Include="Behaviour\Operations\OperationSequenceTests.cs" /> | ||||||
|     <Compile Include="I18n\TextTests.cs" /> |     <Compile Include="I18n\TextTests.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<IOperation> initialize; | ||||||
|  | 		private IOperation operation; | ||||||
|  | 
 | ||||||
|  | 		public bool Abort { get; set; } | ||||||
|  | 		public IProgressIndicator ProgressIndicator { get; set; } | ||||||
|  | 
 | ||||||
|  | 		public DelayedInitializationOperation(Func<IOperation> 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(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										41
									
								
								SafeExamBrowser.Core/Communication/RuntimeProxy.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								SafeExamBrowser.Core/Communication/RuntimeProxy.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -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(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | @ -36,6 +36,9 @@ | ||||||
|   <Entry key="Notification_LogTooltip"> |   <Entry key="Notification_LogTooltip"> | ||||||
|     Application Log |     Application Log | ||||||
|   </Entry> |   </Entry> | ||||||
|  |   <Entry key="ProgressIndicator_CloseRuntimeConnection"> | ||||||
|  |     Closing runtime connection | ||||||
|  |   </Entry> | ||||||
|   <Entry key="ProgressIndicator_CloseServiceConnection"> |   <Entry key="ProgressIndicator_CloseServiceConnection"> | ||||||
|     Closing service connection |     Closing service connection | ||||||
|   </Entry> |   </Entry> | ||||||
|  | @ -54,6 +57,9 @@ | ||||||
|   <Entry key="ProgressIndicator_InitializeProcessMonitoring"> |   <Entry key="ProgressIndicator_InitializeProcessMonitoring"> | ||||||
|     Initializing process monitoring |     Initializing process monitoring | ||||||
|   </Entry> |   </Entry> | ||||||
|  |   <Entry key="ProgressIndicator_InitializeRuntimeConnection"> | ||||||
|  |     Initializing runtime connection | ||||||
|  |   </Entry> | ||||||
|   <Entry key="ProgressIndicator_InitializeServiceConnection"> |   <Entry key="ProgressIndicator_InitializeServiceConnection"> | ||||||
|     Initializing service connection |     Initializing service connection | ||||||
|   </Entry> |   </Entry> | ||||||
|  |  | ||||||
|  | @ -56,11 +56,13 @@ | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <Compile Include="Behaviour\Operations\CommunicationOperation.cs" /> |     <Compile Include="Behaviour\Operations\CommunicationOperation.cs" /> | ||||||
|  |     <Compile Include="Behaviour\Operations\DelayedInitializationOperation.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\I18nOperation.cs" /> |     <Compile Include="Behaviour\Operations\I18nOperation.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\OperationSequence.cs" /> |     <Compile Include="Behaviour\Operations\OperationSequence.cs" /> | ||||||
|     <Compile Include="Communication\BaseProxy.cs" /> |     <Compile Include="Communication\BaseProxy.cs" /> | ||||||
|     <Compile Include="Communication\BaseHost.cs" /> |     <Compile Include="Communication\BaseHost.cs" /> | ||||||
|     <Compile Include="Communication\Messages\Message.cs" /> |     <Compile Include="Communication\Messages\Message.cs" /> | ||||||
|  |     <Compile Include="Communication\RuntimeProxy.cs" /> | ||||||
|     <Compile Include="Communication\ServiceProxy.cs" /> |     <Compile Include="Communication\ServiceProxy.cs" /> | ||||||
|     <Compile Include="Logging\DefaultLogFormatter.cs" /> |     <Compile Include="Logging\DefaultLogFormatter.cs" /> | ||||||
|     <Compile Include="Logging\LogFileWriter.cs" /> |     <Compile Include="Logging\LogFileWriter.cs" /> | ||||||
|  |  | ||||||
|  | @ -20,14 +20,14 @@ using SafeExamBrowser.Runtime.Behaviour.Operations; | ||||||
| namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations | namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations | ||||||
| { | { | ||||||
| 	[TestClass] | 	[TestClass] | ||||||
| 	public class ServiceOperationTests | 	public class ServiceConnectionOperationTests | ||||||
| 	{ | 	{ | ||||||
| 		private Mock<ILogger> logger; | 		private Mock<ILogger> logger; | ||||||
| 		private Mock<IServiceProxy> service; | 		private Mock<IServiceProxy> service; | ||||||
| 		private Mock<IConfigurationRepository> configuration; | 		private Mock<IConfigurationRepository> configuration; | ||||||
| 		private Mock<IProgressIndicator> progressIndicator; | 		private Mock<IProgressIndicator> progressIndicator; | ||||||
| 		private Mock<IText> text; | 		private Mock<IText> text; | ||||||
| 		private ServiceOperation sut; | 		private ServiceConnectionOperation sut; | ||||||
| 
 | 
 | ||||||
| 		[TestInitialize] | 		[TestInitialize] | ||||||
| 		public void Initialize() | 		public void Initialize() | ||||||
|  | @ -38,7 +38,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations | ||||||
| 			progressIndicator = new Mock<IProgressIndicator>(); | 			progressIndicator = new Mock<IProgressIndicator>(); | ||||||
| 			text = new Mock<IText>(); | 			text = new Mock<IText>(); | ||||||
| 
 | 
 | ||||||
| 			sut = new ServiceOperation(configuration.Object, logger.Object, service.Object, text.Object); | 			sut = new ServiceConnectionOperation(configuration.Object, logger.Object, service.Object, text.Object); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		[TestMethod] | 		[TestMethod] | ||||||
|  | @ -82,7 +82,7 @@ | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <Compile Include="Behaviour\Operations\ConfigurationOperationTests.cs" /> |     <Compile Include="Behaviour\Operations\ConfigurationOperationTests.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\KioskModeOperationTests.cs" /> |     <Compile Include="Behaviour\Operations\KioskModeOperationTests.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\ServiceOperationTests.cs" /> |     <Compile Include="Behaviour\Operations\ServiceConnectionOperationTests.cs" /> | ||||||
|     <Compile Include="Behaviour\RuntimeControllerTests.cs" /> |     <Compile Include="Behaviour\RuntimeControllerTests.cs" /> | ||||||
|     <Compile Include="Properties\AssemblyInfo.cs" /> |     <Compile Include="Properties\AssemblyInfo.cs" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|  | @ -17,10 +17,9 @@ using SafeExamBrowser.Contracts.UserInterface; | ||||||
| 
 | 
 | ||||||
| namespace SafeExamBrowser.Runtime.Behaviour.Operations | namespace SafeExamBrowser.Runtime.Behaviour.Operations | ||||||
| { | { | ||||||
| 	internal class ServiceOperation : IOperation | 	internal class ServiceConnectionOperation : IOperation | ||||||
| 	{ | 	{ | ||||||
| 		private bool serviceAvailable; | 		private bool connected, mandatory; | ||||||
| 		private bool serviceMandatory; |  | ||||||
| 		private IConfigurationRepository configuration; | 		private IConfigurationRepository configuration; | ||||||
| 		private ILogger logger; | 		private ILogger logger; | ||||||
| 		private IServiceProxy service; | 		private IServiceProxy service; | ||||||
|  | @ -29,7 +28,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations | ||||||
| 		public bool Abort { get; private set; } | 		public bool Abort { get; private set; } | ||||||
| 		public IProgressIndicator ProgressIndicator { private get; 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.configuration = configuration; | ||||||
| 			this.service = service; | 			this.service = service; | ||||||
|  | @ -44,23 +43,23 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations | ||||||
| 
 | 
 | ||||||
| 			try | 			try | ||||||
| 			{ | 			{ | ||||||
| 				serviceMandatory = configuration.CurrentSettings.ServicePolicy == ServicePolicy.Mandatory; | 				mandatory = configuration.CurrentSettings.ServicePolicy == ServicePolicy.Mandatory; | ||||||
| 				serviceAvailable = service.Connect(); | 				connected = service.Connect(); | ||||||
| 			} | 			} | ||||||
| 			catch (Exception e) | 			catch (Exception e) | ||||||
| 			{ | 			{ | ||||||
| 				LogException(e); | 				LogException(e); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			if (serviceMandatory && !serviceAvailable) | 			if (mandatory && !connected) | ||||||
| 			{ | 			{ | ||||||
| 				Abort = true; | 				Abort = true; | ||||||
| 				logger.Info("Aborting startup because the service is mandatory but not available!"); | 				logger.Info("Aborting startup because the service is mandatory but not available!"); | ||||||
| 			} | 			} | ||||||
| 			else | 			else | ||||||
| 			{ | 			{ | ||||||
| 				service.Ignore = !serviceAvailable; | 				service.Ignore = !connected; | ||||||
| 				logger.Info($"The service is {(serviceMandatory ? "mandatory" : "optional")} and {(serviceAvailable ? "available." : "not available. All service-related operations will be ignored!")}"); | 				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..."); | 			logger.Info("Closing service connection..."); | ||||||
| 			ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_CloseServiceConnection); | 			ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_CloseServiceConnection); | ||||||
| 
 | 
 | ||||||
| 			if (serviceAvailable) | 			if (connected) | ||||||
| 			{ | 			{ | ||||||
| 				try | 				try | ||||||
| 				{ | 				{ | ||||||
|  | @ -82,7 +81,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations | ||||||
| 				} | 				} | ||||||
| 				catch (Exception e) | 				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!"; | 			var message = "Failed to connect to the service component!"; | ||||||
| 
 | 
 | ||||||
| 			if (serviceMandatory) | 			if (mandatory) | ||||||
| 			{ | 			{ | ||||||
| 				logger.Error(message, e); | 				logger.Error(message, e); | ||||||
| 			} | 			} | ||||||
|  | @ -17,7 +17,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations | ||||||
| { | { | ||||||
| 	internal abstract class SessionSequenceOperation : IOperation | 	internal abstract class SessionSequenceOperation : IOperation | ||||||
| 	{ | 	{ | ||||||
| 		private bool sessionInitialized; | 		private bool sessionRunning; | ||||||
| 		private IConfigurationRepository configuration; | 		private IConfigurationRepository configuration; | ||||||
| 		private ILogger logger; | 		private ILogger logger; | ||||||
| 		private IServiceProxy serviceProxy; | 		private IServiceProxy serviceProxy; | ||||||
|  | @ -50,13 +50,13 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations | ||||||
| 			// - Verify session integrity and start event handling -> in runtime controller? | 			// - Verify session integrity and start event handling -> in runtime controller? | ||||||
| 			System.Threading.Thread.Sleep(5000); | 			System.Threading.Thread.Sleep(5000); | ||||||
| 
 | 
 | ||||||
| 			sessionInitialized = true; | 			sessionRunning = true; | ||||||
| 			logger.Info($"Successfully started new session with identifier '{sessionData.Id}'."); | 			logger.Info($"Successfully started new session with identifier '{sessionData.Id}'."); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		protected void StopSession() | 		protected void StopSession() | ||||||
| 		{ | 		{ | ||||||
| 			if (sessionInitialized) | 			if (sessionRunning) | ||||||
| 			{ | 			{ | ||||||
| 				logger.Info($"Stopping session with identifier '{sessionData.Id}'..."); | 				logger.Info($"Stopping session with identifier '{sessionData.Id}'..."); | ||||||
| 				ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_StopSession, true); | 				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? | 				// - Stop event handling and verify session termination -> in runtime controller? | ||||||
| 				System.Threading.Thread.Sleep(5000); | 				System.Threading.Thread.Sleep(5000); | ||||||
| 
 | 
 | ||||||
| 				sessionInitialized = false; | 				sessionRunning = false; | ||||||
| 				logger.Info($"Successfully stopped session with identifier '{sessionData.Id}'."); | 				logger.Info($"Successfully stopped session with identifier '{sessionData.Id}'."); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -59,7 +59,7 @@ namespace SafeExamBrowser.Runtime | ||||||
| 
 | 
 | ||||||
| 			sessionOperations.Enqueue(new SessionSequenceStartOperation(configuration, logger, serviceProxy)); | 			sessionOperations.Enqueue(new SessionSequenceStartOperation(configuration, logger, serviceProxy)); | ||||||
| 			sessionOperations.Enqueue(new ConfigurationOperation(configuration, logger, runtimeInfo, text, uiFactory, args)); | 			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 KioskModeOperation(logger, configuration)); | ||||||
| 			sessionOperations.Enqueue(new SessionSequenceEndOperation(configuration, logger, serviceProxy)); | 			sessionOperations.Enqueue(new SessionSequenceEndOperation(configuration, logger, serviceProxy)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -89,7 +89,7 @@ | ||||||
|     <Compile Include="App.cs" /> |     <Compile Include="App.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\ConfigurationOperation.cs" /> |     <Compile Include="Behaviour\Operations\ConfigurationOperation.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\KioskModeOperation.cs" /> |     <Compile Include="Behaviour\Operations\KioskModeOperation.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\ServiceOperation.cs" /> |     <Compile Include="Behaviour\Operations\ServiceConnectionOperation.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\SessionSequenceEndOperation.cs" /> |     <Compile Include="Behaviour\Operations\SessionSequenceEndOperation.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\SessionSequenceOperation.cs" /> |     <Compile Include="Behaviour\Operations\SessionSequenceOperation.cs" /> | ||||||
|     <Compile Include="Behaviour\Operations\SessionSequenceStartOperation.cs" /> |     <Compile Include="Behaviour\Operations\SessionSequenceStartOperation.cs" /> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 dbuechel
						dbuechel