изменения абстракции фронтенда
This commit is contained in:
+15
-14
@@ -1,5 +1,6 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -43,7 +44,7 @@ public class Tests
|
|||||||
"RequestTypeId": 0,
|
"RequestTypeId": 0,
|
||||||
"CommandId": 2
|
"CommandId": 2
|
||||||
}
|
}
|
||||||
""");
|
"""u8.ToArray());
|
||||||
Assert.Pass(_interactionModule.OutputBuffer.Last());
|
Assert.Pass(_interactionModule.OutputBuffer.Last());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ public class Tests
|
|||||||
"RequestTypeId": 0,
|
"RequestTypeId": 0,
|
||||||
"CommandId": 3
|
"CommandId": 3
|
||||||
}
|
}
|
||||||
""");
|
"""u8.ToArray());
|
||||||
while (_interactionModule.OutputBuffer.Count != 2) ;
|
while (_interactionModule.OutputBuffer.Count != 2) ;
|
||||||
|
|
||||||
Assert.Pass(_interactionModule.OutputBuffer.Last());
|
Assert.Pass(_interactionModule.OutputBuffer.Last());
|
||||||
@@ -87,21 +88,21 @@ public class Tests
|
|||||||
{
|
{
|
||||||
"CommandId": 4
|
"CommandId": 4
|
||||||
}
|
}
|
||||||
""");
|
"""u8.ToArray());
|
||||||
var response =
|
var response =
|
||||||
JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
|
JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
|
||||||
JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
|
JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
|
||||||
?.Result.ToString()
|
?.Result.ToString()
|
||||||
);
|
);
|
||||||
|
|
||||||
_interactionModule.PassCommand(132,
|
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
|
||||||
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId }));
|
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId })));
|
||||||
|
|
||||||
var firstFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
|
var firstFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
|
||||||
.GetInt32();
|
.GetInt32();
|
||||||
|
|
||||||
_interactionModule.PassCommand(132,
|
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
|
||||||
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 4, ObjectId = response.ContextId }));
|
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 4, ObjectId = response.ContextId })));
|
||||||
|
|
||||||
response =
|
response =
|
||||||
JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
|
JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
|
||||||
@@ -109,10 +110,10 @@ public class Tests
|
|||||||
?.Result.ToString()
|
?.Result.ToString()
|
||||||
);
|
);
|
||||||
|
|
||||||
_interactionModule.PassCommand(132,
|
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
|
||||||
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId }));
|
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId })));
|
||||||
_interactionModule.PassCommand(132,
|
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
|
||||||
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId }));
|
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId })));
|
||||||
|
|
||||||
var secondFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
|
var secondFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
|
||||||
.GetInt32();
|
.GetInt32();
|
||||||
@@ -127,14 +128,14 @@ public class Tests
|
|||||||
{
|
{
|
||||||
"CommandId": 6
|
"CommandId": 6
|
||||||
}
|
}
|
||||||
""");
|
"""u8.ToArray());
|
||||||
var response =
|
var response =
|
||||||
JsonSerializer.Deserialize<TransmittedSharedObject<ITestParameter>>(
|
JsonSerializer.Deserialize<TransmittedSharedObject<ITestParameter>>(
|
||||||
JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
|
JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
|
||||||
?.Result.ToString()
|
?.Result.ToString()
|
||||||
);
|
);
|
||||||
var x = response.ContextId;
|
var x = response.ContextId;
|
||||||
_interactionModule.PassCommand(132,
|
_interactionModule.PassCommand(132,Encoding.UTF8.GetBytes(
|
||||||
JsonSerializer.Serialize(new JsonCallRequest
|
JsonSerializer.Serialize(new JsonCallRequest
|
||||||
{
|
{
|
||||||
CommandId = 5,
|
CommandId = 5,
|
||||||
@@ -143,7 +144,7 @@ public class Tests
|
|||||||
A = 10,
|
A = 10,
|
||||||
LinkedObject = new TransmittedSharedObject<ITestParameter> { ContextId = x }
|
LinkedObject = new TransmittedSharedObject<ITestParameter> { ContextId = x }
|
||||||
}
|
}
|
||||||
}));
|
})));
|
||||||
|
|
||||||
var finalResponse = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result").GetInt32();
|
var finalResponse = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result").GetInt32();
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ namespace mROA;
|
|||||||
|
|
||||||
public interface IInteractionModule
|
public interface IInteractionModule
|
||||||
{
|
{
|
||||||
void SetMessageHandler(Action<int, string> handler);
|
void SetMessageHandler(Action<int, byte[]> handler);
|
||||||
void SendTo(int clientId, byte[] message);
|
void SendTo(int clientId, byte[] message);
|
||||||
|
public interface IFrontendInteractionModule
|
||||||
|
{
|
||||||
|
public byte[] ReceiveMessage();
|
||||||
|
public void PostMessage(byte[] message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,13 +4,12 @@ namespace mROA;
|
|||||||
|
|
||||||
public interface ISerialisationModule
|
public interface ISerialisationModule
|
||||||
{
|
{
|
||||||
void HandleIncomingRequest(int clientId, string command);
|
void HandleIncomingRequest(int clientId, byte[] command);
|
||||||
void PostResponse(ICommandExecution call);
|
void PostResponse(ICommandExecution call);
|
||||||
void SetExecuteModule(IExecuteModule executeModule);
|
void SetExecuteModule(IExecuteModule executeModule);
|
||||||
public interface IFrontendSerialisationModule
|
public interface IFrontendSerialisationModule
|
||||||
{
|
{
|
||||||
void HandlePostedResponse(string response);
|
ICommandExecution GetNextCommandExecution(Guid requestId);
|
||||||
void PostCallRequest(ICallRequest callRequest);
|
void PostCallRequest(ICallRequest callRequest);
|
||||||
Task<T> GetCommandExecutionResult<T>(Guid callRequestId, CancellationToken cancellationToken);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,19 +4,13 @@ namespace mROA.Implementation;
|
|||||||
|
|
||||||
public class JsonFrontendSerialisationModule : ISerialisationModule.IFrontendSerialisationModule
|
public class JsonFrontendSerialisationModule : ISerialisationModule.IFrontendSerialisationModule
|
||||||
{
|
{
|
||||||
public void HandlePostedResponse(string response)
|
public ICommandExecution GetNextCommandExecution(Guid requestId)
|
||||||
{
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void PostCallRequest(ICallRequest callRequest)
|
public void PostCallRequest(ICallRequest callRequest)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<T> GetCommandExecutionResult<T>(Guid callRequestId, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ public class JsonSerialisationModule : ISerialisationModule
|
|||||||
|
|
||||||
public void SetExecuteModule(IExecuteModule executeModule) => _executeModule = executeModule;
|
public void SetExecuteModule(IExecuteModule executeModule) => _executeModule = executeModule;
|
||||||
|
|
||||||
public void HandleIncomingRequest(int clientId, string command)
|
public void HandleIncomingRequest(int clientId, byte[] command)
|
||||||
{
|
{
|
||||||
JsonCallRequest request = JsonSerializer.Deserialize<JsonCallRequest>(command);
|
JsonCallRequest request = JsonSerializer.Deserialize<JsonCallRequest>(command);
|
||||||
request.ClientId = clientId;
|
request.ClientId = clientId;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
public class MockSerializationModule : ISerialisationModule
|
public class MockSerializationModule : ISerialisationModule
|
||||||
{
|
{
|
||||||
public void HandleIncomingRequest(int clientId, string command)
|
public void HandleIncomingRequest(int clientId, byte[] command)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
public class ProgramlyInteractionChanel : IInteractionModule
|
public class ProgramlyInteractionChanel : IInteractionModule
|
||||||
{
|
{
|
||||||
public void PassCommand(int clientId, string message) => _handler(clientId, message);
|
public void PassCommand(int clientId, byte[] message) => _handler(clientId, message);
|
||||||
private Action<int, string> _handler;
|
private Action<int, byte[]> _handler;
|
||||||
|
|
||||||
public List<string> OutputBuffer = new List<string>();
|
public List<string> OutputBuffer = new List<string>();
|
||||||
|
|
||||||
public void SetMessageHandler(Action<int, string> handler)
|
public void SetMessageHandler(Action<int, byte[]> handler)
|
||||||
{
|
{
|
||||||
_handler = handler;
|
_handler = handler;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user