изменения абстракции фронтенда

This commit is contained in:
2025-01-25 20:42:21 +03:00
parent 27259d0079
commit 66c78b158f
7 changed files with 31 additions and 32 deletions
+15 -14
View File
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Text.Json;
using mROA.Implementation;
using Newtonsoft.Json;
@@ -43,7 +44,7 @@ public class Tests
"RequestTypeId": 0,
"CommandId": 2
}
""");
"""u8.ToArray());
Assert.Pass(_interactionModule.OutputBuffer.Last());
}
@@ -56,7 +57,7 @@ public class Tests
"RequestTypeId": 0,
"CommandId": 3
}
""");
"""u8.ToArray());
while (_interactionModule.OutputBuffer.Count != 2) ;
Assert.Pass(_interactionModule.OutputBuffer.Last());
@@ -87,21 +88,21 @@ public class Tests
{
"CommandId": 4
}
""");
"""u8.ToArray());
var response =
JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
?.Result.ToString()
);
_interactionModule.PassCommand(132,
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId }));
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId })));
var firstFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
.GetInt32();
_interactionModule.PassCommand(132,
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 4, ObjectId = response.ContextId }));
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 4, ObjectId = response.ContextId })));
response =
JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
@@ -109,10 +110,10 @@ public class Tests
?.Result.ToString()
);
_interactionModule.PassCommand(132,
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId }));
_interactionModule.PassCommand(132,
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId }));
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId })));
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(new JsonCallRequest { CommandId = 2, ObjectId = response.ContextId })));
var secondFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
.GetInt32();
@@ -127,14 +128,14 @@ public class Tests
{
"CommandId": 6
}
""");
"""u8.ToArray());
var response =
JsonSerializer.Deserialize<TransmittedSharedObject<ITestParameter>>(
JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
?.Result.ToString()
);
var x = response.ContextId;
_interactionModule.PassCommand(132,
_interactionModule.PassCommand(132,Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(new JsonCallRequest
{
CommandId = 5,
@@ -143,7 +144,7 @@ public class Tests
A = 10,
LinkedObject = new TransmittedSharedObject<ITestParameter> { ContextId = x }
}
}));
})));
var finalResponse = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result").GetInt32();
+6 -1
View File
@@ -2,6 +2,11 @@ namespace mROA;
public interface IInteractionModule
{
void SetMessageHandler(Action<int, string> handler);
void SetMessageHandler(Action<int, byte[]> handler);
void SendTo(int clientId, byte[] message);
public interface IFrontendInteractionModule
{
public byte[] ReceiveMessage();
public void PostMessage(byte[] message);
}
}
+2 -3
View File
@@ -4,13 +4,12 @@ namespace mROA;
public interface ISerialisationModule
{
void HandleIncomingRequest(int clientId, string command);
void HandleIncomingRequest(int clientId, byte[] command);
void PostResponse(ICommandExecution call);
void SetExecuteModule(IExecuteModule executeModule);
public interface IFrontendSerialisationModule
{
void HandlePostedResponse(string response);
ICommandExecution GetNextCommandExecution(Guid requestId);
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 void HandlePostedResponse(string response)
public ICommandExecution GetNextCommandExecution(Guid requestId)
{
return null;
}
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 HandleIncomingRequest(int clientId, string command)
public void HandleIncomingRequest(int clientId, byte[] command)
{
JsonCallRequest request = JsonSerializer.Deserialize<JsonCallRequest>(command);
request.ClientId = clientId;
@@ -2,7 +2,7 @@
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 void PassCommand(int clientId, string message) => _handler(clientId, message);
private Action<int, string> _handler;
public void PassCommand(int clientId, byte[] message) => _handler(clientId, message);
private Action<int, byte[]> _handler;
public List<string> OutputBuffer = new List<string>();
public void SetMessageHandler(Action<int, string> handler)
public void SetMessageHandler(Action<int, byte[]> handler)
{
_handler = handler;
}