2018-01-24 12:34:32 +01:00
|
|
|
|
/*
|
2023-03-08 00:30:20 +01:00
|
|
|
|
* Copyright (c) 2023 ETH Zürich, Educational Development and Technology (LET)
|
2018-01-24 12:34:32 +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-02-08 13:32:48 +01: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.Configuration.Contracts;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2018-01-24 12:34:32 +01:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Communication.Proxies
|
2018-01-24 12:34:32 +01:00
|
|
|
|
{
|
2018-03-06 14:35:10 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Default implementation of the <see cref="IServiceProxy"/>, to be used for communication with the service application component.
|
|
|
|
|
/// </summary>
|
2018-01-24 12:34:32 +01:00
|
|
|
|
public class ServiceProxy : BaseProxy, IServiceProxy
|
|
|
|
|
{
|
2019-06-18 10:18:56 +02:00
|
|
|
|
public ServiceProxy(string address, IProxyObjectFactory factory, ILogger logger, Interlocutor owner) : base(address, factory, logger, owner)
|
2018-01-24 12:34:32 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 09:12:28 +02:00
|
|
|
|
public CommunicationResult RunSystemConfigurationUpdate()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(SimpleMessagePurport.UpdateSystemConfiguration);
|
|
|
|
|
var success = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Service acknowledged system configuration update.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Service did not acknowledge system configuration update! Received: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(RunSystemConfigurationUpdate)}'", e);
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 09:53:33 +02:00
|
|
|
|
public CommunicationResult StartSession(ServiceConfiguration configuration)
|
2018-02-08 13:32:48 +01:00
|
|
|
|
{
|
2019-06-18 10:18:56 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(new SessionStartMessage(configuration));
|
|
|
|
|
var success = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Service acknowledged session start.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Service did not acknowledge session start! Received: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(StartSession)}'", e);
|
2018-08-10 13:23:24 +02:00
|
|
|
|
|
2019-06-18 10:18:56 +02:00
|
|
|
|
return new CommunicationResult(false);
|
|
|
|
|
}
|
2018-02-08 13:32:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
public CommunicationResult StopSession(Guid sessionId)
|
2018-02-08 13:32:48 +01:00
|
|
|
|
{
|
2019-06-18 10:18:56 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = Send(new SessionStopMessage(sessionId));
|
|
|
|
|
var success = IsAcknowledged(response);
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Service acknowledged session stop.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Service did not acknowledge session stop! Received: {ToString(response)}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new CommunicationResult(success);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Failed to perform '{nameof(StopSession)}'", e);
|
2018-08-10 13:23:24 +02:00
|
|
|
|
|
2019-06-18 10:18:56 +02:00
|
|
|
|
return new CommunicationResult(false);
|
|
|
|
|
}
|
2018-01-25 09:50:46 +01:00
|
|
|
|
}
|
2018-01-24 12:34:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|