diff --git a/SafeExamBrowser.Browser/BrowserApplicationController.cs b/SafeExamBrowser.Browser/BrowserApplicationController.cs index 960eaa33..9ad7eed6 100644 --- a/SafeExamBrowser.Browser/BrowserApplicationController.cs +++ b/SafeExamBrowser.Browser/BrowserApplicationController.cs @@ -12,10 +12,10 @@ using System.Linq; using CefSharp; using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Configuration; -using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.UserInterface; using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using IBrowserSettings = SafeExamBrowser.Contracts.Configuration.Settings.IBrowserSettings; namespace SafeExamBrowser.Browser { @@ -23,11 +23,11 @@ namespace SafeExamBrowser.Browser { private IApplicationButton button; private IList instances = new List(); - private ISettings settings; + private IBrowserSettings settings; private IUserInterfaceFactory uiFactory; private IText text; - public BrowserApplicationController(ISettings settings, IText text, IUserInterfaceFactory uiFactory) + public BrowserApplicationController(IBrowserSettings settings, IText text, IUserInterfaceFactory uiFactory) { this.settings = settings; this.text = text; @@ -38,8 +38,8 @@ namespace SafeExamBrowser.Browser { var cefSettings = new CefSettings { - CachePath = settings.Browser.CachePath, - LogFile = settings.Browser.LogFile + CachePath = settings.CachePath, + LogFile = settings.LogFile }; var success = Cef.Initialize(cefSettings, true, null); @@ -69,7 +69,7 @@ namespace SafeExamBrowser.Browser private void CreateNewInstance() { - var instance = new BrowserApplicationInstance(settings.Browser, text, uiFactory, instances.Count == 0); + var instance = new BrowserApplicationInstance(settings, text, uiFactory, instances.Count == 0); button.RegisterInstance(instance); instances.Add(instance); diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/RuntimeControllerTests.cs b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs similarity index 95% rename from SafeExamBrowser.Core.UnitTests/Behaviour/RuntimeControllerTests.cs rename to SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs index b9d2f2c9..b15f00fa 100644 --- a/SafeExamBrowser.Core.UnitTests/Behaviour/RuntimeControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs @@ -9,16 +9,15 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Contracts.Client; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.Monitoring; using SafeExamBrowser.Contracts.UserInterface.Taskbar; -using SafeExamBrowser.Core.Behaviour; -namespace SafeExamBrowser.Core.UnitTests.Behaviour +namespace SafeExamBrowser.Client.UnitTests { [TestClass] - public class RuntimeControllerTests + public class ClientControllerTests { private Mock displayMonitorMock; private Mock loggerMock; @@ -26,7 +25,7 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour private Mock taskbarMock; private Mock windowMonitorMock; - private IRuntimeController sut; + private IClientController sut; [TestInitialize] public void Initialize() @@ -37,7 +36,7 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour taskbarMock = new Mock(); windowMonitorMock= new Mock(); - sut = new RuntimeController( + sut = new ClientController( displayMonitorMock.Object, loggerMock.Object, processMonitorMock.Object, diff --git a/SafeExamBrowser.Client.UnitTests/Properties/AssemblyInfo.cs b/SafeExamBrowser.Client.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..07a27b35 --- /dev/null +++ b/SafeExamBrowser.Client.UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,16 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SafeExamBrowser.Client.UnitTests")] +[assembly: AssemblyDescription("Safe Exam Browser")] +[assembly: AssemblyCompany("ETH Zürich")] +[assembly: AssemblyProduct("SafeExamBrowser.Client.UnitTests")] +[assembly: AssemblyCopyright("Copyright © 2018 ETH Zürich, Educational Development and Technology (LET)")] + +[assembly: ComVisible(false)] + +[assembly: Guid("15684416-fadf-4c51-85de-4f343bfab752")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj b/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj new file mode 100644 index 00000000..a48b4395 --- /dev/null +++ b/SafeExamBrowser.Client.UnitTests/SafeExamBrowser.Client.UnitTests.csproj @@ -0,0 +1,108 @@ + + + + + Debug + AnyCPU + {15684416-FADF-4C51-85DE-4F343BFAB752} + Library + Properties + SafeExamBrowser.Client.UnitTests + SafeExamBrowser.Client.UnitTests + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + + + + ..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll + + + ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + ..\packages\Moq.4.8.1\lib\net45\Moq.dll + + + + ..\packages\System.Threading.Tasks.Extensions.4.4.0\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + + + ..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll + True + + + + + + + + + + + + + {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7} + SafeExamBrowser.Client + + + {47DA5933-BEF8-4729-94E6-ABDE2DB12262} + SafeExamBrowser.Contracts + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/SafeExamBrowser.Client.UnitTests/app.config b/SafeExamBrowser.Client.UnitTests/app.config new file mode 100644 index 00000000..7d8c9227 --- /dev/null +++ b/SafeExamBrowser.Client.UnitTests/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SafeExamBrowser.Client.UnitTests/packages.config b/SafeExamBrowser.Client.UnitTests/packages.config new file mode 100644 index 00000000..3912bdfc --- /dev/null +++ b/SafeExamBrowser.Client.UnitTests/packages.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/SafeExamBrowser.Core/Behaviour/RuntimeController.cs b/SafeExamBrowser.Client/ClientController.cs similarity index 93% rename from SafeExamBrowser.Core/Behaviour/RuntimeController.cs rename to SafeExamBrowser.Client/ClientController.cs index 1eb11d84..35e0aaa7 100644 --- a/SafeExamBrowser.Core/Behaviour/RuntimeController.cs +++ b/SafeExamBrowser.Client/ClientController.cs @@ -7,14 +7,14 @@ */ using System; -using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Contracts.Client; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.Monitoring; using SafeExamBrowser.Contracts.UserInterface.Taskbar; -namespace SafeExamBrowser.Core.Behaviour +namespace SafeExamBrowser.Client { - public class RuntimeController : IRuntimeController + public class ClientController : IClientController { private IDisplayMonitor displayMonitor; private ILogger logger; @@ -22,7 +22,7 @@ namespace SafeExamBrowser.Core.Behaviour private ITaskbar taskbar; private IWindowMonitor windowMonitor; - public RuntimeController( + public ClientController( IDisplayMonitor displayMonitor, ILogger logger, IProcessMonitor processMonitor, diff --git a/SafeExamBrowser.Client/CompositionRoot.cs b/SafeExamBrowser.Client/CompositionRoot.cs index 23e83740..5074b6d2 100644 --- a/SafeExamBrowser.Client/CompositionRoot.cs +++ b/SafeExamBrowser.Client/CompositionRoot.cs @@ -7,21 +7,103 @@ */ using System.Collections.Generic; +using SafeExamBrowser.Browser; +using SafeExamBrowser.Configuration; +using SafeExamBrowser.Configuration.Settings; using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Contracts.Client; +using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Configuration.Settings; +using SafeExamBrowser.Contracts.I18n; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.Monitoring; +using SafeExamBrowser.Contracts.SystemComponents; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Contracts.UserInterface.Taskbar; +using SafeExamBrowser.Contracts.WindowsApi; +using SafeExamBrowser.Core.Behaviour; +using SafeExamBrowser.Core.Behaviour.Operations; +using SafeExamBrowser.Core.I18n; +using SafeExamBrowser.Core.Logging; +using SafeExamBrowser.Monitoring.Display; +using SafeExamBrowser.Monitoring.Keyboard; +using SafeExamBrowser.Monitoring.Mouse; +using SafeExamBrowser.Monitoring.Processes; +using SafeExamBrowser.Monitoring.Windows; +using SafeExamBrowser.SystemComponents; using SafeExamBrowser.UserInterface.Classic; +using SafeExamBrowser.WindowsApi; namespace SafeExamBrowser.Client { internal class CompositionRoot { - public IShutdownController ShutdownController { get; private set; } - public IStartupController StartupController { get; private set; } - public Queue StartupOperations { get; private set; } - public Taskbar Taskbar { get; private set; } + private IApplicationController browserController; + private IApplicationInfo browserInfo; + private IClientController clientController; + private IDisplayMonitor displayMonitor; + private IKeyboardInterceptor keyboardInterceptor; + private ILogger logger; + private IMouseInterceptor mouseInterceptor; + private IProcessMonitor processMonitor; + private INativeMethods nativeMethods; + private ISettings settings; + private ISystemComponent keyboardLayout; + private ISystemComponent powerSupply; + private ISystemComponent wirelessNetwork; + private ISystemInfo systemInfo; + private IText text; + private IUserInterfaceFactory uiFactory; + private IWindowMonitor windowMonitor; - public void BuildObjectGraph() + internal IShutdownController ShutdownController { get; private set; } + internal IStartupController StartupController { get; private set; } + internal Queue StartupOperations { get; private set; } + internal Taskbar Taskbar { get; private set; } + + internal void BuildObjectGraph() { + browserInfo = new BrowserApplicationInfo(); + nativeMethods = new NativeMethods(); + settings = new SettingsRepository().LoadDefaults(); + systemInfo = new SystemInfo(); + uiFactory = new UserInterfaceFactory(); + InitializeLogger(); + + text = new Text(logger); + Taskbar = new Taskbar(new ModuleLogger(logger, typeof(Taskbar))); + browserController = new BrowserApplicationController(settings.Browser, text, uiFactory); + displayMonitor = new DisplayMonitor(new ModuleLogger(logger, typeof(DisplayMonitor)), nativeMethods); + keyboardInterceptor = new KeyboardInterceptor(settings.Keyboard, new ModuleLogger(logger, typeof(KeyboardInterceptor))); + keyboardLayout = new KeyboardLayout(new ModuleLogger(logger, typeof(KeyboardLayout)), text); + mouseInterceptor = new MouseInterceptor(new ModuleLogger(logger, typeof(MouseInterceptor)), settings.Mouse); + powerSupply = new PowerSupply(new ModuleLogger(logger, typeof(PowerSupply)), text); + processMonitor = new ProcessMonitor(new ModuleLogger(logger, typeof(ProcessMonitor)), nativeMethods); + windowMonitor = new WindowMonitor(new ModuleLogger(logger, typeof(WindowMonitor)), nativeMethods); + wirelessNetwork = new WirelessNetwork(new ModuleLogger(logger, typeof(WirelessNetwork)), text); + + clientController = new ClientController(displayMonitor, new ModuleLogger(logger, typeof(ClientController)), processMonitor, Taskbar, windowMonitor); + ShutdownController = new ShutdownController(logger, settings, text, uiFactory); + StartupController = new StartupController(logger, settings, systemInfo, text, uiFactory); + + StartupOperations = new Queue(); + StartupOperations.Enqueue(new I18nOperation(logger, text)); + StartupOperations.Enqueue(new KeyboardInterceptorOperation(keyboardInterceptor, logger, nativeMethods)); + StartupOperations.Enqueue(new WindowMonitorOperation(logger, windowMonitor)); + StartupOperations.Enqueue(new ProcessMonitorOperation(logger, processMonitor)); + StartupOperations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, Taskbar)); + StartupOperations.Enqueue(new TaskbarOperation(logger, settings.Taskbar, keyboardLayout, powerSupply, wirelessNetwork, systemInfo, Taskbar, text, uiFactory)); + StartupOperations.Enqueue(new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory)); + StartupOperations.Enqueue(new ClientControllerOperation(clientController, logger)); + StartupOperations.Enqueue(new ClipboardOperation(logger, nativeMethods)); + StartupOperations.Enqueue(new MouseInterceptorOperation(logger, mouseInterceptor, nativeMethods)); + } + + private void InitializeLogger() + { + logger = new Logger(); + logger.Subscribe(new LogFileWriter(new DefaultLogFormatter(), settings.Logging.ClientLogFile)); } } } diff --git a/SafeExamBrowser.Client/SafeExamBrowser.Client.csproj b/SafeExamBrowser.Client/SafeExamBrowser.Client.csproj index a211077d..1cd08db5 100644 --- a/SafeExamBrowser.Client/SafeExamBrowser.Client.csproj +++ b/SafeExamBrowser.Client/SafeExamBrowser.Client.csproj @@ -34,6 +34,29 @@ prompt 4 + + app.manifest + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + @@ -46,6 +69,7 @@ + Code @@ -64,6 +88,7 @@ ResXFileCodeGenerator Resources.Designer.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -73,14 +98,38 @@ + + {04E653F1-98E6-4E34-9DD7-7F2BC1A8B767} + SafeExamBrowser.Browser + + + {C388C4DD-A159-457D-AF92-89F7AD185109} + SafeExamBrowser.Configuration + {47DA5933-BEF8-4729-94E6-ABDE2DB12262} SafeExamBrowser.Contracts + + {3D6FDBB6-A4AF-4626-BB2B-BF329D44F9CC} + SafeExamBrowser.Core + + + {EF563531-4EB5-44B9-A5EC-D6D6F204469B} + SafeExamBrowser.Monitoring + + + {ACEE2EF1-14D2-4B52-8994-5C053055BB51} + SafeExamBrowser.SystemComponents + {A502DF54-7169-4647-94BD-18B192924866} SafeExamBrowser.UserInterface.Classic + + {73724659-4150-4792-A94E-42F5F3C1B696} + SafeExamBrowser.WindowsApi + \ No newline at end of file diff --git a/SafeExamBrowser.Client/app.manifest b/SafeExamBrowser.Client/app.manifest new file mode 100644 index 00000000..ff42268f --- /dev/null +++ b/SafeExamBrowser.Client/app.manifest @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj b/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj index 657a7307..a60b92cf 100644 --- a/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj +++ b/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj @@ -53,13 +53,15 @@ - - - - + + + + + + - + diff --git a/SafeExamBrowser.Configuration/Settings.cs b/SafeExamBrowser.Configuration/Settings.cs deleted file mode 100644 index 440c7299..00000000 --- a/SafeExamBrowser.Configuration/Settings.cs +++ /dev/null @@ -1,83 +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 System; -using System.IO; -using System.Reflection; -using SafeExamBrowser.Contracts.Configuration.Settings; - -namespace SafeExamBrowser.Configuration -{ - /// - /// TODO: Replace with proper implementation once configuration aspects are clear... - /// - public class Settings : ISettings - { - private static readonly string LogFileDate = DateTime.Now.ToString("yyyy-MM-dd\\_HH\\hmm\\mss\\s"); - - public Settings() - { - Browser = new BrowserSettings(this); - Keyboard = new KeyboardSettings(); - Mouse = new MouseSettings(); - Taskbar = new TaskbarSettings(); - } - - public string AppDataFolderName => nameof(SafeExamBrowser); - - public IBrowserSettings Browser { get; private set; } - public IKeyboardSettings Keyboard { get; private set; } - public IMouseSettings Mouse { get; private set; } - public ITaskbarSettings Taskbar { get; private set; } - - public string ApplicationLogFile - { - get { return Path.Combine(LogFolderPath, $"{RuntimeIdentifier}_Application.txt"); } - } - - public string LogFolderPath - { - get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppDataFolderName, "Logs"); } - } - - public string ProgramCopyright - { - get - { - var executable = Assembly.GetEntryAssembly(); - var copyright = executable.GetCustomAttribute().Copyright; - - return copyright; - } - } - - public string ProgramTitle - { - get - { - var executable = Assembly.GetEntryAssembly(); - var title = executable.GetCustomAttribute().Title; - - return title; - } - } - - public string ProgramVersion - { - get - { - var executable = Assembly.GetEntryAssembly(); - var version = executable.GetCustomAttribute().InformationalVersion; - - return version; - } - } - - public string RuntimeIdentifier => LogFileDate; - } -} diff --git a/SafeExamBrowser.Configuration/BrowserSettings.cs b/SafeExamBrowser.Configuration/Settings/BrowserSettings.cs similarity index 56% rename from SafeExamBrowser.Configuration/BrowserSettings.cs rename to SafeExamBrowser.Configuration/Settings/BrowserSettings.cs index a5abc17f..6c8f0c9b 100644 --- a/SafeExamBrowser.Configuration/BrowserSettings.cs +++ b/SafeExamBrowser.Configuration/Settings/BrowserSettings.cs @@ -7,42 +7,21 @@ */ using System; -using System.IO; using SafeExamBrowser.Contracts.Configuration.Settings; -namespace SafeExamBrowser.Configuration +namespace SafeExamBrowser.Configuration.Settings { - public class BrowserSettings : IBrowserSettings + [Serializable] + internal class BrowserSettings : IBrowserSettings { - private ISettings settings; - - public BrowserSettings(ISettings settings) - { - this.settings = settings; - } - public bool AllowAddressBar => true; - public bool AllowBackwardNavigation => true; - public bool AllowDeveloperConsole => true; - public bool AllowForwardNavigation => true; - public bool AllowReloading => true; - - public string CachePath - { - get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), settings.AppDataFolderName, "Cache"); } - } - + public string CachePath { get; set; } public bool FullScreenMode => false; - - public string LogFile - { - get { return Path.Combine(settings.LogFolderPath, $"{settings.RuntimeIdentifier}_Browser.txt"); } - } - + public string LogFile { get; set; } public string StartUrl => "www.duckduckgo.com"; } } diff --git a/SafeExamBrowser.Configuration/KeyboardSettings.cs b/SafeExamBrowser.Configuration/Settings/KeyboardSettings.cs similarity index 77% rename from SafeExamBrowser.Configuration/KeyboardSettings.cs rename to SafeExamBrowser.Configuration/Settings/KeyboardSettings.cs index 7c54c966..1bea3dac 100644 --- a/SafeExamBrowser.Configuration/KeyboardSettings.cs +++ b/SafeExamBrowser.Configuration/Settings/KeyboardSettings.cs @@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Configuration.Settings; -namespace SafeExamBrowser.Configuration +namespace SafeExamBrowser.Configuration.Settings { - public class KeyboardSettings : IKeyboardSettings + [Serializable] + internal class KeyboardSettings : IKeyboardSettings { public bool AllowAltTab => false; diff --git a/SafeExamBrowser.Configuration/Settings/LoggingSettings.cs b/SafeExamBrowser.Configuration/Settings/LoggingSettings.cs new file mode 100644 index 00000000..10b9330d --- /dev/null +++ b/SafeExamBrowser.Configuration/Settings/LoggingSettings.cs @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using System; +using SafeExamBrowser.Contracts.Configuration.Settings; + +namespace SafeExamBrowser.Configuration.Settings +{ + [Serializable] + internal class LoggingSettings : ILoggingSettings + { + public DateTime ApplicationStartTime { get; set; } + public string BrowserLogFile { get; set; } + public string ClientLogFile { get; set; } + public string RuntimeLogFile { get; set; } + } +} diff --git a/SafeExamBrowser.Configuration/MouseSettings.cs b/SafeExamBrowser.Configuration/Settings/MouseSettings.cs similarity index 78% rename from SafeExamBrowser.Configuration/MouseSettings.cs rename to SafeExamBrowser.Configuration/Settings/MouseSettings.cs index a28e6f17..223fdb04 100644 --- a/SafeExamBrowser.Configuration/MouseSettings.cs +++ b/SafeExamBrowser.Configuration/Settings/MouseSettings.cs @@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Configuration.Settings; -namespace SafeExamBrowser.Configuration +namespace SafeExamBrowser.Configuration.Settings { - public class MouseSettings : IMouseSettings + [Serializable] + internal class MouseSettings : IMouseSettings { public bool AllowMiddleButton => false; diff --git a/SafeExamBrowser.Configuration/Settings/Settings.cs b/SafeExamBrowser.Configuration/Settings/Settings.cs new file mode 100644 index 00000000..dd869808 --- /dev/null +++ b/SafeExamBrowser.Configuration/Settings/Settings.cs @@ -0,0 +1,37 @@ +/* + * 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.Settings; + +namespace SafeExamBrowser.Configuration.Settings +{ + [Serializable] + internal class Settings : ISettings + { + public string AppDataFolder { get; set; } + public string ProgramCopyright { get; set; } + public string ProgramTitle { get; set; } + public string ProgramVersion { get; set; } + + public IBrowserSettings Browser { get; private set; } + public IKeyboardSettings Keyboard { get; private set; } + public ILoggingSettings Logging { get; private set; } + public IMouseSettings Mouse { get; private set; } + public ITaskbarSettings Taskbar { get; private set; } + + public Settings(BrowserSettings browser, KeyboardSettings keyboard, LoggingSettings logging, MouseSettings mouse, TaskbarSettings taskbar) + { + Browser = browser; + Keyboard = keyboard; + Logging = logging; + Mouse = mouse; + Taskbar = taskbar; + } + } +} diff --git a/SafeExamBrowser.Configuration/Settings/SettingsRepository.cs b/SafeExamBrowser.Configuration/Settings/SettingsRepository.cs new file mode 100644 index 00000000..10fb7eba --- /dev/null +++ b/SafeExamBrowser.Configuration/Settings/SettingsRepository.cs @@ -0,0 +1,52 @@ +/* + * 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 System.IO; +using System.Reflection; +using SafeExamBrowser.Contracts.Configuration.Settings; + +namespace SafeExamBrowser.Configuration.Settings +{ + public class SettingsRepository : ISettingsRepository + { + public ISettings Load(Uri path) + { + // TODO + throw new NotImplementedException(); + } + + public ISettings LoadDefaults() + { + var browser = new BrowserSettings(); + var keyboard = new KeyboardSettings(); + var logging = new LoggingSettings(); + var mouse = new MouseSettings(); + var taskbar = new TaskbarSettings(); + var settings = new Settings(browser, keyboard, logging, mouse, taskbar); + var executable = Assembly.GetEntryAssembly(); + var startTime = DateTime.Now; + var logFolderName = "Logs"; + var logFilePrefix = startTime.ToString("yyyy-MM-dd\\_HH\\hmm\\mss\\s"); + + settings.AppDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(SafeExamBrowser)); + settings.ProgramCopyright = executable.GetCustomAttribute().Copyright; + settings.ProgramTitle = executable.GetCustomAttribute().Title; + settings.ProgramVersion = executable.GetCustomAttribute().InformationalVersion; + + browser.CachePath = Path.Combine(settings.AppDataFolder, "Cache"); + + logging.ApplicationStartTime = DateTime.Now; + logging.BrowserLogFile = Path.Combine(settings.AppDataFolder, logFolderName, $"{logFilePrefix}_Browser.txt"); + logging.ClientLogFile = Path.Combine(settings.AppDataFolder, logFolderName, $"{logFilePrefix}_Client.txt"); + logging.RuntimeLogFile = Path.Combine(settings.AppDataFolder, logFolderName, $"{logFilePrefix}_Runtime.txt"); + + return settings; + } + } +} diff --git a/SafeExamBrowser.Configuration/TaskbarSettings.cs b/SafeExamBrowser.Configuration/Settings/TaskbarSettings.cs similarity index 79% rename from SafeExamBrowser.Configuration/TaskbarSettings.cs rename to SafeExamBrowser.Configuration/Settings/TaskbarSettings.cs index eb029f63..097a0c43 100644 --- a/SafeExamBrowser.Configuration/TaskbarSettings.cs +++ b/SafeExamBrowser.Configuration/Settings/TaskbarSettings.cs @@ -6,11 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Contracts.Configuration.Settings; -namespace SafeExamBrowser.Configuration +namespace SafeExamBrowser.Configuration.Settings { - public class TaskbarSettings : ITaskbarSettings + [Serializable] + internal class TaskbarSettings : ITaskbarSettings { public bool AllowApplicationLog => true; public bool AllowKeyboardLayout => true; diff --git a/SafeExamBrowser.Contracts/Client/IClientController.cs b/SafeExamBrowser.Contracts/Client/IClientController.cs new file mode 100644 index 00000000..1b828385 --- /dev/null +++ b/SafeExamBrowser.Contracts/Client/IClientController.cs @@ -0,0 +1,23 @@ +/* + * 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.Client +{ + public interface IClientController + { + /// + /// Wires up and starts the application event handling. + /// + void Start(); + + /// + /// Stops the event handling and removes all event subscriptions. + /// + void Stop(); + } +} diff --git a/SafeExamBrowser.Contracts/Configuration/Settings/ILoggingSettings.cs b/SafeExamBrowser.Contracts/Configuration/Settings/ILoggingSettings.cs new file mode 100644 index 00000000..2832210f --- /dev/null +++ b/SafeExamBrowser.Contracts/Configuration/Settings/ILoggingSettings.cs @@ -0,0 +1,35 @@ +/* + * 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; + +namespace SafeExamBrowser.Contracts.Configuration.Settings +{ + public interface ILoggingSettings + { + /// + /// The point in time when the application was started. + /// + DateTime ApplicationStartTime { get; } + + /// + /// The file path under which the log of the browser component is to be stored. + /// + string BrowserLogFile { get; } + + /// + /// The file path under which the log of the client component is to be stored. + /// + string ClientLogFile { get; } + + /// + /// The file path under which the log of the runtime component is to be stored. + /// + string RuntimeLogFile { get; } + } +} diff --git a/SafeExamBrowser.Contracts/Configuration/Settings/ISettings.cs b/SafeExamBrowser.Contracts/Configuration/Settings/ISettings.cs index b0a29d47..350ecd3f 100644 --- a/SafeExamBrowser.Contracts/Configuration/Settings/ISettings.cs +++ b/SafeExamBrowser.Contracts/Configuration/Settings/ISettings.cs @@ -11,14 +11,9 @@ namespace SafeExamBrowser.Contracts.Configuration.Settings public interface ISettings { /// - /// The name used for the application data folder. + /// The path of the application data folder. /// - string AppDataFolderName { get; } - - /// - /// The file path under which the application log is to be stored. - /// - string ApplicationLogFile { get; } + string AppDataFolder { get; } /// /// All browser-related settings. @@ -31,9 +26,9 @@ namespace SafeExamBrowser.Contracts.Configuration.Settings IKeyboardSettings Keyboard { get; } /// - /// The path where the log files are to be stored. + /// All logging-related settings. /// - string LogFolderPath { get; } + ILoggingSettings Logging { get; } /// /// All mouse-related settings. @@ -55,11 +50,6 @@ namespace SafeExamBrowser.Contracts.Configuration.Settings /// string ProgramVersion { get; } - /// - /// A string uniquely identifying the runtime of the application, used e.g. for the log file names. - /// - string RuntimeIdentifier { get; } - /// /// All taskbar-related settings. /// diff --git a/SafeExamBrowser.Contracts/Configuration/Settings/ISettingsRepository.cs b/SafeExamBrowser.Contracts/Configuration/Settings/ISettingsRepository.cs new file mode 100644 index 00000000..15fb434a --- /dev/null +++ b/SafeExamBrowser.Contracts/Configuration/Settings/ISettingsRepository.cs @@ -0,0 +1,26 @@ +/* + * 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; + +namespace SafeExamBrowser.Contracts.Configuration.Settings +{ + public interface ISettingsRepository + { + /// + /// Attempts to load settings from the specified path. + /// + /// Thrown if the given path cannot be resolved to a settings file. + ISettings Load(Uri path); + + /// + /// Loads the default settings. + /// + ISettings LoadDefaults(); + } +} diff --git a/SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs b/SafeExamBrowser.Contracts/Runtime/IRuntimeController.cs similarity index 71% rename from SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs rename to SafeExamBrowser.Contracts/Runtime/IRuntimeController.cs index fb7f990f..c6452974 100644 --- a/SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs +++ b/SafeExamBrowser.Contracts/Runtime/IRuntimeController.cs @@ -6,17 +6,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -namespace SafeExamBrowser.Contracts.Behaviour +namespace SafeExamBrowser.Contracts.Runtime { public interface IRuntimeController { /// - /// Wires up the event handling, i.e. subscribes to all relevant application events. + /// Wires up and starts the application event handling. /// void Start(); /// - /// Removes all event subscriptions. + /// Stops the event handling and removes all event subscriptions. /// void Stop(); } diff --git a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj index 99df9a33..b5d01816 100644 --- a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj +++ b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj @@ -53,9 +53,10 @@ - + + @@ -64,10 +65,12 @@ + + @@ -112,5 +115,6 @@ + \ No newline at end of file diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs new file mode 100644 index 00000000..1ebce66a --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/ClientControllerOperationTests.cs @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using SafeExamBrowser.Contracts.Client; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Core.Behaviour.Operations; + +namespace SafeExamBrowser.Core.UnitTests.Behaviour.Operations +{ + [TestClass] + public class ClientControllerOperationTests + { + private Mock loggerMock; + private Mock clientControllerMock; + private Mock splashScreenMock; + + private ClientControllerOperation sut; + + [TestInitialize] + public void Initialize() + { + loggerMock = new Mock(); + clientControllerMock = new Mock(); + splashScreenMock = new Mock(); + + sut = new ClientControllerOperation(clientControllerMock.Object, loggerMock.Object) + { + SplashScreen = splashScreenMock.Object + }; + } + + [TestMethod] + public void MustPerformCorrectly() + { + sut.Perform(); + + clientControllerMock.Verify(r => r.Start(), Times.Once); + } + + [TestMethod] + public void MustRevertCorrectly() + { + sut.Revert(); + + clientControllerMock.Verify(r => r.Stop(), Times.Once); + } + } +} diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs index f9582b21..0ec45251 100644 --- a/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/Operations/RuntimeControllerOperationTests.cs @@ -8,8 +8,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.Runtime; using SafeExamBrowser.Contracts.UserInterface; using SafeExamBrowser.Core.Behaviour.Operations; diff --git a/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj b/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj index 78947157..64fafa5f 100644 --- a/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj +++ b/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj @@ -1,6 +1,6 @@  - + Debug AnyCPU @@ -56,19 +56,25 @@ MinimumRecommendedRules.ruleset - - ..\packages\Castle.Core.4.1.0\lib\net45\Castle.Core.dll + + ..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll - ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - ..\packages\Moq.4.7.63\lib\net45\Moq.dll + + ..\packages\Moq.4.8.1\lib\net45\Moq.dll + + ..\packages\System.Threading.Tasks.Extensions.4.4.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll + + + ..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll + @@ -79,10 +85,10 @@ + - @@ -106,9 +112,6 @@ SafeExamBrowser.Core - - - Always @@ -120,14 +123,18 @@ Always + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - + \ No newline at end of file diff --git a/SafeExamBrowser.Core.UnitTests/app.config b/SafeExamBrowser.Core.UnitTests/app.config new file mode 100644 index 00000000..590e4b8f --- /dev/null +++ b/SafeExamBrowser.Core.UnitTests/app.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SafeExamBrowser.Core.UnitTests/packages.config b/SafeExamBrowser.Core.UnitTests/packages.config index 24b8c592..0c526abe 100644 --- a/SafeExamBrowser.Core.UnitTests/packages.config +++ b/SafeExamBrowser.Core.UnitTests/packages.config @@ -1,7 +1,9 @@  - - - - + + + + + + \ No newline at end of file diff --git a/SafeExamBrowser.Core/Behaviour/Operations/ClientControllerOperation.cs b/SafeExamBrowser.Core/Behaviour/Operations/ClientControllerOperation.cs new file mode 100644 index 00000000..83afc76e --- /dev/null +++ b/SafeExamBrowser.Core/Behaviour/Operations/ClientControllerOperation.cs @@ -0,0 +1,46 @@ +/* + * 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.Client; +using SafeExamBrowser.Contracts.I18n; +using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.UserInterface; + +namespace SafeExamBrowser.Core.Behaviour.Operations +{ + public class ClientControllerOperation : IOperation + { + private ILogger logger; + private IClientController controller; + + public ISplashScreen SplashScreen { private get; set; } + + public ClientControllerOperation(IClientController controller, ILogger logger) + { + this.controller = controller; + this.logger = logger; + } + + public void Perform() + { + logger.Info("Starting event handling..."); + SplashScreen.UpdateText(TextKey.SplashScreen_StartEventHandling); + + controller.Start(); + } + + public void Revert() + { + logger.Info("Stopping event handling..."); + SplashScreen.UpdateText(TextKey.SplashScreen_StopEventHandling); + + controller.Stop(); + } + } +} diff --git a/SafeExamBrowser.Core/Behaviour/Operations/RuntimeControllerOperation.cs b/SafeExamBrowser.Core/Behaviour/Operations/RuntimeControllerOperation.cs index 437b3e84..1b206e2e 100644 --- a/SafeExamBrowser.Core/Behaviour/Operations/RuntimeControllerOperation.cs +++ b/SafeExamBrowser.Core/Behaviour/Operations/RuntimeControllerOperation.cs @@ -9,6 +9,7 @@ using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; +using SafeExamBrowser.Contracts.Runtime; using SafeExamBrowser.Contracts.UserInterface; namespace SafeExamBrowser.Core.Behaviour.Operations diff --git a/SafeExamBrowser.Core/Logging/LogFileWriter.cs b/SafeExamBrowser.Core/Logging/LogFileWriter.cs index 6cf1b7ad..2b42481e 100644 --- a/SafeExamBrowser.Core/Logging/LogFileWriter.cs +++ b/SafeExamBrowser.Core/Logging/LogFileWriter.cs @@ -8,7 +8,6 @@ using System.IO; using System.Text; -using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.Logging; namespace SafeExamBrowser.Core.Logging @@ -19,14 +18,9 @@ namespace SafeExamBrowser.Core.Logging private readonly string filePath; private readonly ILogContentFormatter formatter; - public LogFileWriter(ILogContentFormatter formatter, ISettings settings) + public LogFileWriter(ILogContentFormatter formatter, string filePath) { - if (!Directory.Exists(settings.LogFolderPath)) - { - Directory.CreateDirectory(settings.LogFolderPath); - } - - this.filePath = settings.ApplicationLogFile; + this.filePath = filePath; this.formatter = formatter; } diff --git a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj index 47345186..cf3bbc0f 100644 --- a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj +++ b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj @@ -54,11 +54,11 @@ + - diff --git a/SafeExamBrowser.sln b/SafeExamBrowser.sln index 795f5e22..7a0cd858 100644 --- a/SafeExamBrowser.sln +++ b/SafeExamBrowser.sln @@ -37,6 +37,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.Client", "SafeExamBrowser.Client\SafeExamBrowser.Client.csproj", "{7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.Client.UnitTests", "SafeExamBrowser.Client.UnitTests\SafeExamBrowser.Client.UnitTests.csproj", "{15684416-FADF-4C51-85DE-4F343BFAB752}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -135,12 +137,20 @@ Global {A502DF54-7169-4647-94BD-18B192924866}.Release|x86.Build.0 = Release|Any CPU {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}.Debug|x86.ActiveCfg = Debug|Any CPU - {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}.Debug|x86.Build.0 = Debug|Any CPU + {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}.Debug|x86.ActiveCfg = Debug|x86 + {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}.Debug|x86.Build.0 = Debug|x86 {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}.Release|Any CPU.ActiveCfg = Release|Any CPU {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}.Release|Any CPU.Build.0 = Release|Any CPU {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}.Release|x86.ActiveCfg = Release|Any CPU {7CC5A895-E0D3-4E43-9B39-CCEC05A5A6A7}.Release|x86.Build.0 = Release|Any CPU + {15684416-FADF-4C51-85DE-4F343BFAB752}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {15684416-FADF-4C51-85DE-4F343BFAB752}.Debug|Any CPU.Build.0 = Debug|Any CPU + {15684416-FADF-4C51-85DE-4F343BFAB752}.Debug|x86.ActiveCfg = Debug|x86 + {15684416-FADF-4C51-85DE-4F343BFAB752}.Debug|x86.Build.0 = Debug|x86 + {15684416-FADF-4C51-85DE-4F343BFAB752}.Release|Any CPU.ActiveCfg = Release|Any CPU + {15684416-FADF-4C51-85DE-4F343BFAB752}.Release|Any CPU.Build.0 = Release|Any CPU + {15684416-FADF-4C51-85DE-4F343BFAB752}.Release|x86.ActiveCfg = Release|Any CPU + {15684416-FADF-4C51-85DE-4F343BFAB752}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SafeExamBrowser/App.cs b/SafeExamBrowser/App.cs index 72415694..87495875 100644 --- a/SafeExamBrowser/App.cs +++ b/SafeExamBrowser/App.cs @@ -65,7 +65,8 @@ namespace SafeExamBrowser if (success) { - MainWindow = instances.Taskbar; + // TODO: Probably needs new window to display status of running application... + MainWindow = instances.SplashScreen; MainWindow.Closing += MainWindow_Closing; MainWindow.Show(); } diff --git a/SafeExamBrowser/CompositionRoot.cs b/SafeExamBrowser/CompositionRoot.cs index 804c75b8..1a1cfabb 100644 --- a/SafeExamBrowser/CompositionRoot.cs +++ b/SafeExamBrowser/CompositionRoot.cs @@ -6,29 +6,23 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + using System.Collections.Generic; -using SafeExamBrowser.Browser; +using System.IO; using SafeExamBrowser.Configuration; +using SafeExamBrowser.Configuration.Settings; using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; -using SafeExamBrowser.Contracts.Monitoring; -using SafeExamBrowser.Contracts.SystemComponents; +using SafeExamBrowser.Contracts.Runtime; using SafeExamBrowser.Contracts.UserInterface; -using SafeExamBrowser.Contracts.UserInterface.Taskbar; using SafeExamBrowser.Contracts.WindowsApi; using SafeExamBrowser.Core.Behaviour; using SafeExamBrowser.Core.Behaviour.Operations; using SafeExamBrowser.Core.I18n; using SafeExamBrowser.Core.Logging; -using SafeExamBrowser.Monitoring.Display; -using SafeExamBrowser.Monitoring.Keyboard; -using SafeExamBrowser.Monitoring.Mouse; -using SafeExamBrowser.Monitoring.Processes; -using SafeExamBrowser.Monitoring.Windows; -using SafeExamBrowser.SystemComponents; using SafeExamBrowser.UserInterface.Classic; using SafeExamBrowser.WindowsApi; @@ -36,69 +30,50 @@ namespace SafeExamBrowser { internal class CompositionRoot { - private IApplicationController browserController; - private IApplicationInfo browserInfo; - private IDisplayMonitor displayMonitor; - private IKeyboardInterceptor keyboardInterceptor; private ILogger logger; - private ILogContentFormatter logFormatter; - private IMouseInterceptor mouseInterceptor; private INativeMethods nativeMethods; - private IProcessMonitor processMonitor; private IRuntimeController runtimeController; private ISettings settings; - private ISystemComponent keyboardLayout; - private ISystemComponent powerSupply; - private ISystemComponent wirelessNetwork; private ISystemInfo systemInfo; private IText text; private IUserInterfaceFactory uiFactory; - private IWindowMonitor windowMonitor; - public IShutdownController ShutdownController { get; private set; } - public IStartupController StartupController { get; private set; } - public Queue StartupOperations { get; private set; } - public Taskbar Taskbar { get; private set; } + internal IShutdownController ShutdownController { get; private set; } + internal IStartupController StartupController { get; private set; } + internal Queue StartupOperations { get; private set; } + internal SplashScreen SplashScreen { get; private set; } - public void BuildObjectGraph() + internal void BuildObjectGraph() { - browserInfo = new BrowserApplicationInfo(); - logger = new Logger(); - logFormatter = new DefaultLogFormatter(); nativeMethods = new NativeMethods(); - settings = new Settings(); + settings = new SettingsRepository().LoadDefaults(); systemInfo = new SystemInfo(); uiFactory = new UserInterfaceFactory(); - logger.Subscribe(new LogFileWriter(logFormatter, settings)); + InitializeLogger(); text = new Text(logger); - Taskbar = new Taskbar(new ModuleLogger(logger, typeof(Taskbar))); - browserController = new BrowserApplicationController(settings, 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); - runtimeController = new RuntimeController(displayMonitor, new ModuleLogger(logger, typeof(RuntimeController)), processMonitor, Taskbar, windowMonitor); + runtimeController = new RuntimeController(new ModuleLogger(logger, typeof(RuntimeController))); ShutdownController = new ShutdownController(logger, settings, text, uiFactory); StartupController = new StartupController(logger, settings, systemInfo, text, uiFactory); StartupOperations = new Queue(); StartupOperations.Enqueue(new I18nOperation(logger, text)); - StartupOperations.Enqueue(new KeyboardInterceptorOperation(keyboardInterceptor, logger, nativeMethods)); - StartupOperations.Enqueue(new WindowMonitorOperation(logger, windowMonitor)); - StartupOperations.Enqueue(new ProcessMonitorOperation(logger, processMonitor)); - StartupOperations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, Taskbar)); - StartupOperations.Enqueue(new TaskbarOperation(logger, settings.Taskbar, keyboardLayout, powerSupply, wirelessNetwork, systemInfo, Taskbar, text, uiFactory)); - StartupOperations.Enqueue(new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory)); StartupOperations.Enqueue(new RuntimeControllerOperation(runtimeController, logger)); - StartupOperations.Enqueue(new ClipboardOperation(logger, nativeMethods)); - StartupOperations.Enqueue(new MouseInterceptorOperation(logger, mouseInterceptor, nativeMethods)); + } + + private void InitializeLogger() + { + var logFolder = Path.GetDirectoryName(settings.Logging.RuntimeLogFile); + + if (!Directory.Exists(logFolder)) + { + Directory.CreateDirectory(logFolder); + } + + logger = new Logger(); + logger.Subscribe(new LogFileWriter(new DefaultLogFormatter(), settings.Logging.RuntimeLogFile)); } } } diff --git a/SafeExamBrowser/RuntimeController.cs b/SafeExamBrowser/RuntimeController.cs new file mode 100644 index 00000000..404550a9 --- /dev/null +++ b/SafeExamBrowser/RuntimeController.cs @@ -0,0 +1,33 @@ +/* + * 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.Logging; +using SafeExamBrowser.Contracts.Runtime; + +namespace SafeExamBrowser +{ + public class RuntimeController : IRuntimeController + { + private ILogger logger; + + public RuntimeController(ILogger logger) + { + this.logger = logger; + } + + public void Start() + { + // TODO + } + + public void Stop() + { + // TODO + } + } +} diff --git a/SafeExamBrowser/SafeExamBrowser.csproj b/SafeExamBrowser/SafeExamBrowser.csproj index bd922e4e..71c62aa3 100644 --- a/SafeExamBrowser/SafeExamBrowser.csproj +++ b/SafeExamBrowser/SafeExamBrowser.csproj @@ -101,6 +101,7 @@ Settings.settings True + ResXFileCodeGenerator Resources.Designer.cs