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;
|
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;
|
2017-07-13 08:51:00 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
2017-07-12 15:36:30 +02:00
|
|
|
|
using SafeExamBrowser.Core.Behaviour;
|
2017-07-21 12:05:31 +02:00
|
|
|
|
using SafeExamBrowser.Core.Behaviour.Operations;
|
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-19 14:04:12 +01:00
|
|
|
|
internal ILogger Logger { get; private set; }
|
|
|
|
|
internal RuntimeInfo RuntimeInfo { get; private set; }
|
2018-01-17 08:26:44 +01:00
|
|
|
|
internal IShutdownController ShutdownController { get; private set; }
|
|
|
|
|
internal IStartupController StartupController { get; private set; }
|
2018-01-19 14:04:12 +01:00
|
|
|
|
internal ISystemInfo SystemInfo { 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-19 14:04:12 +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-19 14:04:12 +01:00
|
|
|
|
var text = new Text(Logger);
|
|
|
|
|
var runtimeController = new RuntimeController(new ModuleLogger(Logger, typeof(RuntimeController)));
|
|
|
|
|
|
|
|
|
|
ShutdownController = new ShutdownController(Logger, RuntimeInfo, text, uiFactory);
|
|
|
|
|
StartupController = new StartupController(Logger, RuntimeInfo, SystemInfo, text, uiFactory);
|
2017-07-21 12:05:31 +02:00
|
|
|
|
|
|
|
|
|
StartupOperations = new Queue<IOperation>();
|
2018-01-19 14:04:12 +01:00
|
|
|
|
StartupOperations.Enqueue(new I18nOperation(Logger, text));
|
|
|
|
|
StartupOperations.Enqueue(new ConfigurationOperation(Logger, runtimeController, RuntimeInfo, settingsRepository, text, uiFactory, args));
|
2018-01-17 14:08:39 +01:00
|
|
|
|
//StartupOperations.Enqueue(new KioskModeOperation());
|
2018-01-19 14:04:12 +01:00
|
|
|
|
StartupOperations.Enqueue(new RuntimeControllerOperation(runtimeController, Logger));
|
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-19 14:04:12 +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-19 14:04:12 +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-19 14:04:12 +01:00
|
|
|
|
Logger.Subscribe(logFileWriter);
|
2017-07-06 10:56:03 +02:00
|
|
|
|
}
|
2017-07-05 11:41:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|