Just events not works
This commit is contained in:
@@ -55,10 +55,7 @@ namespace mROA.Implementation.Backend
|
||||
private IRequestExtractor CreateExtractor(IRepresentationModule interaction)
|
||||
{
|
||||
var extractor = new RequestExtractor();
|
||||
var context = new EndPointContext
|
||||
{
|
||||
HostId = 0, OwnerId = -interaction.Id
|
||||
};
|
||||
var context = interaction.Context;
|
||||
extractor.Inject(interaction);
|
||||
if (_contextRepository is IContextRepositoryHub contextHub)
|
||||
context.RealRepository = contextHub.GetRepository(interaction.Id);
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace mROA.Implementation.Backend
|
||||
private IConnectionHub? _hub;
|
||||
private IContextualSerializationToolKit? _serialization;
|
||||
private Dictionary<int, CancellationTokenSource> _extractorsCTS = new();
|
||||
private ICallIndexProvider _callIndexProvider;
|
||||
|
||||
public NetworkGatewayModule(IPEndPoint endpoint, Type interactionModuleType,
|
||||
IInjectableModule[] injectableModules)
|
||||
@@ -49,6 +50,9 @@ namespace mROA.Implementation.Backend
|
||||
case IContextualSerializationToolKit serializationToolkit:
|
||||
_serialization = serializationToolkit;
|
||||
break;
|
||||
case ICallIndexProvider callIndexProvider:
|
||||
_callIndexProvider = callIndexProvider;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +74,7 @@ namespace mROA.Implementation.Backend
|
||||
|
||||
//TODO сделать контекст
|
||||
var context = new EndPointContext();
|
||||
|
||||
context.CallIndexProvider = _callIndexProvider;
|
||||
var streamExtractor =
|
||||
new ChannelInteractionModule.StreamExtractor(client.GetStream(), _serialization, context);
|
||||
interaction.IsConnected = () => streamExtractor.IsConnected;
|
||||
@@ -87,6 +91,7 @@ namespace mROA.Implementation.Backend
|
||||
case EMessageType.ClientConnect:
|
||||
context.HostId = 0;
|
||||
context.OwnerId = -interaction.ConnectionId;
|
||||
interaction.Inject(context);
|
||||
Task.Run(async () => await streamExtractor.LoopedReceive(cts.Token));
|
||||
_ = streamExtractor.SendFromChannel(interaction.TrustedPostChanel, cts.Token);
|
||||
interaction.PostMessageAsync(new NetworkMessageHeader(_serialization!,
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace mROA.Implementation
|
||||
|
||||
public int ConnectionId { get; set; }
|
||||
|
||||
public IEndPointContext Context => _context;
|
||||
public Channel<NetworkMessageHeader> ReceiveChanel { get; }
|
||||
|
||||
public ChannelReader<NetworkMessageHeader> TrustedPostChanel => _outputTrustedChannel.Reader;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation
|
||||
{
|
||||
public class CollectableMethodRepository : IMethodRepository
|
||||
{
|
||||
private List<IMethodInvoker> _methods = new();
|
||||
public void Inject<T>(T dependency)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void AppendInvokers(IEnumerable<IMethodInvoker> methodInvokers)
|
||||
{
|
||||
_methods.AddRange(methodInvokers);
|
||||
}
|
||||
|
||||
public IMethodInvoker GetMethod(int id)
|
||||
{
|
||||
if (id == -1)
|
||||
return MethodInvoker.Dispose;
|
||||
|
||||
if (_methods.Count <= id)
|
||||
return null;
|
||||
|
||||
return _methods[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ namespace mROA.Implementation
|
||||
{
|
||||
public class EndPointContext : IEndPointContext
|
||||
{
|
||||
public IInstanceRepository RealRepository { get; set; }
|
||||
public IInstanceRepository RealRepository { get; set; }
|
||||
public IInstanceRepository RemoteRepository { get; set; }
|
||||
public ICallIndexProvider CallIndexProvider { get; }
|
||||
public ICallIndexProvider CallIndexProvider { get; set; }
|
||||
public CallIndexConfig CallIndexConfig { get; set; }
|
||||
public int HostId { get; set; }
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace mROA.Implementation.Frontend
|
||||
throw new NullReferenceException("Serialization toolkit is not initialized");
|
||||
|
||||
_tcpClient.Connect(_serverEndPoint);
|
||||
|
||||
_tcpClient.NoDelay = true;
|
||||
PrepareExtractor();
|
||||
_interactionModule.IsConnected = () => _currentExtractor.IsConnected;
|
||||
_interactionModule.OnDisconnected += _ => { Reconnect(); };
|
||||
|
||||
@@ -8,9 +8,7 @@ namespace mROA.Implementation
|
||||
public class RemoteInstanceRepository : IInstanceRepository
|
||||
{
|
||||
private List<RemoteObjectBase> _producedProxys = new();
|
||||
|
||||
public static Dictionary<Type, Func<int, IRepresentationModule, IEndPointContext, RemoteObjectBase>>
|
||||
RemoteTypeFactories = new();
|
||||
private ICallIndexProvider _callIndexProvider;
|
||||
|
||||
private IRepresentationModuleProducer? _representationProducer;
|
||||
|
||||
@@ -34,11 +32,11 @@ namespace mROA.Implementation
|
||||
if (_representationProducer == null)
|
||||
throw new NullReferenceException("representation producer is not initialized");
|
||||
|
||||
if (!RemoteTypeFactories.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
|
||||
if (!_callIndexProvider.Activators.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
|
||||
var representationModule =
|
||||
_representationProducer.Produce(context.OwnerId);
|
||||
var remote = remoteType(id.ContextId,
|
||||
representationModule, context);
|
||||
representationModule, context, _callIndexProvider.GetIndices(typeof(T)));
|
||||
|
||||
_producedProxys.Add(remote!);
|
||||
|
||||
@@ -58,7 +56,7 @@ namespace mROA.Implementation
|
||||
var representationModule =
|
||||
_representationProducer.Produce(context.OwnerId);
|
||||
|
||||
var instance = RemoteTypeFactories[type](-1, representationModule, context)!;
|
||||
var instance = _callIndexProvider.Activators[type](-1, representationModule, context, _callIndexProvider.GetIndices(type))!;
|
||||
|
||||
var remoteObjectBase = instance;
|
||||
|
||||
@@ -79,8 +77,15 @@ namespace mROA.Implementation
|
||||
|
||||
public void Inject<T>(T dependency)
|
||||
{
|
||||
if (dependency is IRepresentationModuleProducer serialisationModule)
|
||||
_representationProducer = serialisationModule;
|
||||
switch (dependency)
|
||||
{
|
||||
case IRepresentationModuleProducer serialisationModule:
|
||||
_representationProducer = serialisationModule;
|
||||
break;
|
||||
case ICallIndexProvider callIndexProvider:
|
||||
_callIndexProvider = callIndexProvider;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,12 +32,13 @@ namespace mROA.Implementation
|
||||
|
||||
private readonly ComplexObjectIdentifier _identifier;
|
||||
private readonly IRepresentationModule _representationModule;
|
||||
|
||||
protected RemoteObjectBase(int id, IRepresentationModule representationModule, IEndPointContext context)
|
||||
protected readonly int[] _callIndices;
|
||||
protected RemoteObjectBase(int id, IRepresentationModule representationModule, IEndPointContext context, int[] indices)
|
||||
{
|
||||
_identifier = new ComplexObjectIdentifier { ContextId = id, OwnerId = representationModule.Id };
|
||||
_representationModule = representationModule;
|
||||
_context = context;
|
||||
_callIndices = indices;
|
||||
}
|
||||
|
||||
public int Id => _identifier.ContextId;
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace mROA.Implementation
|
||||
public int Id => (_interaction ?? throw new NullReferenceException("Interaction is not initialized"))
|
||||
.ConnectionId;
|
||||
|
||||
public IEndPointContext Context => _interaction.Context;
|
||||
|
||||
public async Task<(object? Deserialized, EMessageType MessageType)> GetSingle(
|
||||
Predicate<NetworkMessageHeader> rule, IEndPointContext? context,
|
||||
CancellationToken token = default, params Func<NetworkMessageHeader, Type?>[] converter)
|
||||
|
||||
Reference in New Issue
Block a user