Code cleanup
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using mROA.Abstract;
|
||||
using mROA.Implementation;
|
||||
using mROA.Implementation.Attributes;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using mROA.Abstract;
|
||||
using mROA.Implementation;
|
||||
using mROA.Implementation.Attributes;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using mROA.Abstract;
|
||||
using mROA.Implementation;
|
||||
using mROA.Implementation.Attributes;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace <!L namespace>
|
||||
<!D>
|
||||
};
|
||||
|
||||
public void Inject(T dependency)
|
||||
public void Inject(object dependency)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace mROA.Codegen
|
||||
private TemplateDocument _interfaceTemplateOriginal;
|
||||
private TemplateDocument _methodInvokerOriginal;
|
||||
private TemplateDocument _methodRepoTemplate;
|
||||
private int _currentInternalCallIndex = 0;
|
||||
private int _currentInternalCallIndex;
|
||||
|
||||
|
||||
private void GenerateCode(SourceProductionContext context, Compilation compilation,
|
||||
@@ -274,7 +274,7 @@ namespace mROA.Codegen
|
||||
|
||||
if (isUntrusted)
|
||||
{
|
||||
caller = $"CallUntrustedAsync(_callIndices[{_currentInternalCallIndex++}]{parameterLink})";
|
||||
caller = $"CallUntrustedAsync(CallIndices[{_currentInternalCallIndex++}]{parameterLink})";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -285,10 +285,10 @@ namespace mROA.Codegen
|
||||
: string.Empty;
|
||||
|
||||
caller = isVoid
|
||||
? $"CallAsync(_callIndices[{_currentInternalCallIndex++}]{parameterLink}{tokenInsert})"
|
||||
? $"CallAsync(CallIndices[{_currentInternalCallIndex++}]{parameterLink}{tokenInsert})"
|
||||
: isAsync
|
||||
? $"GetResultAsync<{ExtractTaskType(method.ReturnType)}>(_callIndices[{_currentInternalCallIndex++}]{parameterLink}{tokenInsert})"
|
||||
: $"GetResultAsync<{ToFullString(method.ReturnType)}>(_callIndices[{_currentInternalCallIndex++}]{parameterLink}{tokenInsert})";
|
||||
? $"GetResultAsync<{ExtractTaskType(method.ReturnType)}>(CallIndices[{_currentInternalCallIndex++}]{parameterLink}{tokenInsert})"
|
||||
: $"GetResultAsync<{ToFullString(method.ReturnType)}>(CallIndices[{_currentInternalCallIndex++}]{parameterLink}{tokenInsert})";
|
||||
|
||||
if (!isVoid)
|
||||
prefix = "return " + prefix;
|
||||
@@ -501,7 +501,7 @@ namespace mROA.Codegen
|
||||
}
|
||||
|
||||
frontend =
|
||||
$"get => GetResultAsync<{method.ReturnType.ToUnityString()}>(_callIndices[{_currentInternalCallIndex++}]{parametersArray}).GetAwaiter().GetResult();";
|
||||
$"get => GetResultAsync<{method.ReturnType.ToUnityString()}>(CallIndices[{_currentInternalCallIndex++}]{parametersArray}).GetAwaiter().GetResult();";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -547,7 +547,7 @@ namespace mROA.Codegen
|
||||
backend = invokerTemplate.Compile();
|
||||
}
|
||||
|
||||
frontend = $"set => CallAsync(_callIndices[{_currentInternalCallIndex++}], new System.Object[] {{ {parametersArray} }}).Wait();";
|
||||
frontend = $"set => CallAsync(CallIndices[{_currentInternalCallIndex++}], new System.Object[] {{ {parametersArray} }}).Wait();";
|
||||
}
|
||||
|
||||
propsCollection.Add((frontend, method));
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using mROA.Implementation;
|
||||
|
||||
@@ -8,30 +7,12 @@ namespace mROA.Abstract
|
||||
{
|
||||
public interface ICallIndexProvider : IInjectableModule
|
||||
{
|
||||
Dictionary<Type, Func<int, IRepresentationModule, IEndPointContext, int[], RemoteObjectBase>> Activators { get; }
|
||||
Dictionary<Type, Func<int, IRepresentationModule, IEndPointContext, int[], RemoteObjectBase>> Activators
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
void SetupOffset(int offset);
|
||||
int[] GetIndices(Type type);
|
||||
}
|
||||
|
||||
// public class GeneratedInvokersCollection : IReadOnlyList<IMethodInvoker>
|
||||
// {
|
||||
// private readonly List<IMethodInvoker> _invokers = new()
|
||||
// {
|
||||
//
|
||||
// };
|
||||
//
|
||||
// public IEnumerator<IMethodInvoker> GetEnumerator()
|
||||
// {
|
||||
// return _invokers.GetEnumerator();
|
||||
// }
|
||||
//
|
||||
// IEnumerator IEnumerable.GetEnumerator()
|
||||
// {
|
||||
// return GetEnumerator();
|
||||
// }
|
||||
//
|
||||
// public int Count => _invokers.Count;
|
||||
//
|
||||
// public IMethodInvoker this[int index] => _invokers[index];
|
||||
// }
|
||||
}
|
||||
@@ -11,6 +11,6 @@ namespace mROA.Abstract
|
||||
T Deserialize<T>(ReadOnlyMemory<byte> rawMemory, IEndPointContext? context);
|
||||
object? Deserialize(ReadOnlyMemory<byte> rawMemory, Type type, IEndPointContext? context);
|
||||
T Cast<T>(object nonCasted, IEndPointContext? context);
|
||||
object? Cast(object nonCasted, Type type, IEndPointContext? context);
|
||||
object? Cast(object? nonCasted, Type type, IEndPointContext? context);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
using mROA.Implementation;
|
||||
|
||||
namespace mROA.Abstract
|
||||
namespace mROA.Abstract
|
||||
{
|
||||
public interface IEndPointContext : IInjectableModule
|
||||
{
|
||||
IInstanceRepository RealRepository { get; set; }
|
||||
IInstanceRepository RemoteRepository { get; set; }
|
||||
ICallIndexProvider CallIndexProvider { get; set; }
|
||||
IInstanceRepository RemoteRepository { get; set; }
|
||||
ICallIndexProvider CallIndexProvider { get; set; }
|
||||
int HostId { get; set; }
|
||||
int OwnerId { get; set; }
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
public void BindEvents(T source, IEndPointContext context,
|
||||
IRepresentationModuleProducer representationModuleProducer, int index);
|
||||
|
||||
void IEventBinder.BindEvents(object source, IEndPointContext context, IRepresentationModuleProducer representationModuleProducer,
|
||||
void IEventBinder.BindEvents(object source, IEndPointContext context,
|
||||
IRepresentationModuleProducer representationModuleProducer,
|
||||
int index)
|
||||
{
|
||||
BindEvents((T)source, context, representationModuleProducer, index);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace mROA.Abstract
|
||||
int ResisterObject<T>(object o, IEndPointContext context);
|
||||
void ClearObject(ComplexObjectIdentifier id, IEndPointContext context);
|
||||
T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class;
|
||||
T GetSingletonObject<T>(IEndPointContext context) where T : class, IShared;
|
||||
T GetSingletonObject<T>(IEndPointContext context) where T : class, IShared;
|
||||
object GetSingletonObject(Type type, IEndPointContext context);
|
||||
int GetObjectIndex<T>(object o, IEndPointContext context);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace mROA.Abstract
|
||||
{
|
||||
int Id { get; }
|
||||
IEndPointContext Context { get; }
|
||||
|
||||
Task<(object? Deserialized, EMessageType MessageType)> GetSingle(Predicate<NetworkMessageHeader> rule,
|
||||
IEndPointContext? context, CancellationToken token = default,
|
||||
params Func<NetworkMessageHeader, Type?>[] converter);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
namespace mROA.Abstract
|
||||
{
|
||||
// public interface IContextualSerializationToolKit : IInjectableModule
|
||||
// {
|
||||
// byte[] Serialize<T>(T objectToSerialize);
|
||||
// byte[] Serialize(object objectToSerialize, Type type);
|
||||
// T? Deserialize<T>(byte[] rawData);
|
||||
// object? Deserialize(byte[] rawData, Type type);
|
||||
// T? Deserialize<T>(Span<byte> rawData);
|
||||
// object? Deserialize(Span<byte> rawData, Type type);
|
||||
// T? Cast<T>(object? nonCasted);
|
||||
// object? Cast(object? nonCasted, Type type);
|
||||
// }
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace mROA.Implementation
|
||||
namespace mROA.Abstract
|
||||
{
|
||||
#pragma warning disable CS8618, CS9264
|
||||
public interface IShared
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ using System;
|
||||
|
||||
namespace mROA.Implementation.Attributes
|
||||
{
|
||||
public class ApiLevelAttribute : Attribute
|
||||
public class ApiLevelAttribute : Attribute
|
||||
{
|
||||
public int ApiLevel { get; set; }
|
||||
|
||||
public ApiLevelAttribute(int level)
|
||||
{
|
||||
ApiLevel = level;
|
||||
@@ -12,7 +13,6 @@ namespace mROA.Implementation.Attributes
|
||||
|
||||
public ApiLevelAttribute() : this(0)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace mROA.Implementation.Attributes
|
||||
public class UntrustedAttribute : Attribute
|
||||
{
|
||||
public bool UseAwait { get; private set; }
|
||||
|
||||
public UntrustedAttribute(bool useAwait = true)
|
||||
{
|
||||
UseAwait = useAwait;
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace mROA.Implementation.Backend
|
||||
public ICommandExecution Execute(ICallRequest command, IInstanceRepository instanceRepository,
|
||||
IRepresentationModule representationModule, IEndPointContext endPointContext)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ThrowIfNotInjected(instanceRepository);
|
||||
@@ -194,7 +193,7 @@ namespace mROA.Implementation.Backend
|
||||
};
|
||||
_cancellationRepo?.FreeCancelation(command.Id);
|
||||
|
||||
|
||||
|
||||
if (invoker.IsTrusted)
|
||||
representationModule.PostCallMessage(command.Id, EMessageType.FinishedCommandExecution,
|
||||
payload, context);
|
||||
@@ -239,7 +238,7 @@ namespace mROA.Implementation.Backend
|
||||
Result = finalResult
|
||||
};
|
||||
_cancellationRepo!.FreeCancelation(command.Id);
|
||||
|
||||
|
||||
representationModule.PostCallMessage(command.Id, EMessageType.FinishedCommandExecution,
|
||||
payload, context);
|
||||
});
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace mROA.Implementation.Backend
|
||||
|
||||
public IChannelInteractionModule GetInteraction(int id)
|
||||
{
|
||||
return _connections!.GetValueOrDefault(id, null) ?? _connections!.GetValueOrDefault(-id, null) ?? throw new Exception("No connection found");
|
||||
return _connections!.GetValueOrDefault(id, null) ?? _connections!.GetValueOrDefault(-id, null) ??
|
||||
throw new Exception("No connection found");
|
||||
}
|
||||
|
||||
public event ConnectionHandler? OnConnected;
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace mROA.Implementation.Backend
|
||||
if (_contextRepository is IContextRepositoryHub contextHub)
|
||||
contextHub.FreeRepository(representationModule.Id);
|
||||
}
|
||||
|
||||
|
||||
private IRequestExtractor CreateExtractor(IRepresentationModule interaction)
|
||||
{
|
||||
var extractor = new RequestExtractor();
|
||||
@@ -61,9 +61,9 @@ namespace mROA.Implementation.Backend
|
||||
context.RealRepository = contextHub.GetRepository(interaction.Id);
|
||||
else
|
||||
context.RealRepository = _contextRepository!;
|
||||
|
||||
|
||||
context.RemoteRepository = _remoteContextRepository!;
|
||||
|
||||
|
||||
extractor.Inject(context);
|
||||
extractor.Inject(_methodRepository);
|
||||
extractor.Inject(_serializationToolkit);
|
||||
|
||||
@@ -11,15 +11,10 @@ namespace mROA.Implementation.Backend
|
||||
{
|
||||
public static object[] EventBinders = { };
|
||||
|
||||
private static int LastDebugId = -1;
|
||||
private int _debugId = -1;
|
||||
|
||||
private IRepresentationModuleProducer? _representationModuleProducer;
|
||||
|
||||
// [CanBeNull]
|
||||
private Dictionary<int, object?> _singletons;
|
||||
private IStorage<object> _storage;
|
||||
|
||||
private Dictionary<int, object?> _singletons = new();
|
||||
private readonly IStorage<object> _storage;
|
||||
|
||||
public InstanceRepository()
|
||||
{
|
||||
@@ -36,7 +31,7 @@ namespace mROA.Implementation.Backend
|
||||
var interfaces = o.GetType().GetInterfaces();
|
||||
var generic = interfaces.Where(i => sharedType.IsAssignableFrom(i) && i != sharedType)
|
||||
.Select(i => typeof(IEventBinder<>).MakeGenericType(i));
|
||||
|
||||
|
||||
var binders = EventBinders.Where(i => generic.Any(g => g.IsAssignableFrom(i.GetType())));
|
||||
foreach (var binder in binders)
|
||||
((IEventBinder)binder).BindEvents(o, context, _representationModuleProducer!, last);
|
||||
@@ -49,7 +44,7 @@ namespace mROA.Implementation.Backend
|
||||
_storage.Free(id.ContextId);
|
||||
}
|
||||
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class
|
||||
{
|
||||
var value = _storage.GetValue(id.ContextId);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace mROA.Implementation.Backend
|
||||
repository.ClearObject(id, context);
|
||||
}
|
||||
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class
|
||||
{
|
||||
var repository = GetRepositoryByClientId(context.OwnerId);
|
||||
return repository.GetObject<T>(id, context);
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace mROA.Implementation.Backend
|
||||
{
|
||||
await interaction.ReceiveChanel.Writer.WriteAsync(message);
|
||||
};
|
||||
Task.Run(() => streamExtractor.SingleReceive());
|
||||
_ = Task.Run(() => streamExtractor.SingleReceive());
|
||||
var connectionRequest = await interaction.ReceiveChanel.Reader.ReadAsync();
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace mROA.Implementation.Backend
|
||||
private CancellationTokenSource _tokenSource = new();
|
||||
private IContextualSerializationToolKit _serializationToolkit;
|
||||
private IEndPointContext _context;
|
||||
|
||||
public UdpGateway(IPEndPoint listeningEndpoint)
|
||||
{
|
||||
_client = new UdpClient(listeningEndpoint);
|
||||
|
||||
@@ -10,15 +10,27 @@ namespace mROA.Implementation.Bootstrap
|
||||
|
||||
public void Build()
|
||||
{
|
||||
|
||||
foreach (var module in Modules)
|
||||
foreach (var injection in Modules)
|
||||
module.Inject(injection);
|
||||
}
|
||||
|
||||
public T? GetModule<T>()
|
||||
public T GetModule<T>()
|
||||
{
|
||||
return Modules.OfType<T>().FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool TryGetModule<T>(out IInjectableModule module) where T : IInjectableModule
|
||||
{
|
||||
var mod = Modules.OfType<T>().FirstOrDefault();
|
||||
if (mod is null)
|
||||
{
|
||||
module = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
module = mod;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ namespace mROA.Implementation
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
return $"Call request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,12 +160,11 @@ namespace mROA.Implementation
|
||||
|
||||
public class StreamExtractor
|
||||
{
|
||||
private static Stopwatch profiler = new Stopwatch();
|
||||
private const int BufferSize = ushort.MaxValue;
|
||||
|
||||
private readonly Stream _ioStream;
|
||||
private readonly IContextualSerializationToolKit _serializationToolkit;
|
||||
private const int BufferSize = ushort.MaxValue;
|
||||
private readonly Memory<byte> _buffer = new byte[BufferSize];
|
||||
private bool _manualConnectionState = true;
|
||||
private readonly IEndPointContext _context;
|
||||
private readonly byte[] _lenBuffer;
|
||||
|
||||
@@ -175,7 +174,6 @@ namespace mROA.Implementation
|
||||
_ioStream = ioStream;
|
||||
_serializationToolkit = serializationToolkit;
|
||||
_context = context;
|
||||
profiler.Start();
|
||||
_lenBuffer = new byte[2];
|
||||
}
|
||||
|
||||
@@ -196,7 +194,6 @@ namespace mROA.Implementation
|
||||
var localSpan = _buffer[..len];
|
||||
|
||||
await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: token);
|
||||
profiler.Restart();
|
||||
var message = _serializationToolkit.Deserialize<NetworkMessageHeader>(localSpan, _context);
|
||||
MessageReceived(message);
|
||||
}
|
||||
@@ -217,7 +214,6 @@ namespace mROA.Implementation
|
||||
header.CopyTo(_buffer);
|
||||
var sendingSpan = _buffer[..(len + 2)];
|
||||
await _ioStream.WriteAsync(sendingSpan, token);
|
||||
profiler.Restart();
|
||||
}
|
||||
|
||||
public async Task SendFromChannel(ChannelReader<NetworkMessageHeader> channel,
|
||||
@@ -230,8 +226,7 @@ namespace mROA.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsConnected => _ioStream is { CanRead: true, CanWrite: true } && _manualConnectionState;
|
||||
public bool IsConnected => _ioStream is { CanRead: true, CanWrite: true };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,25 +5,22 @@ namespace mROA.Implementation
|
||||
{
|
||||
public class CollectableMethodRepository : IMethodRepository
|
||||
{
|
||||
private List<IMethodInvoker> _methods = new();
|
||||
private List<IMethodInvoker> _methods = new();
|
||||
|
||||
public void Inject(object 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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using mROA.Abstract;
|
||||
using mROA.Implementation.Bootstrap;
|
||||
using mROA.Implementation.Frontend;
|
||||
|
||||
namespace mROA.Implementation.CommandExecution
|
||||
|
||||
@@ -5,14 +5,14 @@ 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; set; }
|
||||
public CallIndexConfig CallIndexConfig { get; set; }
|
||||
public int HostId { get; set; }
|
||||
|
||||
public int OwnerId { get; set; }
|
||||
|
||||
|
||||
|
||||
public void Inject(object dependency)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,8 @@ namespace mROA.Implementation
|
||||
{
|
||||
public class EventBinder<T> : IEventBinder<T>
|
||||
{
|
||||
public Action<T, IEndPointContext, IRepresentationModuleProducer, int> BindAction { get; set; } = (_, _, _, _) => { };
|
||||
public Action<T, IEndPointContext, IRepresentationModuleProducer, int> BindAction { get; set; } =
|
||||
(_, _, _, _) => { };
|
||||
|
||||
public void BindEvents(T source, IEndPointContext context,
|
||||
IRepresentationModuleProducer representationModuleProducer, int index)
|
||||
|
||||
@@ -43,45 +43,37 @@ namespace mROA.Implementation.Frontend
|
||||
{
|
||||
ThrowIfNotInjected();
|
||||
|
||||
var streamTokenSource = new CancellationTokenSource();
|
||||
|
||||
try
|
||||
var query = _representationModule!.GetStream(m =>
|
||||
m.MessageType is EMessageType.CallRequest or EMessageType.CancelRequest
|
||||
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,
|
||||
m => m.MessageType == EMessageType.ClientDisconnect ? typeof(ClientDisconnect) : null);
|
||||
|
||||
|
||||
await foreach (var command in query)
|
||||
{
|
||||
|
||||
var streamTokenSource = new CancellationTokenSource();
|
||||
|
||||
var query = _representationModule!.GetStream(m =>
|
||||
m.MessageType is EMessageType.CallRequest or EMessageType.CancelRequest
|
||||
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,
|
||||
m => m.MessageType == EMessageType.ClientDisconnect ? typeof(ClientDisconnect) : null);
|
||||
|
||||
|
||||
await foreach (var command in query)
|
||||
switch (command.originalType)
|
||||
{
|
||||
switch (command.originalType)
|
||||
{
|
||||
case EMessageType.CallRequest:
|
||||
HandleCallRequest((DefaultCallRequest)command.parced);
|
||||
break;
|
||||
case EMessageType.ClientDisconnect:
|
||||
return;
|
||||
case EMessageType.EventRequest:
|
||||
HandleEventRequest((DefaultCallRequest)command.parced);
|
||||
break;
|
||||
case EMessageType.CancelRequest:
|
||||
HandleCancelRequest((command.parced as CancelRequest)!);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
case EMessageType.CallRequest:
|
||||
HandleCallRequest((DefaultCallRequest)command.parced);
|
||||
break;
|
||||
case EMessageType.ClientDisconnect:
|
||||
return;
|
||||
case EMessageType.EventRequest:
|
||||
HandleEventRequest((DefaultCallRequest)command.parced);
|
||||
break;
|
||||
case EMessageType.CancelRequest:
|
||||
HandleCancelRequest((command.parced as CancelRequest)!);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void ThrowIfNotInjected()
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace mROA.Implementation.Frontend
|
||||
private IChannelInteractionModule _channelInteractionModule;
|
||||
private CancellationTokenSource _tokenSource = new();
|
||||
private IEndPointContext _context;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_tokenSource.Cancel();
|
||||
@@ -62,7 +63,6 @@ namespace mROA.Implementation.Frontend
|
||||
var serialized = _serializationToolkit.Serialize(post, _context);
|
||||
|
||||
await udpClient.SendAsync(serialized, serialized.Length);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace mROA.Implementation
|
||||
{
|
||||
Id = 0;
|
||||
}
|
||||
|
||||
public ClientRecovery(int id)
|
||||
{
|
||||
Id = id;
|
||||
|
||||
@@ -21,10 +21,12 @@ namespace mROA.Implementation
|
||||
}
|
||||
|
||||
public static readonly NetworkMessageHeader Null = new();
|
||||
|
||||
public NetworkMessageHeader()
|
||||
{
|
||||
Data = Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public NetworkMessageHeader(IContextualSerializationToolKit serializationToolkit,
|
||||
INetworkMessage networkMessage, IEndPointContext? context)
|
||||
{
|
||||
@@ -32,6 +34,7 @@ namespace mROA.Implementation
|
||||
Data = serializationToolkit.Serialize(networkMessage, context);
|
||||
Id = Guid.NewGuid();
|
||||
}
|
||||
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public EMessageType MessageType { get; set; }
|
||||
|
||||
@@ -32,7 +32,8 @@ namespace mROA.Implementation
|
||||
if (_representationProducer == null)
|
||||
throw new NullReferenceException("representation producer is not initialized");
|
||||
|
||||
if (!_callIndexProvider.Activators.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,
|
||||
@@ -56,7 +57,8 @@ namespace mROA.Implementation
|
||||
var representationModule =
|
||||
_representationProducer.Produce(context.OwnerId);
|
||||
|
||||
var instance = _callIndexProvider.Activators[type](-1, representationModule, context, _callIndexProvider.GetIndices(type))!;
|
||||
var instance = _callIndexProvider.Activators[type](-1, representationModule, context,
|
||||
_callIndexProvider.GetIndices(type))!;
|
||||
|
||||
var remoteObjectBase = instance;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace mROA.Implementation
|
||||
|
||||
private readonly ComplexObjectIdentifier _identifier;
|
||||
private readonly IRepresentationModule _representationModule;
|
||||
protected readonly int[] _callIndices;
|
||||
protected readonly int[] CallIndices;
|
||||
|
||||
protected RemoteObjectBase(int id, IRepresentationModule representationModule, IEndPointContext context,
|
||||
int[] indices)
|
||||
@@ -40,7 +40,7 @@ namespace mROA.Implementation
|
||||
_identifier = new ComplexObjectIdentifier { ContextId = id, OwnerId = representationModule.Id };
|
||||
_representationModule = representationModule;
|
||||
_context = context;
|
||||
_callIndices = indices;
|
||||
CallIndices = indices;
|
||||
}
|
||||
|
||||
public int Id => _identifier.ContextId;
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using mROA.Abstract;
|
||||
|
||||
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
||||
|
||||
namespace mROA.Implementation
|
||||
@@ -71,11 +72,11 @@ namespace mROA.Implementation
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < converter.Length; i++)
|
||||
{
|
||||
var func = converter[i];
|
||||
if (func(message) is {} t)
|
||||
if (func(message) is { } t)
|
||||
{
|
||||
var deserialized = _serialization.Deserialize(message.Data, t, context);
|
||||
yield return (deserialized, message.MessageType)!;
|
||||
@@ -85,7 +86,8 @@ namespace mROA.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PostCallMessageAsync<T>(Guid id, EMessageType eMessageType, T payload, IEndPointContext? context) where T : notnull
|
||||
public async Task PostCallMessageAsync<T>(Guid id, EMessageType eMessageType, T payload,
|
||||
IEndPointContext? context) where T : notnull
|
||||
{
|
||||
if (_interaction == null)
|
||||
throw new NullReferenceException("Interaction toolkit is not initialized");
|
||||
|
||||
@@ -60,7 +60,9 @@ namespace mROA.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
[SerializationIgnore] [JsonIgnore] public IEndPointContext EndPointContext { get; set; }
|
||||
[SerializationIgnore]
|
||||
[JsonIgnore]
|
||||
public IEndPointContext EndPointContext { get; set; }
|
||||
|
||||
public ComplexObjectIdentifier Identifier
|
||||
{
|
||||
|
||||
+6
-6
@@ -26,15 +26,15 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.5" />
|
||||
<PackageReference Include="System.Threading.Channels" Version="9.0.5" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.5"/>
|
||||
<PackageReference Include="System.Threading.Channels" Version="9.0.5"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="mroaLogo.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
<None Update="mroaLogo.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user