Очистка от устаревшего кода

This commit is contained in:
2025-03-11 14:43:16 +03:00
parent 22016f1c81
commit 8beca7f8d7
9 changed files with 56 additions and 79 deletions
+7 -17
View File
@@ -2,30 +2,20 @@ using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using mROA.Implementation; using mROA.Implementation;
using mROA.Implementation.CommandExecution;
namespace mROA.Abstract namespace mROA.Abstract
{ {
public interface ISerialisationModule : IInjectableModule
{
void HandleIncomingRequest(int clientId, byte[] message);
void PostResponse(NetworkMessage message, int clientId);
void SendWelcomeMessage(int clientId);
public interface IFrontendSerialisationModule : IInjectableModule
{
int ClientId { get; }
Task<T> GetNextCommandExecution<T>(Guid requestId) where T : ICommandExecution;
Task<FinalCommandExecution<T>> GetFinalCommandExecution<T>(Guid requestId);
void PostCallRequest(ICallRequest callRequest);
}
}
public interface IRepresentationModule : IInjectableModule public interface IRepresentationModule : IInjectableModule
{ {
int Id { get; } int Id { get; }
Task<T> GetMessageAsync<T>(Guid? requestId = null, MessageType? messageType = null, CancellationToken token = default);
Task<T> GetMessageAsync<T>(Guid? requestId = null, MessageType? messageType = null,
CancellationToken token = default);
T GetMessage<T>(Guid? requestId = null, MessageType? messageType = null); T GetMessage<T>(Guid? requestId = null, MessageType? messageType = null);
Task<byte[]> GetRawMessage(Guid? requestId = null, MessageType? messageType = null, CancellationToken token = default);
Task<byte[]> GetRawMessage(Guid? requestId = null, MessageType? messageType = null,
CancellationToken token = default);
Task PostCallMessageAsync<T>(Guid id, MessageType messageType, T payload) where T : notnull; Task PostCallMessageAsync<T>(Guid id, MessageType messageType, T payload) where T : notnull;
Task PostCallMessageAsync(Guid id, MessageType messageType, object payload, Type payloadType); Task PostCallMessageAsync(Guid id, MessageType messageType, object payload, Type payloadType);
@@ -81,7 +81,7 @@ namespace mROA.Implementation.Backend
if (invoker.ParameterTypes.Length != 0) if (invoker.ParameterTypes.Length != 0)
{ {
castedParams = new object[invoker.ParameterTypes.Length]; castedParams = new object[invoker.ParameterTypes.Length];
for (int i = 0; i < castedParams.Length; i++) for (var i = 0; i < castedParams.Length; i++)
{ {
castedParams[i] = _serialization.Cast(command.Parameters![i], invoker.ParameterTypes[i]); castedParams[i] = _serialization.Cast(command.Parameters![i], invoker.ParameterTypes[i]);
} }
@@ -89,15 +89,16 @@ namespace mROA.Implementation.Backend
var execContext = new RequestContext(command.Id, representationModule.Id); var execContext = new RequestContext(command.Id, representationModule.Id);
if (invoker is AsyncMethodInvoker { IsVoid: false } asyncNonVoidMethodInvoker) switch (invoker)
{
case AsyncMethodInvoker { IsVoid: false } asyncNonVoidMethodInvoker:
return TypedExecuteAsync(asyncNonVoidMethodInvoker, context, castedParams, command, return TypedExecuteAsync(asyncNonVoidMethodInvoker, context, castedParams, command,
_cancellationRepo, _cancellationRepo,
representationModule, execContext); representationModule, execContext);
case AsyncMethodInvoker asyncMethodInvoker:
if (invoker is AsyncMethodInvoker asyncMethodInvoker)
return ExecuteAsync(asyncMethodInvoker, context, castedParams, command, _cancellationRepo, return ExecuteAsync(asyncMethodInvoker, context, castedParams, command, _cancellationRepo,
representationModule, execContext); representationModule, execContext);
default:
var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext); var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext);
if (command.CommandId == -1) if (command.CommandId == -1)
{ {
@@ -109,6 +110,7 @@ namespace mROA.Implementation.Backend
return result; return result;
} }
}
catch (Exception e) catch (Exception e)
{ {
return new ExceptionCommandExecution return new ExceptionCommandExecution
@@ -12,7 +12,7 @@ namespace mROA.Implementation.Backend
{ {
private const int StartupSize = 1024; private const int StartupSize = 1024;
private const int GrowSize = 128; private const int GrowSize = 128;
public static object[] EventBinders = new object[] { }; public static object[] EventBinders = { };
private static int LastDebugId = -1; private static int LastDebugId = -1;
private int _debugId = -1; private int _debugId = -1;
@@ -55,12 +55,7 @@ namespace mROA.Implementation.Backend
_lastIndexFinder = Task.FromResult(id.ContextId); _lastIndexFinder = Task.FromResult(id.ContextId);
} }
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell) public T GetObject<T>(ComplexObjectIdentifier id)
{
return (T)GetObject(sharedObjectShellShell.Identifier.ContextId);
}
public T? GetObject<T>(ComplexObjectIdentifier id)
{ {
return id.ContextId == -1 || _storage.Length <= id.ContextId return id.ContextId == -1 || _storage.Length <= id.ContextId
? throw new NullReferenceException("Cannot find that object. It is null") ? throw new NullReferenceException("Cannot find that object. It is null")
@@ -99,12 +94,6 @@ namespace mROA.Implementation.Backend
Activator.CreateInstance); Activator.CreateInstance);
} }
public object GetObject(int id)
{
// Debug.Log($"Reading object {id} from repository with debug ID {_debugId}");
return (id == -1 || _storage.Length <= id ? null : _storage[id]) ?? throw new NullReferenceException();
}
private int FindLastIndex() private int FindLastIndex()
{ {
for (var i = 0; i < _storage.Length; i++) for (var i = 0; i < _storage.Length; i++)
@@ -8,13 +8,14 @@ namespace mROA.Implementation.Backend
{ {
public class NetworkGatewayModule : IGatewayModule public class NetworkGatewayModule : IGatewayModule
{ {
private readonly Type? _interactionModuleType;
private readonly IInjectableModule[]? _injectableModules; private readonly IInjectableModule[]? _injectableModules;
private readonly Type? _interactionModuleType;
private readonly TcpListener _tcpListener; private readonly TcpListener _tcpListener;
private IConnectionHub? _hub; private IConnectionHub? _hub;
private ISerializationToolkit? _serialization; private ISerializationToolkit? _serialization;
public NetworkGatewayModule(IPEndPoint endpoint, Type interactionModuleType, IInjectableModule[] injectableModules) public NetworkGatewayModule(IPEndPoint endpoint, Type interactionModuleType,
IInjectableModule[] injectableModules)
{ {
_tcpListener = new(endpoint); _tcpListener = new(endpoint);
_interactionModuleType = interactionModuleType; _interactionModuleType = interactionModuleType;
@@ -44,6 +45,19 @@ namespace mROA.Implementation.Backend
_tcpListener.Stop(); _tcpListener.Stop();
} }
public void Inject<T>(T dependency)
{
switch (dependency)
{
case IConnectionHub interactionModule:
_hub = interactionModule;
break;
case ISerializationToolkit serializationToolkit:
_serialization = serializationToolkit;
break;
}
}
private void HandleIncomingConnections() private void HandleIncomingConnections()
{ {
if (_hub is null) if (_hub is null)
@@ -79,13 +93,5 @@ namespace mROA.Implementation.Backend
Console.WriteLine("Client registered"); Console.WriteLine("Client registered");
} }
} }
public void Inject<T>(T dependency)
{
if (dependency is IConnectionHub interactionModule)
_hub = interactionModule;
if (dependency is ISerializationToolkit serializationToolkit)
_serialization = serializationToolkit;
}
} }
} }
+1
View File
@@ -13,6 +13,7 @@ namespace mROA.Implementation
public int OwnerId public int OwnerId
{ {
get => OwnerFunc(); get => OwnerFunc();
// ReSharper disable once UnusedMember.Global
set { OwnerFunc = () => value; } set { OwnerFunc = () => value; }
} }
} }
@@ -98,20 +98,13 @@ namespace mROA.Implementation.Frontend
var result = _executeModule.Execute(request, _contextRepository, _representationModule); var result = _executeModule.Execute(request, _contextRepository, _representationModule);
var resultType = MessageType.Unknown; var resultType = result switch
switch (result)
{ {
case FinalCommandExecution: FinalCommandExecution => MessageType.FinishedCommandExecution,
resultType = MessageType.FinishedCommandExecution; AsyncCommandExecution => MessageType.AsyncCommandExecution,
break; ExceptionCommandExecution => MessageType.ExceptionCommandExecution,
case AsyncCommandExecution: _ => MessageType.Unknown
resultType = MessageType.AsyncCommandExecution; };
break;
case ExceptionCommandExecution:
resultType = MessageType.ExceptionCommandExecution;
break;
}
_representationModule.PostCallMessage(request.Id, resultType, result, result.GetType()); _representationModule.PostCallMessage(request.Id, resultType, result, result.GetType());
} }
@@ -81,7 +81,7 @@ namespace mROA.Implementation
var secondBit = (byte)BaseStream.ReadByte(); var secondBit = (byte)BaseStream.ReadByte();
var len = BitConverter.ToUInt16(new[] { firstBit, secondBit }); var len = BitConverter.ToUInt16(new[] { firstBit, secondBit });
var localSpan = _buffer.Slice(0, len); var localSpan = _buffer[..len];
await BaseStream.ReadExactlyAsync(localSpan); await BaseStream.ReadExactlyAsync(localSpan);
@@ -60,10 +60,5 @@ namespace mROA.Implementation
if (dependency is IRepresentationModuleProducer serialisationModule) if (dependency is IRepresentationModuleProducer serialisationModule)
_representationProducer = serialisationModule; _representationProducer = serialisationModule;
} }
public object GetObject(int id)
{
throw new NotSupportedException();
}
} }
} }
+1
View File
@@ -10,6 +10,7 @@ namespace mROA.Implementation
{ {
public interface ISharedObjectShell public interface ISharedObjectShell
{ {
// ReSharper disable once UnusedMemberInSuper.Global
IEndPointContext EndPointContext { get; set; } IEndPointContext EndPointContext { get; set; }
ComplexObjectIdentifier Identifier { get; set; } ComplexObjectIdentifier Identifier { get; set; }
object UniversalValue { get; set; } object UniversalValue { get; set; }