Очистка от устаревшего кода
This commit is contained in:
@@ -2,30 +2,20 @@ using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using mROA.Implementation;
|
||||
using mROA.Implementation.CommandExecution;
|
||||
|
||||
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
|
||||
{
|
||||
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);
|
||||
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(Guid id, MessageType messageType, object payload, Type payloadType);
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace mROA.Implementation.Backend
|
||||
if (invoker.ParameterTypes.Length != 0)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
@@ -89,25 +89,27 @@ namespace mROA.Implementation.Backend
|
||||
|
||||
var execContext = new RequestContext(command.Id, representationModule.Id);
|
||||
|
||||
if (invoker is AsyncMethodInvoker { IsVoid: false } asyncNonVoidMethodInvoker)
|
||||
return TypedExecuteAsync(asyncNonVoidMethodInvoker, context, castedParams, command,
|
||||
_cancellationRepo,
|
||||
representationModule, execContext);
|
||||
|
||||
if (invoker is AsyncMethodInvoker asyncMethodInvoker)
|
||||
return ExecuteAsync(asyncMethodInvoker, context, castedParams, command, _cancellationRepo,
|
||||
representationModule, execContext);
|
||||
|
||||
var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext);
|
||||
if (command.CommandId == -1)
|
||||
switch (invoker)
|
||||
{
|
||||
case AsyncMethodInvoker { IsVoid: false } asyncNonVoidMethodInvoker:
|
||||
return TypedExecuteAsync(asyncNonVoidMethodInvoker, context, castedParams, command,
|
||||
_cancellationRepo,
|
||||
representationModule, execContext);
|
||||
case AsyncMethodInvoker asyncMethodInvoker:
|
||||
return ExecuteAsync(asyncMethodInvoker, context, castedParams, command, _cancellationRepo,
|
||||
representationModule, execContext);
|
||||
default:
|
||||
var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext);
|
||||
if (command.CommandId == -1)
|
||||
{
|
||||
#if TRACE
|
||||
Console.WriteLine("Disposing object");
|
||||
#endif
|
||||
contextRepository.ClearObject(command.ObjectId);
|
||||
}
|
||||
contextRepository.ClearObject(command.ObjectId);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace mROA.Implementation.Backend
|
||||
{
|
||||
private const int StartupSize = 1024;
|
||||
private const int GrowSize = 128;
|
||||
public static object[] EventBinders = new object[] { };
|
||||
public static object[] EventBinders = { };
|
||||
|
||||
private static int LastDebugId = -1;
|
||||
private int _debugId = -1;
|
||||
@@ -55,12 +55,7 @@ namespace mROA.Implementation.Backend
|
||||
_lastIndexFinder = Task.FromResult(id.ContextId);
|
||||
}
|
||||
|
||||
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
||||
{
|
||||
return (T)GetObject(sharedObjectShellShell.Identifier.ContextId);
|
||||
}
|
||||
|
||||
public T? GetObject<T>(ComplexObjectIdentifier id)
|
||||
public T GetObject<T>(ComplexObjectIdentifier id)
|
||||
{
|
||||
return id.ContextId == -1 || _storage.Length <= id.ContextId
|
||||
? throw new NullReferenceException("Cannot find that object. It is null")
|
||||
@@ -99,12 +94,6 @@ namespace mROA.Implementation.Backend
|
||||
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()
|
||||
{
|
||||
for (var i = 0; i < _storage.Length; i++)
|
||||
|
||||
@@ -8,13 +8,14 @@ namespace mROA.Implementation.Backend
|
||||
{
|
||||
public class NetworkGatewayModule : IGatewayModule
|
||||
{
|
||||
private readonly Type? _interactionModuleType;
|
||||
private readonly IInjectableModule[]? _injectableModules;
|
||||
private readonly Type? _interactionModuleType;
|
||||
private readonly TcpListener _tcpListener;
|
||||
private IConnectionHub? _hub;
|
||||
private ISerializationToolkit? _serialization;
|
||||
|
||||
public NetworkGatewayModule(IPEndPoint endpoint, Type interactionModuleType, IInjectableModule[] injectableModules)
|
||||
public NetworkGatewayModule(IPEndPoint endpoint, Type interactionModuleType,
|
||||
IInjectableModule[] injectableModules)
|
||||
{
|
||||
_tcpListener = new(endpoint);
|
||||
_interactionModuleType = interactionModuleType;
|
||||
@@ -44,6 +45,19 @@ namespace mROA.Implementation.Backend
|
||||
_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()
|
||||
{
|
||||
if (_hub is null)
|
||||
@@ -79,13 +93,5 @@ namespace mROA.Implementation.Backend
|
||||
Console.WriteLine("Client registered");
|
||||
}
|
||||
}
|
||||
|
||||
public void Inject<T>(T dependency)
|
||||
{
|
||||
if (dependency is IConnectionHub interactionModule)
|
||||
_hub = interactionModule;
|
||||
if (dependency is ISerializationToolkit serializationToolkit)
|
||||
_serialization = serializationToolkit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ namespace mROA.Implementation
|
||||
public int OwnerId
|
||||
{
|
||||
get => OwnerFunc();
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
set { OwnerFunc = () => value; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,20 +98,13 @@ namespace mROA.Implementation.Frontend
|
||||
|
||||
var result = _executeModule.Execute(request, _contextRepository, _representationModule);
|
||||
|
||||
var resultType = MessageType.Unknown;
|
||||
|
||||
switch (result)
|
||||
var resultType = result switch
|
||||
{
|
||||
case FinalCommandExecution:
|
||||
resultType = MessageType.FinishedCommandExecution;
|
||||
break;
|
||||
case AsyncCommandExecution:
|
||||
resultType = MessageType.AsyncCommandExecution;
|
||||
break;
|
||||
case ExceptionCommandExecution:
|
||||
resultType = MessageType.ExceptionCommandExecution;
|
||||
break;
|
||||
}
|
||||
FinalCommandExecution => MessageType.FinishedCommandExecution,
|
||||
AsyncCommandExecution => MessageType.AsyncCommandExecution,
|
||||
ExceptionCommandExecution => MessageType.ExceptionCommandExecution,
|
||||
_ => MessageType.Unknown
|
||||
};
|
||||
|
||||
_representationModule.PostCallMessage(request.Id, resultType, result, result.GetType());
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace mROA.Implementation
|
||||
var secondBit = (byte)BaseStream.ReadByte();
|
||||
|
||||
var len = BitConverter.ToUInt16(new[] { firstBit, secondBit });
|
||||
var localSpan = _buffer.Slice(0, len);
|
||||
var localSpan = _buffer[..len];
|
||||
|
||||
await BaseStream.ReadExactlyAsync(localSpan);
|
||||
|
||||
|
||||
@@ -60,10 +60,5 @@ namespace mROA.Implementation
|
||||
if (dependency is IRepresentationModuleProducer serialisationModule)
|
||||
_representationProducer = serialisationModule;
|
||||
}
|
||||
|
||||
public object GetObject(int id)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ namespace mROA.Implementation
|
||||
{
|
||||
public interface ISharedObjectShell
|
||||
{
|
||||
// ReSharper disable once UnusedMemberInSuper.Global
|
||||
IEndPointContext EndPointContext { get; set; }
|
||||
ComplexObjectIdentifier Identifier { get; set; }
|
||||
object UniversalValue { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user