From 40a7f86dcfd2a927c227abd90ec6218532292f82 Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Thu, 13 Mar 2025 20:01:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=B2=D1=82=D0=BE=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B9=20=D0=BA=D0=BB=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example.Frontend/Program.cs | 2 +- mROA/Abstract/IConnectionHub.cs | 1 + mROA/Abstract/IEndPointContext.cs | 2 +- mROA/Abstract/IExecuteModule.cs | 3 ++- mROA/Abstract/IFrontendBridge.cs | 1 - mROA/Abstract/IGatewayModule.cs | 2 +- mROA/Abstract/IMethodInvoker.cs | 4 ++-- mROA/Abstract/IRequestExtractor.cs | 2 +- mROA/Abstract/ISerializationToolkit.cs | 1 - .../Attributes/SerializationIgnoreAttribute.cs | 1 - .../Attributes/SharedObjectInterfaceAttribute.cs | 4 +++- .../Attributes/SharedObjectSingletonAttribute.cs | 4 +++- .../Backend/BackendIdentityGenerator.cs | 2 +- .../Backend/BasicConfigurationExtensions.cs | 5 +++-- mROA/Implementation/Backend/ConnectionHub.cs | 8 ++++---- mROA/Implementation/Backend/ContextRepository.cs | 2 +- .../Backend/MultiClientContextRepository.cs | 2 +- mROA/Implementation/CancellationRepository.cs | 4 ++-- mROA/Implementation/ComplexObjectIdentifier.cs | 3 +++ .../CreativeRepresentationModuleProducer.cs | 2 +- mROA/Implementation/ExtensibleStorage.cs | 1 + mROA/Implementation/Frontend/NetworkFrontendBridge.cs | 5 +++-- mROA/Implementation/Frontend/RemoteException.cs | 2 +- mROA/Implementation/Frontend/RequestExtractor.cs | 4 ++-- mROA/Implementation/NetworkMessage.cs | 11 ++++++++++- .../Implementation/NextGenerationInteractionModule.cs | 2 +- mROA/Implementation/RemoteContextRepository.cs | 2 +- .../StaticRepresentationModuleProducer.cs | 4 ++-- mROA/LegacyExtentions.cs | 1 + mROA/mROA.csproj | 4 ++-- 30 files changed, 55 insertions(+), 36 deletions(-) diff --git a/Example.Frontend/Program.cs b/Example.Frontend/Program.cs index c4fb975..156026d 100644 --- a/Example.Frontend/Program.cs +++ b/Example.Frontend/Program.cs @@ -24,7 +24,7 @@ class Program builder.Modules.Add(new RemoteContextRepository()); builder.Modules.Add(new NextGenerationInteractionModule()); builder.Modules.Add(new RepresentationModule()); - builder.Modules.Add(new NetworkFrontendBridge(new IPEndPoint(IPAddress.Parse("95.105.78.72"), 4567))); + builder.Modules.Add(new NetworkFrontendBridge(new IPEndPoint(IPAddress.Loopback, 4567))); builder.Modules.Add(new StaticRepresentationModuleProducer()); builder.Modules.Add(new RequestExtractor()); builder.Modules.Add(new BasicExecutionModule()); diff --git a/mROA/Abstract/IConnectionHub.cs b/mROA/Abstract/IConnectionHub.cs index 43dc945..34106f3 100644 --- a/mROA/Abstract/IConnectionHub.cs +++ b/mROA/Abstract/IConnectionHub.cs @@ -1,6 +1,7 @@ namespace mROA.Abstract { public delegate void ConnectionHandler(IRepresentationModule representationModule); + public delegate void DisconnectionHandler(IRepresentationModule representationModule); public interface IConnectionHub : IInjectableModule diff --git a/mROA/Abstract/IEndPointContext.cs b/mROA/Abstract/IEndPointContext.cs index 5d6e4c6..0267321 100644 --- a/mROA/Abstract/IEndPointContext.cs +++ b/mROA/Abstract/IEndPointContext.cs @@ -4,7 +4,7 @@ { IContextRepository RealRepository { get; } IContextRepository RemoteRepository { get; } - int HostId { get; } + int HostId { get; } int OwnerId { get; } } } \ No newline at end of file diff --git a/mROA/Abstract/IExecuteModule.cs b/mROA/Abstract/IExecuteModule.cs index 29f5211..3ae2d13 100644 --- a/mROA/Abstract/IExecuteModule.cs +++ b/mROA/Abstract/IExecuteModule.cs @@ -4,6 +4,7 @@ namespace mROA.Abstract { public interface IExecuteModule : IInjectableModule { - ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository, IRepresentationModule representationModule); + ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository, + IRepresentationModule representationModule); } } \ No newline at end of file diff --git a/mROA/Abstract/IFrontendBridge.cs b/mROA/Abstract/IFrontendBridge.cs index 7d4eb3f..909f486 100644 --- a/mROA/Abstract/IFrontendBridge.cs +++ b/mROA/Abstract/IFrontendBridge.cs @@ -2,6 +2,5 @@ namespace mROA.Abstract { public interface IFrontendBridge : IInjectableModule { - } } \ No newline at end of file diff --git a/mROA/Abstract/IGatewayModule.cs b/mROA/Abstract/IGatewayModule.cs index 46d96bd..77c869f 100644 --- a/mROA/Abstract/IGatewayModule.cs +++ b/mROA/Abstract/IGatewayModule.cs @@ -3,7 +3,7 @@ using System; namespace mROA.Abstract { public interface IGatewayModule : IDisposable, IInjectableModule - { + { void Run(); } } \ No newline at end of file diff --git a/mROA/Abstract/IMethodInvoker.cs b/mROA/Abstract/IMethodInvoker.cs index eb5e182..dcb04db 100644 --- a/mROA/Abstract/IMethodInvoker.cs +++ b/mROA/Abstract/IMethodInvoker.cs @@ -3,10 +3,10 @@ using System; namespace mROA.Abstract { public interface IMethodInvoker - { + { bool IsVoid { get; } Type[] ParameterTypes { get; } Type? ReturnType { get; } - Type SuitableType { get; } + Type SuitableType { get; } } } \ No newline at end of file diff --git a/mROA/Abstract/IRequestExtractor.cs b/mROA/Abstract/IRequestExtractor.cs index 30711fc..d49194b 100644 --- a/mROA/Abstract/IRequestExtractor.cs +++ b/mROA/Abstract/IRequestExtractor.cs @@ -4,6 +4,6 @@ namespace mROA.Abstract { public interface IRequestExtractor : IInjectableModule { - Task StartExtraction(); + Task StartExtraction(); } } \ No newline at end of file diff --git a/mROA/Abstract/ISerializationToolkit.cs b/mROA/Abstract/ISerializationToolkit.cs index c7ce9f4..497c953 100644 --- a/mROA/Abstract/ISerializationToolkit.cs +++ b/mROA/Abstract/ISerializationToolkit.cs @@ -12,6 +12,5 @@ namespace mROA.Abstract object? Deserialize(Span rawData, Type type); T? Cast(object? nonCasted); object? Cast(object? nonCasted, Type type); - } } \ No newline at end of file diff --git a/mROA/Implementation/Attributes/SerializationIgnoreAttribute.cs b/mROA/Implementation/Attributes/SerializationIgnoreAttribute.cs index b63d4d3..cd32ca7 100644 --- a/mROA/Implementation/Attributes/SerializationIgnoreAttribute.cs +++ b/mROA/Implementation/Attributes/SerializationIgnoreAttribute.cs @@ -4,6 +4,5 @@ namespace mROA.Implementation.Attributes { public class SerializationIgnoreAttribute : Attribute { - } } \ No newline at end of file diff --git a/mROA/Implementation/Attributes/SharedObjectInterfaceAttribute.cs b/mROA/Implementation/Attributes/SharedObjectInterfaceAttribute.cs index c187036..adcc66e 100644 --- a/mROA/Implementation/Attributes/SharedObjectInterfaceAttribute.cs +++ b/mROA/Implementation/Attributes/SharedObjectInterfaceAttribute.cs @@ -2,5 +2,7 @@ namespace mROA.Implementation.Attributes { - public class SharedObjectInterfaceAttribute : Attribute { } + public class SharedObjectInterfaceAttribute : Attribute + { + } } \ No newline at end of file diff --git a/mROA/Implementation/Attributes/SharedObjectSingletonAttribute.cs b/mROA/Implementation/Attributes/SharedObjectSingletonAttribute.cs index 84002ac..ec2f228 100644 --- a/mROA/Implementation/Attributes/SharedObjectSingletonAttribute.cs +++ b/mROA/Implementation/Attributes/SharedObjectSingletonAttribute.cs @@ -2,5 +2,7 @@ namespace mROA.Implementation.Attributes { - public class SharedObjectSingletonAttribute : Attribute { } + public class SharedObjectSingletonAttribute : Attribute + { + } } \ No newline at end of file diff --git a/mROA/Implementation/Backend/BackendIdentityGenerator.cs b/mROA/Implementation/Backend/BackendIdentityGenerator.cs index ae49490..dce88be 100644 --- a/mROA/Implementation/Backend/BackendIdentityGenerator.cs +++ b/mROA/Implementation/Backend/BackendIdentityGenerator.cs @@ -7,7 +7,7 @@ namespace mROA.Implementation.Backend private int _currentId; public int GetNextIdentity() - { + { return ++_currentId; } diff --git a/mROA/Implementation/Backend/BasicConfigurationExtensions.cs b/mROA/Implementation/Backend/BasicConfigurationExtensions.cs index b7f2460..b8e0f7c 100644 --- a/mROA/Implementation/Backend/BasicConfigurationExtensions.cs +++ b/mROA/Implementation/Backend/BasicConfigurationExtensions.cs @@ -8,11 +8,12 @@ namespace mROA.Implementation.Backend { public static class BasicConfigurationExtensions { - public static void UseNetworkGateway(this FullMixBuilder builder, IPEndPoint endPoint, Type interactionModuleType, params IInjectableModule[] injectableModules) + public static void UseNetworkGateway(this FullMixBuilder builder, IPEndPoint endPoint, + Type interactionModuleType, params IInjectableModule[] injectableModules) { builder.Modules.Add(new NetworkGatewayModule(endPoint, interactionModuleType, injectableModules)); } - + public static void UseBasicExecution(this FullMixBuilder builder) { builder.Modules.Add(new BasicExecutionModule()); diff --git a/mROA/Implementation/Backend/ConnectionHub.cs b/mROA/Implementation/Backend/ConnectionHub.cs index 61fa56c..f26a304 100644 --- a/mROA/Implementation/Backend/ConnectionHub.cs +++ b/mROA/Implementation/Backend/ConnectionHub.cs @@ -8,12 +8,12 @@ namespace mROA.Implementation.Backend { private readonly Dictionary _connections = new(); private ISerializationToolkit? _serializationToolkit; - + public void RegisterInteraction(INextGenerationInteractionModule interaction) { if (_serializationToolkit is null) throw new NullReferenceException("Serialization toolkit is null"); - + _connections.Add(interaction.ConnectionId, interaction); var module = new RepresentationModule(); module.Inject(_serializationToolkit); @@ -28,11 +28,11 @@ namespace mROA.Implementation.Backend public event ConnectionHandler? OnConnected; public event DisconnectionHandler? OnDisconnected; + public void Inject(T dependency) { - if (dependency is ISerializationToolkit serializationToolkit) + if (dependency is ISerializationToolkit serializationToolkit) _serializationToolkit = serializationToolkit; - } } } \ No newline at end of file diff --git a/mROA/Implementation/Backend/ContextRepository.cs b/mROA/Implementation/Backend/ContextRepository.cs index cbc1220..71ee389 100644 --- a/mROA/Implementation/Backend/ContextRepository.cs +++ b/mROA/Implementation/Backend/ContextRepository.cs @@ -51,7 +51,7 @@ namespace mROA.Implementation.Backend public T GetObject(ComplexObjectIdentifier id) { var value = _storage.GetValue(id.ContextId); - + if (value == null) { throw new NullReferenceException("Cannot find that object. It is null"); diff --git a/mROA/Implementation/Backend/MultiClientContextRepository.cs b/mROA/Implementation/Backend/MultiClientContextRepository.cs index 9078788..065c746 100644 --- a/mROA/Implementation/Backend/MultiClientContextRepository.cs +++ b/mROA/Implementation/Backend/MultiClientContextRepository.cs @@ -31,7 +31,7 @@ namespace mROA.Implementation.Backend var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()); repository.ClearObject(id); } - + public T GetObject(ComplexObjectIdentifier id) { var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()); diff --git a/mROA/Implementation/CancellationRepository.cs b/mROA/Implementation/CancellationRepository.cs index 3c5659e..d6543aa 100644 --- a/mROA/Implementation/CancellationRepository.cs +++ b/mROA/Implementation/CancellationRepository.cs @@ -7,7 +7,8 @@ namespace mROA.Implementation { public class CancellationRepository : ICancellationRepository { - private Dictionary _cancellations = new(); + private Dictionary _cancellations = new(); + public void RegisterCancellation(Guid id, CancellationTokenSource cts) { _cancellations.TryAdd(id, cts); @@ -25,7 +26,6 @@ namespace mROA.Implementation public void Inject(T dependency) { - } } } \ No newline at end of file diff --git a/mROA/Implementation/ComplexObjectIdentifier.cs b/mROA/Implementation/ComplexObjectIdentifier.cs index 37d87a2..d95d378 100644 --- a/mROA/Implementation/ComplexObjectIdentifier.cs +++ b/mROA/Implementation/ComplexObjectIdentifier.cs @@ -7,11 +7,13 @@ namespace mROA.Implementation { public int ContextId; public int OwnerId; + public ComplexObjectIdentifier(int contextId, int ownerId) { ContextId = contextId; OwnerId = ownerId; } + public static ComplexObjectIdentifier Singleton(int ownerId) => new() { ContextId = -1, OwnerId = ownerId }; public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = 0 }; @@ -20,6 +22,7 @@ namespace mROA.Implementation public int ClientId => Math.Abs(OwnerId); public bool IsSererStored => OwnerId > 0; public bool IsClientStored => OwnerId < 0; + public override string ToString() { return $"{{ {nameof(ContextId)}: {ContextId}, {nameof(OwnerId)}: {OwnerId} }}"; diff --git a/mROA/Implementation/CreativeRepresentationModuleProducer.cs b/mROA/Implementation/CreativeRepresentationModuleProducer.cs index 5ac35cc..0e21899 100644 --- a/mROA/Implementation/CreativeRepresentationModuleProducer.cs +++ b/mROA/Implementation/CreativeRepresentationModuleProducer.cs @@ -36,7 +36,7 @@ namespace mROA.Implementation var interaction = _hub.GetInteracion(id); produced.Inject(interaction); - + return produced; } } diff --git a/mROA/Implementation/ExtensibleStorage.cs b/mROA/Implementation/ExtensibleStorage.cs index a9c6d18..6543519 100644 --- a/mROA/Implementation/ExtensibleStorage.cs +++ b/mROA/Implementation/ExtensibleStorage.cs @@ -18,6 +18,7 @@ namespace mROA.Implementation { return null; } + return _array[index]; } diff --git a/mROA/Implementation/Frontend/NetworkFrontendBridge.cs b/mROA/Implementation/Frontend/NetworkFrontendBridge.cs index 2bff07f..4efe1fd 100644 --- a/mROA/Implementation/Frontend/NetworkFrontendBridge.cs +++ b/mROA/Implementation/Frontend/NetworkFrontendBridge.cs @@ -36,13 +36,14 @@ namespace mROA.Implementation.Frontend throw new Exception("Interaction module was not injected"); if (_serialization == null) throw new NullReferenceException("Serialization toolkit is not initialized"); - + _tcpClient.Connect(_ipEndPoint); _interactionModule.BaseStream = _tcpClient.GetStream(); var welcomeMessage = _interactionModule.GetNextMessageReceiving().GetAwaiter().GetResult(); if (welcomeMessage.SchemaId != MessageType.IdAssigning) { - throw new Exception($"Incorrect message type. Must be IdAssigning, current : {welcomeMessage.SchemaId.ToString()}"); + throw new Exception( + $"Incorrect message type. Must be IdAssigning, current : {welcomeMessage.SchemaId.ToString()}"); } diff --git a/mROA/Implementation/Frontend/RemoteException.cs b/mROA/Implementation/Frontend/RemoteException.cs index 093d9c1..e63e8b3 100644 --- a/mROA/Implementation/Frontend/RemoteException.cs +++ b/mROA/Implementation/Frontend/RemoteException.cs @@ -2,7 +2,7 @@ namespace mROA.Implementation.Frontend { - public class RemoteException : Exception + public class RemoteException : Exception { public Guid CallRequestId; private readonly string _error; diff --git a/mROA/Implementation/Frontend/RequestExtractor.cs b/mROA/Implementation/Frontend/RequestExtractor.cs index 0788ba9..baf6be3 100644 --- a/mROA/Implementation/Frontend/RequestExtractor.cs +++ b/mROA/Implementation/Frontend/RequestExtractor.cs @@ -58,7 +58,7 @@ namespace mROA.Implementation.Frontend throw new NullReferenceException("Representation module is null."); if (_methodRepository == null) throw new NullReferenceException("Method repository is null."); - + var multiClientOwnershipRepository = TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository; multiClientOwnershipRepository?.RegisterOwnership(_representationModule.Id); @@ -134,4 +134,4 @@ namespace mROA.Implementation.Frontend }); } } -} +} \ No newline at end of file diff --git a/mROA/Implementation/NetworkMessage.cs b/mROA/Implementation/NetworkMessage.cs index dd71589..9522bea 100644 --- a/mROA/Implementation/NetworkMessage.cs +++ b/mROA/Implementation/NetworkMessage.cs @@ -1,5 +1,6 @@ using System; using System.Text.Json.Serialization; + // ReSharper disable UnusedMember.Global namespace mROA.Implementation @@ -7,6 +8,7 @@ namespace mROA.Implementation public class NetworkMessage { public Guid Id { get; set; } + [JsonConverter(typeof(JsonStringEnumConverter))] public MessageType SchemaId { get; set; } @@ -15,6 +17,13 @@ namespace mROA.Implementation public enum MessageType { - Unknown, FinishedCommandExecution, ExceptionCommandExecution, AsyncCommandExecution, CallRequest, IdAssigning, CancelRequest, EventRequest + Unknown, + FinishedCommandExecution, + ExceptionCommandExecution, + AsyncCommandExecution, + CallRequest, + IdAssigning, + CancelRequest, + EventRequest } } \ No newline at end of file diff --git a/mROA/Implementation/NextGenerationInteractionModule.cs b/mROA/Implementation/NextGenerationInteractionModule.cs index 733c921..f7ece15 100644 --- a/mROA/Implementation/NextGenerationInteractionModule.cs +++ b/mROA/Implementation/NextGenerationInteractionModule.cs @@ -51,7 +51,7 @@ namespace mROA.Implementation var rawMessage = _serialization.Serialize(message); var header = BitConverter.GetBytes((ushort)rawMessage.Length).AsMemory(0, sizeof(ushort)); - + await BaseStream.WriteAsync(header); await BaseStream.WriteAsync(rawMessage); } diff --git a/mROA/Implementation/RemoteContextRepository.cs b/mROA/Implementation/RemoteContextRepository.cs index f5d734d..8c8ded5 100644 --- a/mROA/Implementation/RemoteContextRepository.cs +++ b/mROA/Implementation/RemoteContextRepository.cs @@ -46,7 +46,7 @@ namespace mROA.Implementation { if (_representationProducer == null) throw new NullReferenceException("representation producer is not initialized"); - + var representationModule = _representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId()); diff --git a/mROA/Implementation/StaticRepresentationModuleProducer.cs b/mROA/Implementation/StaticRepresentationModuleProducer.cs index 188bfec..8aeabd4 100644 --- a/mROA/Implementation/StaticRepresentationModuleProducer.cs +++ b/mROA/Implementation/StaticRepresentationModuleProducer.cs @@ -6,14 +6,14 @@ namespace mROA.Implementation public class StaticRepresentationModuleProducer : IRepresentationModuleProducer { private IRepresentationModule? _representationModule; - + public IRepresentationModule Produce(int ownership) { if (_representationModule == null) throw new NullReferenceException("The representation module is not initialized."); return _representationModule; } - + public void Inject(T dependency) { if (dependency is IRepresentationModule serialisationModule) diff --git a/mROA/LegacyExtentions.cs b/mROA/LegacyExtentions.cs index d0a3b29..ed05e04 100644 --- a/mROA/LegacyExtentions.cs +++ b/mROA/LegacyExtentions.cs @@ -36,6 +36,7 @@ namespace mROA return totalRead; } } + return totalRead; } } diff --git a/mROA/mROA.csproj b/mROA/mROA.csproj index e62894c..5c9aea9 100644 --- a/mROA/mROA.csproj +++ b/mROA/mROA.csproj @@ -17,7 +17,7 @@ - + @@ -25,7 +25,7 @@ - +