2017-07-05 11:41:19 +02:00
|
|
|
|
/*
|
2019-01-09 11:25:21 +01:00
|
|
|
|
* Copyright (c) 2019 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-08-31 10:06:27 +02:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using SafeExamBrowser.Communication.Hosts;
|
|
|
|
|
using SafeExamBrowser.Communication.Proxies;
|
2017-07-20 14:16:47 +02:00
|
|
|
|
using SafeExamBrowser.Configuration;
|
2018-12-14 09:50:10 +01:00
|
|
|
|
using SafeExamBrowser.Configuration.Cryptography;
|
|
|
|
|
using SafeExamBrowser.Configuration.DataCompression;
|
2018-11-08 09:39:52 +01:00
|
|
|
|
using SafeExamBrowser.Configuration.DataFormats;
|
2018-12-14 09:50:10 +01:00
|
|
|
|
using SafeExamBrowser.Configuration.DataResources;
|
2017-07-13 08:51:00 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Core.OperationModel;
|
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
2017-07-13 08:51:00 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
2019-01-23 15:57:49 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Runtime;
|
|
|
|
|
using SafeExamBrowser.Contracts.SystemComponents;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Core.OperationModel;
|
|
|
|
|
using SafeExamBrowser.Core.Operations;
|
|
|
|
|
using SafeExamBrowser.I18n;
|
|
|
|
|
using SafeExamBrowser.Logging;
|
2018-02-06 15:12:11 +01:00
|
|
|
|
using SafeExamBrowser.Runtime.Communication;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Runtime.Operations;
|
2019-01-23 15:57:49 +01:00
|
|
|
|
using SafeExamBrowser.SystemComponents;
|
2019-01-11 15:32:47 +01:00
|
|
|
|
using SafeExamBrowser.UserInterface.Desktop;
|
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-06-29 09:50:20 +02:00
|
|
|
|
private AppConfig appConfig;
|
2018-11-08 09:39:52 +01:00
|
|
|
|
private IConfigurationRepository configuration;
|
2018-01-23 15:33:54 +01:00
|
|
|
|
private ILogger logger;
|
|
|
|
|
private ISystemInfo systemInfo;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
private IText text;
|
|
|
|
|
private ITextResource textResource;
|
2018-01-23 15:33:54 +01:00
|
|
|
|
|
2018-01-24 07:46:22 +01:00
|
|
|
|
internal IRuntimeController RuntimeController { get; private set; }
|
2017-07-13 08:51:00 +02:00
|
|
|
|
|
2018-02-21 14:01:21 +01:00
|
|
|
|
internal void BuildObjectGraph(Action shutdown)
|
2017-07-06 10:56:03 +02:00
|
|
|
|
{
|
2018-10-02 08:02:48 +02:00
|
|
|
|
const int FIVE_SECONDS = 5000;
|
|
|
|
|
const int FIFTEEN_SECONDS = 15000;
|
2018-03-21 15:28:59 +01:00
|
|
|
|
|
2018-01-18 15:14:05 +01:00
|
|
|
|
var args = Environment.GetCommandLineArgs();
|
2018-02-08 13:32:48 +01:00
|
|
|
|
var nativeMethods = new NativeMethods();
|
2017-07-14 10:28:59 +02:00
|
|
|
|
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger = new Logger();
|
|
|
|
|
systemInfo = new SystemInfo();
|
2017-07-06 10:56:03 +02:00
|
|
|
|
|
2018-11-08 09:39:52 +01:00
|
|
|
|
InitializeConfiguration();
|
2018-01-19 14:04:12 +01:00
|
|
|
|
InitializeLogging();
|
2018-08-31 10:06:27 +02:00
|
|
|
|
InitializeText();
|
2017-07-31 20:22:53 +02:00
|
|
|
|
|
2018-03-14 12:07:20 +01:00
|
|
|
|
var messageBox = new MessageBox(text);
|
2018-08-31 15:29:36 +02:00
|
|
|
|
var desktopFactory = new DesktopFactory(new ModuleLogger(logger, nameof(DesktopFactory)));
|
|
|
|
|
var explorerShell = new ExplorerShell(new ModuleLogger(logger, nameof(ExplorerShell)), nativeMethods);
|
|
|
|
|
var processFactory = new ProcessFactory(new ModuleLogger(logger, nameof(ProcessFactory)));
|
2018-03-15 09:55:04 +01:00
|
|
|
|
var proxyFactory = new ProxyFactory(new ProxyObjectFactory(), logger);
|
2018-10-12 11:16:59 +02:00
|
|
|
|
var runtimeHost = new RuntimeHost(appConfig.RuntimeAddress, new HostObjectFactory(), new ModuleLogger(logger, nameof(RuntimeHost)), FIVE_SECONDS);
|
2018-08-31 15:29:36 +02:00
|
|
|
|
var serviceProxy = new ServiceProxy(appConfig.ServiceAddress, new ProxyObjectFactory(), new ModuleLogger(logger, nameof(ServiceProxy)));
|
2018-10-12 11:16:59 +02:00
|
|
|
|
var sessionContext = new SessionContext();
|
2018-08-16 11:23:37 +02:00
|
|
|
|
var uiFactory = new UserInterfaceFactory(text);
|
2018-01-19 14:04:12 +01:00
|
|
|
|
|
2018-02-08 13:32:48 +01:00
|
|
|
|
var bootstrapOperations = new Queue<IOperation>();
|
2018-10-10 09:19:03 +02:00
|
|
|
|
var sessionOperations = new Queue<IRepeatableOperation>();
|
2018-02-08 13:32:48 +01:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
bootstrapOperations.Enqueue(new I18nOperation(logger, text, textResource));
|
2018-09-28 11:05:49 +02:00
|
|
|
|
bootstrapOperations.Enqueue(new CommunicationHostOperation(runtimeHost, logger));
|
2017-07-21 12:05:31 +02:00
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
sessionOperations.Enqueue(new SessionInitializationOperation(configuration, logger, runtimeHost, sessionContext));
|
2018-12-14 09:50:10 +01:00
|
|
|
|
sessionOperations.Enqueue(new ConfigurationOperation(args, configuration, new HashAlgorithm(), logger, sessionContext));
|
2018-10-12 11:16:59 +02:00
|
|
|
|
sessionOperations.Enqueue(new ClientTerminationOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, FIFTEEN_SECONDS));
|
|
|
|
|
sessionOperations.Enqueue(new KioskModeTerminationOperation(desktopFactory, explorerShell, logger, processFactory, sessionContext));
|
|
|
|
|
sessionOperations.Enqueue(new ServiceOperation(logger, serviceProxy, sessionContext));
|
|
|
|
|
sessionOperations.Enqueue(new KioskModeOperation(desktopFactory, explorerShell, logger, processFactory, sessionContext));
|
|
|
|
|
sessionOperations.Enqueue(new ClientOperation(logger, processFactory, proxyFactory, runtimeHost, sessionContext, FIFTEEN_SECONDS));
|
|
|
|
|
sessionOperations.Enqueue(new SessionActivationOperation(logger, sessionContext));
|
2018-02-02 09:18:35 +01:00
|
|
|
|
|
2018-03-21 10:23:15 +01:00
|
|
|
|
var bootstrapSequence = new OperationSequence(logger, bootstrapOperations);
|
2018-10-10 09:19:03 +02:00
|
|
|
|
var sessionSequence = new RepeatableOperationSequence(logger, sessionOperations);
|
2018-02-02 09:18:35 +01:00
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
RuntimeController = new RuntimeController(appConfig, logger, messageBox, bootstrapSequence, sessionSequence, runtimeHost, serviceProxy, sessionContext, shutdown, text, uiFactory);
|
2018-01-23 15:33:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void LogStartupInformation()
|
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
logger.Log($"/* {appConfig.ProgramTitle}, Version {appConfig.ProgramVersion}");
|
|
|
|
|
logger.Log($"/* {appConfig.ProgramCopyright}");
|
2018-02-20 15:15:26 +01:00
|
|
|
|
logger.Log($"/* ");
|
|
|
|
|
logger.Log($"/* Please visit https://www.github.com/SafeExamBrowser for more information.");
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger.Log(string.Empty);
|
2018-06-29 09:50:20 +02:00
|
|
|
|
logger.Log($"# Application started at {appConfig.ApplicationStartTime.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger.Log($"# Running on {systemInfo.OperatingSystemInfo}");
|
2018-06-29 09:50:20 +02:00
|
|
|
|
logger.Log($"# Runtime-ID: {appConfig.RuntimeId}");
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger.Log(string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void LogShutdownInformation()
|
|
|
|
|
{
|
2018-02-06 15:12:11 +01:00
|
|
|
|
logger?.Log($"# Application terminated at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
2018-01-17 14:08:39 +01:00
|
|
|
|
}
|
2018-01-17 08:26:44 +01:00
|
|
|
|
|
2018-11-08 09:39:52 +01:00
|
|
|
|
private void InitializeConfiguration()
|
2018-09-04 10:58:56 +02:00
|
|
|
|
{
|
|
|
|
|
var executable = Assembly.GetExecutingAssembly();
|
|
|
|
|
var programCopyright = executable.GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright;
|
|
|
|
|
var programTitle = executable.GetCustomAttribute<AssemblyTitleAttribute>().Title;
|
|
|
|
|
var programVersion = executable.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
2018-11-15 08:45:17 +01:00
|
|
|
|
var compressor = new GZipCompressor(new ModuleLogger(logger, nameof(GZipCompressor)));
|
|
|
|
|
var repositoryLogger = new ModuleLogger(logger, nameof(ConfigurationRepository));
|
2018-11-08 09:39:52 +01:00
|
|
|
|
|
2018-12-11 16:06:10 +01:00
|
|
|
|
configuration = new ConfigurationRepository(new HashAlgorithm(), repositoryLogger, executable.Location, programCopyright, programTitle, programVersion);
|
2018-11-08 09:39:52 +01:00
|
|
|
|
appConfig = configuration.InitializeAppConfig();
|
2018-09-04 10:58:56 +02:00
|
|
|
|
|
2018-12-21 11:36:20 +01:00
|
|
|
|
configuration.Register(new BinaryParser(compressor, new HashAlgorithm(), new ModuleLogger(logger, nameof(BinaryParser))));
|
|
|
|
|
configuration.Register(new BinarySerializer(compressor, new ModuleLogger(logger, nameof(BinarySerializer))));
|
|
|
|
|
configuration.Register(new XmlParser(new ModuleLogger(logger, nameof(XmlParser))));
|
|
|
|
|
configuration.Register(new XmlSerializer(new ModuleLogger(logger, nameof(XmlSerializer))));
|
|
|
|
|
configuration.Register(new FileResourceLoader(new ModuleLogger(logger, nameof(FileResourceLoader))));
|
|
|
|
|
configuration.Register(new FileResourceSaver(new ModuleLogger(logger, nameof(FileResourceSaver))));
|
|
|
|
|
configuration.Register(new NetworkResourceLoader(appConfig, new ModuleLogger(logger, nameof(NetworkResourceLoader))));
|
2018-09-04 10:58:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-19 14:04:12 +01:00
|
|
|
|
private void InitializeLogging()
|
2018-01-17 14:08:39 +01:00
|
|
|
|
{
|
2018-06-29 09:50:20 +02:00
|
|
|
|
var logFileWriter = new LogFileWriter(new DefaultLogFormatter(), appConfig.RuntimeLogFile);
|
2018-01-17 08:26:44 +01:00
|
|
|
|
|
2018-01-17 14:08:39 +01:00
|
|
|
|
logFileWriter.Initialize();
|
2019-01-23 08:12:15 +01:00
|
|
|
|
logger.LogLevel = LogLevel.Debug;
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger.Subscribe(logFileWriter);
|
2017-07-06 10:56:03 +02:00
|
|
|
|
}
|
2018-08-31 10:06:27 +02:00
|
|
|
|
|
|
|
|
|
private void InitializeText()
|
|
|
|
|
{
|
|
|
|
|
var location = Assembly.GetAssembly(typeof(XmlTextResource)).Location;
|
|
|
|
|
var path = $@"{Path.GetDirectoryName(location)}\Text.xml";
|
|
|
|
|
|
|
|
|
|
text = new Text(logger);
|
|
|
|
|
textResource = new XmlTextResource(path);
|
|
|
|
|
}
|
2017-07-05 11:41:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|