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;
|
|
|
|
|
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-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-10 15:47:12 +02:00
|
|
|
|
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.");
|
2017-07-07 15:46:32 +02:00
|
|
|
|
logger.Subscribe(splashScreen);
|
2017-07-10 15:47:12 +02:00
|
|
|
|
|
2017-07-12 15:36:30 +02:00
|
|
|
|
splashScreen.SetMaxProgress(3);
|
|
|
|
|
logger.Info("Initializing browser.");
|
|
|
|
|
|
|
|
|
|
var browserButton = uiFactory.CreateButton(browserInfo);
|
|
|
|
|
|
|
|
|
|
taskbar.AddButton(browserButton);
|
|
|
|
|
|
2017-07-10 15:47:12 +02:00
|
|
|
|
splashScreen.UpdateProgress();
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
|
|
|
|
// TODO (depending on specification):
|
|
|
|
|
// - WCF service connection, termination if not available
|
|
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
// - Parse command line arguments
|
2017-07-10 15:47:12 +02:00
|
|
|
|
// - Detecting operating system and log that information
|
2017-07-07 15:46:32 +02:00
|
|
|
|
// - Logging of all running processes
|
|
|
|
|
// - Setting of wallpaper
|
|
|
|
|
// - Initialization of taskbar
|
2017-07-11 15:29:29 +02:00
|
|
|
|
// - Killing explorer.exe
|
2017-07-07 15:46:32 +02:00
|
|
|
|
// - Minimizing all open windows
|
|
|
|
|
// - Emptying clipboard
|
|
|
|
|
// - Activation of process monitoring
|
|
|
|
|
|
2017-07-11 15:29:29 +02:00
|
|
|
|
Thread.Sleep(1000);
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-10 15:47:12 +02:00
|
|
|
|
splashScreen.UpdateProgress();
|
2017-07-07 15:46:32 +02:00
|
|
|
|
logger.Info("Baapa-dee boopa-dee!");
|
|
|
|
|
|
2017-07-11 15:29:29 +02:00
|
|
|
|
Thread.Sleep(1000);
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-10 15:47:12 +02:00
|
|
|
|
splashScreen.UpdateProgress();
|
2017-07-07 15:46:32 +02:00
|
|
|
|
logger.Info("Closing splash screen.");
|
|
|
|
|
|
2017-07-11 15:29:29 +02:00
|
|
|
|
Thread.Sleep(1000);
|
2017-07-10 15:47:12 +02:00
|
|
|
|
logger.Unsubscribe(splashScreen);
|
2017-07-07 15:46:32 +02:00
|
|
|
|
logger.Info("Application successfully initialized!");
|
2017-07-10 15:47:12 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
}
|
|
|
|
|
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-10 15:47:12 +02:00
|
|
|
|
|
|
|
|
|
return false;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|