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;
|
2017-07-20 14:16:47 +02:00
|
|
|
|
using SafeExamBrowser.Configuration;
|
2017-07-12 15:36:30 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour;
|
2018-03-06 11:49:51 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour.OperationModel;
|
2017-07-13 08:51:00 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
2018-03-13 10:57:47 +01:00
|
|
|
|
using SafeExamBrowser.Core.Behaviour.OperationModel;
|
2018-03-16 15:46:53 +01:00
|
|
|
|
using SafeExamBrowser.Core.Communication.Hosts;
|
2018-03-16 09:28:33 +01:00
|
|
|
|
using SafeExamBrowser.Core.Communication.Proxies;
|
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;
|
2018-02-06 15:12:11 +01:00
|
|
|
|
using SafeExamBrowser.Runtime.Communication;
|
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-06-29 09:50:20 +02:00
|
|
|
|
private AppConfig appConfig;
|
2018-01-23 15:33:54 +01:00
|
|
|
|
private ILogger logger;
|
|
|
|
|
private ISystemInfo systemInfo;
|
|
|
|
|
|
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-03-21 15:28:59 +01:00
|
|
|
|
const int TEN_SECONDS = 10000;
|
|
|
|
|
|
2018-01-18 15:14:05 +01:00
|
|
|
|
var args = Environment.GetCommandLineArgs();
|
2018-02-06 15:12:11 +01:00
|
|
|
|
var configuration = new ConfigurationRepository();
|
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();
|
2018-06-29 09:50:20 +02:00
|
|
|
|
appConfig = configuration.AppConfig;
|
2018-01-23 15:33:54 +01:00
|
|
|
|
systemInfo = new SystemInfo();
|
2017-07-06 10:56:03 +02:00
|
|
|
|
|
2018-01-19 14:04:12 +01:00
|
|
|
|
InitializeLogging();
|
2017-07-31 20:22:53 +02:00
|
|
|
|
|
2018-01-23 15:33:54 +01:00
|
|
|
|
var text = new Text(logger);
|
2018-03-14 12:07:20 +01:00
|
|
|
|
var messageBox = new MessageBox(text);
|
2018-08-16 11:23:37 +02:00
|
|
|
|
var desktopFactory = new DesktopFactory(new ModuleLogger(logger, typeof(DesktopFactory)));
|
2018-08-17 14:48:50 +02:00
|
|
|
|
var explorerShell = new ExplorerShell(new ModuleLogger(logger, typeof(ExplorerShell)), nativeMethods);
|
2018-08-16 11:23:37 +02:00
|
|
|
|
var processFactory = new ProcessFactory(new ModuleLogger(logger, typeof(ProcessFactory)));
|
2018-03-15 09:55:04 +01:00
|
|
|
|
var proxyFactory = new ProxyFactory(new ProxyObjectFactory(), logger);
|
2018-06-28 13:40:30 +02:00
|
|
|
|
var resourceLoader = new ResourceLoader();
|
2018-06-29 09:50:20 +02:00
|
|
|
|
var runtimeHost = new RuntimeHost(appConfig.RuntimeAddress, configuration, new HostObjectFactory(), new ModuleLogger(logger, typeof(RuntimeHost)));
|
|
|
|
|
var serviceProxy = new ServiceProxy(appConfig.ServiceAddress, new ProxyObjectFactory(), new ModuleLogger(logger, typeof(ServiceProxy)));
|
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>();
|
|
|
|
|
var sessionOperations = new Queue<IOperation>();
|
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
bootstrapOperations.Enqueue(new I18nOperation(logger, text));
|
2018-02-06 15:12:11 +01:00
|
|
|
|
bootstrapOperations.Enqueue(new CommunicationOperation(runtimeHost, logger));
|
2017-07-21 12:05:31 +02:00
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
sessionOperations.Enqueue(new ConfigurationOperation(appConfig, configuration, logger, messageBox, resourceLoader, runtimeHost, text, uiFactory, args));
|
2018-03-21 10:23:15 +01:00
|
|
|
|
sessionOperations.Enqueue(new SessionInitializationOperation(configuration, logger, runtimeHost));
|
|
|
|
|
sessionOperations.Enqueue(new ServiceOperation(configuration, logger, serviceProxy, text));
|
2018-03-21 15:28:59 +01:00
|
|
|
|
sessionOperations.Enqueue(new ClientTerminationOperation(configuration, logger, processFactory, proxyFactory, runtimeHost, TEN_SECONDS));
|
2018-08-17 14:48:50 +02:00
|
|
|
|
sessionOperations.Enqueue(new KioskModeOperation(configuration, desktopFactory, explorerShell, logger, processFactory));
|
2018-03-21 15:28:59 +01:00
|
|
|
|
sessionOperations.Enqueue(new ClientOperation(configuration, logger, processFactory, proxyFactory, runtimeHost, TEN_SECONDS));
|
2018-02-02 09:18:35 +01:00
|
|
|
|
|
2018-03-21 10:23:15 +01:00
|
|
|
|
var bootstrapSequence = new OperationSequence(logger, bootstrapOperations);
|
2018-02-02 09:18:35 +01:00
|
|
|
|
var sessionSequence = new OperationSequence(logger, sessionOperations);
|
|
|
|
|
|
2018-06-29 09:50:20 +02:00
|
|
|
|
RuntimeController = new RuntimeController(appConfig, configuration, logger, messageBox, bootstrapSequence, sessionSequence, runtimeHost, serviceProxy, shutdown, 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-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();
|
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
|
|
|
|
}
|
|
|
|
|
}
|