2018-01-17 08:26:44 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
using System;
|
2018-01-24 07:46:22 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour;
|
2018-02-01 08:37:12 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour.Operations;
|
2018-01-24 07:46:22 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Communication;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
2018-01-26 12:33:36 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
2018-01-26 12:33:36 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
|
2018-01-18 08:16:20 +01:00
|
|
|
|
namespace SafeExamBrowser.Runtime.Behaviour
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
2018-01-18 08:16:20 +01:00
|
|
|
|
internal class RuntimeController : IRuntimeController
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
|
|
|
|
private ILogger logger;
|
2018-02-02 09:18:35 +01:00
|
|
|
|
private IOperationSequence bootstrapSequence;
|
|
|
|
|
private IOperationSequence sessionSequence;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
private IRuntimeInfo runtimeInfo;
|
2018-01-26 12:33:36 +01:00
|
|
|
|
private IRuntimeWindow runtimeWindow;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
private IServiceProxy serviceProxy;
|
2018-01-24 07:46:22 +01:00
|
|
|
|
private ISettingsRepository settingsRepository;
|
2018-02-02 09:18:35 +01:00
|
|
|
|
private ISplashScreen splashScreen;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
private Action terminationCallback;
|
|
|
|
|
private IText text;
|
|
|
|
|
private IUserInterfaceFactory uiFactory;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
|
2018-01-24 07:46:22 +01:00
|
|
|
|
public RuntimeController(
|
|
|
|
|
ILogger logger,
|
2018-02-02 09:18:35 +01:00
|
|
|
|
IOperationSequence bootstrapSequence,
|
|
|
|
|
IOperationSequence sessionSequence,
|
2018-01-30 14:41:36 +01:00
|
|
|
|
IRuntimeInfo runtimeInfo,
|
|
|
|
|
IServiceProxy serviceProxy,
|
2018-01-24 07:46:22 +01:00
|
|
|
|
ISettingsRepository settingsRepository,
|
2018-01-30 14:41:36 +01:00
|
|
|
|
Action terminationCallback,
|
|
|
|
|
IText text,
|
|
|
|
|
IUserInterfaceFactory uiFactory)
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
|
|
|
|
this.logger = logger;
|
2018-02-02 09:18:35 +01:00
|
|
|
|
this.bootstrapSequence = bootstrapSequence;
|
|
|
|
|
this.sessionSequence = sessionSequence;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
this.runtimeInfo = runtimeInfo;
|
|
|
|
|
this.serviceProxy = serviceProxy;
|
2018-01-24 07:46:22 +01:00
|
|
|
|
this.settingsRepository = settingsRepository;
|
2018-01-30 14:41:36 +01:00
|
|
|
|
this.terminationCallback = terminationCallback;
|
|
|
|
|
this.text = text;
|
|
|
|
|
this.uiFactory = uiFactory;
|
2018-01-24 07:46:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
public bool TryStart()
|
2018-01-24 07:46:22 +01:00
|
|
|
|
{
|
2018-02-01 08:37:12 +01:00
|
|
|
|
logger.Info("--- Initiating startup procedure ---");
|
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
splashScreen = uiFactory.CreateSplashScreen(runtimeInfo, text);
|
|
|
|
|
splashScreen.Show();
|
2018-01-24 07:46:22 +01:00
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
bootstrapSequence.ProgressIndicator = splashScreen;
|
|
|
|
|
|
|
|
|
|
var success = bootstrapSequence.TryPerform();
|
|
|
|
|
|
|
|
|
|
System.Threading.Thread.Sleep(5000);
|
2018-01-30 14:41:36 +01:00
|
|
|
|
|
2018-01-24 07:46:22 +01:00
|
|
|
|
if (success)
|
|
|
|
|
{
|
2018-02-02 09:18:35 +01:00
|
|
|
|
runtimeWindow = uiFactory.CreateRuntimeWindow(runtimeInfo, text);
|
|
|
|
|
|
2018-02-01 08:37:12 +01:00
|
|
|
|
logger.Info("--- Application successfully initialized! ---");
|
|
|
|
|
logger.Log(string.Empty);
|
2018-01-30 14:41:36 +01:00
|
|
|
|
logger.Subscribe(runtimeWindow);
|
2018-02-01 08:37:12 +01:00
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
splashScreen.Hide();
|
|
|
|
|
|
|
|
|
|
StartSession(true);
|
2018-02-01 08:37:12 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Info("--- Application startup aborted! ---");
|
|
|
|
|
logger.Log(string.Empty);
|
2018-01-24 07:46:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 08:37:12 +01:00
|
|
|
|
public void Terminate()
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
StopSession();
|
2018-01-26 12:33:36 +01:00
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
// TODO:
|
|
|
|
|
// - Disconnect from service
|
|
|
|
|
// - Terminate runtime communication host
|
|
|
|
|
// - Revert kiosk mode (or do that when stopping session?)
|
|
|
|
|
|
|
|
|
|
logger.Unsubscribe(runtimeWindow);
|
2018-02-02 09:18:35 +01:00
|
|
|
|
runtimeWindow?.Close();
|
|
|
|
|
splashScreen?.Show();
|
2018-02-01 08:37:12 +01:00
|
|
|
|
|
|
|
|
|
logger.Log(string.Empty);
|
|
|
|
|
logger.Info("--- Initiating shutdown procedure ---");
|
|
|
|
|
|
2018-02-02 09:18:35 +01:00
|
|
|
|
var success = bootstrapSequence.TryRevert();
|
2018-02-01 08:37:12 +01:00
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
logger.Info("--- Application successfully finalized! ---");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Info("--- Shutdown procedure failed! ---");
|
|
|
|
|
}
|
2018-02-02 09:18:35 +01:00
|
|
|
|
|
|
|
|
|
splashScreen?.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StartSession(bool initial = false)
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Starting new session...");
|
|
|
|
|
runtimeWindow.UpdateText(TextKey.RuntimeWindow_StartSession, true);
|
|
|
|
|
runtimeWindow.Show();
|
|
|
|
|
|
|
|
|
|
sessionSequence.ProgressIndicator = runtimeWindow;
|
|
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
// - Initialize configuration
|
|
|
|
|
// - Initialize kiosk mode
|
|
|
|
|
// - Initialize session data
|
|
|
|
|
// - Create and connect to client
|
|
|
|
|
// - Initialize session with service
|
|
|
|
|
// - Verify session integrity and start event handling
|
|
|
|
|
var success = initial ? sessionSequence.TryPerform() : sessionSequence.TryRepeat();
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.Threading.Thread.Sleep(5000);
|
|
|
|
|
|
|
|
|
|
runtimeWindow.UpdateText(TextKey.RuntimeWindow_ApplicationRunning);
|
|
|
|
|
|
|
|
|
|
if (settingsRepository.Current.KioskMode == KioskMode.DisableExplorerShell)
|
|
|
|
|
{
|
|
|
|
|
runtimeWindow.Hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.Threading.Thread.Sleep(5000);
|
|
|
|
|
|
|
|
|
|
terminationCallback.Invoke();
|
2018-01-17 08:26:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
private void StopSession()
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
logger.Info("Stopping current session...");
|
|
|
|
|
runtimeWindow.Show();
|
|
|
|
|
runtimeWindow.BringToForeground();
|
2018-02-02 09:18:35 +01:00
|
|
|
|
runtimeWindow.UpdateText(TextKey.RuntimeWindow_StopSession, true);
|
2018-01-30 14:41:36 +01:00
|
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
// - Terminate client (or does it terminate itself?)
|
|
|
|
|
// - Finalize session with service
|
|
|
|
|
// - Stop event handling and close session
|
2018-01-17 08:26:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|