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 System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour;
|
|
|
|
|
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
|
|
|
|
{
|
2018-01-24 07:46:22 +01:00
|
|
|
|
private Queue<IOperation> operations;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
private ILogger logger;
|
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;
|
|
|
|
|
private IShutdownController shutdownController;
|
|
|
|
|
private IStartupController startupController;
|
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-01-30 14:41:36 +01:00
|
|
|
|
IRuntimeInfo runtimeInfo,
|
|
|
|
|
IServiceProxy serviceProxy,
|
2018-01-24 07:46:22 +01:00
|
|
|
|
ISettingsRepository settingsRepository,
|
|
|
|
|
IShutdownController shutdownController,
|
2018-01-30 14:41:36 +01:00
|
|
|
|
IStartupController startupController,
|
|
|
|
|
Action terminationCallback,
|
|
|
|
|
IText text,
|
|
|
|
|
IUserInterfaceFactory uiFactory)
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
|
|
|
|
this.logger = logger;
|
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;
|
|
|
|
|
this.shutdownController = shutdownController;
|
|
|
|
|
this.startupController = startupController;
|
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
|
|
|
|
|
|
|
|
|
operations = new Queue<IOperation>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool TryInitializeApplication(Queue<IOperation> operations)
|
|
|
|
|
{
|
|
|
|
|
var success = startupController.TryInitializeApplication(operations);
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
runtimeWindow = uiFactory.CreateRuntimeWindow(runtimeInfo, text);
|
|
|
|
|
|
2018-01-24 07:46:22 +01:00
|
|
|
|
if (success)
|
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
this.operations = new Queue<IOperation>(operations);
|
|
|
|
|
logger.Subscribe(runtimeWindow);
|
2018-01-24 07:46:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
public void StartSession()
|
2018-01-24 07:46:22 +01:00
|
|
|
|
{
|
2018-01-30 14:41:36 +01:00
|
|
|
|
runtimeWindow.Show();
|
|
|
|
|
|
|
|
|
|
logger.Info("Starting new session...");
|
|
|
|
|
runtimeWindow.UpdateStatus(TextKey.RuntimeWindow_StartSession, true);
|
|
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
// - Initialize configuration
|
|
|
|
|
// - Initialize kiosk mode
|
|
|
|
|
// - Initialize session data
|
|
|
|
|
// - Start runtime communication host
|
|
|
|
|
// - Create and connect to client
|
|
|
|
|
// - Initialize session with service
|
|
|
|
|
// - Verify session integrity and start event handling
|
|
|
|
|
System.Threading.Thread.Sleep(10000);
|
|
|
|
|
|
|
|
|
|
runtimeWindow.UpdateStatus(TextKey.RuntimeWindow_ApplicationRunning);
|
|
|
|
|
|
|
|
|
|
if (settingsRepository.Current.KioskMode == KioskMode.DisableExplorerShell)
|
|
|
|
|
{
|
|
|
|
|
runtimeWindow.Hide();
|
|
|
|
|
}
|
2018-01-17 08:26:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 14:41:36 +01:00
|
|
|
|
public void FinalizeApplication()
|
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);
|
|
|
|
|
runtimeWindow.Close();
|
|
|
|
|
shutdownController.FinalizeApplication(new Queue<IOperation>(operations.Reverse()));
|
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();
|
|
|
|
|
runtimeWindow.UpdateStatus(TextKey.RuntimeWindow_StopSession, true);
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|