diff --git a/SafeExamBrowser.Client.Contracts/IClientController.cs b/SafeExamBrowser.Client.Contracts/IClientController.cs index b9fe22b1..66c6502a 100644 --- a/SafeExamBrowser.Client.Contracts/IClientController.cs +++ b/SafeExamBrowser.Client.Contracts/IClientController.cs @@ -6,12 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using System; -using SafeExamBrowser.Browser.Contracts; -using SafeExamBrowser.Communication.Contracts.Hosts; -using SafeExamBrowser.Configuration.Contracts; -using SafeExamBrowser.Settings; - namespace SafeExamBrowser.Client.Contracts { /// @@ -19,31 +13,6 @@ namespace SafeExamBrowser.Client.Contracts /// public interface IClientController { - /// - /// The global configuration information to be used during application execution. - /// - AppConfig AppConfig { set; } - - /// - /// The browser application. - /// - IBrowserApplication Browser { set; } - - /// - /// The client host used for communication handling. - /// - IClientHost ClientHost { set; } - - /// - /// The session identifier of the currently running session. - /// - Guid SessionId { set; } - - /// - /// The settings to be used during application execution. - /// - AppSettings Settings { set; } - /// /// Reverts any changes, releases all used resources and terminates the client. /// @@ -53,5 +22,10 @@ namespace SafeExamBrowser.Client.Contracts /// Tries to start the client. Returns true if successful, otherwise false. /// bool TryStart(); + + /// + /// Instructs the controller to update the application configuration. + /// + void UpdateAppConfig(); } } diff --git a/SafeExamBrowser.Client.Contracts/SafeExamBrowser.Client.Contracts.csproj b/SafeExamBrowser.Client.Contracts/SafeExamBrowser.Client.Contracts.csproj index a91e9f5c..69930e32 100644 --- a/SafeExamBrowser.Client.Contracts/SafeExamBrowser.Client.Contracts.csproj +++ b/SafeExamBrowser.Client.Contracts/SafeExamBrowser.Client.Contracts.csproj @@ -59,26 +59,10 @@ - - {5fb5273d-277c-41dd-8593-a25ce1aff2e9} - SafeExamBrowser.Browser.Contracts - - - {0cd2c5fe-711a-4c32-afe0-bb804fe8b220} - SafeExamBrowser.Communication.Contracts - - - {7d74555e-63e1-4c46-bd0a-8580552368c8} - SafeExamBrowser.Configuration.Contracts - {fe0e1224-b447-4b14-81e7-ed7d84822aa0} SafeExamBrowser.Core.Contracts - - {30b2d907-5861-4f39-abad-c4abf1b3470e} - SafeExamBrowser.Settings - \ No newline at end of file diff --git a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs index 39206dba..c293bf1e 100644 --- a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs @@ -40,6 +40,7 @@ namespace SafeExamBrowser.Client.UnitTests private Mock applicationMonitor; private Mock browserController; private Mock clientHost; + private ClientContext context; private Mock displayMonitor; private Mock explorerShell; private Mock hashAlgorithm; @@ -65,6 +66,7 @@ namespace SafeExamBrowser.Client.UnitTests applicationMonitor = new Mock(); browserController = new Mock(); clientHost = new Mock(); + context = new ClientContext(); displayMonitor = new Mock(); explorerShell = new Mock(); hashAlgorithm = new Mock(); @@ -87,6 +89,7 @@ namespace SafeExamBrowser.Client.UnitTests sut = new ClientController( actionCenter.Object, applicationMonitor.Object, + context, displayMonitor.Object, explorerShell.Object, hashAlgorithm.Object, @@ -100,11 +103,11 @@ namespace SafeExamBrowser.Client.UnitTests text.Object, uiFactory.Object); - sut.AppConfig = appConfig; - sut.Browser = browserController.Object; - sut.ClientHost = clientHost.Object; - sut.SessionId = sessionId; - sut.Settings = settings; + context.AppConfig = appConfig; + context.Browser = browserController.Object; + context.ClientHost = clientHost.Object; + context.SessionId = sessionId; + context.Settings = settings; } [TestMethod] @@ -540,8 +543,8 @@ namespace SafeExamBrowser.Client.UnitTests [TestMethod] public void Shutdown_MustNotFailIfDependenciesAreNull() { - sut.Browser = null; - sut.ClientHost = null; + context.Browser = null; + context.ClientHost = null; sut.Terminate(); } @@ -591,7 +594,7 @@ namespace SafeExamBrowser.Client.UnitTests uiFactory.Setup(u => u.CreateSplashScreen(It.IsAny())).Returns(splashScreen.Object); sut.TryStart(); - sut.AppConfig = appConfig; + sut.UpdateAppConfig(); splashScreen.VerifySet(s => s.AppConfig = appConfig, Times.Once); } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs index 4437629b..acb181d8 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/BrowserOperationTests.cs @@ -8,7 +8,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using SafeExamBrowser.Applications.Contracts; +using SafeExamBrowser.Browser.Contracts; using SafeExamBrowser.Client.Operations; using SafeExamBrowser.Logging.Contracts; using SafeExamBrowser.UserInterface.Contracts; @@ -20,7 +20,8 @@ namespace SafeExamBrowser.Client.UnitTests.Operations public class BrowserOperationTests { private Mock actionCenter; - private Mock application; + private Mock browser; + private ClientContext context; private Mock logger; private Mock taskbar; private Mock uiFactory; @@ -31,12 +32,15 @@ namespace SafeExamBrowser.Client.UnitTests.Operations public void Initialize() { actionCenter = new Mock(); - application = new Mock(); + browser = new Mock(); + context = new ClientContext(); logger = new Mock(); taskbar = new Mock(); uiFactory = new Mock(); - sut = new BrowserOperation(actionCenter.Object, application.Object, logger.Object, taskbar.Object, uiFactory.Object); + context.Browser = browser.Object; + + sut = new BrowserOperation(actionCenter.Object, context, logger.Object, taskbar.Object, uiFactory.Object); } [TestMethod] @@ -44,7 +48,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations { sut.Perform(); - application.Verify(c => c.Initialize(), Times.Once); + browser.Verify(c => c.Initialize(), Times.Once); actionCenter.Verify(a => a.AddApplicationControl(It.IsAny()), Times.Once); taskbar.Verify(t => t.AddApplicationControl(It.IsAny()), Times.Once); } @@ -53,7 +57,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations public void MustRevertCorrectly() { sut.Revert(); - application.Verify(c => c.Terminate(), Times.Once); + browser.Verify(c => c.Terminate(), Times.Once); } } } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/ClientHostDisconnectionOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/ClientHostDisconnectionOperationTests.cs index a1002715..7c1971de 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/ClientHostDisconnectionOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/ClientHostDisconnectionOperationTests.cs @@ -7,7 +7,6 @@ */ using System; -using System.Diagnostics; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -22,6 +21,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations public class ClientHostDisconnectionOperationTests { private Mock clientHost; + private ClientContext context; private Mock logger; private ClientHostDisconnectionOperation sut; @@ -30,9 +30,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations public void Initialize() { clientHost = new Mock(); + context = new ClientContext(); logger = new Mock(); - sut = new ClientHostDisconnectionOperation(clientHost.Object, logger.Object, 0); + context.ClientHost = clientHost.Object; + + sut = new ClientHostDisconnectionOperation(context, logger.Object, 0); } [TestMethod] @@ -42,7 +45,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations var before = default(DateTime); var timeout_ms = 200; - sut = new ClientHostDisconnectionOperation(clientHost.Object, logger.Object, timeout_ms); + sut = new ClientHostDisconnectionOperation(context, logger.Object, timeout_ms); clientHost.SetupGet(h => h.IsConnected).Returns(true).Callback(() => Task.Delay(10).ContinueWith((_) => { @@ -66,7 +69,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations var before = default(DateTime); var timeout_ms = 200; - sut = new ClientHostDisconnectionOperation(clientHost.Object, logger.Object, timeout_ms); + sut = new ClientHostDisconnectionOperation(context, logger.Object, timeout_ms); clientHost.SetupGet(h => h.IsConnected).Returns(true); diff --git a/SafeExamBrowser.Client.UnitTests/Operations/ClipboardOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/ClipboardOperationTests.cs index bf6dd161..4c7e34ca 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/ClipboardOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/ClipboardOperationTests.cs @@ -17,6 +17,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestClass] public class ClipboardOperationTests { + private ClientContext context; private Mock loggerMock; private Mock nativeMethodsMock; @@ -25,10 +26,11 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestInitialize] public void Initialize() { + context = new ClientContext(); loggerMock = new Mock(); nativeMethodsMock = new Mock(); - sut = new ClipboardOperation(loggerMock.Object, nativeMethodsMock.Object); + sut = new ClipboardOperation(context, loggerMock.Object, nativeMethodsMock.Object); } [TestMethod] diff --git a/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs index 20cfd1a8..436e1945 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/ConfigurationOperationTests.cs @@ -22,7 +22,6 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestClass] public class ConfigurationOperationTests { - private ClientConfiguration configuration; private ClientContext context; private Mock logger; private Mock runtime; @@ -31,12 +30,11 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestInitialize] public void Initialize() { - configuration = new ClientConfiguration(); context = new ClientContext(); logger = new Mock(); runtime = new Mock(); - sut = new ConfigurationOperation(configuration, context, logger.Object, runtime.Object); + sut = new ConfigurationOperation(context, logger.Object, runtime.Object); } [TestMethod] @@ -56,9 +54,9 @@ namespace SafeExamBrowser.Client.UnitTests.Operations var result = sut.Perform(); - Assert.AreSame(configuration.AppConfig, response.Configuration.AppConfig); - Assert.AreEqual(configuration.SessionId, response.Configuration.SessionId); - Assert.AreSame(configuration.Settings, response.Configuration.Settings); + Assert.AreSame(context.AppConfig, response.Configuration.AppConfig); + Assert.AreEqual(context.SessionId, response.Configuration.SessionId); + Assert.AreSame(context.Settings, response.Configuration.Settings); Assert.AreEqual(OperationResult.Success, result); } diff --git a/SafeExamBrowser.Client.UnitTests/Operations/DisplayMonitorOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/DisplayMonitorOperationTests.cs index bcbc722b..eee72d81 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/DisplayMonitorOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/DisplayMonitorOperationTests.cs @@ -18,6 +18,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestClass] public class DisplayMonitorOperationTests { + private ClientContext context; private Mock displayMonitorMock; private Mock loggerMock; private Mock taskbarMock; @@ -27,11 +28,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestInitialize] public void Initialize() { - loggerMock = new Mock(); + context = new ClientContext(); displayMonitorMock = new Mock(); + loggerMock = new Mock(); taskbarMock = new Mock(); - sut = new DisplayMonitorOperation(displayMonitorMock.Object, loggerMock.Object, taskbarMock.Object); + sut = new DisplayMonitorOperation(context, displayMonitorMock.Object, loggerMock.Object, taskbarMock.Object); } [TestMethod] diff --git a/SafeExamBrowser.Client.UnitTests/Operations/KeyboardInterceptorOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/KeyboardInterceptorOperationTests.cs index b1181644..ddaecd49 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/KeyboardInterceptorOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/KeyboardInterceptorOperationTests.cs @@ -17,6 +17,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestClass] public class KeyboardInterceptorOperationTests { + private ClientContext context; private Mock keyboardInterceptorMock; private Mock loggerMock; @@ -25,10 +26,11 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestInitialize] public void Initialize() { + context = new ClientContext(); keyboardInterceptorMock = new Mock(); loggerMock = new Mock(); - sut = new KeyboardInterceptorOperation(keyboardInterceptorMock.Object, loggerMock.Object); + sut = new KeyboardInterceptorOperation(context, keyboardInterceptorMock.Object, loggerMock.Object); } [TestMethod] diff --git a/SafeExamBrowser.Client.UnitTests/Operations/MouseInterceptorOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/MouseInterceptorOperationTests.cs index 89505bb3..e7716fea 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/MouseInterceptorOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/MouseInterceptorOperationTests.cs @@ -17,6 +17,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestClass] public class MouseInterceptorOperationTests { + private ClientContext context; private Mock mouseInterceptorMock; private Mock loggerMock; @@ -25,10 +26,11 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestInitialize] public void Initialize() { + context = new ClientContext(); mouseInterceptorMock = new Mock(); loggerMock = new Mock(); - sut = new MouseInterceptorOperation(loggerMock.Object, mouseInterceptorMock.Object); + sut = new MouseInterceptorOperation(context, loggerMock.Object, mouseInterceptorMock.Object); } [TestMethod] diff --git a/SafeExamBrowser.Client.UnitTests/Operations/RuntimeConnectionOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/RuntimeConnectionOperationTests.cs index 5bafc65e..66881a8b 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/RuntimeConnectionOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/RuntimeConnectionOperationTests.cs @@ -19,6 +19,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestClass] public class RuntimeConnectionOperationTests { + private ClientContext context; private Mock logger; private Mock runtime; private Guid token; @@ -27,11 +28,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestInitialize] public void Initialize() { + context = new ClientContext(); logger = new Mock(); runtime = new Mock(); token = Guid.NewGuid(); - sut = new RuntimeConnectionOperation(logger.Object, runtime.Object, token); + sut = new RuntimeConnectionOperation(context, logger.Object, runtime.Object, token); } [TestMethod] diff --git a/SafeExamBrowser.Client.UnitTests/Operations/ShellOperationTests.cs b/SafeExamBrowser.Client.UnitTests/Operations/ShellOperationTests.cs index d29de61e..fa81b364 100644 --- a/SafeExamBrowser.Client.UnitTests/Operations/ShellOperationTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Operations/ShellOperationTests.cs @@ -11,9 +11,9 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using SafeExamBrowser.Client.Contracts; using SafeExamBrowser.Client.Operations; -using SafeExamBrowser.Settings.UserInterface; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.Logging.Contracts; +using SafeExamBrowser.Settings; using SafeExamBrowser.SystemComponents.Contracts; using SafeExamBrowser.SystemComponents.Contracts.Audio; using SafeExamBrowser.SystemComponents.Contracts.Keyboard; @@ -30,10 +30,9 @@ namespace SafeExamBrowser.Client.UnitTests.Operations { private Mock actionCenter; private List activators; - private ActionCenterSettings actionCenterSettings; private Mock audio; + private ClientContext context; private Mock logger; - private TaskbarSettings taskbarSettings; private Mock terminationActivator; private Mock aboutInfo; private Mock aboutController; @@ -54,8 +53,8 @@ namespace SafeExamBrowser.Client.UnitTests.Operations { actionCenter = new Mock(); activators = new List(); - actionCenterSettings = new ActionCenterSettings(); audio = new Mock(); + context = new ClientContext(); logger = new Mock(); aboutInfo = new Mock(); aboutController = new Mock(); @@ -65,12 +64,13 @@ namespace SafeExamBrowser.Client.UnitTests.Operations powerSupply = new Mock(); systemInfo = new Mock(); taskbar = new Mock(); - taskbarSettings = new TaskbarSettings(); terminationActivator = new Mock(); text = new Mock(); uiFactory = new Mock(); wirelessAdapter = new Mock(); + context.Settings = new AppSettings(); + uiFactory .Setup(u => u.CreateNotificationControl(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new Mock().Object); @@ -78,10 +78,10 @@ namespace SafeExamBrowser.Client.UnitTests.Operations sut = new ShellOperation( actionCenter.Object, activators, - actionCenterSettings, audio.Object, aboutInfo.Object, aboutController.Object, + context, keyboard.Object, logger.Object, logInfo.Object, @@ -89,7 +89,6 @@ namespace SafeExamBrowser.Client.UnitTests.Operations powerSupply.Object, systemInfo.Object, taskbar.Object, - taskbarSettings, terminationActivator.Object, text.Object, uiFactory.Object, @@ -106,7 +105,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations new Mock() }; - actionCenterSettings.EnableActionCenter = true; + context.Settings.ActionCenter.EnableActionCenter = true; foreach (var activator in activatorMocks) { @@ -126,10 +125,10 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestMethod] public void Perform_MustInitializeClock() { - actionCenterSettings.EnableActionCenter = true; - actionCenterSettings.ShowClock = true; - taskbarSettings.EnableTaskbar = true; - taskbarSettings.ShowClock = true; + context.Settings.ActionCenter.EnableActionCenter = true; + context.Settings.ActionCenter.ShowClock = true; + context.Settings.Taskbar.EnableTaskbar = true; + context.Settings.Taskbar.ShowClock = true; sut.Perform(); @@ -140,10 +139,10 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestMethod] public void Perform_MustNotInitializeClock() { - actionCenterSettings.EnableActionCenter = true; - actionCenterSettings.ShowClock = false; - taskbarSettings.EnableTaskbar = true; - taskbarSettings.ShowClock = false; + context.Settings.ActionCenter.EnableActionCenter = true; + context.Settings.ActionCenter.ShowClock = false; + context.Settings.Taskbar.EnableTaskbar = true; + context.Settings.Taskbar.ShowClock = false; sut.Perform(); @@ -154,12 +153,12 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestMethod] public void Perform_MustInitializeNotifications() { - actionCenterSettings.EnableActionCenter = true; - actionCenterSettings.ShowApplicationInfo = true; - actionCenterSettings.ShowApplicationLog = true; - taskbarSettings.EnableTaskbar = true; - taskbarSettings.ShowApplicationInfo = true; - taskbarSettings.ShowApplicationLog = true; + context.Settings.ActionCenter.EnableActionCenter = true; + context.Settings.ActionCenter.ShowApplicationInfo = true; + context.Settings.ActionCenter.ShowApplicationLog = true; + context.Settings.Taskbar.EnableTaskbar = true; + context.Settings.Taskbar.ShowApplicationInfo = true; + context.Settings.Taskbar.ShowApplicationLog = true; sut.Perform(); @@ -172,10 +171,10 @@ namespace SafeExamBrowser.Client.UnitTests.Operations { var logControl = new Mock(); - actionCenterSettings.EnableActionCenter = true; - actionCenterSettings.ShowApplicationLog = false; - taskbarSettings.EnableTaskbar = true; - taskbarSettings.ShowApplicationLog = false; + context.Settings.ActionCenter.EnableActionCenter = true; + context.Settings.ActionCenter.ShowApplicationLog = false; + context.Settings.Taskbar.EnableTaskbar = true; + context.Settings.Taskbar.ShowApplicationLog = false; uiFactory .Setup(f => f.CreateNotificationControl(It.IsAny(), It.Is(i => i == logInfo.Object), It.IsAny())) @@ -190,14 +189,14 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestMethod] public void Perform_MustInitializeSystemComponents() { - actionCenterSettings.EnableActionCenter = true; - actionCenterSettings.ShowAudio = true; - actionCenterSettings.ShowKeyboardLayout = true; - actionCenterSettings.ShowWirelessNetwork = true; - taskbarSettings.EnableTaskbar = true; - taskbarSettings.ShowAudio = true; - taskbarSettings.ShowKeyboardLayout = true; - taskbarSettings.ShowWirelessNetwork = true; + context.Settings.ActionCenter.EnableActionCenter = true; + context.Settings.ActionCenter.ShowAudio = true; + context.Settings.ActionCenter.ShowKeyboardLayout = true; + context.Settings.ActionCenter.ShowWirelessNetwork = true; + context.Settings.Taskbar.EnableTaskbar = true; + context.Settings.Taskbar.ShowAudio = true; + context.Settings.Taskbar.ShowKeyboardLayout = true; + context.Settings.Taskbar.ShowWirelessNetwork = true; systemInfo.SetupGet(s => s.HasBattery).Returns(true); uiFactory.Setup(f => f.CreateAudioControl(It.IsAny(), It.IsAny())).Returns(new Mock().Object); @@ -218,14 +217,14 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestMethod] public void Perform_MustNotInitializeSystemComponents() { - actionCenterSettings.EnableActionCenter = true; - actionCenterSettings.ShowAudio = false; - actionCenterSettings.ShowKeyboardLayout = false; - actionCenterSettings.ShowWirelessNetwork = false; - taskbarSettings.EnableTaskbar = true; - taskbarSettings.ShowAudio = false; - taskbarSettings.ShowKeyboardLayout = false; - taskbarSettings.ShowWirelessNetwork = false; + context.Settings.ActionCenter.EnableActionCenter = true; + context.Settings.ActionCenter.ShowAudio = false; + context.Settings.ActionCenter.ShowKeyboardLayout = false; + context.Settings.ActionCenter.ShowWirelessNetwork = false; + context.Settings.Taskbar.EnableTaskbar = true; + context.Settings.Taskbar.ShowAudio = false; + context.Settings.Taskbar.ShowKeyboardLayout = false; + context.Settings.Taskbar.ShowWirelessNetwork = false; systemInfo.SetupGet(s => s.HasBattery).Returns(false); uiFactory.Setup(f => f.CreateAudioControl(It.IsAny(), It.IsAny())).Returns(new Mock().Object); @@ -246,7 +245,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestMethod] public void Perform_MustNotInitializeActionCenterIfNotEnabled() { - actionCenterSettings.EnableActionCenter = false; + context.Settings.ActionCenter.EnableActionCenter = false; sut.Perform(); actionCenter.VerifyNoOtherCalls(); } @@ -254,7 +253,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations [TestMethod] public void Perform_MustNotInitializeTaskbarIfNotEnabled() { - taskbarSettings.EnableTaskbar = false; + context.Settings.Taskbar.EnableTaskbar = false; sut.Perform(); taskbar.VerifyNoOtherCalls(); } @@ -269,7 +268,7 @@ namespace SafeExamBrowser.Client.UnitTests.Operations new Mock() }; - actionCenterSettings.EnableActionCenter = true; + context.Settings.ActionCenter.EnableActionCenter = true; foreach (var activator in activatorMocks) { diff --git a/SafeExamBrowser.Client/ClientContext.cs b/SafeExamBrowser.Client/ClientContext.cs index f780b278..e729521f 100644 --- a/SafeExamBrowser.Client/ClientContext.cs +++ b/SafeExamBrowser.Client/ClientContext.cs @@ -6,13 +6,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; +using SafeExamBrowser.Browser.Contracts; +using SafeExamBrowser.Communication.Contracts.Hosts; using SafeExamBrowser.Configuration.Contracts; using SafeExamBrowser.Settings; namespace SafeExamBrowser.Client { /// - /// Holds all configuration and runtime data for the client. + /// Holds all configuration and session data for the client. /// internal class ClientContext { @@ -21,6 +24,21 @@ namespace SafeExamBrowser.Client /// internal AppConfig AppConfig { get; set; } + /// + /// The browser application. + /// + internal IBrowserApplication Browser { get; set; } + + /// + /// The client communication host. + /// + internal IClientHost ClientHost { get; set; } + + /// + /// The identifier of the current session. + /// + internal Guid SessionId { get; set; } + /// /// The settings for the current session. /// diff --git a/SafeExamBrowser.Client/ClientController.cs b/SafeExamBrowser.Client/ClientController.cs index 2d278072..122a7229 100644 --- a/SafeExamBrowser.Client/ClientController.cs +++ b/SafeExamBrowser.Client/ClientController.cs @@ -15,7 +15,6 @@ using SafeExamBrowser.Communication.Contracts.Data; using SafeExamBrowser.Communication.Contracts.Events; using SafeExamBrowser.Communication.Contracts.Hosts; using SafeExamBrowser.Communication.Contracts.Proxies; -using SafeExamBrowser.Configuration.Contracts; using SafeExamBrowser.Configuration.Contracts.Cryptography; using SafeExamBrowser.Core.Contracts.OperationModel; using SafeExamBrowser.Core.Contracts.OperationModel.Events; @@ -36,6 +35,7 @@ namespace SafeExamBrowser.Client { private IActionCenter actionCenter; private IApplicationMonitor applicationMonitor; + private ClientContext context; private IDisplayMonitor displayMonitor; private IExplorerShell explorerShell; private IHashAlgorithm hashAlgorithm; @@ -49,29 +49,15 @@ namespace SafeExamBrowser.Client private ITerminationActivator terminationActivator; private IText text; private IUserInterfaceFactory uiFactory; - private AppConfig appConfig; - public IBrowserApplication Browser { private get; set; } - public IClientHost ClientHost { private get; set; } - public Guid SessionId { private get; set; } - public AppSettings Settings { private get; set; } - - public AppConfig AppConfig - { - set - { - appConfig = value; - - if (splashScreen != null) - { - splashScreen.AppConfig = value; - } - } - } + private IBrowserApplication Browser => context.Browser; + private IClientHost ClientHost => context.ClientHost; + private AppSettings Settings => context.Settings; public ClientController( IActionCenter actionCenter, IApplicationMonitor applicationMonitor, + ClientContext context, IDisplayMonitor displayMonitor, IExplorerShell explorerShell, IHashAlgorithm hashAlgorithm, @@ -87,6 +73,7 @@ namespace SafeExamBrowser.Client { this.actionCenter = actionCenter; this.applicationMonitor = applicationMonitor; + this.context = context; this.displayMonitor = displayMonitor; this.explorerShell = explorerShell; this.hashAlgorithm = hashAlgorithm; @@ -147,7 +134,7 @@ namespace SafeExamBrowser.Client logger.Log(string.Empty); logger.Info("Initiating shutdown procedure..."); - splashScreen = uiFactory.CreateSplashScreen(appConfig); + splashScreen = uiFactory.CreateSplashScreen(context.AppConfig); actionCenter.Close(); taskbar.Close(); @@ -169,6 +156,14 @@ namespace SafeExamBrowser.Client splashScreen.Close(); } + public void UpdateAppConfig() + { + if (splashScreen != null) + { + splashScreen.AppConfig = context.AppConfig; + } + } + private void RegisterEvents() { actionCenter.QuitButtonClicked += Shell_QuitButtonClicked; @@ -239,7 +234,7 @@ namespace SafeExamBrowser.Client { args.AllowDownload = true; args.Callback = Browser_ConfigurationDownloadFinished; - args.DownloadPath = Path.Combine(appConfig.DownloadDirectory, fileName); + args.DownloadPath = Path.Combine(context.AppConfig.DownloadDirectory, fileName); logger.Info($"Allowed download request for configuration file '{fileName}'."); } else @@ -259,7 +254,7 @@ namespace SafeExamBrowser.Client { logger.Info($"Sent reconfiguration request for '{filePath}' to the runtime."); - splashScreen = uiFactory.CreateSplashScreen(appConfig); + splashScreen = uiFactory.CreateSplashScreen(context.AppConfig); splashScreen.SetIndeterminate(); splashScreen.UpdateStatus(TextKey.OperationStatus_InitializeSession, true); splashScreen.Show(); diff --git a/SafeExamBrowser.Client/CompositionRoot.cs b/SafeExamBrowser.Client/CompositionRoot.cs index c350287b..07fb6099 100644 --- a/SafeExamBrowser.Client/CompositionRoot.cs +++ b/SafeExamBrowser.Client/CompositionRoot.cs @@ -12,17 +12,14 @@ using System.Diagnostics; using System.IO; using System.Reflection; using SafeExamBrowser.Browser; -using SafeExamBrowser.Browser.Contracts; using SafeExamBrowser.Client.Communication; using SafeExamBrowser.Client.Contracts; using SafeExamBrowser.Client.Notifications; using SafeExamBrowser.Client.Operations; using SafeExamBrowser.Communication.Contracts; -using SafeExamBrowser.Communication.Contracts.Hosts; using SafeExamBrowser.Communication.Contracts.Proxies; using SafeExamBrowser.Communication.Hosts; using SafeExamBrowser.Communication.Proxies; -using SafeExamBrowser.Configuration.Contracts; using SafeExamBrowser.Configuration.Cryptography; using SafeExamBrowser.Core.Contracts.OperationModel; using SafeExamBrowser.Core.OperationModel; @@ -56,8 +53,9 @@ namespace SafeExamBrowser.Client { internal class CompositionRoot { + private const int FIVE_SECONDS = 5000; + private Guid authenticationToken; - private ClientConfiguration configuration; private ClientContext context; private string logFilePath; private LogLevel logLevel; @@ -66,8 +64,6 @@ namespace SafeExamBrowser.Client private IActionCenter actionCenter; private IApplicationMonitor applicationMonitor; - private IBrowserApplication browser; - private IClientHost clientHost; private ILogger logger; private IMessageBox messageBox; private INativeMethods nativeMethods; @@ -85,7 +81,6 @@ namespace SafeExamBrowser.Client { ValidateCommandLineArguments(); - configuration = new ClientConfiguration(); logger = new Logger(); nativeMethods = new NativeMethods(); systemInfo = new SystemInfo(); @@ -109,25 +104,25 @@ namespace SafeExamBrowser.Client var operations = new Queue(); operations.Enqueue(new I18nOperation(logger, text, textResource)); - operations.Enqueue(new RuntimeConnectionOperation(logger, runtimeProxy, authenticationToken)); - operations.Enqueue(new ConfigurationOperation(configuration, context, logger, runtimeProxy)); + operations.Enqueue(new RuntimeConnectionOperation(context, logger, runtimeProxy, authenticationToken)); + operations.Enqueue(new ConfigurationOperation(context, logger, runtimeProxy)); operations.Enqueue(new DelegateOperation(UpdateAppConfig)); operations.Enqueue(new LazyInitializationOperation(BuildClientHostOperation)); - operations.Enqueue(new LazyInitializationOperation(BuildClientHostDisconnectionOperation)); + operations.Enqueue(new ClientHostDisconnectionOperation(context, logger, FIVE_SECONDS)); operations.Enqueue(new LazyInitializationOperation(BuildKeyboardInterceptorOperation)); operations.Enqueue(new LazyInitializationOperation(BuildMouseInterceptorOperation)); - operations.Enqueue(new LazyInitializationOperation(BuildApplicationOperation)); - operations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, taskbar)); + operations.Enqueue(new ApplicationOperation(applicationMonitor, context, logger)); + operations.Enqueue(new DisplayMonitorOperation(context, displayMonitor, logger, taskbar)); operations.Enqueue(new LazyInitializationOperation(BuildShellOperation)); operations.Enqueue(new LazyInitializationOperation(BuildBrowserOperation)); - operations.Enqueue(new ClipboardOperation(logger, nativeMethods)); - operations.Enqueue(new DelegateOperation(UpdateClientControllerDependencies)); + operations.Enqueue(new ClipboardOperation(context, logger, nativeMethods)); var sequence = new OperationSequence(logger, operations); ClientController = new ClientController( actionCenter, applicationMonitor, + context, displayMonitor, explorerShell, hashAlgorithm, @@ -198,57 +193,43 @@ namespace SafeExamBrowser.Client textResource = new XmlTextResource(path); } - private IOperation BuildApplicationOperation() - { - return new ApplicationOperation(applicationMonitor, context, logger); - } - private IOperation BuildBrowserOperation() { var moduleLogger = new ModuleLogger(logger, nameof(BrowserApplication)); - var browser = new BrowserApplication(configuration.AppConfig, configuration.Settings.Browser, messageBox, moduleLogger, text, uiFactory); + var browser = new BrowserApplication(context.AppConfig, context.Settings.Browser, messageBox, moduleLogger, text, uiFactory); var browserInfo = new BrowserApplicationInfo(); - var operation = new BrowserOperation(actionCenter, browser, logger, taskbar, uiFactory); + var operation = new BrowserOperation(actionCenter, context, logger, taskbar, uiFactory); - this.browser = browser; + context.Browser = browser; return operation; } private IOperation BuildClientHostOperation() { - const int FIVE_SECONDS = 5000; var processId = Process.GetCurrentProcess().Id; var factory = new HostObjectFactory(); - var host = new ClientHost(configuration.AppConfig.ClientAddress, factory, new ModuleLogger(logger, nameof(ClientHost)), processId, FIVE_SECONDS); - var operation = new CommunicationHostOperation(host, logger); + var clientHost = new ClientHost(context.AppConfig.ClientAddress, factory, new ModuleLogger(logger, nameof(ClientHost)), processId, FIVE_SECONDS); + var operation = new CommunicationHostOperation(clientHost, logger); - clientHost = host; - clientHost.AuthenticationToken = authenticationToken; - - return operation; - } - - private IOperation BuildClientHostDisconnectionOperation() - { - var timeout_ms = 5000; - var operation = new ClientHostDisconnectionOperation(clientHost, logger, timeout_ms); + context.ClientHost = clientHost; + context.ClientHost.AuthenticationToken = authenticationToken; return operation; } private IOperation BuildKeyboardInterceptorOperation() { - var keyboardInterceptor = new KeyboardInterceptor(configuration.Settings.Keyboard, new ModuleLogger(logger, nameof(KeyboardInterceptor)), nativeMethods); - var operation = new KeyboardInterceptorOperation(keyboardInterceptor, logger); + var keyboardInterceptor = new KeyboardInterceptor(new ModuleLogger(logger, nameof(KeyboardInterceptor)), nativeMethods, context.Settings.Keyboard); + var operation = new KeyboardInterceptorOperation(context, keyboardInterceptor, logger); return operation; } private IOperation BuildMouseInterceptorOperation() { - var mouseInterceptor = new MouseInterceptor(new ModuleLogger(logger, nameof(MouseInterceptor)), configuration.Settings.Mouse, nativeMethods); - var operation = new MouseInterceptorOperation(logger, mouseInterceptor); + var mouseInterceptor = new MouseInterceptor(new ModuleLogger(logger, nameof(MouseInterceptor)), nativeMethods, context.Settings.Mouse); + var operation = new MouseInterceptorOperation(context, logger, mouseInterceptor); return operation; } @@ -256,8 +237,8 @@ namespace SafeExamBrowser.Client private IOperation BuildShellOperation() { var aboutInfo = new AboutNotificationInfo(text); - var aboutController = new AboutNotificationController(configuration.AppConfig, uiFactory); - var audio = new Audio(configuration.Settings.Audio, new ModuleLogger(logger, nameof(Audio))); + var aboutController = new AboutNotificationController(context.AppConfig, uiFactory); + var audio = new Audio(context.Settings.Audio, new ModuleLogger(logger, nameof(Audio))); var keyboard = new Keyboard(new ModuleLogger(logger, nameof(Keyboard))); var logInfo = new LogNotificationInfo(text); var logController = new LogNotificationController(logger, uiFactory); @@ -271,10 +252,10 @@ namespace SafeExamBrowser.Client var operation = new ShellOperation( actionCenter, activators, - configuration.Settings.ActionCenter, audio, aboutInfo, aboutController, + context, keyboard, logger, logInfo, @@ -282,7 +263,6 @@ namespace SafeExamBrowser.Client powerSupply, systemInfo, taskbar, - configuration.Settings.Taskbar, terminationActivator, text, uiFactory, @@ -337,15 +317,7 @@ namespace SafeExamBrowser.Client private void UpdateAppConfig() { - ClientController.AppConfig = configuration.AppConfig; - } - - private void UpdateClientControllerDependencies() - { - ClientController.Browser = browser; - ClientController.ClientHost = clientHost; - ClientController.SessionId = configuration.SessionId; - ClientController.Settings = configuration.Settings; + ClientController.UpdateAppConfig(); } } } diff --git a/SafeExamBrowser.Client/Operations/BrowserOperation.cs b/SafeExamBrowser.Client/Operations/BrowserOperation.cs index dc062a5f..3a813074 100644 --- a/SafeExamBrowser.Client/Operations/BrowserOperation.cs +++ b/SafeExamBrowser.Client/Operations/BrowserOperation.cs @@ -6,7 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Core.Contracts.OperationModel; using SafeExamBrowser.Core.Contracts.OperationModel.Events; using SafeExamBrowser.I18n.Contracts; @@ -16,50 +15,48 @@ using SafeExamBrowser.UserInterface.Contracts.Shell; namespace SafeExamBrowser.Client.Operations { - internal class BrowserOperation : IOperation + internal class BrowserOperation : ClientOperation { private IActionCenter actionCenter; - private IApplication browser; private ILogger logger; private ITaskbar taskbar; private IUserInterfaceFactory uiFactory; - public event ActionRequiredEventHandler ActionRequired { add { } remove { } } - public event StatusChangedEventHandler StatusChanged; + public override event ActionRequiredEventHandler ActionRequired { add { } remove { } } + public override event StatusChangedEventHandler StatusChanged; public BrowserOperation( IActionCenter actionCenter, - IApplication browser, + ClientContext context, ILogger logger, ITaskbar taskbar, - IUserInterfaceFactory uiFactory) + IUserInterfaceFactory uiFactory) : base(context) { this.actionCenter = actionCenter; - this.browser = browser; this.logger = logger; this.taskbar = taskbar; this.uiFactory = uiFactory; } - public OperationResult Perform() + public override OperationResult Perform() { logger.Info("Initializing browser..."); StatusChanged?.Invoke(TextKey.OperationStatus_InitializeBrowser); - browser.Initialize(); + Context.Browser.Initialize(); - actionCenter.AddApplicationControl(uiFactory.CreateApplicationControl(browser, Location.ActionCenter)); - taskbar.AddApplicationControl(uiFactory.CreateApplicationControl(browser, Location.Taskbar)); + actionCenter.AddApplicationControl(uiFactory.CreateApplicationControl(Context.Browser, Location.ActionCenter)); + taskbar.AddApplicationControl(uiFactory.CreateApplicationControl(Context.Browser, Location.Taskbar)); return OperationResult.Success; } - public OperationResult Revert() + public override OperationResult Revert() { logger.Info("Terminating browser..."); StatusChanged?.Invoke(TextKey.OperationStatus_TerminateBrowser); - browser.Terminate(); + Context.Browser.Terminate(); return OperationResult.Success; } diff --git a/SafeExamBrowser.Client/Operations/ClientHostDisconnectionOperation.cs b/SafeExamBrowser.Client/Operations/ClientHostDisconnectionOperation.cs index 83a293b2..35cdbb80 100644 --- a/SafeExamBrowser.Client/Operations/ClientHostDisconnectionOperation.cs +++ b/SafeExamBrowser.Client/Operations/ClientHostDisconnectionOperation.cs @@ -8,7 +8,6 @@ using System.Threading; using SafeExamBrowser.Communication.Contracts.Events; -using SafeExamBrowser.Communication.Contracts.Hosts; using SafeExamBrowser.Core.Contracts.OperationModel; using SafeExamBrowser.Core.Contracts.OperationModel.Events; using SafeExamBrowser.I18n.Contracts; @@ -20,43 +19,41 @@ namespace SafeExamBrowser.Client.Operations /// During application shutdown, it could happen that the client stops its communication host before the runtime had the chance to /// disconnect from it. This operation prevents the described race condition by waiting on the runtime to disconnect from the client. /// - internal class ClientHostDisconnectionOperation : IOperation + internal class ClientHostDisconnectionOperation : ClientOperation { - private IClientHost clientHost; private ILogger logger; private int timeout_ms; - public event ActionRequiredEventHandler ActionRequired { add { } remove { } } - public event StatusChangedEventHandler StatusChanged; + public override event ActionRequiredEventHandler ActionRequired { add { } remove { } } + public override event StatusChangedEventHandler StatusChanged; - public ClientHostDisconnectionOperation(IClientHost clientHost, ILogger logger, int timeout_ms) + public ClientHostDisconnectionOperation(ClientContext context, ILogger logger, int timeout_ms) : base(context) { - this.clientHost = clientHost; this.logger = logger; this.timeout_ms = timeout_ms; } - public OperationResult Perform() + public override OperationResult Perform() { return OperationResult.Success; } - public OperationResult Revert() + public override OperationResult Revert() { StatusChanged?.Invoke(TextKey.OperationStatus_WaitRuntimeDisconnection); - if (clientHost.IsConnected) + if (Context.ClientHost.IsConnected) { var disconnected = false; var disconnectedEvent = new AutoResetEvent(false); var disconnectedEventHandler = new CommunicationEventHandler(() => disconnectedEvent.Set()); - clientHost.RuntimeDisconnected += disconnectedEventHandler; + Context.ClientHost.RuntimeDisconnected += disconnectedEventHandler; logger.Info("Waiting for runtime to disconnect from client communication host..."); disconnected = disconnectedEvent.WaitOne(timeout_ms); - clientHost.RuntimeDisconnected -= disconnectedEventHandler; + Context.ClientHost.RuntimeDisconnected -= disconnectedEventHandler; if (disconnected) { diff --git a/SafeExamBrowser.Client/Operations/ClipboardOperation.cs b/SafeExamBrowser.Client/Operations/ClipboardOperation.cs index b816f4a8..a0840ac5 100644 --- a/SafeExamBrowser.Client/Operations/ClipboardOperation.cs +++ b/SafeExamBrowser.Client/Operations/ClipboardOperation.cs @@ -14,28 +14,28 @@ using SafeExamBrowser.WindowsApi.Contracts; namespace SafeExamBrowser.Client.Operations { - internal class ClipboardOperation : IOperation + internal class ClipboardOperation : ClientOperation { private ILogger logger; private INativeMethods nativeMethods; - public event ActionRequiredEventHandler ActionRequired { add { } remove { } } - public event StatusChangedEventHandler StatusChanged; + public override event ActionRequiredEventHandler ActionRequired { add { } remove { } } + public override event StatusChangedEventHandler StatusChanged; - public ClipboardOperation(ILogger logger, INativeMethods nativeMethods) + public ClipboardOperation(ClientContext context, ILogger logger, INativeMethods nativeMethods) : base(context) { this.logger = logger; this.nativeMethods = nativeMethods; } - public OperationResult Perform() + public override OperationResult Perform() { EmptyClipboard(); return OperationResult.Success; } - public OperationResult Revert() + public override OperationResult Revert() { EmptyClipboard(); diff --git a/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs b/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs index 96120b82..b11fc7a8 100644 --- a/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs +++ b/SafeExamBrowser.Client/Operations/ConfigurationOperation.cs @@ -7,7 +7,6 @@ */ using SafeExamBrowser.Communication.Contracts.Proxies; -using SafeExamBrowser.Configuration.Contracts; using SafeExamBrowser.Core.Contracts.OperationModel; using SafeExamBrowser.Core.Contracts.OperationModel.Events; using SafeExamBrowser.I18n.Contracts; @@ -17,17 +16,14 @@ namespace SafeExamBrowser.Client.Operations { internal class ConfigurationOperation : ClientOperation { - private ClientConfiguration configuration; private ILogger logger; private IRuntimeProxy runtime; public override event ActionRequiredEventHandler ActionRequired { add { } remove { } } public override event StatusChangedEventHandler StatusChanged; - // TODO: Remove and delete ClientConfiguration! - public ConfigurationOperation(ClientConfiguration configuration, ClientContext context, ILogger logger, IRuntimeProxy runtime) : base(context) + public ConfigurationOperation(ClientContext context, ILogger logger, IRuntimeProxy runtime) : base(context) { - this.configuration = configuration; this.logger = logger; this.runtime = runtime; } @@ -38,19 +34,16 @@ namespace SafeExamBrowser.Client.Operations StatusChanged?.Invoke(TextKey.OperationStatus_InitializeConfiguration); var communication = runtime.GetConfiguration(); - var config = communication.Value.Configuration; + var configuration = communication.Value.Configuration; - configuration.AppConfig = config.AppConfig; - configuration.SessionId = config.SessionId; - configuration.Settings = config.Settings; - - Context.AppConfig = config.AppConfig; - Context.Settings = config.Settings; + Context.AppConfig = configuration.AppConfig; + Context.SessionId = configuration.SessionId; + Context.Settings = configuration.Settings; logger.Info("Successfully retrieved the application configuration from the runtime."); - logger.Info($" -> Client-ID: {configuration.AppConfig.ClientId}"); - logger.Info($" -> Runtime-ID: {configuration.AppConfig.RuntimeId}"); - logger.Info($" -> Session-ID: {configuration.SessionId}"); + logger.Info($" -> Client-ID: {Context.AppConfig.ClientId}"); + logger.Info($" -> Runtime-ID: {Context.AppConfig.RuntimeId}"); + logger.Info($" -> Session-ID: {Context.SessionId}"); return OperationResult.Success; } diff --git a/SafeExamBrowser.Client/Operations/DisplayMonitorOperation.cs b/SafeExamBrowser.Client/Operations/DisplayMonitorOperation.cs index 1c4b5d75..24eba5aa 100644 --- a/SafeExamBrowser.Client/Operations/DisplayMonitorOperation.cs +++ b/SafeExamBrowser.Client/Operations/DisplayMonitorOperation.cs @@ -15,23 +15,23 @@ using SafeExamBrowser.UserInterface.Contracts.Shell; namespace SafeExamBrowser.Client.Operations { - internal class DisplayMonitorOperation : IOperation + internal class DisplayMonitorOperation : ClientOperation { private IDisplayMonitor displayMonitor; private ILogger logger; private ITaskbar taskbar; - public event ActionRequiredEventHandler ActionRequired { add { } remove { } } - public event StatusChangedEventHandler StatusChanged; + public override event ActionRequiredEventHandler ActionRequired { add { } remove { } } + public override event StatusChangedEventHandler StatusChanged; - public DisplayMonitorOperation(IDisplayMonitor displayMonitor, ILogger logger, ITaskbar taskbar) + public DisplayMonitorOperation(ClientContext context, IDisplayMonitor displayMonitor, ILogger logger, ITaskbar taskbar) : base(context) { this.displayMonitor = displayMonitor; this.logger = logger; this.taskbar = taskbar; } - public OperationResult Perform() + public override OperationResult Perform() { logger.Info("Initializing working area..."); StatusChanged?.Invoke(TextKey.OperationStatus_InitializeWorkingArea); @@ -43,7 +43,7 @@ namespace SafeExamBrowser.Client.Operations return OperationResult.Success; } - public OperationResult Revert() + public override OperationResult Revert() { logger.Info("Restoring working area..."); StatusChanged?.Invoke(TextKey.OperationStatus_RestoreWorkingArea); diff --git a/SafeExamBrowser.Client/Operations/KeyboardInterceptorOperation.cs b/SafeExamBrowser.Client/Operations/KeyboardInterceptorOperation.cs index 3fb8fd3a..095bcbf1 100644 --- a/SafeExamBrowser.Client/Operations/KeyboardInterceptorOperation.cs +++ b/SafeExamBrowser.Client/Operations/KeyboardInterceptorOperation.cs @@ -14,21 +14,21 @@ using SafeExamBrowser.Monitoring.Contracts.Keyboard; namespace SafeExamBrowser.Client.Operations { - internal class KeyboardInterceptorOperation : IOperation + internal class KeyboardInterceptorOperation : ClientOperation { private IKeyboardInterceptor keyboardInterceptor; private ILogger logger; - public event ActionRequiredEventHandler ActionRequired { add { } remove { } } - public event StatusChangedEventHandler StatusChanged; + public override event ActionRequiredEventHandler ActionRequired { add { } remove { } } + public override event StatusChangedEventHandler StatusChanged; - public KeyboardInterceptorOperation(IKeyboardInterceptor keyboardInterceptor, ILogger logger) + public KeyboardInterceptorOperation(ClientContext context, IKeyboardInterceptor keyboardInterceptor, ILogger logger) : base(context) { this.keyboardInterceptor = keyboardInterceptor; this.logger = logger; } - public OperationResult Perform() + public override OperationResult Perform() { logger.Info("Starting keyboard interception..."); StatusChanged?.Invoke(TextKey.OperationStatus_StartKeyboardInterception); @@ -38,7 +38,7 @@ namespace SafeExamBrowser.Client.Operations return OperationResult.Success; } - public OperationResult Revert() + public override OperationResult Revert() { logger.Info("Stopping keyboard interception..."); StatusChanged?.Invoke(TextKey.OperationStatus_StopKeyboardInterception); diff --git a/SafeExamBrowser.Client/Operations/MouseInterceptorOperation.cs b/SafeExamBrowser.Client/Operations/MouseInterceptorOperation.cs index e77dc2d8..85194719 100644 --- a/SafeExamBrowser.Client/Operations/MouseInterceptorOperation.cs +++ b/SafeExamBrowser.Client/Operations/MouseInterceptorOperation.cs @@ -14,21 +14,21 @@ using SafeExamBrowser.Monitoring.Contracts.Mouse; namespace SafeExamBrowser.Client.Operations { - internal class MouseInterceptorOperation : IOperation + internal class MouseInterceptorOperation : ClientOperation { private ILogger logger; private IMouseInterceptor mouseInterceptor; - public event ActionRequiredEventHandler ActionRequired { add { } remove { } } - public event StatusChangedEventHandler StatusChanged; + public override event ActionRequiredEventHandler ActionRequired { add { } remove { } } + public override event StatusChangedEventHandler StatusChanged; - public MouseInterceptorOperation(ILogger logger, IMouseInterceptor mouseInterceptor) + public MouseInterceptorOperation(ClientContext context, ILogger logger, IMouseInterceptor mouseInterceptor) : base(context) { this.logger = logger; this.mouseInterceptor = mouseInterceptor; } - public OperationResult Perform() + public override OperationResult Perform() { logger.Info("Starting mouse interception..."); StatusChanged?.Invoke(TextKey.OperationStatus_StartMouseInterception); @@ -38,7 +38,7 @@ namespace SafeExamBrowser.Client.Operations return OperationResult.Success; } - public OperationResult Revert() + public override OperationResult Revert() { logger.Info("Stopping mouse interception..."); StatusChanged?.Invoke(TextKey.OperationStatus_StopMouseInterception); diff --git a/SafeExamBrowser.Client/Operations/RuntimeConnectionOperation.cs b/SafeExamBrowser.Client/Operations/RuntimeConnectionOperation.cs index d8a87454..2f55cb27 100644 --- a/SafeExamBrowser.Client/Operations/RuntimeConnectionOperation.cs +++ b/SafeExamBrowser.Client/Operations/RuntimeConnectionOperation.cs @@ -15,23 +15,23 @@ using SafeExamBrowser.Logging.Contracts; namespace SafeExamBrowser.Client.Operations { - internal class RuntimeConnectionOperation : IOperation + internal class RuntimeConnectionOperation : ClientOperation { private ILogger logger; private IRuntimeProxy runtime; private Guid token; - public event ActionRequiredEventHandler ActionRequired { add { } remove { } } - public event StatusChangedEventHandler StatusChanged; + public override event ActionRequiredEventHandler ActionRequired { add { } remove { } } + public override event StatusChangedEventHandler StatusChanged; - public RuntimeConnectionOperation(ILogger logger, IRuntimeProxy runtime, Guid token) + public RuntimeConnectionOperation(ClientContext context, ILogger logger, IRuntimeProxy runtime, Guid token) : base(context) { this.logger = logger; this.runtime = runtime; this.token = token; } - public OperationResult Perform() + public override OperationResult Perform() { logger.Info("Initializing runtime connection..."); StatusChanged?.Invoke(TextKey.OperationStatus_InitializeRuntimeConnection); @@ -50,7 +50,7 @@ namespace SafeExamBrowser.Client.Operations return connected ? OperationResult.Success : OperationResult.Failed; } - public OperationResult Revert() + public override OperationResult Revert() { logger.Info("Closing runtime connection..."); StatusChanged?.Invoke(TextKey.OperationStatus_CloseRuntimeConnection); diff --git a/SafeExamBrowser.Client/Operations/ShellOperation.cs b/SafeExamBrowser.Client/Operations/ShellOperation.cs index 7a145f03..fbe90366 100644 --- a/SafeExamBrowser.Client/Operations/ShellOperation.cs +++ b/SafeExamBrowser.Client/Operations/ShellOperation.cs @@ -8,7 +8,6 @@ using System.Collections.Generic; using SafeExamBrowser.Client.Contracts; -using SafeExamBrowser.Settings.UserInterface; using SafeExamBrowser.Core.Contracts.OperationModel; using SafeExamBrowser.Core.Contracts.OperationModel.Events; using SafeExamBrowser.I18n.Contracts; @@ -24,11 +23,10 @@ using SafeExamBrowser.WindowsApi.Contracts; namespace SafeExamBrowser.Client.Operations { - internal class ShellOperation : IOperation + internal class ShellOperation : ClientOperation { private IActionCenter actionCenter; private IEnumerable activators; - private ActionCenterSettings actionCenterSettings; private IAudio audio; private INotificationInfo aboutInfo; private INotificationController aboutController; @@ -39,22 +37,21 @@ namespace SafeExamBrowser.Client.Operations private IPowerSupply powerSupply; private ISystemInfo systemInfo; private ITaskbar taskbar; - private TaskbarSettings taskbarSettings; private ITerminationActivator terminationActivator; private IText text; private IUserInterfaceFactory uiFactory; private IWirelessAdapter wirelessAdapter; - public event ActionRequiredEventHandler ActionRequired { add { } remove { } } - public event StatusChangedEventHandler StatusChanged; + public override event ActionRequiredEventHandler ActionRequired { add { } remove { } } + public override event StatusChangedEventHandler StatusChanged; public ShellOperation( IActionCenter actionCenter, IEnumerable activators, - ActionCenterSettings actionCenterSettings, IAudio audio, INotificationInfo aboutInfo, INotificationController aboutController, + ClientContext context, IKeyboard keyboard, ILogger logger, INotificationInfo logInfo, @@ -62,17 +59,15 @@ namespace SafeExamBrowser.Client.Operations IPowerSupply powerSupply, ISystemInfo systemInfo, ITaskbar taskbar, - TaskbarSettings taskbarSettings, ITerminationActivator terminationActivator, IText text, IUserInterfaceFactory uiFactory, - IWirelessAdapter wirelessAdapter) + IWirelessAdapter wirelessAdapter) : base(context) { this.aboutInfo = aboutInfo; this.aboutController = aboutController; this.actionCenter = actionCenter; this.activators = activators; - this.actionCenterSettings = actionCenterSettings; this.audio = audio; this.keyboard = keyboard; this.logger = logger; @@ -80,7 +75,6 @@ namespace SafeExamBrowser.Client.Operations this.logController = logController; this.powerSupply = powerSupply; this.systemInfo = systemInfo; - this.taskbarSettings = taskbarSettings; this.terminationActivator = terminationActivator; this.text = text; this.taskbar = taskbar; @@ -88,7 +82,7 @@ namespace SafeExamBrowser.Client.Operations this.wirelessAdapter = wirelessAdapter; } - public OperationResult Perform() + public override OperationResult Perform() { logger.Info("Initializing shell..."); StatusChanged?.Invoke(TextKey.OperationStatus_InitializeShell); @@ -101,7 +95,7 @@ namespace SafeExamBrowser.Client.Operations return OperationResult.Success; } - public OperationResult Revert() + public override OperationResult Revert() { logger.Info("Terminating shell..."); StatusChanged?.Invoke(TextKey.OperationStatus_TerminateShell); @@ -117,7 +111,7 @@ namespace SafeExamBrowser.Client.Operations { terminationActivator.Start(); - if (actionCenterSettings.EnableActionCenter) + if (Context.Settings.ActionCenter.EnableActionCenter) { foreach (var activator in activators) { @@ -129,7 +123,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeActionCenter() { - if (actionCenterSettings.EnableActionCenter) + if (Context.Settings.ActionCenter.EnableActionCenter) { logger.Info("Initializing action center..."); actionCenter.InitializeText(text); @@ -150,7 +144,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeTaskbar() { - if (taskbarSettings.EnableTaskbar) + if (Context.Settings.Taskbar.EnableTaskbar) { logger.Info("Initializing taskbar..."); taskbar.InitializeText(text); @@ -179,7 +173,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeAboutNotificationForActionCenter() { - if (actionCenterSettings.ShowApplicationInfo) + if (Context.Settings.ActionCenter.ShowApplicationInfo) { actionCenter.AddNotificationControl(uiFactory.CreateNotificationControl(aboutController, aboutInfo, Location.ActionCenter)); } @@ -187,7 +181,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeAboutNotificationForTaskbar() { - if (taskbarSettings.ShowApplicationInfo) + if (Context.Settings.Taskbar.ShowApplicationInfo) { taskbar.AddNotificationControl(uiFactory.CreateNotificationControl(aboutController, aboutInfo, Location.Taskbar)); } @@ -195,7 +189,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeAudioForActionCenter() { - if (actionCenterSettings.ShowAudio) + if (Context.Settings.ActionCenter.ShowAudio) { actionCenter.AddSystemControl(uiFactory.CreateAudioControl(audio, Location.ActionCenter)); } @@ -203,7 +197,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeAudioForTaskbar() { - if (taskbarSettings.ShowAudio) + if (Context.Settings.Taskbar.ShowAudio) { taskbar.AddSystemControl(uiFactory.CreateAudioControl(audio, Location.Taskbar)); } @@ -211,17 +205,17 @@ namespace SafeExamBrowser.Client.Operations private void InitializeClockForActionCenter() { - actionCenter.ShowClock = actionCenterSettings.ShowClock; + actionCenter.ShowClock = Context.Settings.ActionCenter.ShowClock; } private void InitializeClockForTaskbar() { - taskbar.ShowClock = taskbarSettings.ShowClock; + taskbar.ShowClock = Context.Settings.Taskbar.ShowClock; } private void InitializeLogNotificationForActionCenter() { - if (actionCenterSettings.ShowApplicationLog) + if (Context.Settings.ActionCenter.ShowApplicationLog) { actionCenter.AddNotificationControl(uiFactory.CreateNotificationControl(logController, logInfo, Location.ActionCenter)); } @@ -229,7 +223,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeLogNotificationForTaskbar() { - if (taskbarSettings.ShowApplicationLog) + if (Context.Settings.Taskbar.ShowApplicationLog) { taskbar.AddNotificationControl(uiFactory.CreateNotificationControl(logController, logInfo, Location.Taskbar)); } @@ -237,7 +231,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeKeyboardLayoutForActionCenter() { - if (actionCenterSettings.ShowKeyboardLayout) + if (Context.Settings.ActionCenter.ShowKeyboardLayout) { actionCenter.AddSystemControl(uiFactory.CreateKeyboardLayoutControl(keyboard, Location.ActionCenter)); } @@ -245,7 +239,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeKeyboardLayoutForTaskbar() { - if (taskbarSettings.ShowKeyboardLayout) + if (Context.Settings.Taskbar.ShowKeyboardLayout) { taskbar.AddSystemControl(uiFactory.CreateKeyboardLayoutControl(keyboard, Location.Taskbar)); } @@ -269,7 +263,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeWirelessNetworkForActionCenter() { - if (actionCenterSettings.ShowWirelessNetwork) + if (Context.Settings.ActionCenter.ShowWirelessNetwork) { actionCenter.AddSystemControl(uiFactory.CreateWirelessNetworkControl(wirelessAdapter, Location.ActionCenter)); } @@ -277,7 +271,7 @@ namespace SafeExamBrowser.Client.Operations private void InitializeWirelessNetworkForTaskbar() { - if (taskbarSettings.ShowWirelessNetwork) + if (Context.Settings.Taskbar.ShowWirelessNetwork) { taskbar.AddSystemControl(uiFactory.CreateWirelessNetworkControl(wirelessAdapter, Location.Taskbar)); } @@ -287,7 +281,7 @@ namespace SafeExamBrowser.Client.Operations { terminationActivator.Stop(); - if (actionCenterSettings.EnableActionCenter) + if (Context.Settings.ActionCenter.EnableActionCenter) { foreach (var activator in activators) { diff --git a/SafeExamBrowser.Monitoring/Keyboard/KeyboardInterceptor.cs b/SafeExamBrowser.Monitoring/Keyboard/KeyboardInterceptor.cs index 86b3b19c..10c3c8d2 100644 --- a/SafeExamBrowser.Monitoring/Keyboard/KeyboardInterceptor.cs +++ b/SafeExamBrowser.Monitoring/Keyboard/KeyboardInterceptor.cs @@ -24,7 +24,7 @@ namespace SafeExamBrowser.Monitoring.Keyboard private INativeMethods nativeMethods; private KeyboardSettings settings; - public KeyboardInterceptor(KeyboardSettings settings, ILogger logger, INativeMethods nativeMethods) + public KeyboardInterceptor(ILogger logger, INativeMethods nativeMethods, KeyboardSettings settings) { this.logger = logger; this.nativeMethods = nativeMethods; diff --git a/SafeExamBrowser.Monitoring/Mouse/MouseInterceptor.cs b/SafeExamBrowser.Monitoring/Mouse/MouseInterceptor.cs index 99bd65d9..fbd49c28 100644 --- a/SafeExamBrowser.Monitoring/Mouse/MouseInterceptor.cs +++ b/SafeExamBrowser.Monitoring/Mouse/MouseInterceptor.cs @@ -22,7 +22,7 @@ namespace SafeExamBrowser.Monitoring.Mouse private INativeMethods nativeMethods; private MouseSettings settings; - public MouseInterceptor(ILogger logger, MouseSettings settings, INativeMethods nativeMethods) + public MouseInterceptor(ILogger logger, INativeMethods nativeMethods, MouseSettings settings) { this.logger = logger; this.nativeMethods = nativeMethods; diff --git a/SafeExamBrowser.Settings/Applications/BlacklistApplication.cs b/SafeExamBrowser.Settings/Applications/BlacklistApplication.cs index b7e19013..1993c6a7 100644 --- a/SafeExamBrowser.Settings/Applications/BlacklistApplication.cs +++ b/SafeExamBrowser.Settings/Applications/BlacklistApplication.cs @@ -11,23 +11,23 @@ using System; namespace SafeExamBrowser.Settings.Applications { /// - /// TODO + /// Defines an application which is blacklisted, i.e. not allowed to run during a session. /// [Serializable] public class BlacklistApplication { /// - /// + /// Specifies whether the application may be automatically terminated when starting a session. /// public bool AutoTerminate { get; set; } /// - /// + /// The name of the main executable of the application. /// public string ExecutableName { get; set; } /// - /// + /// The original file name of the main executable of the application, if available. /// public string ExecutableOriginalName { get; set; } }