/* * 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/. */ using System.Collections.Generic; using System.Linq; using SafeExamBrowser.Contracts.Behaviour; using SafeExamBrowser.Contracts.Communication; using SafeExamBrowser.Contracts.Configuration.Settings; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.UserInterface; namespace SafeExamBrowser.Runtime.Behaviour { internal class RuntimeController : IRuntimeController { private ICommunication serviceProxy; private Queue operations; private ILogger logger; private IRuntimeWindow runtimeWindow; private ISettingsRepository settingsRepository; private IShutdownController shutdownController; private IStartupController startupController; public ISettings Settings { private get; set; } public RuntimeController( ICommunication serviceProxy, ILogger logger, IRuntimeWindow runtimeWindow, ISettingsRepository settingsRepository, IShutdownController shutdownController, IStartupController startupController) { this.serviceProxy = serviceProxy; this.logger = logger; this.runtimeWindow = runtimeWindow; this.settingsRepository = settingsRepository; this.shutdownController = shutdownController; this.startupController = startupController; operations = new Queue(); } public bool TryInitializeApplication(Queue operations) { operations = new Queue(operations); var success = startupController.TryInitializeApplication(operations); if (success) { Start(); } return success; } public void FinalizeApplication() { Stop(); shutdownController.FinalizeApplication(new Queue(operations.Reverse())); } private void Start() { logger.Info("Starting event handling..."); // TODO SplashScreen.UpdateText(TextKey.SplashScreen_StartEventHandling); runtimeWindow.UpdateStatus(TextKey.RuntimeWindow_ApplicationRunning); } private void Stop() { logger.Info("Stopping event handling..."); // TODO SplashScreen.UpdateText(TextKey.SplashScreen_StopEventHandling); } } }