2018-02-12 12:21:55 +01:00
|
|
|
|
/*
|
2021-02-03 00:45:33 +01:00
|
|
|
|
* Copyright (c) 2021 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-07-04 09:53:33 +02:00
|
|
|
|
using System;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Communication.Contracts;
|
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Data;
|
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Proxies;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Communication.Proxies
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-03-06 14:35:10 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Default implementation of the <see cref="IRuntimeProxy"/>, to be used for communication with the runtime application component.
|
|
|
|
|
/// </summary>
|
2018-02-12 12:21:55 +01:00
|
|
|
|
public class RuntimeProxy : BaseProxy, IRuntimeProxy
|
|
|
|
|
{
|
2019-06-18 10:18:56 +02:00
|
|
|
|
public RuntimeProxy(string address, IProxyObjectFactory factory, ILogger logger, Interlocutor owner) : base(address, factory, logger, owner)
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
public CommunicationResult<ConfigurationResponse> GetConfiguration()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
try
|
2018-02-20 15:15:26 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
var response = Send(SimpleMessagePurport.ConfigurationNeeded);
|
|
|
|
|
var success = response is ConfigurationResponse;
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Received configuration response.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Did not retrieve configuration response! Received: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult<ConfigurationResponse>(success, response as ConfigurationResponse);
|
2018-02-20 15:15:26 +01:00
|
|
|
|
}
|
2018-08-10 13:23:24 +02:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(GetConfiguration)}'", e);
|
2018-02-20 15:15:26 +01:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
return new CommunicationResult<ConfigurationResponse>(false, default(ConfigurationResponse));
|
|
|
|
|
}
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
public CommunicationResult InformClientReady()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(SimpleMessagePurport.ClientIsReady);
|
|
|
|
|
var success = IsAcknowledged(response);
|
2018-02-20 15:15:26 +01:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Runtime acknowledged that the client is ready.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Runtime did not acknowledge that the client is ready! Response: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2018-02-20 15:15:26 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
Logger.Error($"Failed to perform '{nameof(InformClientReady)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
2018-02-20 15:15:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 12:55:20 +02:00
|
|
|
|
public CommunicationResult RequestReconfiguration(string filePath, string url)
|
2018-03-08 15:27:12 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-09-24 12:55:20 +02:00
|
|
|
|
var response = Send(new ReconfigurationMessage(filePath, url));
|
2018-08-10 13:23:24 +02:00
|
|
|
|
var success = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Runtime acknowledged reconfiguration request.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Runtime did not acknowledge reconfiguration request! Response: {ToString(response)}.");
|
|
|
|
|
}
|
2018-03-08 15:27:12 +01:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2018-03-08 15:27:12 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
Logger.Error($"Failed to perform '{nameof(RequestReconfiguration)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
2018-03-08 15:27:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
public CommunicationResult RequestShutdown()
|
2018-02-20 15:15:26 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(SimpleMessagePurport.RequestShutdown);
|
|
|
|
|
var success = IsAcknowledged(response);
|
2018-02-20 15:15:26 +01:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Runtime acknowledged shutdown request.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Runtime did not acknowledge shutdown request! Response: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2018-02-22 16:15:06 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
Logger.Error($"Failed to perform '{nameof(RequestShutdown)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
2018-02-22 16:15:06 +01:00
|
|
|
|
}
|
2018-02-20 15:15:26 +01:00
|
|
|
|
}
|
2018-07-04 09:53:33 +02:00
|
|
|
|
|
2020-07-31 19:57:08 +02:00
|
|
|
|
public CommunicationResult SubmitExamSelectionResult(Guid requestId, bool success, string selectedExamId = null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(new ExamSelectionReplyMessage(requestId, success, selectedExamId));
|
|
|
|
|
var acknowledged = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (acknowledged)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Runtime acknowledged server exam selection transmission.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Runtime did not acknowledge server exam selection transmission! Response: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(acknowledged);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(SubmitExamSelectionResult)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 14:02:36 +02:00
|
|
|
|
public CommunicationResult SubmitMessageBoxResult(Guid requestId, int result)
|
2018-12-14 12:31:31 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-08-30 14:02:36 +02:00
|
|
|
|
var response = Send(new MessageBoxReplyMessage(requestId, result));
|
2018-12-14 12:31:31 +01:00
|
|
|
|
var acknowledged = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (acknowledged)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Runtime acknowledged message box result transmission.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Runtime did not acknowledge message box result transmission! Response: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(acknowledged);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(SubmitMessageBoxResult)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
public CommunicationResult SubmitPassword(Guid requestId, bool success, string password = null)
|
2018-07-04 09:53:33 +02:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(new PasswordReplyMessage(requestId, success, password));
|
|
|
|
|
var acknowledged = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (acknowledged)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Runtime acknowledged password transmission.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Runtime did not acknowledge password transmission! Response: {ToString(response)}.");
|
|
|
|
|
}
|
2018-07-04 09:53:33 +02:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
return new CommunicationResult(acknowledged);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2018-07-04 09:53:33 +02:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
Logger.Error($"Failed to perform '{nameof(SubmitPassword)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
2018-07-04 09:53:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-31 20:35:18 +02:00
|
|
|
|
|
|
|
|
|
public CommunicationResult SubmitServerFailureActionResult(Guid requestId, bool abort, bool fallback, bool retry)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(new ServerFailureActionReplyMessage(abort, fallback, retry, requestId));
|
|
|
|
|
var acknowledged = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (acknowledged)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Runtime acknowledged server failure action transmission.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Runtime did not acknowledge server failure action transmission! Response: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(acknowledged);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(SubmitServerFailureActionResult)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|