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

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
@@ -4,6 +4,5 @@ namespace mROA.Implementation.Attributes
{
public class SerializationIgnoreAttribute : Attribute
{
}
}
@@ -2,5 +2,7 @@
namespace mROA.Implementation.Attributes
{
public class SharedObjectInterfaceAttribute : Attribute { }
public class SharedObjectInterfaceAttribute : Attribute
{
}
}
@@ -2,5 +2,7 @@
namespace mROA.Implementation.Attributes
{
public class SharedObjectSingletonAttribute : Attribute { }
public class SharedObjectSingletonAttribute : Attribute
{
}
}
@@ -7,7 +7,7 @@ namespace mROA.Implementation.Backend
private int _currentId;
public int GetNextIdentity()
{
{
return ++_currentId;
}
@@ -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());
+4 -4
View File
@@ -8,12 +8,12 @@ namespace mROA.Implementation.Backend
{
private readonly Dictionary<int, INextGenerationInteractionModule> _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>(T dependency)
{
if (dependency is ISerializationToolkit serializationToolkit)
if (dependency is ISerializationToolkit serializationToolkit)
_serializationToolkit = serializationToolkit;
}
}
}
@@ -51,7 +51,7 @@ namespace mROA.Implementation.Backend
public T GetObject<T>(ComplexObjectIdentifier id)
{
var value = _storage.GetValue(id.ContextId);
if (value == 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());
repository.ClearObject(id);
}
public T GetObject<T>(ComplexObjectIdentifier id)
{
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
@@ -7,7 +7,8 @@ namespace mROA.Implementation
{
public class CancellationRepository : ICancellationRepository
{
private Dictionary<Guid, CancellationTokenSource> _cancellations = new();
private Dictionary<Guid, CancellationTokenSource> _cancellations = new();
public void RegisterCancellation(Guid id, CancellationTokenSource cts)
{
_cancellations.TryAdd(id, cts);
@@ -25,7 +26,6 @@ namespace mROA.Implementation
public void Inject<T>(T dependency)
{
}
}
}
@@ -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} }}";
@@ -36,7 +36,7 @@ namespace mROA.Implementation
var interaction = _hub.GetInteracion(id);
produced.Inject(interaction);
return produced;
}
}
+1
View File
@@ -18,6 +18,7 @@ namespace mROA.Implementation
{
return null;
}
return _array[index];
}
@@ -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()}");
}
@@ -2,7 +2,7 @@
namespace mROA.Implementation.Frontend
{
public class RemoteException : Exception
public class RemoteException : Exception
{
public Guid CallRequestId;
private readonly string _error;
@@ -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
});
}
}
}
}
+10 -1
View File
@@ -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
}
}
@@ -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);
}
@@ -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());
@@ -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>(T dependency)
{
if (dependency is IRepresentationModule serialisationModule)