diff --git a/SafeExamBrowser.Browser/BrowserApplicationInfo.cs b/SafeExamBrowser.Browser/BrowserApplicationInfo.cs new file mode 100644 index 00000000..23661e5a --- /dev/null +++ b/SafeExamBrowser.Browser/BrowserApplicationInfo.cs @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using SafeExamBrowser.Contracts.Configuration; + +namespace SafeExamBrowser.Browser +{ + public class BrowserApplicationInfo : IApplicationInfo + { + public string Name => "Chromium Browser"; + public string Tooltip => Name; + public IApplicationIconResource IconResource { get; } = new BrowserIconResource(); + } +} diff --git a/SafeExamBrowser.Browser/BrowserIconResource.cs b/SafeExamBrowser.Browser/BrowserIconResource.cs new file mode 100644 index 00000000..c1d97705 --- /dev/null +++ b/SafeExamBrowser.Browser/BrowserIconResource.cs @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2017 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; + +namespace SafeExamBrowser.Browser +{ + public class BrowserIconResource : IApplicationIconResource + { + public Uri Uri => new Uri("pack://application:,,,/SafeExamBrowser.Browser;component/Images/ChromiumLogo.png"); + public bool IsUriResource => true; + } +} diff --git a/SafeExamBrowser.Browser/Images/ChromiumLogo.png b/SafeExamBrowser.Browser/Images/ChromiumLogo.png new file mode 100644 index 00000000..0ebfdbe3 Binary files /dev/null and b/SafeExamBrowser.Browser/Images/ChromiumLogo.png differ diff --git a/SafeExamBrowser.Browser/Images/ChromiumLogo_Attribution.txt b/SafeExamBrowser.Browser/Images/ChromiumLogo_Attribution.txt new file mode 100644 index 00000000..b20cc5dd --- /dev/null +++ b/SafeExamBrowser.Browser/Images/ChromiumLogo_Attribution.txt @@ -0,0 +1,2 @@ +The "Chromium 11 Logo" by The Chromium Development Documentation Project / The Chromium Authors is licensed under +Creative Commons attribution 2.5. Source: https://commons.wikimedia.org/wiki/File:Chromium_11_Logo.svg \ No newline at end of file diff --git a/SafeExamBrowser.Browser/Properties/AssemblyInfo.cs b/SafeExamBrowser.Browser/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..4de2a54f --- /dev/null +++ b/SafeExamBrowser.Browser/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SafeExamBrowser.Browser")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SafeExamBrowser.Browser")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("04e653f1-98e6-4e34-9dd7-7f2bc1a8b767")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj b/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj new file mode 100644 index 00000000..c9969365 --- /dev/null +++ b/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {04E653F1-98E6-4E34-9DD7-7F2BC1A8B767} + Library + Properties + SafeExamBrowser.Browser + SafeExamBrowser.Browser + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + {47DA5933-BEF8-4729-94E6-ABDE2DB12262} + SafeExamBrowser.Contracts + + + + + + + + + \ No newline at end of file diff --git a/SafeExamBrowser.Contracts/Behaviour/IApplicationController.cs b/SafeExamBrowser.Contracts/Behaviour/IApplicationController.cs new file mode 100644 index 00000000..b3f04f7c --- /dev/null +++ b/SafeExamBrowser.Contracts/Behaviour/IApplicationController.cs @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2017 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.UserInterface; + +namespace SafeExamBrowser.Contracts.Behaviour +{ + public interface IApplicationController + { + /// + /// The handler to be executed when an application's taskbar button gets clicked. + /// + TaskbarButtonClickHandler OnClick { get; } + } +} diff --git a/SafeExamBrowser.Contracts/Configuration/IShutdownController.cs b/SafeExamBrowser.Contracts/Behaviour/IShutdownController.cs similarity index 67% rename from SafeExamBrowser.Contracts/Configuration/IShutdownController.cs rename to SafeExamBrowser.Contracts/Behaviour/IShutdownController.cs index 2acf5cdb..0da0e1a5 100644 --- a/SafeExamBrowser.Contracts/Configuration/IShutdownController.cs +++ b/SafeExamBrowser.Contracts/Behaviour/IShutdownController.cs @@ -6,10 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -namespace SafeExamBrowser.Contracts.Configuration +namespace SafeExamBrowser.Contracts.Behaviour { public interface IShutdownController { + /// + /// Reverts any changes performed during the startup or runtime and releases all used resources. + /// void FinalizeApplication(); } } diff --git a/SafeExamBrowser.Contracts/Configuration/IStartupController.cs b/SafeExamBrowser.Contracts/Behaviour/IStartupController.cs similarity index 64% rename from SafeExamBrowser.Contracts/Configuration/IStartupController.cs rename to SafeExamBrowser.Contracts/Behaviour/IStartupController.cs index f04ae701..913402bd 100644 --- a/SafeExamBrowser.Contracts/Configuration/IStartupController.cs +++ b/SafeExamBrowser.Contracts/Behaviour/IStartupController.cs @@ -6,10 +6,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -namespace SafeExamBrowser.Contracts.Configuration +namespace SafeExamBrowser.Contracts.Behaviour { public interface IStartupController { + /// + /// Tries to initialize the application. Returns true if the initialization was successful, + /// false otherwise. + /// bool TryInitializeApplication(); } } diff --git a/SafeExamBrowser.Contracts/Configuration/IApplicationIconResource.cs b/SafeExamBrowser.Contracts/Configuration/IApplicationIconResource.cs new file mode 100644 index 00000000..dde1084b --- /dev/null +++ b/SafeExamBrowser.Contracts/Configuration/IApplicationIconResource.cs @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017 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 +{ + public interface IApplicationIconResource + { + /// + /// The Uri pointing to the application icon. + /// + Uri Uri { get; } + + /// + /// Indicates whether the icon resource consists of a Uri. + /// + bool IsUriResource { get; } + } +} diff --git a/SafeExamBrowser.Contracts/Configuration/IApplicationInfo.cs b/SafeExamBrowser.Contracts/Configuration/IApplicationInfo.cs new file mode 100644 index 00000000..d00de367 --- /dev/null +++ b/SafeExamBrowser.Contracts/Configuration/IApplicationInfo.cs @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017 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.Configuration +{ + public interface IApplicationInfo + { + /// + /// The name of the application. + /// + string Name { get; } + + /// + /// The tooltip for the application. + /// + string Tooltip { get; } + + /// + /// The resource providing the application icon. + /// + IApplicationIconResource IconResource { get; } + } +} diff --git a/SafeExamBrowser.Contracts/Configuration/ISettings.cs b/SafeExamBrowser.Contracts/Configuration/ISettings.cs index 70ed699f..6a49de0b 100644 --- a/SafeExamBrowser.Contracts/Configuration/ISettings.cs +++ b/SafeExamBrowser.Contracts/Configuration/ISettings.cs @@ -10,9 +10,24 @@ namespace SafeExamBrowser.Contracts.Configuration { public interface ISettings { + /// + /// The copyright information for the application, to be displayed in e.g. the log or the splash screen. + /// string CopyrightInfo { get; } + + /// + /// The path where the log files are to be stored. + /// string LogFolderPath { get; } + + /// + /// The information to be printed at the beginning of the application log. + /// string LogHeader { get; } + + /// + /// The program version of the application. + /// string ProgramVersion { get; } } } diff --git a/SafeExamBrowser.Contracts/I18n/IText.cs b/SafeExamBrowser.Contracts/I18n/IText.cs index eff2d16e..02d8671f 100644 --- a/SafeExamBrowser.Contracts/I18n/IText.cs +++ b/SafeExamBrowser.Contracts/I18n/IText.cs @@ -10,6 +10,10 @@ namespace SafeExamBrowser.Contracts.I18n { public interface IText { + /// + /// Gets the text associated with the specified key. If the key was not found, a default text indicating + /// that the given key is not configured shall be returned. + /// string Get(Key key); } } diff --git a/SafeExamBrowser.Contracts/I18n/ITextResource.cs b/SafeExamBrowser.Contracts/I18n/ITextResource.cs index 64fdb881..5b43ee0c 100644 --- a/SafeExamBrowser.Contracts/I18n/ITextResource.cs +++ b/SafeExamBrowser.Contracts/I18n/ITextResource.cs @@ -12,6 +12,9 @@ namespace SafeExamBrowser.Contracts.I18n { public interface ITextResource { + /// + /// Loads all text data from a resource. + /// IDictionary LoadText(); } } diff --git a/SafeExamBrowser.Contracts/I18n/Key.cs b/SafeExamBrowser.Contracts/I18n/Key.cs index 7368b4f4..046515a8 100644 --- a/SafeExamBrowser.Contracts/I18n/Key.cs +++ b/SafeExamBrowser.Contracts/I18n/Key.cs @@ -8,6 +8,9 @@ namespace SafeExamBrowser.Contracts.I18n { + /// + /// Defines all text components of the user interface. + /// public enum Key { MessageBox_ShutdownError, diff --git a/SafeExamBrowser.Contracts/Logging/ILogContent.cs b/SafeExamBrowser.Contracts/Logging/ILogContent.cs index e4755041..31ff459e 100644 --- a/SafeExamBrowser.Contracts/Logging/ILogContent.cs +++ b/SafeExamBrowser.Contracts/Logging/ILogContent.cs @@ -10,6 +10,9 @@ using System; namespace SafeExamBrowser.Contracts.Logging { + /// + /// Defines a content element of the application log. + /// public interface ILogContent : ICloneable { } diff --git a/SafeExamBrowser.Contracts/Logging/ILogMessage.cs b/SafeExamBrowser.Contracts/Logging/ILogMessage.cs index 5fc62eba..c905295c 100644 --- a/SafeExamBrowser.Contracts/Logging/ILogMessage.cs +++ b/SafeExamBrowser.Contracts/Logging/ILogMessage.cs @@ -12,9 +12,24 @@ namespace SafeExamBrowser.Contracts.Logging { public interface ILogMessage : ILogContent { + /// + /// The date when the message was logged. + /// DateTime DateTime { get; } + + /// + /// The severity of the message. + /// LogLevel Severity { get; } + + /// + /// The message itself. + /// string Message { get; } + + /// + /// Information about the thread on which the message was logged. + /// IThreadInfo ThreadInfo { get; } } } diff --git a/SafeExamBrowser.Contracts/Logging/ILogObserver.cs b/SafeExamBrowser.Contracts/Logging/ILogObserver.cs index 25c3d58d..9e96e3f1 100644 --- a/SafeExamBrowser.Contracts/Logging/ILogObserver.cs +++ b/SafeExamBrowser.Contracts/Logging/ILogObserver.cs @@ -10,6 +10,9 @@ namespace SafeExamBrowser.Contracts.Logging { public interface ILogObserver { + /// + /// Notifies an observer once new content has been added to the application log. + /// void Notify(ILogContent content); } } diff --git a/SafeExamBrowser.Contracts/Logging/ILogText.cs b/SafeExamBrowser.Contracts/Logging/ILogText.cs index 5b3dc81d..64a9ec77 100644 --- a/SafeExamBrowser.Contracts/Logging/ILogText.cs +++ b/SafeExamBrowser.Contracts/Logging/ILogText.cs @@ -10,6 +10,9 @@ namespace SafeExamBrowser.Contracts.Logging { public interface ILogText : ILogContent { + /// + /// The raw text to be appended to the application log. + /// string Text { get; } } } diff --git a/SafeExamBrowser.Contracts/Logging/ILogger.cs b/SafeExamBrowser.Contracts/Logging/ILogger.cs index 8074e267..8b4979ce 100644 --- a/SafeExamBrowser.Contracts/Logging/ILogger.cs +++ b/SafeExamBrowser.Contracts/Logging/ILogger.cs @@ -13,14 +13,50 @@ namespace SafeExamBrowser.Contracts.Logging { public interface ILogger { + /// + /// Logs the given message with severity INFO. + /// void Info(string message); + + /// + /// Logs the given message with severity WARNING. + /// void Warn(string message); + + /// + /// Logs the given message with severity ERROR. + /// void Error(string message); + + /// + /// Logs the given message with severity ERROR and includes information about + /// the specified exception (i.e. type, message and stacktrace). + /// void Error(string message, Exception exception); + + /// + /// Logs the given message as raw text. + /// void Log(string message); + + /// + /// Appends the given content to the log. + /// void Log(ILogContent content); + + /// + /// Suscribes an observer to the application log. + /// void Subscribe(ILogObserver observer); + + /// + /// Unsubscribes an observer from the application log. + /// void Unsubscribe(ILogObserver observer); + + /// + /// Returns a copy of the current log content. + /// IList GetLog(); } } diff --git a/SafeExamBrowser.Contracts/Logging/IThreadInfo.cs b/SafeExamBrowser.Contracts/Logging/IThreadInfo.cs index 1dc23ff3..296b19fb 100644 --- a/SafeExamBrowser.Contracts/Logging/IThreadInfo.cs +++ b/SafeExamBrowser.Contracts/Logging/IThreadInfo.cs @@ -12,8 +12,19 @@ namespace SafeExamBrowser.Contracts.Logging { public interface IThreadInfo : ICloneable { + /// + /// The id of the thread. + /// int Id { get; } + + /// + /// The thread's name. + /// string Name { get; } + + /// + /// A flag indicating whether the thread has a name. + /// bool HasName { get; } } } diff --git a/SafeExamBrowser.Contracts/Logging/LogLevel.cs b/SafeExamBrowser.Contracts/Logging/LogLevel.cs index 53428f9a..4eb47a55 100644 --- a/SafeExamBrowser.Contracts/Logging/LogLevel.cs +++ b/SafeExamBrowser.Contracts/Logging/LogLevel.cs @@ -8,6 +8,9 @@ namespace SafeExamBrowser.Contracts.Logging { + /// + /// Defines the severity levels of the application log. + /// public enum LogLevel { Info = 1, diff --git a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj index 01114287..1e4bce48 100644 --- a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj +++ b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj @@ -40,9 +40,12 @@ + + + - - + + @@ -58,6 +61,7 @@ + diff --git a/SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs b/SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs index d5181d98..d70a988a 100644 --- a/SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs +++ b/SafeExamBrowser.Contracts/UserInterface/IMessageBox.cs @@ -10,6 +10,9 @@ namespace SafeExamBrowser.Contracts.UserInterface { public interface IMessageBox { + /// + /// Shows a message box according to the specified parameters. + /// void Show(string message, string title, MessageBoxAction action = MessageBoxAction.Confirm, MessageBoxIcon icon = MessageBoxIcon.Information); } } diff --git a/SafeExamBrowser.Contracts/UserInterface/ISplashScreen.cs b/SafeExamBrowser.Contracts/UserInterface/ISplashScreen.cs index 67396d7e..c6696ec7 100644 --- a/SafeExamBrowser.Contracts/UserInterface/ISplashScreen.cs +++ b/SafeExamBrowser.Contracts/UserInterface/ISplashScreen.cs @@ -12,9 +12,24 @@ namespace SafeExamBrowser.Contracts.UserInterface { public interface ISplashScreen : ILogObserver { + /// + /// Closes the splash screen. + /// void Close(); + + /// + /// Set the maximum of the splash screen's progress bar. + /// void SetMaxProgress(int max); + + /// + /// Shows the splash screen to the user. + /// void Show(); - void UpdateProgress(); + + /// + /// Updates the progress bar of the splash screen according to the specified amount. + /// + void UpdateProgress(int amount = 1); } } diff --git a/SafeExamBrowser.Contracts/UserInterface/ITaskbar.cs b/SafeExamBrowser.Contracts/UserInterface/ITaskbar.cs index d14f864f..709a0883 100644 --- a/SafeExamBrowser.Contracts/UserInterface/ITaskbar.cs +++ b/SafeExamBrowser.Contracts/UserInterface/ITaskbar.cs @@ -10,9 +10,24 @@ namespace SafeExamBrowser.Contracts.UserInterface { public interface ITaskbar { + /// + /// Adds the given application button to the taskbar. + /// void AddButton(ITaskbarButton button); + + /// + /// Moves the taskbar to the given location on the screen. + /// void SetPosition(int x, int y); - void SetSize(int widht, int height); + + /// + /// Sets the size of the taskbar. + /// + void SetSize(int width, int height); + + /// + /// Displays the taskbar on the screen. + /// void Show(); } } diff --git a/SafeExamBrowser.Contracts/UserInterface/ITaskbarButton.cs b/SafeExamBrowser.Contracts/UserInterface/ITaskbarButton.cs index f61bc4d1..5e4859d4 100644 --- a/SafeExamBrowser.Contracts/UserInterface/ITaskbarButton.cs +++ b/SafeExamBrowser.Contracts/UserInterface/ITaskbarButton.cs @@ -6,12 +6,31 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; + namespace SafeExamBrowser.Contracts.UserInterface { - public delegate void TaskbarButtonClickHandler(); + public delegate void TaskbarButtonClickHandler(Guid? instanceId = null); public interface ITaskbarButton { + /// + /// OnClick handler, executed when the user clicks on the application button. If multiple instances of + /// an application are active, the handler is only executed when the user selects one of the instances. + /// event TaskbarButtonClickHandler OnClick; + + /// + /// Registers a new instance of an application, to be displayed when the user clicks the taskbar button. + /// + /// The identifier for the application instance. + /// An optional title to be displayed (if multiple instances are active). + void RegisterInstance(Guid id, string title = null); + + /// + /// Unregisters an application instance, e.g. if it gets closed. + /// + /// The identifier for the application instance. + void UnregisterInstance(Guid id); } } diff --git a/SafeExamBrowser.Contracts/UserInterface/IUiElementFactory.cs b/SafeExamBrowser.Contracts/UserInterface/IUiElementFactory.cs new file mode 100644 index 00000000..f397772f --- /dev/null +++ b/SafeExamBrowser.Contracts/UserInterface/IUiElementFactory.cs @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using SafeExamBrowser.Contracts.Configuration; + +namespace SafeExamBrowser.Contracts.UserInterface +{ + public interface IUiElementFactory + { + /// + /// Creates a taskbar button, initialized with the given application information. + /// + ITaskbarButton CreateButton(IApplicationInfo info); + } +} diff --git a/SafeExamBrowser.Contracts/UserInterface/MessageBoxAction.cs b/SafeExamBrowser.Contracts/UserInterface/MessageBoxAction.cs index b61d961f..4d2e987a 100644 --- a/SafeExamBrowser.Contracts/UserInterface/MessageBoxAction.cs +++ b/SafeExamBrowser.Contracts/UserInterface/MessageBoxAction.cs @@ -8,6 +8,9 @@ namespace SafeExamBrowser.Contracts.UserInterface { + /// + /// Defines all actions available for a message box. + /// public enum MessageBoxAction { Confirm diff --git a/SafeExamBrowser.Contracts/UserInterface/MessageBoxIcon.cs b/SafeExamBrowser.Contracts/UserInterface/MessageBoxIcon.cs index 548e8494..9f2a5901 100644 --- a/SafeExamBrowser.Contracts/UserInterface/MessageBoxIcon.cs +++ b/SafeExamBrowser.Contracts/UserInterface/MessageBoxIcon.cs @@ -8,6 +8,9 @@ namespace SafeExamBrowser.Contracts.UserInterface { + /// + /// Defines all icons available in a message box. + /// public enum MessageBoxIcon { Information, diff --git a/SafeExamBrowser.Core/Configuration/ShutdownController.cs b/SafeExamBrowser.Core/Behaviour/ShutdownController.cs similarity index 92% rename from SafeExamBrowser.Core/Configuration/ShutdownController.cs rename to SafeExamBrowser.Core/Behaviour/ShutdownController.cs index 643fba22..b31f6f6b 100644 --- a/SafeExamBrowser.Core/Configuration/ShutdownController.cs +++ b/SafeExamBrowser.Core/Behaviour/ShutdownController.cs @@ -7,12 +7,12 @@ */ using System; -using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; -namespace SafeExamBrowser.Core.Configuration +namespace SafeExamBrowser.Core.Behaviour { public class ShutdownController : IShutdownController { diff --git a/SafeExamBrowser.Core/Configuration/StartupController.cs b/SafeExamBrowser.Core/Behaviour/StartupController.cs similarity index 79% rename from SafeExamBrowser.Core/Configuration/StartupController.cs rename to SafeExamBrowser.Core/Behaviour/StartupController.cs index c86325f3..95d71155 100644 --- a/SafeExamBrowser.Core/Configuration/StartupController.cs +++ b/SafeExamBrowser.Core/Behaviour/StartupController.cs @@ -8,30 +8,35 @@ using System; using System.Threading; +using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; -namespace SafeExamBrowser.Core.Configuration +namespace SafeExamBrowser.Core.Behaviour { public class StartupController : IStartupController { + private IApplicationInfo browserInfo; private ILogger logger; private IMessageBox messageBox; private ISettings settings; private ISplashScreen splashScreen; private ITaskbar taskbar; private IText text; + private IUiElementFactory uiFactory; - public StartupController(ILogger logger, IMessageBox messageBox, ISettings settings, ISplashScreen splashScreen, ITaskbar taskbar, IText text) + public StartupController(IApplicationInfo browserInfo, ILogger logger, IMessageBox messageBox, ISettings settings, ISplashScreen splashScreen, ITaskbar taskbar, IText text, IUiElementFactory uiFactory) { + this.browserInfo = browserInfo; this.logger = logger; this.messageBox = messageBox; this.settings = settings; this.splashScreen = splashScreen; this.taskbar = taskbar; this.text = text; + this.uiFactory = uiFactory; } public bool TryInitializeApplication() @@ -41,10 +46,15 @@ namespace SafeExamBrowser.Core.Configuration logger.Log(settings.LogHeader); logger.Log($"{Environment.NewLine}# Application started at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}{Environment.NewLine}"); logger.Info("Initiating startup procedure."); - logger.Subscribe(splashScreen); - splashScreen.SetMaxProgress(4); + splashScreen.SetMaxProgress(3); + logger.Info("Initializing browser."); + + var browserButton = uiFactory.CreateButton(browserInfo); + + taskbar.AddButton(browserButton); + splashScreen.UpdateProgress(); // TODO (depending on specification): @@ -72,8 +82,6 @@ namespace SafeExamBrowser.Core.Configuration logger.Info("Closing splash screen."); Thread.Sleep(1000); - - splashScreen.UpdateProgress(); logger.Unsubscribe(splashScreen); logger.Info("Application successfully initialized!"); diff --git a/SafeExamBrowser.Core/Logging/LogMessage.cs b/SafeExamBrowser.Core/Logging/LogMessage.cs index 5f35ad37..a39d6cf4 100644 --- a/SafeExamBrowser.Core/Logging/LogMessage.cs +++ b/SafeExamBrowser.Core/Logging/LogMessage.cs @@ -20,15 +20,10 @@ namespace SafeExamBrowser.Core.Entities public LogMessage(DateTime dateTime, LogLevel severity, string message, IThreadInfo threadInfo) { - if (threadInfo == null) - { - throw new ArgumentNullException(nameof(threadInfo)); - } - DateTime = dateTime; Severity = severity; Message = message; - ThreadInfo = threadInfo; + ThreadInfo = threadInfo ?? throw new ArgumentNullException(nameof(threadInfo)); } public object Clone() diff --git a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj index f05e7753..36b64c06 100644 --- a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj +++ b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj @@ -41,8 +41,8 @@ - - + + diff --git a/SafeExamBrowser.UserInterface/Controls/TaskbarButton.xaml b/SafeExamBrowser.UserInterface/Controls/TaskbarButton.xaml index cb1caf2a..99526f0e 100644 --- a/SafeExamBrowser.UserInterface/Controls/TaskbarButton.xaml +++ b/SafeExamBrowser.UserInterface/Controls/TaskbarButton.xaml @@ -7,7 +7,7 @@ mc:Ignorable="d" d:DesignHeight="40" d:DesignWidth="40"> - diff --git a/SafeExamBrowser.UserInterface/Controls/TaskbarButton.xaml.cs b/SafeExamBrowser.UserInterface/Controls/TaskbarButton.xaml.cs index 78e33223..cc03e4d6 100644 --- a/SafeExamBrowser.UserInterface/Controls/TaskbarButton.xaml.cs +++ b/SafeExamBrowser.UserInterface/Controls/TaskbarButton.xaml.cs @@ -9,6 +9,7 @@ using System; using System.Windows.Controls; using System.Windows.Media.Imaging; +using SafeExamBrowser.Contracts.Configuration; using SafeExamBrowser.Contracts.UserInterface; namespace SafeExamBrowser.UserInterface.Controls @@ -17,17 +18,44 @@ namespace SafeExamBrowser.UserInterface.Controls { public event TaskbarButtonClickHandler OnClick; - public TaskbarButton(string imageUri) + public TaskbarButton(IApplicationInfo info) { InitializeComponent(); + InitializeButton(info); + } - var icon = new BitmapImage(); + public void RegisterInstance(Guid id, string title = null) + { + throw new NotImplementedException(); + } - icon.BeginInit(); - icon.UriSource = new Uri(imageUri); - icon.EndInit(); + public void UnregisterInstance(Guid id) + { + throw new NotImplementedException(); + } - IconImage.Source = icon; + private void InitializeButton(IApplicationInfo info) + { + Button.ToolTip = info.Tooltip; + + if (info.IconResource.IsUriResource) + { + var icon = new BitmapImage(); + + icon.BeginInit(); + icon.UriSource = info.IconResource.Uri; + icon.EndInit(); + + IconImage.Source = icon; + } + } + + private void Button_Click(object sender, System.Windows.RoutedEventArgs e) + { + // TODO + OnClick?.Invoke(); + + throw new NotImplementedException(); } } } diff --git a/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj b/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj index 693734cf..43f02d4d 100644 --- a/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj +++ b/SafeExamBrowser.UserInterface/SafeExamBrowser.UserInterface.csproj @@ -72,6 +72,7 @@ Taskbar.xaml + diff --git a/SafeExamBrowser.UserInterface/SplashScreen.xaml.cs b/SafeExamBrowser.UserInterface/SplashScreen.xaml.cs index 583bb8b7..c340e95c 100644 --- a/SafeExamBrowser.UserInterface/SplashScreen.xaml.cs +++ b/SafeExamBrowser.UserInterface/SplashScreen.xaml.cs @@ -45,9 +45,9 @@ namespace SafeExamBrowser.UserInterface model.MaxProgress = max; } - public void UpdateProgress() + public void UpdateProgress(int amount = 1) { - model.CurrentProgress += 1; + model.CurrentProgress += amount; } } } diff --git a/SafeExamBrowser.UserInterface/Taskbar.xaml.cs b/SafeExamBrowser.UserInterface/Taskbar.xaml.cs index 129b08ac..393b161f 100644 --- a/SafeExamBrowser.UserInterface/Taskbar.xaml.cs +++ b/SafeExamBrowser.UserInterface/Taskbar.xaml.cs @@ -32,9 +32,9 @@ namespace SafeExamBrowser.UserInterface Top = y; } - public void SetSize(int widht, int height) + public void SetSize(int width, int height) { - Width = widht; + Width = width; Height = height; } } diff --git a/SafeExamBrowser.UserInterface/UiElementFactory.cs b/SafeExamBrowser.UserInterface/UiElementFactory.cs new file mode 100644 index 00000000..e2291995 --- /dev/null +++ b/SafeExamBrowser.UserInterface/UiElementFactory.cs @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +using SafeExamBrowser.Contracts.Configuration; +using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.UserInterface.Controls; + +namespace SafeExamBrowser.UserInterface +{ + public class UiElementFactory : IUiElementFactory + { + public ITaskbarButton CreateButton(IApplicationInfo info) + { + return new TaskbarButton(info); + } + } +} diff --git a/SafeExamBrowser.sln b/SafeExamBrowser.sln index d8ea5884..d36f315a 100644 --- a/SafeExamBrowser.sln +++ b/SafeExamBrowser.sln @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.Core.UnitTe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.Contracts", "SafeExamBrowser.Contracts\SafeExamBrowser.Contracts.csproj", "{47DA5933-BEF8-4729-94E6-ABDE2DB12262}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SafeExamBrowser.Browser", "SafeExamBrowser.Browser\SafeExamBrowser.Browser.csproj", "{04E653F1-98E6-4E34-9DD7-7F2BC1A8B767}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {47DA5933-BEF8-4729-94E6-ABDE2DB12262}.Debug|Any CPU.Build.0 = Debug|Any CPU {47DA5933-BEF8-4729-94E6-ABDE2DB12262}.Release|Any CPU.ActiveCfg = Release|Any CPU {47DA5933-BEF8-4729-94E6-ABDE2DB12262}.Release|Any CPU.Build.0 = Release|Any CPU + {04E653F1-98E6-4E34-9DD7-7F2BC1A8B767}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {04E653F1-98E6-4E34-9DD7-7F2BC1A8B767}.Debug|Any CPU.Build.0 = Debug|Any CPU + {04E653F1-98E6-4E34-9DD7-7F2BC1A8B767}.Release|Any CPU.ActiveCfg = Release|Any CPU + {04E653F1-98E6-4E34-9DD7-7F2BC1A8B767}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SafeExamBrowser/App.cs b/SafeExamBrowser/App.cs index 876c200f..a0335e1d 100644 --- a/SafeExamBrowser/App.cs +++ b/SafeExamBrowser/App.cs @@ -15,7 +15,6 @@ namespace SafeExamBrowser public class App : Application { private static readonly Mutex mutex = new Mutex(true, "safe_exam_browser_single_instance_mutex"); - private CompositionRoot instances; [STAThread] @@ -78,14 +77,18 @@ namespace SafeExamBrowser if (success) { - instances.Taskbar.Dispatcher.Invoke(() => + Dispatcher.Invoke(() => { MainWindow = instances.Taskbar; MainWindow.Show(); }); } + else + { + Dispatcher.Invoke(Shutdown); + } - instances.SplashScreen.Dispatcher.Invoke(instances.SplashScreen.Close); + Dispatcher.Invoke(instances.SplashScreen.Close); } } } diff --git a/SafeExamBrowser/CompositionRoot.cs b/SafeExamBrowser/CompositionRoot.cs index d5ed86fb..8e41a7ab 100644 --- a/SafeExamBrowser/CompositionRoot.cs +++ b/SafeExamBrowser/CompositionRoot.cs @@ -6,10 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using SafeExamBrowser.Contracts.Configuration; -using SafeExamBrowser.Contracts.I18n; -using SafeExamBrowser.Contracts.Logging; -using SafeExamBrowser.Contracts.UserInterface; +using SafeExamBrowser.Browser; +using SafeExamBrowser.Contracts.Behaviour; +using SafeExamBrowser.Core.Behaviour; using SafeExamBrowser.Core.Configuration; using SafeExamBrowser.Core.I18n; using SafeExamBrowser.Core.Logging; @@ -19,28 +18,27 @@ namespace SafeExamBrowser { internal class CompositionRoot { - public ILogger Logger { get; private set; } - public IMessageBox MessageBox { get; private set; } - public ISettings Settings { get; private set; } public IShutdownController ShutdownController { get; set; } public IStartupController StartupController { get; private set; } - public IText Text { get; private set; } + public SplashScreen SplashScreen { get; private set; } public Taskbar Taskbar { get; private set; } public void BuildObjectGraph() { - MessageBox = new WpfMessageBox(); - Settings = new Settings(); - Taskbar = new Taskbar(); + var browserInfo = new BrowserApplicationInfo(); + var messageBox = new WpfMessageBox(); + var settings = new Settings(); + var logger = new Logger(); + var text = new Text(new XmlTextResource()); + var uiFactory = new UiElementFactory(); - Logger = new Logger(); - Logger.Subscribe(new LogFileWriter(Settings)); + logger.Subscribe(new LogFileWriter(settings)); - Text = new Text(new XmlTextResource()); - SplashScreen = new SplashScreen(Settings); - ShutdownController = new ShutdownController(Logger, MessageBox, Text); - StartupController = new StartupController(Logger, MessageBox, Settings, SplashScreen, Taskbar, Text); + Taskbar = new Taskbar(); + SplashScreen = new SplashScreen(settings); + ShutdownController = new ShutdownController(logger, messageBox, text); + StartupController = new StartupController(browserInfo, logger, messageBox, settings, SplashScreen, Taskbar, text, uiFactory); } } } diff --git a/SafeExamBrowser/SafeExamBrowser.csproj b/SafeExamBrowser/SafeExamBrowser.csproj index 1bf280d0..03506c44 100644 --- a/SafeExamBrowser/SafeExamBrowser.csproj +++ b/SafeExamBrowser/SafeExamBrowser.csproj @@ -93,6 +93,10 @@ + + {04E653F1-98E6-4E34-9DD7-7F2BC1A8B767} + SafeExamBrowser.Browser + {47DA5933-BEF8-4729-94E6-ABDE2DB12262} SafeExamBrowser.Contracts