Execution module solved

This commit is contained in:
2025-05-04 20:14:46 +03:00
parent 8f97e5b0a6
commit 149ea07569
11 changed files with 23 additions and 557 deletions
@@ -28,7 +28,7 @@ namespace mROA.Implementation.Backend
}
public ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository,
IRepresentationModule representationModule)
IRepresentationModule representationModule, IEndPointContext endPointContext)
{
#if TRACE
Console.WriteLine(command.GetType().Name);
@@ -58,7 +58,7 @@ namespace mROA.Implementation.Backend
object?[]? castedParams = null;
if (invoker.ParameterTypes.Length != 0)
castedParams = CastedParams(command, invoker);
castedParams = CastedParams(command, invoker, endPointContext);
var execContext = new RequestContext(command.Id, representationModule.Id);
@@ -68,10 +68,10 @@ namespace mROA.Implementation.Backend
case AsyncMethodInvoker { IsVoid: false } asyncNonVoidMethodInvoker:
return TypedExecuteAsync(asyncNonVoidMethodInvoker, context, castedParams, command,
_cancellationRepo!,
representationModule, execContext);
representationModule, execContext, endPointContext);
case AsyncMethodInvoker asyncMethodInvoker:
return ExecuteAsync(asyncMethodInvoker, context, castedParams, command, _cancellationRepo!,
representationModule, execContext);
representationModule, execContext, endPointContext);
default:
var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext);
if (command.CommandId == -1)
@@ -104,12 +104,12 @@ namespace mROA.Implementation.Backend
return context;
}
private object?[] CastedParams(ICallRequest command, IMethodInvoker invoker)
private object?[] CastedParams(ICallRequest command, IMethodInvoker invoker, IEndPointContext context)
{
object?[] castedParams = new object[invoker.ParameterTypes.Length];
for (var i = 0; i < castedParams.Length; i++)
{
castedParams[i] = _serialization!.Cast(command.Parameters![i], invoker.ParameterTypes[i]);
castedParams[i] = _serialization!.Cast(command.Parameters![i], invoker.ParameterTypes[i], context);
}
return castedParams;
@@ -184,7 +184,7 @@ namespace mROA.Implementation.Backend
private ICommandExecution ExecuteAsync(AsyncMethodInvoker invoker, object instance, object?[]? parameters,
ICallRequest command, ICancellationRepository cancellationRepository,
IRepresentationModule representationModule, RequestContext executionContext)
IRepresentationModule representationModule, RequestContext executionContext, IEndPointContext context)
{
var tokenSource = new CancellationTokenSource();
cancellationRepository.RegisterCancellation(command.Id, tokenSource);
@@ -211,7 +211,7 @@ namespace mROA.Implementation.Backend
multiClientOwnershipRepository?.RegisterOwnership(representationModule.Id);
if (invoker.IsTrusted)
representationModule.PostCallMessage(command.Id, EMessageType.FinishedCommandExecution,
payload);
payload, context);
multiClientOwnershipRepository?.FreeOwnership();
});
@@ -237,7 +237,7 @@ namespace mROA.Implementation.Backend
private ICommandExecution TypedExecuteAsync(AsyncMethodInvoker invoker, object instance, object?[]? parameters,
ICallRequest command, ICancellationRepository cancellationRepository,
IRepresentationModule representationModule, RequestContext executionContext)
IRepresentationModule representationModule, RequestContext executionContext, IEndPointContext context)
{
var tokenSource = new CancellationTokenSource();
cancellationRepository.RegisterCancellation(command.Id, tokenSource);
@@ -259,7 +259,7 @@ namespace mROA.Implementation.Backend
TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository;
multiClientOwnershipRepository?.RegisterOwnership(representationModule.Id);
representationModule.PostCallMessage(command.Id, EMessageType.FinishedCommandExecution,
payload);
payload, context);
multiClientOwnershipRepository?.FreeOwnership();
});
+6 -3
View File
@@ -17,7 +17,7 @@ namespace mROA.Implementation.Backend
private Dictionary<IPEndPoint, int> _reservedPorts = new();
private CancellationTokenSource _tokenSource = new();
private IContextualSerializationToolKit _serializationToolkit;
private IEndPointContext _context;
public UdpGateway(IPEndPoint listeningEndpoint)
{
_client = new UdpClient(listeningEndpoint);
@@ -34,6 +34,9 @@ namespace mROA.Implementation.Backend
case IContextualSerializationToolKit serializationToolkit:
_serializationToolkit = serializationToolkit;
break;
case IEndPointContext context:
_context = context;
break;
}
}
@@ -51,7 +54,7 @@ namespace mROA.Implementation.Backend
while (token.IsCancellationRequested == false)
{
var incoming = await _client.ReceiveAsync();
var parsed = _serializationToolkit.Deserialize<NetworkMessageHeader>(incoming.Buffer);
var parsed = _serializationToolkit.Deserialize<NetworkMessageHeader>(incoming.Buffer, _context);
try
{
int channelId;
@@ -87,7 +90,7 @@ namespace mROA.Implementation.Backend
or EventRequest))
continue;
var parsed = _serializationToolkit.Serialize(post);
var parsed = _serializationToolkit.Serialize(post, _context);
await _client.SendAsync(parsed, parsed.Length, endpoint);
}
}
@@ -1,5 +1,7 @@
using System;
#if TRACE
using System.Diagnostics;
#endif
using System.Threading;
using System.Threading.Tasks;
using mROA.Abstract;
@@ -18,6 +20,7 @@ namespace mROA.Implementation.Frontend
private IRepresentationModule? _representationModule;
private IContextualSerializationToolKit? _serializationToolkit;
private IEndPointContext _context;
public void Inject<T>(T dependency)
{
switch (dependency)
@@ -70,7 +73,8 @@ namespace mROA.Implementation.Frontend
var query = _representationModule!.GetStream(m =>
m.MessageType is EMessageType.CallRequest or EMessageType.CancelRequest
or EMessageType.EventRequest or EMessageType.ClientDisconnect, _context, streamTokenSource.Token,
or EMessageType.EventRequest or EMessageType.ClientDisconnect, _context,
streamTokenSource.Token,
m => m.MessageType == EMessageType.CallRequest ? typeof(DefaultCallRequest) : null,
m => m.MessageType == EMessageType.CancelRequest ? typeof(CancelRequest) : null,
m => m.MessageType == EMessageType.EventRequest ? typeof(DefaultCallRequest) : null,
@@ -11,7 +11,7 @@ namespace mROA.Implementation.Frontend
{
private IContextualSerializationToolKit _serializationToolkit;
private IChannelInteractionModule _channelInteractionModule;
private CancellationTokenSource _tokenSource = new CancellationTokenSource();
private CancellationTokenSource _tokenSource = new();
public void Dispose()
{