Автоматический клинап

This commit is contained in:
2025-03-13 20:01:17 +03:00
parent 1ff521c614
commit 40a7f86dcf
30 changed files with 55 additions and 36 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ class Program
builder.Modules.Add(new RemoteContextRepository()); builder.Modules.Add(new RemoteContextRepository());
builder.Modules.Add(new NextGenerationInteractionModule()); builder.Modules.Add(new NextGenerationInteractionModule());
builder.Modules.Add(new RepresentationModule()); 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 StaticRepresentationModuleProducer());
builder.Modules.Add(new RequestExtractor()); builder.Modules.Add(new RequestExtractor());
builder.Modules.Add(new BasicExecutionModule()); builder.Modules.Add(new BasicExecutionModule());
+1
View File
@@ -1,6 +1,7 @@
namespace mROA.Abstract namespace mROA.Abstract
{ {
public delegate void ConnectionHandler(IRepresentationModule representationModule); public delegate void ConnectionHandler(IRepresentationModule representationModule);
public delegate void DisconnectionHandler(IRepresentationModule representationModule); public delegate void DisconnectionHandler(IRepresentationModule representationModule);
public interface IConnectionHub : IInjectableModule public interface IConnectionHub : IInjectableModule
+1 -1
View File
@@ -4,7 +4,7 @@
{ {
IContextRepository RealRepository { get; } IContextRepository RealRepository { get; }
IContextRepository RemoteRepository { get; } IContextRepository RemoteRepository { get; }
int HostId { get; } int HostId { get; }
int OwnerId { get; } int OwnerId { get; }
} }
} }
+2 -1
View File
@@ -4,6 +4,7 @@ namespace mROA.Abstract
{ {
public interface IExecuteModule : IInjectableModule public interface IExecuteModule : IInjectableModule
{ {
ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository, IRepresentationModule representationModule); ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository,
IRepresentationModule representationModule);
} }
} }
-1
View File
@@ -2,6 +2,5 @@ namespace mROA.Abstract
{ {
public interface IFrontendBridge : IInjectableModule public interface IFrontendBridge : IInjectableModule
{ {
} }
} }
+1 -1
View File
@@ -3,7 +3,7 @@ using System;
namespace mROA.Abstract namespace mROA.Abstract
{ {
public interface IGatewayModule : IDisposable, IInjectableModule public interface IGatewayModule : IDisposable, IInjectableModule
{ {
void Run(); void Run();
} }
} }
+2 -2
View File
@@ -3,10 +3,10 @@ using System;
namespace mROA.Abstract namespace mROA.Abstract
{ {
public interface IMethodInvoker public interface IMethodInvoker
{ {
bool IsVoid { get; } bool IsVoid { get; }
Type[] ParameterTypes { get; } Type[] ParameterTypes { get; }
Type? ReturnType { get; } Type? ReturnType { get; }
Type SuitableType { get; } Type SuitableType { get; }
} }
} }
+1 -1
View File
@@ -4,6 +4,6 @@ namespace mROA.Abstract
{ {
public interface IRequestExtractor : IInjectableModule public interface IRequestExtractor : IInjectableModule
{ {
Task StartExtraction(); Task StartExtraction();
} }
} }
-1
View File
@@ -12,6 +12,5 @@ namespace mROA.Abstract
object? Deserialize(Span<byte> rawData, Type type); object? Deserialize(Span<byte> rawData, Type type);
T? Cast<T>(object? nonCasted); T? Cast<T>(object? nonCasted);
object? Cast(object? nonCasted, Type type); object? Cast(object? nonCasted, Type type);
} }
} }
@@ -4,6 +4,5 @@ namespace mROA.Implementation.Attributes
{ {
public class SerializationIgnoreAttribute : Attribute public class SerializationIgnoreAttribute : Attribute
{ {
} }
} }
@@ -2,5 +2,7 @@
namespace mROA.Implementation.Attributes namespace mROA.Implementation.Attributes
{ {
public class SharedObjectInterfaceAttribute : Attribute { } public class SharedObjectInterfaceAttribute : Attribute
{
}
} }
@@ -2,5 +2,7 @@
namespace mROA.Implementation.Attributes namespace mROA.Implementation.Attributes
{ {
public class SharedObjectSingletonAttribute : Attribute { } public class SharedObjectSingletonAttribute : Attribute
{
}
} }
@@ -7,7 +7,7 @@ namespace mROA.Implementation.Backend
private int _currentId; private int _currentId;
public int GetNextIdentity() public int GetNextIdentity()
{ {
return ++_currentId; return ++_currentId;
} }
@@ -8,11 +8,12 @@ namespace mROA.Implementation.Backend
{ {
public static class BasicConfigurationExtensions 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)); builder.Modules.Add(new NetworkGatewayModule(endPoint, interactionModuleType, injectableModules));
} }
public static void UseBasicExecution(this FullMixBuilder builder) public static void UseBasicExecution(this FullMixBuilder builder)
{ {
builder.Modules.Add(new BasicExecutionModule()); builder.Modules.Add(new BasicExecutionModule());
+4 -4
View File
@@ -8,12 +8,12 @@ namespace mROA.Implementation.Backend
{ {
private readonly Dictionary<int, INextGenerationInteractionModule> _connections = new(); private readonly Dictionary<int, INextGenerationInteractionModule> _connections = new();
private ISerializationToolkit? _serializationToolkit; private ISerializationToolkit? _serializationToolkit;
public void RegisterInteraction(INextGenerationInteractionModule interaction) public void RegisterInteraction(INextGenerationInteractionModule interaction)
{ {
if (_serializationToolkit is null) if (_serializationToolkit is null)
throw new NullReferenceException("Serialization toolkit is null"); throw new NullReferenceException("Serialization toolkit is null");
_connections.Add(interaction.ConnectionId, interaction); _connections.Add(interaction.ConnectionId, interaction);
var module = new RepresentationModule(); var module = new RepresentationModule();
module.Inject(_serializationToolkit); module.Inject(_serializationToolkit);
@@ -28,11 +28,11 @@ namespace mROA.Implementation.Backend
public event ConnectionHandler? OnConnected; public event ConnectionHandler? OnConnected;
public event DisconnectionHandler? OnDisconnected; public event DisconnectionHandler? OnDisconnected;
public void Inject<T>(T dependency) public void Inject<T>(T dependency)
{ {
if (dependency is ISerializationToolkit serializationToolkit) if (dependency is ISerializationToolkit serializationToolkit)
_serializationToolkit = serializationToolkit; _serializationToolkit = serializationToolkit;
} }
} }
} }
@@ -51,7 +51,7 @@ namespace mROA.Implementation.Backend
public T GetObject<T>(ComplexObjectIdentifier id) public T GetObject<T>(ComplexObjectIdentifier id)
{ {
var value = _storage.GetValue(id.ContextId); var value = _storage.GetValue(id.ContextId);
if (value == null) if (value == null)
{ {
throw new NullReferenceException("Cannot find that object. It is null"); throw new NullReferenceException("Cannot find that object. It is null");
@@ -31,7 +31,7 @@ namespace mROA.Implementation.Backend
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()); var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
repository.ClearObject(id); repository.ClearObject(id);
} }
public T GetObject<T>(ComplexObjectIdentifier id) public T GetObject<T>(ComplexObjectIdentifier id)
{ {
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()); var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
@@ -7,7 +7,8 @@ namespace mROA.Implementation
{ {
public class CancellationRepository : ICancellationRepository public class CancellationRepository : ICancellationRepository
{ {
private Dictionary<Guid, CancellationTokenSource> _cancellations = new(); private Dictionary<Guid, CancellationTokenSource> _cancellations = new();
public void RegisterCancellation(Guid id, CancellationTokenSource cts) public void RegisterCancellation(Guid id, CancellationTokenSource cts)
{ {
_cancellations.TryAdd(id, cts); _cancellations.TryAdd(id, cts);
@@ -25,7 +26,6 @@ namespace mROA.Implementation
public void Inject<T>(T dependency) public void Inject<T>(T dependency)
{ {
} }
} }
} }
@@ -7,11 +7,13 @@ namespace mROA.Implementation
{ {
public int ContextId; public int ContextId;
public int OwnerId; public int OwnerId;
public ComplexObjectIdentifier(int contextId, int ownerId) public ComplexObjectIdentifier(int contextId, int ownerId)
{ {
ContextId = contextId; ContextId = contextId;
OwnerId = ownerId; OwnerId = ownerId;
} }
public static ComplexObjectIdentifier Singleton(int ownerId) => new() { ContextId = -1, OwnerId = ownerId }; public static ComplexObjectIdentifier Singleton(int ownerId) => new() { ContextId = -1, OwnerId = ownerId };
public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = 0 }; public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = 0 };
@@ -20,6 +22,7 @@ namespace mROA.Implementation
public int ClientId => Math.Abs(OwnerId); public int ClientId => Math.Abs(OwnerId);
public bool IsSererStored => OwnerId > 0; public bool IsSererStored => OwnerId > 0;
public bool IsClientStored => OwnerId < 0; public bool IsClientStored => OwnerId < 0;
public override string ToString() public override string ToString()
{ {
return $"{{ {nameof(ContextId)}: {ContextId}, {nameof(OwnerId)}: {OwnerId} }}"; return $"{{ {nameof(ContextId)}: {ContextId}, {nameof(OwnerId)}: {OwnerId} }}";
@@ -36,7 +36,7 @@ namespace mROA.Implementation
var interaction = _hub.GetInteracion(id); var interaction = _hub.GetInteracion(id);
produced.Inject(interaction); produced.Inject(interaction);
return produced; return produced;
} }
} }
+1
View File
@@ -18,6 +18,7 @@ namespace mROA.Implementation
{ {
return null; return null;
} }
return _array[index]; return _array[index];
} }
@@ -36,13 +36,14 @@ namespace mROA.Implementation.Frontend
throw new Exception("Interaction module was not injected"); throw new Exception("Interaction module was not injected");
if (_serialization == null) if (_serialization == null)
throw new NullReferenceException("Serialization toolkit is not initialized"); throw new NullReferenceException("Serialization toolkit is not initialized");
_tcpClient.Connect(_ipEndPoint); _tcpClient.Connect(_ipEndPoint);
_interactionModule.BaseStream = _tcpClient.GetStream(); _interactionModule.BaseStream = _tcpClient.GetStream();
var welcomeMessage = _interactionModule.GetNextMessageReceiving().GetAwaiter().GetResult(); var welcomeMessage = _interactionModule.GetNextMessageReceiving().GetAwaiter().GetResult();
if (welcomeMessage.SchemaId != MessageType.IdAssigning) 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()}");
} }
@@ -2,7 +2,7 @@
namespace mROA.Implementation.Frontend namespace mROA.Implementation.Frontend
{ {
public class RemoteException : Exception public class RemoteException : Exception
{ {
public Guid CallRequestId; public Guid CallRequestId;
private readonly string _error; private readonly string _error;
@@ -58,7 +58,7 @@ namespace mROA.Implementation.Frontend
throw new NullReferenceException("Representation module is null."); throw new NullReferenceException("Representation module is null.");
if (_methodRepository == null) if (_methodRepository == null)
throw new NullReferenceException("Method repository is null."); throw new NullReferenceException("Method repository is null.");
var multiClientOwnershipRepository = var multiClientOwnershipRepository =
TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository; TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository;
multiClientOwnershipRepository?.RegisterOwnership(_representationModule.Id); multiClientOwnershipRepository?.RegisterOwnership(_representationModule.Id);
@@ -134,4 +134,4 @@ namespace mROA.Implementation.Frontend
}); });
} }
} }
} }
+10 -1
View File
@@ -1,5 +1,6 @@
using System; using System;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
namespace mROA.Implementation namespace mROA.Implementation
@@ -7,6 +8,7 @@ namespace mROA.Implementation
public class NetworkMessage public class NetworkMessage
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))] [JsonConverter(typeof(JsonStringEnumConverter))]
public MessageType SchemaId { get; set; } public MessageType SchemaId { get; set; }
@@ -15,6 +17,13 @@ namespace mROA.Implementation
public enum MessageType public enum MessageType
{ {
Unknown, FinishedCommandExecution, ExceptionCommandExecution, AsyncCommandExecution, CallRequest, IdAssigning, CancelRequest, EventRequest Unknown,
FinishedCommandExecution,
ExceptionCommandExecution,
AsyncCommandExecution,
CallRequest,
IdAssigning,
CancelRequest,
EventRequest
} }
} }
@@ -51,7 +51,7 @@ namespace mROA.Implementation
var rawMessage = _serialization.Serialize(message); var rawMessage = _serialization.Serialize(message);
var header = BitConverter.GetBytes((ushort)rawMessage.Length).AsMemory(0, sizeof(ushort)); var header = BitConverter.GetBytes((ushort)rawMessage.Length).AsMemory(0, sizeof(ushort));
await BaseStream.WriteAsync(header); await BaseStream.WriteAsync(header);
await BaseStream.WriteAsync(rawMessage); await BaseStream.WriteAsync(rawMessage);
} }
@@ -46,7 +46,7 @@ namespace mROA.Implementation
{ {
if (_representationProducer == null) if (_representationProducer == null)
throw new NullReferenceException("representation producer is not initialized"); throw new NullReferenceException("representation producer is not initialized");
var representationModule = var representationModule =
_representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId()); _representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId());
@@ -6,14 +6,14 @@ namespace mROA.Implementation
public class StaticRepresentationModuleProducer : IRepresentationModuleProducer public class StaticRepresentationModuleProducer : IRepresentationModuleProducer
{ {
private IRepresentationModule? _representationModule; private IRepresentationModule? _representationModule;
public IRepresentationModule Produce(int ownership) public IRepresentationModule Produce(int ownership)
{ {
if (_representationModule == null) if (_representationModule == null)
throw new NullReferenceException("The representation module is not initialized."); throw new NullReferenceException("The representation module is not initialized.");
return _representationModule; return _representationModule;
} }
public void Inject<T>(T dependency) public void Inject<T>(T dependency)
{ {
if (dependency is IRepresentationModule serialisationModule) if (dependency is IRepresentationModule serialisationModule)
+1
View File
@@ -36,6 +36,7 @@ namespace mROA
return totalRead; return totalRead;
} }
} }
return totalRead; return totalRead;
} }
} }
+2 -2
View File
@@ -17,7 +17,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants /> <DefineConstants/>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
@@ -25,7 +25,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="System.Text.Json" Version="9.0.2" /> <PackageReference Include="System.Text.Json" Version="9.0.2"/>
</ItemGroup> </ItemGroup>
</Project> </Project>