предфинальное изменение сигнатуры интерфейса модуля исполнения

This commit is contained in:
2025-02-14 22:26:55 +03:00
parent 8c601c0183
commit 809cc05b0a
9 changed files with 69 additions and 61 deletions
+1 -1
View File
@@ -4,5 +4,5 @@ namespace mROA.Abstract;
public interface IExecuteModule : IInjectableModule
{
ICommandExecution Execute(ICallRequest command);
ICommandExecution Execute(ICallRequest command, IContextRepository executionContextRepository);
}
@@ -6,22 +6,13 @@ namespace mROA.Implementation.Backend;
public class BasicExecutionModule : IExecuteModule
{
private IMethodRepository? _methodRepo;
private IContextRepository? _contextRepo;
public void Inject<T>(T dependency)
{
switch (dependency)
{
case IMethodRepository methodRepo:
_methodRepo = methodRepo;
break;
case IContextRepository contextRepo:
_contextRepo = contextRepo;
break;
}
if (dependency is IMethodRepository methodRepo) _methodRepo = methodRepo;
}
public ICommandExecution Execute(ICallRequest command)
public ICommandExecution Execute(ICallRequest command, IContextRepository _contextRepo)
{
if (_methodRepo is null)
throw new NullReferenceException("Method repository was not defined");
@@ -8,6 +8,7 @@ public class JsonSerialisationModule : ISerialisationModule
private IInteractionModule? _dataSource;
private IExecuteModule? _executeModule;
private IMethodRepository? _methodRepository;
private IContextRepository? _contextRepo;
public void HandleIncomingRequest(int clientId, byte[] message)
{
@@ -21,10 +22,11 @@ public class JsonSerialisationModule : ISerialisationModule
if (command.Parameter is not null)
{
var parameter = _methodRepository!.GetMethod(command.CommandId).GetParameters().First().ParameterType;
command.Parameter = ((JsonElement)command.Parameter).Deserialize(parameter);
var jsElement = (JsonElement)command.Parameter;
command.Parameter = jsElement.Deserialize(parameter);
}
var response = _executeModule!.Execute(command);
var response = _executeModule!.Execute(command, _contextRepo);
response.ClientId = clientId;
var resultType = response is FinalCommandExecution
? MessageType.FinishedCommandExecution
@@ -52,11 +54,20 @@ public class JsonSerialisationModule : ISerialisationModule
public void Inject<T>(T dependency)
{
if (dependency is IInteractionModule interactionModule)
_dataSource = interactionModule;
if (dependency is IExecuteModule executeModule)
_executeModule = executeModule;
if (dependency is IMethodRepository methodRepository)
_methodRepository = methodRepository;
switch (dependency)
{
case IInteractionModule interactionModule:
_dataSource = interactionModule;
break;
case IExecuteModule executeModule:
_executeModule = executeModule;
break;
case IMethodRepository methodRepository:
_methodRepository = methodRepository;
break;
case IContextRepository contextRepository:
_contextRepo = contextRepository;
break;
}
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ public static class TransmissionConfig
public class SharedObject<T> where T : notnull
{
private IContextRepository GetDefaultContextRepository() =>
(OwnerId == TransmissionConfig.OwnershipRepository!.GetOwnershipId()
(OwnerId == TransmissionConfig.OwnershipRepository!.GetHostOwnershipId()
? TransmissionConfig.RealContextRepository
: TransmissionConfig.RemoteEndpointContextRepository) ??
throw new NullReferenceException(