2017-07-07 15:46:32 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET)
|
|
|
|
|
*
|
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-07-13 08:51:00 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
using System.Threading;
|
2017-07-12 15:36:30 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
|
|
|
|
|
2017-07-12 15:36:30 +02:00
|
|
|
|
namespace SafeExamBrowser.Core.Behaviour
|
2017-07-07 15:46:32 +02:00
|
|
|
|
{
|
|
|
|
|
public class StartupController : IStartupController
|
|
|
|
|
{
|
2017-07-12 15:36:30 +02:00
|
|
|
|
private IApplicationInfo browserInfo;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
private ILogger logger;
|
|
|
|
|
private IMessageBox messageBox;
|
2017-07-10 15:47:12 +02:00
|
|
|
|
private ISettings settings;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
private ISplashScreen splashScreen;
|
2017-07-10 15:47:12 +02:00
|
|
|
|
private ITaskbar taskbar;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
private IText text;
|
2017-07-12 15:36:30 +02:00
|
|
|
|
private IUiElementFactory uiFactory;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private IEnumerable<Action> StartupOperations
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
yield return InitializeApplicationLog;
|
|
|
|
|
yield return HandleCommandLineArguments;
|
|
|
|
|
yield return DetectOperatingSystem;
|
|
|
|
|
yield return EstablishWcfServiceConnection;
|
|
|
|
|
yield return DeactivateWindowsFeatures;
|
|
|
|
|
yield return InitializeProcessMonitoring;
|
|
|
|
|
yield return InitializeWorkArea;
|
|
|
|
|
yield return InitializeTaskbar;
|
|
|
|
|
yield return InitializeBrowser;
|
|
|
|
|
yield return FinishInitialization;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-12 15:36:30 +02:00
|
|
|
|
public StartupController(IApplicationInfo browserInfo, ILogger logger, IMessageBox messageBox, ISettings settings, ISplashScreen splashScreen, ITaskbar taskbar, IText text, IUiElementFactory uiFactory)
|
2017-07-07 15:46:32 +02:00
|
|
|
|
{
|
2017-07-12 15:36:30 +02:00
|
|
|
|
this.browserInfo = browserInfo;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.messageBox = messageBox;
|
2017-07-10 15:47:12 +02:00
|
|
|
|
this.settings = settings;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
this.splashScreen = splashScreen;
|
2017-07-10 15:47:12 +02:00
|
|
|
|
this.taskbar = taskbar;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
this.text = text;
|
2017-07-12 15:36:30 +02:00
|
|
|
|
this.uiFactory = uiFactory;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-10 15:47:12 +02:00
|
|
|
|
public bool TryInitializeApplication()
|
2017-07-07 15:46:32 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-13 08:51:00 +02:00
|
|
|
|
foreach (var operation in StartupOperations)
|
|
|
|
|
{
|
|
|
|
|
operation();
|
2017-07-10 15:47:12 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
splashScreen.UpdateProgress();
|
2017-07-12 15:36:30 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
// TODO: Remove!
|
|
|
|
|
Thread.Sleep(250);
|
|
|
|
|
}
|
2017-07-12 15:36:30 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"Failed to initialize application!", e);
|
|
|
|
|
messageBox.Show(text.Get(Key.MessageBox_StartupError), text.Get(Key.MessageBox_StartupErrorTitle), icon: MessageBoxIcon.Error);
|
2017-07-12 15:36:30 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private void InitializeApplicationLog()
|
|
|
|
|
{
|
|
|
|
|
logger.Log(settings.LogHeader);
|
|
|
|
|
logger.Log($"{Environment.NewLine}# Application started at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}{Environment.NewLine}");
|
|
|
|
|
logger.Info("Initiating startup procedure.");
|
|
|
|
|
logger.Subscribe(splashScreen);
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
splashScreen.SetMaxProgress(StartupOperations.Count());
|
|
|
|
|
}
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private void HandleCommandLineArguments()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Parsing command line arguments.");
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
// TODO
|
|
|
|
|
}
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private void DetectOperatingSystem()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Detecting operating system.");
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
// TODO
|
|
|
|
|
}
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private void EstablishWcfServiceConnection()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Establishing connection to WCF service.");
|
2017-07-10 15:47:12 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
// TODO
|
|
|
|
|
}
|
2017-07-10 15:47:12 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private void DeactivateWindowsFeatures()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Deactivating Windows Update.");
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
logger.Info("Disabling lock screen options.");
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeProcessMonitoring()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Initializing process monitoring.");
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeWorkArea()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Initializing work area.");
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
// - Killing explorer.exe
|
|
|
|
|
// - Minimizing all open windows
|
|
|
|
|
// - Emptying clipboard
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeTaskbar()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Initializing taskbar.");
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeBrowser()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Initializing browser.");
|
|
|
|
|
|
|
|
|
|
var browserButton = uiFactory.CreateButton(browserInfo);
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
taskbar.AddButton(browserButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FinishInitialization()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Application successfully initialized!");
|
|
|
|
|
logger.Unsubscribe(splashScreen);
|
2017-07-07 15:46:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|