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