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)
|
if (success)
|
||||||
{
|
{
|
||||||
RegisterEvents();
|
RegisterEvents();
|
||||||
|
// TODO: Handle communication exception!
|
||||||
runtime.InformClientReady();
|
runtime.InformClientReady();
|
||||||
splashScreen.Hide();
|
splashScreen.Hide();
|
||||||
|
|
||||||
|
@ -174,14 +175,9 @@ namespace SafeExamBrowser.Client.Behaviour
|
||||||
|
|
||||||
private void Taskbar_QuitButtonClicked()
|
private void Taskbar_QuitButtonClicked()
|
||||||
{
|
{
|
||||||
// TODO: MessageBox asking whether user really wants to quit -> args.Cancel
|
// TODO: MessageBox asking whether user really wants to quit -> only then request shutdown!
|
||||||
|
// TODO: Handle communication exception!
|
||||||
var acknowledged = runtime.RequestShutdown();
|
runtime.RequestShutdown();
|
||||||
|
|
||||||
if (!acknowledged)
|
|
||||||
{
|
|
||||||
logger.Warn("The runtime did not acknowledge the shutdown request!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WindowMonitor_WindowChanged(IntPtr window)
|
private void WindowMonitor_WindowChanged(IntPtr window)
|
||||||
|
|
|
@ -15,11 +15,13 @@ namespace SafeExamBrowser.Contracts.Communication
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instructs the client to initiate its shutdown procedure.
|
/// Instructs the client to initiate its shutdown procedure.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||||
void InitiateShutdown();
|
void InitiateShutdown();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instructs the client to submit its authentication data.
|
/// Instructs the client to submit its authentication data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||||
AuthenticationResponse RequestAuthentication();
|
AuthenticationResponse RequestAuthentication();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,15 @@ namespace SafeExamBrowser.Contracts.Communication
|
||||||
public interface ICommunicationProxy
|
public interface ICommunicationProxy
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
|
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||||
bool Connect(Guid? token = null);
|
bool Connect(Guid? token = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
|
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||||
bool Disconnect();
|
bool Disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,18 +15,19 @@ namespace SafeExamBrowser.Contracts.Communication
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the application configuration from the runtime.
|
/// Retrieves the application configuration from the runtime.
|
||||||
/// </summary>
|
/// </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();
|
ClientConfiguration GetConfiguration();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Informs the runtime that the client is ready.
|
/// Informs the runtime that the client is ready.
|
||||||
/// </summary>
|
/// </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();
|
void InformClientReady();
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
bool RequestShutdown();
|
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||||
|
void RequestShutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,13 @@ namespace SafeExamBrowser.Contracts.Communication
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instructs the service to start a new session according to the given parameters.
|
/// Instructs the service to start a new session according to the given parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||||
void StartSession(Guid sessionId, Settings settings);
|
void StartSession(Guid sessionId, Settings settings);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instructs the service to stop the specified session.
|
/// Instructs the service to stop the specified session.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <exception cref="System.ServiceModel.*">If the communication failed.</exception>
|
||||||
void StopSession(Guid sessionId);
|
void StopSession(Guid sessionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,11 @@ namespace SafeExamBrowser.Contracts.Communication.Responses
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Acknowledged = 1,
|
Acknowledged = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Signals an interlocutor that it is not authorized to communicate.
|
||||||
|
/// </summary>
|
||||||
|
Unauthorized,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Signals an interlocutor that a message has not been understood.
|
/// Signals an interlocutor that a message has not been understood.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -97,7 +97,7 @@ namespace SafeExamBrowser.Core.Communication
|
||||||
{
|
{
|
||||||
lock (@lock)
|
lock (@lock)
|
||||||
{
|
{
|
||||||
var response = default(Response);
|
var response = new SimpleResponse(SimpleResponsePurport.Unauthorized) as Response;
|
||||||
|
|
||||||
if (IsAuthorized(message?.CommunicationToken))
|
if (IsAuthorized(message?.CommunicationToken))
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,21 +37,23 @@ namespace SafeExamBrowser.Core.Communication
|
||||||
{
|
{
|
||||||
var response = Send(SimpleMessagePurport.ClientIsReady);
|
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)}.");
|
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 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;
|
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\ConfigurationOperationTests.cs" />
|
||||||
<Compile Include="Behaviour\Operations\KioskModeOperationTests.cs" />
|
<Compile Include="Behaviour\Operations\KioskModeOperationTests.cs" />
|
||||||
<Compile Include="Behaviour\Operations\ServiceConnectionOperationTests.cs" />
|
<Compile Include="Behaviour\Operations\ServiceConnectionOperationTests.cs" />
|
||||||
|
<Compile Include="Behaviour\Operations\SessionSequenceOperationTests.cs" />
|
||||||
<Compile Include="Behaviour\RuntimeControllerTests.cs" />
|
<Compile Include="Behaviour\RuntimeControllerTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -58,9 +58,9 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations
|
||||||
logger.Info($"Loading configuration from '{uri.AbsolutePath}'...");
|
logger.Info($"Loading configuration from '{uri.AbsolutePath}'...");
|
||||||
settings = repository.LoadSettings(uri);
|
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.");
|
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?!
|
// 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: Use configuration repository as container?
|
||||||
|
// -> IDEA: Introduce IRepeatParams or alike?
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Revert()
|
public void Revert()
|
||||||
|
@ -115,7 +116,7 @@ namespace SafeExamBrowser.Runtime.Behaviour.Operations
|
||||||
return isValidUri;
|
return isValidUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool UserWantsToAbortStartup()
|
private bool IsConfigurationSufficient()
|
||||||
{
|
{
|
||||||
var message = text.Get(TextKey.MessageBox_ConfigureClientSuccess);
|
var message = text.Get(TextKey.MessageBox_ConfigureClientSuccess);
|
||||||
var title = text.Get(TextKey.MessageBox_ConfigureClientSuccessTitle);
|
var title = text.Get(TextKey.MessageBox_ConfigureClientSuccessTitle);
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using SafeExamBrowser.Contracts.Communication;
|
using SafeExamBrowser.Contracts.Communication;
|
||||||
using SafeExamBrowser.Contracts.Communication.Messages;
|
using SafeExamBrowser.Contracts.Communication.Messages;
|
||||||
using SafeExamBrowser.Contracts.Communication.Responses;
|
using SafeExamBrowser.Contracts.Communication.Responses;
|
||||||
|
@ -39,7 +38,7 @@ namespace SafeExamBrowser.Runtime.Communication
|
||||||
|
|
||||||
protected override void OnDisconnect()
|
protected override void OnDisconnect()
|
||||||
{
|
{
|
||||||
Task.Run(() => ClientDisconnected?.Invoke());
|
ClientDisconnected?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Response OnReceive(Message message)
|
protected override Response OnReceive(Message message)
|
||||||
|
|
Loading…
Reference in a new issue