2018-01-24 12:34:32 +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 SafeExamBrowser.Contracts.Communication;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
using SafeExamBrowser.Core.Communication.Messages;
|
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Core.Communication
|
|
|
|
|
{
|
|
|
|
|
public class ServiceProxy : BaseProxy, IServiceProxy
|
|
|
|
|
{
|
2018-01-25 09:50:46 +01:00
|
|
|
|
public bool Ignore { private get; set; }
|
|
|
|
|
|
2018-01-24 12:34:32 +01:00
|
|
|
|
public ServiceProxy(ILogger logger, string address) : base(logger, address)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Connect()
|
|
|
|
|
{
|
2018-01-25 09:50:46 +01:00
|
|
|
|
if (!IgnoreOperation(nameof(Connect)))
|
|
|
|
|
{
|
|
|
|
|
return base.Connect().ConnectionEstablished;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2018-01-24 12:34:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Disconnect()
|
|
|
|
|
{
|
2018-01-25 09:50:46 +01:00
|
|
|
|
if (!IgnoreOperation(nameof(Disconnect)))
|
|
|
|
|
{
|
|
|
|
|
FailIfNotConnected(nameof(Disconnect));
|
|
|
|
|
|
|
|
|
|
Disconnect(new Message { CommunicationToken = CommunicationToken.Value });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IgnoreOperation(string operationName)
|
|
|
|
|
{
|
|
|
|
|
if (Ignore)
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug($"Skipping {operationName} because the ignore flag is set.");
|
|
|
|
|
}
|
2018-01-24 12:34:32 +01:00
|
|
|
|
|
2018-01-25 09:50:46 +01:00
|
|
|
|
return Ignore;
|
2018-01-24 12:34:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|