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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
using System.ServiceModel;
|
2018-03-15 14:32:07 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Communication.Data;
|
|
|
|
|
using SafeExamBrowser.Contracts.Communication.Proxies;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
|
2018-03-16 09:28:33 +01:00
|
|
|
|
namespace SafeExamBrowser.Core.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
|
|
|
|
|
{
|
2018-03-15 09:55:04 +01:00
|
|
|
|
public RuntimeProxy(string address, IProxyObjectFactory factory, ILogger logger) : base(address, factory, logger)
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 15:42:54 +01:00
|
|
|
|
public ClientConfiguration GetConfiguration()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-02-20 15:15:26 +01:00
|
|
|
|
var response = Send(SimpleMessagePurport.ConfigurationNeeded);
|
|
|
|
|
|
|
|
|
|
if (response is ConfigurationResponse configurationResponse)
|
|
|
|
|
{
|
|
|
|
|
return configurationResponse.Configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new CommunicationException($"Could not retrieve client configuration! Received: {ToString(response)}.");
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-14 15:26:05 +01:00
|
|
|
|
public void InformClientReady()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-02-20 15:15:26 +01:00
|
|
|
|
var response = Send(SimpleMessagePurport.ClientIsReady);
|
|
|
|
|
|
2018-02-22 16:15:06 +01:00
|
|
|
|
if (!IsAcknowledged(response))
|
2018-02-20 15:15:26 +01:00
|
|
|
|
{
|
|
|
|
|
throw new CommunicationException($"Runtime did not acknowledge that client is ready! Response: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-21 07:56:25 +02:00
|
|
|
|
public void RequestReconfiguration(string filePath)
|
2018-03-08 15:27:12 +01:00
|
|
|
|
{
|
2018-06-21 07:56:25 +02:00
|
|
|
|
var response = Send(new ReconfigurationMessage(filePath));
|
2018-03-08 15:27:12 +01:00
|
|
|
|
|
2018-06-21 07:56:25 +02:00
|
|
|
|
if (!IsAcknowledged(response))
|
2018-03-08 15:27:12 +01:00
|
|
|
|
{
|
2018-06-21 07:56:25 +02:00
|
|
|
|
throw new CommunicationException($"Runtime did not acknowledge reconfiguration request! Response: {ToString(response)}.");
|
2018-03-08 15:27:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 16:15:06 +01:00
|
|
|
|
public void RequestShutdown()
|
2018-02-20 15:15:26 +01:00
|
|
|
|
{
|
|
|
|
|
var response = Send(SimpleMessagePurport.RequestShutdown);
|
|
|
|
|
|
2018-02-22 16:15:06 +01:00
|
|
|
|
if (!IsAcknowledged(response))
|
|
|
|
|
{
|
|
|
|
|
throw new CommunicationException($"Runtime did not acknowledge shutdown request! Response: {ToString(response)}.");
|
|
|
|
|
}
|
2018-02-20 15:15:26 +01:00
|
|
|
|
}
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|