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-30 14:41:36 +01:00
|
|
|
|
using System.Windows;
|
2017-07-20 14:16:47 +02:00
|
|
|
|
using SafeExamBrowser.Configuration;
|
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;
|
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-01-23 15:33:54 +01:00
|
|
|
|
private ILogger logger;
|
2018-02-15 15:42:54 +01:00
|
|
|
|
private RuntimeInfo runtimeInfo;
|
2018-01-23 15:33:54 +01:00
|
|
|
|
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-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-02-06 15:12:11 +01:00
|
|
|
|
var configuration = new ConfigurationRepository();
|
2018-02-08 13:32:48 +01:00
|
|
|
|
var nativeMethods = new NativeMethods();
|
2018-02-14 15:26:05 +01:00
|
|
|
|
Action shutdown = Application.Current.Shutdown;
|
2017-07-14 10:28:59 +02:00
|
|
|
|
|
2018-01-23 15:33:54 +01:00
|
|
|
|
logger = new Logger();
|
2018-02-06 15:12:11 +01:00
|
|
|
|
runtimeInfo = configuration.RuntimeInfo;
|
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-02-07 13:25:49 +01:00
|
|
|
|
var uiFactory = new UserInterfaceFactory(text);
|
2018-02-14 15:26:05 +01:00
|
|
|
|
var desktop = new Desktop(new ModuleLogger(logger, typeof(Desktop)));
|
|
|
|
|
var processFactory = new ProcessFactory(desktop, new ModuleLogger(logger, typeof(ProcessFactory)));
|
|
|
|
|
var clientProxy = new ClientProxy(runtimeInfo.ClientAddress, new ModuleLogger(logger, typeof(ClientProxy)));
|
|
|
|
|
var runtimeHost = new RuntimeHost(runtimeInfo.RuntimeAddress, configuration, new ModuleLogger(logger, typeof(RuntimeHost)));
|
2018-02-06 15:12:11 +01:00
|
|
|
|
var serviceProxy = new ServiceProxy(runtimeInfo.ServiceAddress, new ModuleLogger(logger, typeof(ServiceProxy)));
|
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-02-14 15:26:05 +01:00
|
|
|
|
sessionOperations.Enqueue(new SessionSequenceStartOperation(clientProxy, configuration, logger, processFactory, runtimeHost, serviceProxy));
|
2018-02-06 15:12:11 +01:00
|
|
|
|
sessionOperations.Enqueue(new ConfigurationOperation(configuration, logger, runtimeInfo, text, uiFactory, args));
|
2018-02-12 12:21:55 +01:00
|
|
|
|
sessionOperations.Enqueue(new ServiceConnectionOperation(configuration, logger, serviceProxy, text));
|
2018-02-06 15:12:11 +01:00
|
|
|
|
sessionOperations.Enqueue(new KioskModeOperation(logger, configuration));
|
2018-02-14 15:26:05 +01:00
|
|
|
|
sessionOperations.Enqueue(new SessionSequenceEndOperation(clientProxy, configuration, logger, processFactory, runtimeHost, serviceProxy));
|
2018-02-02 09:18:35 +01:00
|
|
|
|
|
2018-02-06 15:12:11 +01:00
|
|
|
|
var boostrapSequence = new OperationSequence(logger, bootstrapOperations);
|
2018-02-02 09:18:35 +01:00
|
|
|
|
var sessionSequence = new OperationSequence(logger, sessionOperations);
|
|
|
|
|
|
2018-02-14 15:26:05 +01:00
|
|
|
|
RuntimeController = new RuntimeController(clientProxy, configuration, logger, boostrapSequence, sessionSequence, runtimeHost, runtimeInfo, serviceProxy, shutdown, uiFactory);
|
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()
|
|
|
|
|
{
|
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-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
|
|
|
|
}
|
|
|
|
|
}
|