Автоматический клинап
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace mROA.Abstract
|
||||
{
|
||||
public delegate void ConnectionHandler(IRepresentationModule representationModule);
|
||||
|
||||
public delegate void DisconnectionHandler(IRepresentationModule representationModule);
|
||||
|
||||
public interface IConnectionHub : IInjectableModule
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
{
|
||||
IContextRepository RealRepository { get; }
|
||||
IContextRepository RemoteRepository { get; }
|
||||
int HostId { get; }
|
||||
int HostId { get; }
|
||||
int OwnerId { get; }
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,5 @@ namespace mROA.Abstract
|
||||
{
|
||||
public interface IFrontendBridge : IInjectableModule
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using System;
|
||||
namespace mROA.Abstract
|
||||
{
|
||||
public interface IGatewayModule : IDisposable, IInjectableModule
|
||||
{
|
||||
{
|
||||
void Run();
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ namespace mROA.Abstract
|
||||
{
|
||||
public interface IRequestExtractor : IInjectableModule
|
||||
{
|
||||
Task StartExtraction();
|
||||
Task StartExtraction();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,5 @@ namespace mROA.Abstract
|
||||
object? Deserialize(Span<byte> rawData, Type type);
|
||||
T? Cast<T>(object? nonCasted);
|
||||
object? Cast(object? nonCasted, Type type);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace mROA
|
||||
return totalRead;
|
||||
}
|
||||
}
|
||||
|
||||
return totalRead;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DefineConstants />
|
||||
<DefineConstants/>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
@@ -25,7 +25,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.2"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user