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;
|
2017-07-19 14:43:54 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Monitoring;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
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-14 10:28:59 +02:00
|
|
|
|
private IApplicationController browserController;
|
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-17 16:59:50 +02:00
|
|
|
|
private INotificationInfo aboutInfo;
|
2017-07-19 14:43:54 +02:00
|
|
|
|
private IProcessMonitor processMonitor;
|
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-20 14:16:47 +02:00
|
|
|
|
private IWorkingArea workingArea;
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private IEnumerable<Action> StartupOperations
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
yield return HandleCommandLineArguments;
|
|
|
|
|
yield return DetectOperatingSystem;
|
|
|
|
|
yield return EstablishWcfServiceConnection;
|
|
|
|
|
yield return DeactivateWindowsFeatures;
|
|
|
|
|
yield return InitializeProcessMonitoring;
|
2017-07-20 14:16:47 +02:00
|
|
|
|
yield return InitializeWorkingArea;
|
2017-07-13 08:51:00 +02:00
|
|
|
|
yield return InitializeTaskbar;
|
|
|
|
|
yield return InitializeBrowser;
|
|
|
|
|
yield return FinishInitialization;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-14 10:28:59 +02:00
|
|
|
|
public StartupController(
|
|
|
|
|
IApplicationController browserController,
|
|
|
|
|
IApplicationInfo browserInfo,
|
|
|
|
|
ILogger logger,
|
|
|
|
|
IMessageBox messageBox,
|
2017-07-17 16:59:50 +02:00
|
|
|
|
INotificationInfo aboutInfo,
|
2017-07-19 14:43:54 +02:00
|
|
|
|
IProcessMonitor processMonitor,
|
2017-07-14 10:28:59 +02:00
|
|
|
|
ISettings settings,
|
|
|
|
|
ITaskbar taskbar,
|
|
|
|
|
IText text,
|
2017-07-20 14:16:47 +02:00
|
|
|
|
IUiElementFactory uiFactory,
|
|
|
|
|
IWorkingArea workingArea)
|
2017-07-07 15:46:32 +02:00
|
|
|
|
{
|
2017-07-17 16:59:50 +02:00
|
|
|
|
this.browserController = browserController;
|
|
|
|
|
this.browserInfo = browserInfo;
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.messageBox = messageBox;
|
|
|
|
|
this.aboutInfo = aboutInfo;
|
2017-07-19 14:43:54 +02:00
|
|
|
|
this.processMonitor = processMonitor;
|
2017-07-17 16:59:50 +02:00
|
|
|
|
this.settings = settings;
|
|
|
|
|
this.taskbar = taskbar;
|
|
|
|
|
this.text = text;
|
|
|
|
|
this.uiFactory = uiFactory;
|
2017-07-20 14:16:47 +02:00
|
|
|
|
this.workingArea = workingArea;
|
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-14 10:28:59 +02:00
|
|
|
|
InitializeApplicationLog();
|
|
|
|
|
InitializeSplashScreen();
|
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
foreach (var operation in StartupOperations)
|
|
|
|
|
{
|
|
|
|
|
operation();
|
|
|
|
|
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()
|
|
|
|
|
{
|
2017-07-14 10:28:59 +02:00
|
|
|
|
var titleLine = $"/* {settings.ProgramTitle}, Version {settings.ProgramVersion}{Environment.NewLine}";
|
|
|
|
|
var copyrightLine = $"/* {settings.ProgramCopyright}{Environment.NewLine}";
|
|
|
|
|
var emptyLine = $"/* {Environment.NewLine}";
|
|
|
|
|
var githubLine = $"/* Please visit https://github.com/SafeExamBrowser for more information.";
|
|
|
|
|
|
|
|
|
|
logger.Log($"{titleLine}{copyrightLine}{emptyLine}{githubLine}");
|
2017-07-13 08:51:00 +02:00
|
|
|
|
logger.Log($"{Environment.NewLine}# Application started at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}{Environment.NewLine}");
|
2017-07-20 14:16:47 +02:00
|
|
|
|
logger.Info("--- Initiating startup procedure ---");
|
2017-07-14 10:28:59 +02:00
|
|
|
|
}
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-14 10:28:59 +02:00
|
|
|
|
private void InitializeSplashScreen()
|
|
|
|
|
{
|
2017-07-19 14:43:54 +02:00
|
|
|
|
splashScreen = uiFactory.CreateSplashScreen(settings, text);
|
2017-07-13 08:51:00 +02:00
|
|
|
|
splashScreen.SetMaxProgress(StartupOperations.Count());
|
2017-07-14 10:28:59 +02:00
|
|
|
|
splashScreen.UpdateText(Key.SplashScreen_StartupProcedure);
|
2017-07-19 14:43:54 +02:00
|
|
|
|
splashScreen.InvokeShow();
|
2017-07-13 08:51:00 +02:00
|
|
|
|
}
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private void HandleCommandLineArguments()
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private void DetectOperatingSystem()
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
2017-07-07 15:46:32 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private void EstablishWcfServiceConnection()
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
2017-07-10 15:47:12 +02:00
|
|
|
|
|
2017-07-13 08:51:00 +02:00
|
|
|
|
private void DeactivateWindowsFeatures()
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeProcessMonitoring()
|
|
|
|
|
{
|
2017-07-20 14:16:47 +02:00
|
|
|
|
logger.Info("--- Initializing process monitoring ---");
|
2017-07-19 14:43:54 +02:00
|
|
|
|
splashScreen.UpdateText(Key.SplashScreen_InitializeProcessMonitoring);
|
2017-07-13 08:51:00 +02:00
|
|
|
|
|
|
|
|
|
// TODO
|
2017-07-19 14:43:54 +02:00
|
|
|
|
|
|
|
|
|
processMonitor.StartMonitoringExplorer();
|
2017-07-13 08:51:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 14:16:47 +02:00
|
|
|
|
private void InitializeWorkingArea()
|
2017-07-13 08:51:00 +02:00
|
|
|
|
{
|
2017-07-20 14:16:47 +02:00
|
|
|
|
logger.Info("--- Initializing working area ---");
|
|
|
|
|
splashScreen.UpdateText(Key.SplashScreen_WaitExplorerTermination, true);
|
|
|
|
|
processMonitor.CloseExplorerShell();
|
2017-07-13 08:51:00 +02:00
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
// - Minimizing all open windows
|
|
|
|
|
// - Emptying clipboard
|
2017-07-19 14:43:54 +02:00
|
|
|
|
|
2017-07-20 14:16:47 +02:00
|
|
|
|
splashScreen.UpdateText(Key.SplashScreen_InitializeWorkingArea);
|
|
|
|
|
workingArea.InitializeFor(taskbar);
|
2017-07-13 08:51:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeTaskbar()
|
|
|
|
|
{
|
2017-07-20 14:16:47 +02:00
|
|
|
|
logger.Info("--- Initializing taskbar ---");
|
2017-07-19 14:43:54 +02:00
|
|
|
|
splashScreen.UpdateText(Key.SplashScreen_InitializeTaskbar);
|
|
|
|
|
|
|
|
|
|
// TODO
|
2017-07-13 08:51:00 +02:00
|
|
|
|
|
2017-07-17 16:59:50 +02:00
|
|
|
|
var aboutNotification = uiFactory.CreateNotification(aboutInfo);
|
|
|
|
|
|
|
|
|
|
taskbar.AddNotification(aboutNotification);
|
2017-07-13 08:51:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeBrowser()
|
|
|
|
|
{
|
2017-07-20 14:16:47 +02:00
|
|
|
|
logger.Info("--- Initializing browser ---");
|
2017-07-14 10:28:59 +02:00
|
|
|
|
splashScreen.UpdateText(Key.SplashScreen_InitializeBrowser);
|
2017-07-13 08:51:00 +02:00
|
|
|
|
|
2017-07-19 14:43:54 +02:00
|
|
|
|
// TODO
|
|
|
|
|
|
2017-07-17 08:28:18 +02:00
|
|
|
|
var browserButton = uiFactory.CreateApplicationButton(browserInfo);
|
|
|
|
|
|
2017-07-14 10:28:59 +02:00
|
|
|
|
browserController.RegisterApplicationButton(browserButton);
|
2017-07-13 08:51:00 +02:00
|
|
|
|
taskbar.AddButton(browserButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FinishInitialization()
|
|
|
|
|
{
|
2017-07-20 14:16:47 +02:00
|
|
|
|
logger.Info("--- Application successfully initialized! ---");
|
2017-07-19 14:43:54 +02:00
|
|
|
|
splashScreen.InvokeClose();
|
2017-07-07 15:46:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|