фикс номер 1: кажется дело было в выполненности таска приема
This commit is contained in:
@@ -48,7 +48,7 @@ public class BasicExecutionModule : IExecuteModule
|
||||
return new TypedFinalCommandExecution
|
||||
{
|
||||
CommandId = command.CommandId, Result = finalResult,
|
||||
Id = command.CallRequestId,
|
||||
Id = command.Id,
|
||||
Type = currentCommand.ReturnType
|
||||
};
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class BasicExecutionModule : IExecuteModule
|
||||
{
|
||||
return new ExceptionCommandExecution
|
||||
{
|
||||
Id = command.CallRequestId, CommandId = command.CommandId,
|
||||
Id = command.Id, CommandId = command.CommandId,
|
||||
Exception = e.ToString()
|
||||
};
|
||||
}
|
||||
@@ -75,13 +75,13 @@ public class BasicExecutionModule : IExecuteModule
|
||||
result.Wait(token);
|
||||
|
||||
|
||||
return new FinalCommandExecution { CommandId = command.CommandId, Id = command.CallRequestId };
|
||||
return new FinalCommandExecution { CommandId = command.CommandId, Id = command.Id };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ExceptionCommandExecution
|
||||
{
|
||||
Id = command.CallRequestId, CommandId = command.CommandId,
|
||||
Id = command.Id, CommandId = command.CommandId,
|
||||
Exception = e.ToString()
|
||||
};
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class BasicExecutionModule : IExecuteModule
|
||||
var finalResult = result.GetType().GetProperty("Result")?.GetValue(result);
|
||||
return new TypedFinalCommandExecution
|
||||
{
|
||||
Id = command.CallRequestId,
|
||||
Id = command.Id,
|
||||
Result = finalResult,
|
||||
CommandId = command.CommandId,
|
||||
Type = finalResult?.GetType()
|
||||
@@ -112,7 +112,7 @@ public class BasicExecutionModule : IExecuteModule
|
||||
{
|
||||
return new ExceptionCommandExecution
|
||||
{
|
||||
Id = command.CallRequestId, CommandId = command.CommandId,
|
||||
Id = command.Id, CommandId = command.CommandId,
|
||||
Exception = e.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace mROA.Implementation;
|
||||
|
||||
public interface ICallRequest
|
||||
{
|
||||
Guid CallRequestId { get; }
|
||||
Guid Id { get; }
|
||||
int CommandId { get; }
|
||||
int ObjectId { get; }
|
||||
object? Parameter { get; }
|
||||
@@ -12,7 +12,7 @@ public interface ICallRequest
|
||||
|
||||
public class DefaultCallRequest : ICallRequest
|
||||
{
|
||||
public Guid CallRequestId { get; set; } = Guid.NewGuid();
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public int CommandId { get; init; }
|
||||
public int ObjectId { get; init; } = -1;
|
||||
|
||||
|
||||
@@ -61,6 +61,8 @@ public class RequestExtractor : IRequestExtractor
|
||||
var request =
|
||||
_representationModule!.GetMessage<DefaultCallRequest>(messageType: MessageType.CallRequest);
|
||||
|
||||
Console.WriteLine("Executing {0}", request.Id);
|
||||
|
||||
if (request.Parameter is not null)
|
||||
{
|
||||
var parameterType = _methodRepository!.GetMethod(request.CommandId).GetParameters().First()
|
||||
@@ -75,7 +77,7 @@ public class RequestExtractor : IRequestExtractor
|
||||
? MessageType.FinishedCommandExecution
|
||||
: MessageType.ExceptionCommandExecution;
|
||||
|
||||
_representationModule.PostCallMessage(request.CallRequestId, resultType, result, result.GetType());
|
||||
_representationModule.PostCallMessage(request.Id, resultType, result, result.GetType());
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation;
|
||||
@@ -6,6 +7,7 @@ namespace mROA.Implementation;
|
||||
public class NetworkMessage
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public MessageType SchemaId { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation;
|
||||
@@ -11,7 +13,9 @@ public class NextGenerationInteractionModule : INextGenerationInteractionModule
|
||||
private Task<NetworkMessage>? _currentReceiving;
|
||||
private const int BufferSize = ushort.MaxValue;
|
||||
private readonly byte[] _buffer = new byte[BufferSize];
|
||||
private List<NetworkMessage> _messageBuffer = [];
|
||||
|
||||
|
||||
public void Inject<T>(T dependency)
|
||||
{
|
||||
switch (dependency)
|
||||
@@ -28,10 +32,11 @@ public class NextGenerationInteractionModule : INextGenerationInteractionModule
|
||||
|
||||
public Task<NetworkMessage> GetNextMessageReceiving()
|
||||
{
|
||||
if (_currentReceiving is { IsCompleted: false })
|
||||
Console.WriteLine(_currentReceiving?.Status);
|
||||
if (_currentReceiving is { Status: TaskStatus.Running })
|
||||
return _currentReceiving;
|
||||
|
||||
_currentReceiving = GetNextMessage();
|
||||
_currentReceiving = Task.Run(GetNextMessage);
|
||||
return _currentReceiving;
|
||||
}
|
||||
|
||||
@@ -40,12 +45,15 @@ public class NextGenerationInteractionModule : INextGenerationInteractionModule
|
||||
if (BaseStream == null)
|
||||
throw new NullReferenceException("BaseStream is null");
|
||||
|
||||
Console.WriteLine("Sending {0}", JsonSerializer.Serialize(message));
|
||||
|
||||
|
||||
var rawMessage = _serialization.Serialize(message);
|
||||
await BaseStream.WriteAsync(BitConverter.GetBytes((ushort)rawMessage.Length).AsMemory(0, sizeof(ushort)));
|
||||
await BaseStream.WriteAsync(rawMessage);
|
||||
}
|
||||
|
||||
private async Task<NetworkMessage> GetNextMessage()
|
||||
private NetworkMessage GetNextMessage()
|
||||
{
|
||||
if (BaseStream == null)
|
||||
throw new NullReferenceException("BaseStream is null");
|
||||
@@ -53,10 +61,17 @@ public class NextGenerationInteractionModule : INextGenerationInteractionModule
|
||||
if (_serialization == null)
|
||||
throw new NullReferenceException("Serialization toolkit is null");
|
||||
|
||||
await BaseStream.ReadExactlyAsync(_buffer, 0, 2);
|
||||
|
||||
Console.WriteLine("Receiving message");
|
||||
BaseStream.ReadExactly(_buffer, 0, 2);
|
||||
var len = BitConverter.ToUInt16(_buffer, 0);
|
||||
await BaseStream.ReadExactlyAsync(_buffer, 0, len);
|
||||
BaseStream.ReadExactly(_buffer, 0, len);
|
||||
|
||||
Console.WriteLine("Receiving {0}", Encoding.Default.GetString(_buffer[..len]));
|
||||
|
||||
return _serialization.Deserialize<NetworkMessage>(_buffer[..len])!;
|
||||
var message = JsonSerializer.Deserialize<NetworkMessage>(Encoding.Default.GetString(_buffer[..len]));
|
||||
_messageBuffer.Add(message!);
|
||||
|
||||
return message!;
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,14 @@ public abstract class RemoteObjectBase
|
||||
{
|
||||
var request = new DefaultCallRequest
|
||||
{ CommandId = methodId, ObjectId = _id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
||||
await _representationModule.PostCallMessageAsync(request.CallRequestId, MessageType.CallRequest, request);
|
||||
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||
|
||||
var successResponse =
|
||||
_representationModule.GetMessageAsync<FinalCommandExecution<T>>(
|
||||
messageType: MessageType.FinishedCommandExecution, requestId: request.CallRequestId);
|
||||
messageType: MessageType.FinishedCommandExecution, requestId: request.Id);
|
||||
var errorResponse =
|
||||
_representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
||||
messageType: MessageType.ExceptionCommandExecution, requestId: request.CallRequestId);
|
||||
messageType: MessageType.ExceptionCommandExecution, requestId: request.Id);
|
||||
Task.WaitAny(successResponse, errorResponse);
|
||||
|
||||
if (successResponse.IsCompletedSuccessfully)
|
||||
@@ -40,14 +40,14 @@ public abstract class RemoteObjectBase
|
||||
{
|
||||
var request = new DefaultCallRequest
|
||||
{ CommandId = methodId, ObjectId = _id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
||||
await _representationModule.PostCallMessageAsync(request.CallRequestId, MessageType.CallRequest, request);
|
||||
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||
|
||||
var successResponse =
|
||||
_representationModule.GetMessageAsync<FinalCommandExecution>(
|
||||
messageType: MessageType.FinishedCommandExecution, requestId: request.CallRequestId);
|
||||
messageType: MessageType.FinishedCommandExecution, requestId: request.Id);
|
||||
var errorResponse =
|
||||
_representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
||||
messageType: MessageType.ExceptionCommandExecution, requestId: request.CallRequestId);
|
||||
messageType: MessageType.ExceptionCommandExecution, requestId: request.Id);
|
||||
|
||||
Task.WaitAny(successResponse, errorResponse);
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ public class RepresentationModule : IRepresentationModule
|
||||
while (true)
|
||||
{
|
||||
var message = await _interaction.GetNextMessageReceiving();
|
||||
Console.WriteLine("Message received {0}", JsonSerializer.Serialize(message));
|
||||
if ((requestId is null || message.Id == requestId) &&
|
||||
(messageType is null || message.SchemaId == messageType))
|
||||
return message.Data;
|
||||
|
||||
Reference in New Issue
Block a user