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-24 07:46:22 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour;
|
|
|
|
|
using SafeExamBrowser.Contracts.Communication;
|
2018-01-18 15:14:05 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
|
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 12:34:32 +01:00
|
|
|
|
private ICommunication serviceProxy;
|
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-24 07:46:22 +01:00
|
|
|
|
private ISettingsRepository settingsRepository;
|
|
|
|
|
private IShutdownController shutdownController;
|
|
|
|
|
private IStartupController startupController;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
|
2018-01-18 15:14:05 +01:00
|
|
|
|
public ISettings Settings { private get; set; }
|
|
|
|
|
|
2018-01-24 07:46:22 +01:00
|
|
|
|
public RuntimeController(
|
2018-01-24 12:34:32 +01:00
|
|
|
|
ICommunication serviceProxy,
|
2018-01-24 07:46:22 +01:00
|
|
|
|
ILogger logger,
|
|
|
|
|
ISettingsRepository settingsRepository,
|
|
|
|
|
IShutdownController shutdownController,
|
|
|
|
|
IStartupController startupController)
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
2018-01-24 07:46:22 +01:00
|
|
|
|
this.serviceProxy = serviceProxy;
|
2018-01-17 08:26:44 +01:00
|
|
|
|
this.logger = logger;
|
2018-01-24 07:46:22 +01:00
|
|
|
|
this.settingsRepository = settingsRepository;
|
|
|
|
|
this.shutdownController = shutdownController;
|
|
|
|
|
this.startupController = startupController;
|
|
|
|
|
|
|
|
|
|
operations = new Queue<IOperation>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool TryInitializeApplication(Queue<IOperation> operations)
|
|
|
|
|
{
|
|
|
|
|
operations = new Queue<IOperation>(operations);
|
|
|
|
|
|
|
|
|
|
var success = startupController.TryInitializeApplication(operations);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FinalizeApplication()
|
|
|
|
|
{
|
|
|
|
|
Stop();
|
|
|
|
|
shutdownController.FinalizeApplication(new Queue<IOperation>(operations.Reverse()));
|
2018-01-17 08:26:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-24 07:46:22 +01:00
|
|
|
|
private void Start()
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
2018-01-24 07:46:22 +01:00
|
|
|
|
logger.Info("Starting event handling...");
|
|
|
|
|
// TODO SplashScreen.UpdateText(TextKey.SplashScreen_StartEventHandling);
|
2018-01-17 08:26:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-24 07:46:22 +01:00
|
|
|
|
private void Stop()
|
2018-01-17 08:26:44 +01:00
|
|
|
|
{
|
2018-01-24 07:46:22 +01:00
|
|
|
|
logger.Info("Stopping event handling...");
|
|
|
|
|
// TODO SplashScreen.UpdateText(TextKey.SplashScreen_StopEventHandling);
|
2018-01-17 08:26:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|