2018-02-12 12:21:55 +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/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Core.OperationModel;
|
2018-03-15 14:32:07 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Communication.Proxies;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.I18n;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Client.Operations
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
|
|
|
|
internal class RuntimeConnectionOperation : IOperation
|
|
|
|
|
{
|
|
|
|
|
private bool connected;
|
|
|
|
|
private ILogger logger;
|
|
|
|
|
private IRuntimeProxy runtime;
|
|
|
|
|
private Guid token;
|
|
|
|
|
|
|
|
|
|
public IProgressIndicator ProgressIndicator { private get; set; }
|
|
|
|
|
|
|
|
|
|
public RuntimeConnectionOperation(ILogger logger, IRuntimeProxy runtime, Guid token)
|
|
|
|
|
{
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.runtime = runtime;
|
|
|
|
|
this.token = token;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-28 15:49:06 +01:00
|
|
|
|
public OperationResult Perform()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
|
|
|
|
logger.Info("Initializing runtime connection...");
|
|
|
|
|
ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_InitializeRuntimeConnection);
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
connected = runtime.Connect(token);
|
|
|
|
|
|
|
|
|
|
if (connected)
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
logger.Info("Successfully connected to the runtime.");
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
2018-08-10 13:23:24 +02:00
|
|
|
|
else
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-02-14 15:26:05 +01:00
|
|
|
|
logger.Error("Failed to connect to the runtime. Aborting startup...");
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
2018-02-28 15:49:06 +01:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
return connected ? OperationResult.Success : OperationResult.Failed;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-28 15:49:06 +01:00
|
|
|
|
public OperationResult Repeat()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-02-28 15:49:06 +01:00
|
|
|
|
return OperationResult.Success;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Revert()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Closing runtime connection...");
|
|
|
|
|
ProgressIndicator?.UpdateText(TextKey.ProgressIndicator_CloseRuntimeConnection);
|
|
|
|
|
|
|
|
|
|
if (connected)
|
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
var success = runtime.Disconnect();
|
|
|
|
|
|
|
|
|
|
if (success)
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
logger.Info("Successfully disconnected from the runtime.");
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
2018-08-10 13:23:24 +02:00
|
|
|
|
else
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
logger.Error("Failed to disconnect from the runtime!");
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|