SEBWIN-219: Started refining communication API & mechanics.
This commit is contained in:
parent
4e7b8fc88e
commit
268eda9f90
12 changed files with 58 additions and 25 deletions
|
@ -86,6 +86,7 @@ namespace SafeExamBrowser.Client.Behaviour
|
|||
if (success)
|
||||
{
|
||||
RegisterEvents();
|
||||
// TODO: Handle communication exception!
|
||||
runtime.InformClientReady();
|
||||
splashScreen.Hide();
|
||||
|
||||
|
@ -174,14 +175,9 @@ namespace SafeExamBrowser.Client.Behaviour
|
|||
|
||||
private void Taskbar_QuitButtonClicked()
|
||||
{
|
||||
// TODO: MessageBox asking whether user really wants to quit -> args.Cancel
|
||||
|
||||
var acknowledged = runtime.RequestShutdown();
|
||||
|
||||
if (!acknowledged)
|
||||
{
|
||||
logger.Warn("The runtime did not acknowledge the shutdown request!");
|
||||
}
|
||||
// TODO: MessageBox asking whether user really wants to quit -> only then request shutdown!
|
||||
// TODO: Handle communication exception!
|
||||
runtime.RequestShutdown();
|
||||
}
|
||||
|
||||
private void WindowMonitor_WindowChanged(IntPtr window)
|
||||
|
|
|
@ -15,11 +15,13 @@ namespace SafeExamBrowser.Contracts.Communication
|
|||
/// <summary>
|
||||
/// Instructs the client to initiate its shutdown procedure.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||
void InitiateShutdown();
|
||||
|
||||
/// <summary>
|
||||
/// Instructs the client to submit its authentication data.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||
AuthenticationResponse RequestAuthentication();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,13 +13,15 @@ namespace SafeExamBrowser.Contracts.Communication
|
|||
public interface ICommunicationProxy
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to establish a connection. Returns <c>true</c> if successful, otherwise <c>false</c>.
|
||||
/// Tries to establish a connection. Returns <c>true</c> if the connection has been accepted, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||
bool Connect(Guid? token = null);
|
||||
|
||||
/// <summary>
|
||||
/// Terminates an open connection. Returns <c>true</c> if successful, otherwise <c>false</c>.
|
||||
/// Terminates an open connection. Returns <c>true</c> if the disconnection has been acknowledged, otherwise <c>false</c>.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||
bool Disconnect();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,18 +15,19 @@ namespace SafeExamBrowser.Contracts.Communication
|
|||
/// <summary>
|
||||
/// Retrieves the application configuration from the runtime.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ServiceModel.CommunicationException">If the configuration could not be retrieved.</exception>
|
||||
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||
ClientConfiguration GetConfiguration();
|
||||
|
||||
/// <summary>
|
||||
/// Informs the runtime that the client is ready.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ServiceModel.CommunicationException">If the runtime did not acknowledge the status update.</exception>
|
||||
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||
void InformClientReady();
|
||||
|
||||
/// <summary>
|
||||
/// Requests the runtime to shut down the application. Returns <c>true</c> if the request was acknowledged, otherwise <c>false</c>.
|
||||
/// Requests the runtime to shut down the application.
|
||||
/// </summary>
|
||||
bool RequestShutdown();
|
||||
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||
void RequestShutdown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,13 @@ namespace SafeExamBrowser.Contracts.Communication
|
|||
/// <summary>
|
||||
/// Instructs the service to start a new session according to the given parameters.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||
void StartSession(Guid sessionId, Settings settings);
|
||||
|
||||
/// <summary>
|
||||
/// Instructs the service to stop the specified session.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||
void StopSession(Guid sessionId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,11 @@ namespace SafeExamBrowser.Contracts.Communication.Responses
|
|||
/// </summary>
|
||||
Acknowledged = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Signals an interlocutor that it is not authorized to communicate.
|
||||
/// </summary>
|
||||
Unauthorized,
|
||||
|
||||
/// <summary>
|
||||
/// Signals an interlocutor that a message has not been understood.
|
||||
/// </summary>
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace SafeExamBrowser.Core.Communication
|
|||
{
|
||||
lock (@lock)
|
||||
{
|
||||
var response = default(Response);
|
||||
var response = new SimpleResponse(SimpleResponsePurport.Unauthorized) as Response;
|
||||
|
||||
if (IsAuthorized(message?.CommunicationToken))
|
||||
{
|
||||
|
|
|
@ -37,21 +37,23 @@ namespace SafeExamBrowser.Core.Communication
|
|||
{
|
||||
var response = Send(SimpleMessagePurport.ClientIsReady);
|
||||
|
||||
if (!IsAcknowledgeResponse(response))
|
||||
if (!IsAcknowledged(response))
|
||||
{
|
||||
throw new CommunicationException($"Runtime did not acknowledge that client is ready! Response: {ToString(response)}.");
|
||||
}
|
||||
}
|
||||
|
||||
public bool RequestShutdown()
|
||||
public void RequestShutdown()
|
||||
{
|
||||
var response = Send(SimpleMessagePurport.RequestShutdown);
|
||||
var acknowledged = IsAcknowledgeResponse(response);
|
||||
|
||||
return acknowledged;
|
||||
if (!IsAcknowledged(response))
|
||||
{
|
||||
throw new CommunicationException($"Runtime did not acknowledge shutdown request! Response: {ToString(response)}.");
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsAcknowledgeResponse(Response response)
|
||||
private bool IsAcknowledged(Response response)
|
||||
{
|
||||
return response is SimpleResponse simpleResponse && simpleResponse.Purport == SimpleResponsePurport.Acknowledged;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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 Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Behaviour.Operations
|
||||
{
|
||||
[TestClass]
|
||||
public class SessionSequenceOperationTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void TODO()
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -83,6 +83,7 @@
|
|||
<Compile Include="Behaviour\Operations\ConfigurationOperationTests.cs" />
|
||||
<Compile Include="Behaviour\Operations\KioskModeOperationTests.cs" />
|
||||
<Compile Include="Behaviour\Operations\ServiceConnectionOperationTests.cs" />
|
||||
<Compile Include="Behaviour\Operations\SessionSequenceOperationTests.cs" />
|
||||
<Compile Include="Behaviour\RuntimeControllerTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -58,9 +58,9 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations
|
|||
logger.Info($"Loading configuration from '{uri.AbsolutePath}'...");
|
||||
settings = repository.LoadSettings(uri);
|
||||
|
||||
if (settings.ConfigurationMode == ConfigurationMode.ConfigureClient && UserWantsToAbortStartup())
|
||||
if (settings.ConfigurationMode == ConfigurationMode.ConfigureClient)
|
||||
{
|
||||
Abort = true;
|
||||
Abort = IsConfigurationSufficient();
|
||||
logger.Info($"The user chose to {(Abort ? "abort" : "continue")} the application startup after successful client configuration.");
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations
|
|||
{
|
||||
// TODO: How will the new settings be retrieved? Uri passed to the repository? If yes, how does the Uri get here?!
|
||||
// -> IDEA: Use configuration repository as container?
|
||||
// -> IDEA: Introduce IRepeatParams or alike?
|
||||
}
|
||||
|
||||
public void Revert()
|
||||
|
@ -115,7 +116,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations
|
|||
return isValidUri;
|
||||
}
|
||||
|
||||
private bool UserWantsToAbortStartup()
|
||||
private bool IsConfigurationSufficient()
|
||||
{
|
||||
var message = text.Get(TextKey.MessageBox_ConfigureClientSuccess);
|
||||
var title = text.Get(TextKey.MessageBox_ConfigureClientSuccessTitle);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using SafeExamBrowser.Contracts.Communication;
|
||||
using SafeExamBrowser.Contracts.Communication.Messages;
|
||||
using SafeExamBrowser.Contracts.Communication.Responses;
|
||||
|
@ -39,7 +38,7 @@ namespace SafeExamBrowser.Runtime.Communication
|
|||
|
||||
protected override void OnDisconnect()
|
||||
{
|
||||
Task.Run(() => ClientDisconnected?.Invoke());
|
||||
ClientDisconnected?.Invoke();
|
||||
}
|
||||
|
||||
protected override Response OnReceive(Message message)
|
||||
|
|
Loading…
Reference in a new issue