2018-02-12 12:21:55 +01:00
|
|
|
|
/*
|
2022-01-21 16:33:52 +01:00
|
|
|
|
* Copyright (c) 2022 ETH Zürich, Educational Development and Technology (LET)
|
2018-02-12 12:21:55 +01:00
|
|
|
|
*
|
|
|
|
|
* 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;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Proxies;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
|
|
|
|
|
using SafeExamBrowser.I18n.Contracts;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Client.Operations
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2019-10-01 16:24:10 +02:00
|
|
|
|
internal class RuntimeConnectionOperation : ClientOperation
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
|
|
|
|
private ILogger logger;
|
|
|
|
|
private IRuntimeProxy runtime;
|
|
|
|
|
private Guid token;
|
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public override event ActionRequiredEventHandler ActionRequired { add { } remove { } }
|
|
|
|
|
public override event StatusChangedEventHandler StatusChanged;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public RuntimeConnectionOperation(ClientContext context, ILogger logger, IRuntimeProxy runtime, Guid token) : base(context)
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.runtime = runtime;
|
|
|
|
|
this.token = token;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public override OperationResult Perform()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
|
|
|
|
logger.Info("Initializing runtime connection...");
|
2018-10-03 15:42:50 +02:00
|
|
|
|
StatusChanged?.Invoke(TextKey.OperationStatus_InitializeRuntimeConnection);
|
2018-02-12 12:21:55 +01:00
|
|
|
|
|
2019-06-18 10:18:56 +02:00
|
|
|
|
var connected = runtime.Connect(token);
|
2018-08-10 13:23:24 +02:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public override OperationResult Revert()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
|
|
|
|
logger.Info("Closing runtime connection...");
|
2018-10-03 15:42:50 +02:00
|
|
|
|
StatusChanged?.Invoke(TextKey.OperationStatus_CloseRuntimeConnection);
|
2018-02-12 12:21:55 +01:00
|
|
|
|
|
2019-06-18 10:18:56 +02:00
|
|
|
|
if (runtime.IsConnected)
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
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
|
|
|
|
}
|
2018-10-10 09:19:03 +02:00
|
|
|
|
|
|
|
|
|
return success ? OperationResult.Success : OperationResult.Failed;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
2018-10-10 09:19:03 +02:00
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|