2017-07-05 11:41:19 +02:00
|
|
|
|
/*
|
2018-01-16 08:24:00 +01:00
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
2017-07-28 14:52:15 +02:00
|
|
|
|
*
|
2017-07-05 11:41:19 +02:00
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-01-17 14:08:39 +01:00
|
|
|
|
using System;
|
2017-07-21 12:05:31 +02:00
|
|
|
|
using System.Collections.Generic;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
using System.IO;
|
2018-01-17 14:08:39 +01:00
|
|
|
|
using System.Reflection;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
using System.Windows;
|
2017-07-20 14:16:47 +02:00
|
|
|
|
using SafeExamBrowser.Configuration;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
using SafeExamBrowser.Configuration.Settings;
|
2017-07-12 15:36:30 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour;
|
2018-02-01 08:37:12 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour.Operations;
|
2017-07-13 08:51:00 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
2017-07-21 12:05:31 +02:00
|
|
|
|
using SafeExamBrowser.Core.Behaviour.Operations;
|
2018-01-23 15:33:54 +01:00
|
|
|
|
using SafeExamBrowser.Core.Communication;
|
2017-07-05 17:21:52 +02:00
|
|
|
|
using SafeExamBrowser.Core.I18n;
|
2017-07-06 18:18:39 +02:00
|
|
|
|
using SafeExamBrowser.Core.Logging;
|
2018-01-18 08:16:20 +01:00
|
|
|
|
using SafeExamBrowser.Runtime.Behaviour;
|
|
|
|
|
using SafeExamBrowser.Runtime.Behaviour.Operations;
|
2017-08-22 09:37:17 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Classic;
|
2017-07-27 11:46:31 +02:00
|
|
|
|
using SafeExamBrowser.WindowsApi;
|
2017-07-05 17:21:52 +02:00
|
|
|
|
|
2018-01-18 08:16:20 +01:00
|
|
|
|
namespace SafeExamBrowser.Runtime
|
2017-07-05 11:41:19 +02:00
|
|
|
|
{
|
2017-07-07 15:46:32 +02:00
|
|
|
|
internal class CompositionRoot
|
2017-07-05 11:41:19 +02:00
|
|
|
|
{
|
2018-01-23 15:33:54 +01:00
|
|
|
|
private ILogger logger;
|
|
|
|
|
private RuntimeInfo runtimeInfo;
|
|
|
|
|
private ISystemInfo systemInfo;
|
|
|
|
|
|
2018-01-24 07:46:22 +01:00
|
|
|
|
internal IRuntimeController RuntimeController { get; private set; }
|
2018-01-17 08:26:44 +01:00
|
|
|
|
internal Queue<IOperation> StartupOperations { get; private set; }
|
2017-07-13 08:51:00 +02:00
|
|
|
|
|
2018-01-17 08:26:44 +01:00
|
|
|
|
internal void BuildObjectGraph()
|
2017-07-06 10:56:03 +02:00
|
|
|
|
{
|
2018-01-18 15:14:05 +01:00
|
|
|
|
var args = Environment.GetCommandLineArgs();
|
2018-01-17 14:08:39 +01:00
|
|
|
|
var nativeMethods = new NativeMethods();
|
2018-01-18 15:14:05 +01:00
|
|
|
|
var settingsRepository = new SettingsRepository();
|
2018-01-17 14:08:39 +01:00
|
|
|
|
var uiFactory = new UserInterfaceFactory();
|
2017-07-14 10:28:59 +02:00
|
|
|
|
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger = new Logger();
|
|
|
|
|
runtimeInfo = new RuntimeInfo();
|
|
|
|
|
systemInfo = new SystemInfo();
|
2017-07-06 10:56:03 +02:00
|
|
|
|
|
2018-01-19 14:04:12 +01:00
|
|
|
|
InitializeRuntimeInfo();
|
|
|
|
|
InitializeLogging();
|
2017-07-31 20:22:53 +02:00
|
|
|
|
|
2018-01-23 15:33:54 +01:00
|
|
|
|
var text = new Text(logger);
|
2018-02-01 08:37:12 +01:00
|
|
|
|
var operationSequence = new OperationSequence(logger, runtimeInfo, text, uiFactory);
|
2018-01-24 12:34:32 +01:00
|
|
|
|
var serviceProxy = new ServiceProxy(new ModuleLogger(logger, typeof(ServiceProxy)), "net.pipe://localhost/safeexambrowser/service");
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-02-01 08:37:12 +01:00
|
|
|
|
RuntimeController = new RuntimeController(logger, operationSequence, runtimeInfo, serviceProxy, settingsRepository, Application.Current.Shutdown, text, uiFactory);
|
2017-07-21 12:05:31 +02:00
|
|
|
|
|
|
|
|
|
StartupOperations = new Queue<IOperation>();
|
2018-01-23 15:33:54 +01:00
|
|
|
|
StartupOperations.Enqueue(new I18nOperation(logger, text));
|
|
|
|
|
StartupOperations.Enqueue(new ConfigurationOperation(logger, runtimeInfo, settingsRepository, text, uiFactory, args));
|
2018-01-24 12:34:32 +01:00
|
|
|
|
StartupOperations.Enqueue(new ServiceOperation(logger, serviceProxy, settingsRepository, text));
|
2018-01-30 14:41:36 +01:00
|
|
|
|
StartupOperations.Enqueue(new KioskModeOperation(logger, settingsRepository));
|
2018-01-23 15:33:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void LogStartupInformation()
|
|
|
|
|
{
|
|
|
|
|
var titleLine = $"/* {runtimeInfo.ProgramTitle}, Version {runtimeInfo.ProgramVersion}{Environment.NewLine}";
|
|
|
|
|
var copyrightLine = $"/* {runtimeInfo.ProgramCopyright}{Environment.NewLine}";
|
|
|
|
|
var emptyLine = $"/* {Environment.NewLine}";
|
|
|
|
|
var githubLine = $"/* Please visit https://www.github.com/SafeExamBrowser for more information.";
|
|
|
|
|
|
|
|
|
|
logger.Log($"{titleLine}{copyrightLine}{emptyLine}{githubLine}");
|
|
|
|
|
logger.Log(string.Empty);
|
|
|
|
|
logger.Log($"# Application started at {runtimeInfo.ApplicationStartTime.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
|
|
|
|
logger.Log($"# Running on {systemInfo.OperatingSystemInfo}");
|
|
|
|
|
logger.Log(string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void LogShutdownInformation()
|
|
|
|
|
{
|
|
|
|
|
logger?.Log($"{Environment.NewLine}# Application terminated at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
2018-01-17 08:26:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-19 14:04:12 +01:00
|
|
|
|
private void InitializeRuntimeInfo()
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
2018-01-17 14:08:39 +01:00
|
|
|
|
var appDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(SafeExamBrowser));
|
|
|
|
|
var executable = Assembly.GetEntryAssembly();
|
|
|
|
|
var startTime = DateTime.Now;
|
|
|
|
|
var logFolder = Path.Combine(appDataFolder, "Logs");
|
|
|
|
|
var logFilePrefix = startTime.ToString("yyyy-MM-dd\\_HH\\hmm\\mss\\s");
|
|
|
|
|
|
2018-01-23 15:33:54 +01:00
|
|
|
|
runtimeInfo.ApplicationStartTime = startTime;
|
|
|
|
|
runtimeInfo.AppDataFolder = appDataFolder;
|
|
|
|
|
runtimeInfo.BrowserCachePath = Path.Combine(appDataFolder, "Cache");
|
|
|
|
|
runtimeInfo.BrowserLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Browser.txt");
|
|
|
|
|
runtimeInfo.ClientLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Client.txt");
|
|
|
|
|
runtimeInfo.DefaultSettingsFileName = "SebClientSettings.seb";
|
|
|
|
|
runtimeInfo.ProgramCopyright = executable.GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright;
|
|
|
|
|
runtimeInfo.ProgramDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), nameof(SafeExamBrowser));
|
|
|
|
|
runtimeInfo.ProgramTitle = executable.GetCustomAttribute<AssemblyTitleAttribute>().Title;
|
|
|
|
|
runtimeInfo.ProgramVersion = executable.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
|
|
|
|
runtimeInfo.RuntimeLogFile = Path.Combine(logFolder, $"{logFilePrefix}_Runtime.txt");
|
2018-01-17 14:08:39 +01:00
|
|
|
|
}
|
2018-01-17 08:26:44 +01:00
|
|
|
|
|
2018-01-19 14:04:12 +01:00
|
|
|
|
private void InitializeLogging()
|
2018-01-17 14:08:39 +01:00
|
|
|
|
{
|
2018-01-23 15:33:54 +01:00
|
|
|
|
var logFileWriter = new LogFileWriter(new DefaultLogFormatter(), runtimeInfo.RuntimeLogFile);
|
2018-01-17 08:26:44 +01:00
|
|
|
|
|
2018-01-17 14:08:39 +01:00
|
|
|
|
logFileWriter.Initialize();
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger.Subscribe(logFileWriter);
|
2017-07-06 10:56:03 +02:00
|
|
|
|
}
|
2017-07-05 11:41:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|