Prefinal local endpoint context override
This commit is contained in:
@@ -49,7 +49,7 @@ namespace mROA.Implementation.Backend
|
||||
if (invoker == null)
|
||||
throw new Exception($"Command {command.CommandId} not found");
|
||||
|
||||
var context = GetContext(command, contextRepository, invoker);
|
||||
var context = GetContext(command, contextRepository, invoker, endPointContext);
|
||||
|
||||
if (context == null)
|
||||
throw new NullReferenceException("Instance can't be null");
|
||||
@@ -96,10 +96,10 @@ namespace mROA.Implementation.Backend
|
||||
}
|
||||
|
||||
private static object GetContext(ICallRequest command, IContextRepository contextRepository,
|
||||
IMethodInvoker invoker)
|
||||
IMethodInvoker invoker, IEndPointContext endPointContext)
|
||||
{
|
||||
var context = command.ObjectId.ContextId != -1
|
||||
? contextRepository.GetObject<object>(command.ObjectId)
|
||||
? contextRepository.GetObject<object>(command.ObjectId, endPointContext)
|
||||
: contextRepository.GetSingleObject(invoker.SuitableType, command.ObjectId.OwnerId);
|
||||
return context;
|
||||
}
|
||||
@@ -152,8 +152,8 @@ namespace mROA.Implementation.Backend
|
||||
{
|
||||
return new AsyncCommandExecution();
|
||||
}
|
||||
|
||||
if (invoker.IsVoid )
|
||||
|
||||
if (invoker.IsVoid)
|
||||
{
|
||||
return new FinalCommandExecution
|
||||
{
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace mROA.Implementation.Backend
|
||||
_storage.Free(id.ContextId);
|
||||
}
|
||||
|
||||
public T GetObject<T>(ComplexObjectIdentifier id)
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
|
||||
{
|
||||
var value = _storage.GetValue(id.ContextId);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using mROA.Abstract;
|
||||
using mROA.Implementation.Frontend;
|
||||
|
||||
namespace mROA.Implementation.Backend
|
||||
{
|
||||
@@ -12,12 +12,6 @@ namespace mROA.Implementation.Backend
|
||||
private IMethodRepository? _methodRepository;
|
||||
private IContextualSerializationToolKit? _serializationToolkit;
|
||||
private IExecuteModule? _executeModule;
|
||||
private readonly Type _extractorType;
|
||||
|
||||
public HubRequestExtractor(Type extractorType)
|
||||
{
|
||||
_extractorType = extractorType;
|
||||
}
|
||||
|
||||
public void Inject<T>(T dependency)
|
||||
{
|
||||
@@ -49,7 +43,7 @@ namespace mROA.Implementation.Backend
|
||||
private void HubOnOnConnected(IRepresentationModule interaction)
|
||||
{
|
||||
var extractor = CreateExtractor(interaction);
|
||||
extractor.StartExtraction().ContinueWith(t => OnDisconnected(interaction));
|
||||
extractor.StartExtraction().ContinueWith(_ => OnDisconnected(interaction));
|
||||
}
|
||||
|
||||
private void OnDisconnected(IRepresentationModule representationModule)
|
||||
@@ -60,16 +54,22 @@ namespace mROA.Implementation.Backend
|
||||
|
||||
private IRequestExtractor CreateExtractor(IRepresentationModule interaction)
|
||||
{
|
||||
var extractor = (IRequestExtractor)Activator.CreateInstance(_extractorType)!;
|
||||
var extractor = new RequestExtractor();
|
||||
var context = new EndPointContext
|
||||
{
|
||||
HostId = 0, OwnerId = interaction.Id
|
||||
};
|
||||
extractor.Inject(interaction);
|
||||
|
||||
if (_contextRepository is IContextRepositoryHub contextHub)
|
||||
extractor.Inject(contextHub.GetRepository(interaction.Id));
|
||||
context.RealRepository = contextHub.GetRepository(interaction.Id);
|
||||
else
|
||||
extractor.Inject(interaction);
|
||||
context.RealRepository = _contextRepository!;
|
||||
|
||||
context.RemoteRepository = _remoteContextRepository!;
|
||||
extractor.Inject(_methodRepository);
|
||||
extractor.Inject(_serializationToolkit);
|
||||
extractor.Inject(_executeModule);
|
||||
extractor.Inject(_remoteContextRepository);
|
||||
return extractor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ namespace mROA.Implementation.Backend
|
||||
repository.ClearObject(id);
|
||||
}
|
||||
|
||||
public T GetObject<T>(ComplexObjectIdentifier id)
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
|
||||
{
|
||||
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
||||
return repository.GetObject<T>(id);
|
||||
return repository.GetObject<T>(id, context);
|
||||
}
|
||||
|
||||
public object GetSingleObject(Type type, int ownerId)
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace mROA.Implementation
|
||||
_storages.Find(i => i.Key == id.OwnerId).Value.Free(id.ContextId);
|
||||
}
|
||||
|
||||
public T GetObject<T>(ComplexObjectIdentifier id)
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace mROA.Implementation
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public T GetObject<T>(ComplexObjectIdentifier id)
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
|
||||
{
|
||||
var index = _producedRemoteEndpoints.Find(i => i.Identifier.Equals(id));
|
||||
if (index is not null)
|
||||
@@ -35,7 +35,7 @@ namespace mROA.Implementation
|
||||
var representationModule =
|
||||
_representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
||||
var remote = (T)Activator.CreateInstance(remoteType, id.ContextId,
|
||||
representationModule)!;
|
||||
representationModule, context)!;
|
||||
|
||||
_producedRemoteEndpoints.Add((remote as RemoteObjectBase)!);
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace mROA.Implementation
|
||||
set
|
||||
{
|
||||
_identifier = value;
|
||||
Value = GetDefaultContextRepository().GetObject<T>(Identifier);
|
||||
Value = GetDefaultContextRepository().GetObject<T>(Identifier, EndPointContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user