/* * 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 SafeExamBrowser.Contracts.Communication; using SafeExamBrowser.Contracts.Core.OperationModel; using SafeExamBrowser.Contracts.Core.OperationModel.Events; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.Logging; namespace SafeExamBrowser.Core.Operations { /// /// An operation to handle the lifetime of an . The host is started during , /// stopped and restarted during (if not running) and stopped during . /// public class CommunicationHostOperation : IOperation { private ICommunicationHost host; private ILogger logger; public event ActionRequiredEventHandler ActionRequired { add { } remove { } } public event StatusChangedEventHandler StatusChanged; public CommunicationHostOperation(ICommunicationHost host, ILogger logger) { this.host = host; this.logger = logger; } public OperationResult Perform() { logger.Info("Starting communication host..."); StatusChanged?.Invoke(TextKey.ProgressIndicator_StartCommunicationHost); host.Start(); return OperationResult.Success; } public OperationResult Repeat() { if (!host.IsRunning) { logger.Info("Restarting communication host..."); StatusChanged?.Invoke(TextKey.ProgressIndicator_RestartCommunicationHost); host.Stop(); host.Start(); } return OperationResult.Success; } public void Revert() { logger.Info("Stopping communication host..."); StatusChanged?.Invoke(TextKey.ProgressIndicator_StopCommunicationHost); host.Stop(); } } }