Чистка от старого кода
This commit is contained in:
@@ -14,7 +14,6 @@ class Program
|
|||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var builder = new FullMixBuilder();
|
var builder = new FullMixBuilder();
|
||||||
// builder.UseJsonSerialisation();
|
|
||||||
builder.Modules.Add(new CborSerializationToolkit());
|
builder.Modules.Add(new CborSerializationToolkit());
|
||||||
builder.Modules.Add(new BackendIdentityGenerator());
|
builder.Modules.Add(new BackendIdentityGenerator());
|
||||||
builder.UseNetworkGateway(IPEndPoint.Parse("192.168.1.101:6000"), typeof(NextGenerationInteractionModule),
|
builder.UseNetworkGateway(IPEndPoint.Parse("192.168.1.101:6000"), typeof(NextGenerationInteractionModule),
|
||||||
|
|||||||
@@ -183,25 +183,6 @@ namespace mROA.Implementation.Backend
|
|||||||
multiClientOwnershipRepository?.FreeOwnership();
|
multiClientOwnershipRepository?.FreeOwnership();
|
||||||
});
|
});
|
||||||
|
|
||||||
// result.ContinueWith(_ =>
|
|
||||||
// {
|
|
||||||
// if (token.IsCancellationRequested)
|
|
||||||
// return;
|
|
||||||
//
|
|
||||||
// var payload = new FinalCommandExecution
|
|
||||||
// {
|
|
||||||
// Id = command.Id
|
|
||||||
// };
|
|
||||||
// _cancellationRepo?.FreeCancelation(command.Id);
|
|
||||||
//
|
|
||||||
// var multiClientOwnershipRepository =
|
|
||||||
// TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository;
|
|
||||||
//
|
|
||||||
// multiClientOwnershipRepository?.RegisterOwnership(representationModule.Id);
|
|
||||||
// representationModule.PostCallMessage(command.Id, MessageType.FinishedCommandExecution, payload);
|
|
||||||
// multiClientOwnershipRepository?.FreeOwnership();
|
|
||||||
// }, token);
|
|
||||||
|
|
||||||
return new AsyncCommandExecution
|
return new AsyncCommandExecution
|
||||||
{
|
{
|
||||||
Id = command.Id
|
Id = command.Id
|
||||||
@@ -245,24 +226,6 @@ namespace mROA.Implementation.Backend
|
|||||||
multiClientOwnershipRepository?.FreeOwnership();
|
multiClientOwnershipRepository?.FreeOwnership();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// result.ContinueWith(t =>
|
|
||||||
// {
|
|
||||||
// var finalResult = t.GetType().GetProperty("Result")?.GetValue(t);
|
|
||||||
// var payload = new FinalCommandExecution<object>
|
|
||||||
// {
|
|
||||||
// Id = command.Id,
|
|
||||||
// Result = finalResult
|
|
||||||
// };
|
|
||||||
// _cancellationRepo!.FreeCancelation(command.Id);
|
|
||||||
//
|
|
||||||
// var multiClientOwnershipRepository =
|
|
||||||
// TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository;
|
|
||||||
// multiClientOwnershipRepository?.RegisterOwnership(representationModule.Id);
|
|
||||||
// representationModule.PostCallMessage(command.Id, MessageType.FinishedCommandExecution, payload);
|
|
||||||
// multiClientOwnershipRepository?.FreeOwnership();
|
|
||||||
// }, token);
|
|
||||||
|
|
||||||
return new AsyncCommandExecution
|
return new AsyncCommandExecution
|
||||||
{
|
{
|
||||||
Id = command.Id
|
Id = command.Id
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
// using System.Text;
|
|
||||||
// using System.Text.Json;
|
|
||||||
// using mROA.Abstract;
|
|
||||||
//
|
|
||||||
// namespace mROA.Implementation.Backend;
|
|
||||||
//
|
|
||||||
// public class JsonSerialisationModule : ISerialisationModule
|
|
||||||
// {
|
|
||||||
// private IInteractionModule? _dataSource;
|
|
||||||
// private IExecuteModule? _executeModule;
|
|
||||||
// private IMethodRepository? _methodRepository;
|
|
||||||
// private IContextRepository? _contextRepo;
|
|
||||||
//
|
|
||||||
// public void HandleIncomingRequest(int clientId, byte[] message)
|
|
||||||
// {
|
|
||||||
// MultiClientOwnershipRepository? ownership = null;
|
|
||||||
// if (TransmissionConfig.OwnershipRepository is MultiClientOwnershipRepository)
|
|
||||||
// {
|
|
||||||
// ownership = TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository;
|
|
||||||
// ownership.RegisterOwnership(clientId);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// NetworkMessage input = JsonSerializer.Deserialize<NetworkMessage>(message)!;
|
|
||||||
// Console.WriteLine(Encoding.Default.GetString(input.Data));
|
|
||||||
// if (input.SchemaId == MessageType.CallRequest)
|
|
||||||
// {
|
|
||||||
// var command = JsonSerializer.Deserialize<DefaultCallRequest>(input.Data)!;
|
|
||||||
// if (command.Parameter is not null)
|
|
||||||
// {
|
|
||||||
// var parameter = _methodRepository!.GetMethod(command.CommandId).GetParameters().First().ParameterType;
|
|
||||||
// var jsElement = (JsonElement)command.Parameter;
|
|
||||||
// command.Parameter = jsElement.Deserialize(parameter);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// var response = _executeModule!.Execute(command, _contextRepo);
|
|
||||||
// response.ClientId = clientId;
|
|
||||||
// var resultType = response is FinalCommandExecution
|
|
||||||
// ? MessageType.FinishedCommandExecution
|
|
||||||
// : MessageType.ErrorCommandExecution;
|
|
||||||
// PostResponse(
|
|
||||||
// new NetworkMessage
|
|
||||||
// {
|
|
||||||
// SchemaId = resultType,
|
|
||||||
// Id = command.CallRequestId,
|
|
||||||
// Data = JsonSerializer.SerializeToUtf8Bytes(response, response.GetType())
|
|
||||||
// }, clientId);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// ownership?.FreeOwnership();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void PostResponse(NetworkMessage message, int clientId)
|
|
||||||
// {
|
|
||||||
// _dataSource!.SendTo(clientId, JsonSerializer.SerializeToUtf8Bytes(message));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void SendWelcomeMessage(int clientId)
|
|
||||||
// {
|
|
||||||
// _dataSource!.SendTo(clientId, JsonSerializer.SerializeToUtf8Bytes(new NetworkMessage { Data = JsonSerializer.SerializeToUtf8Bytes(new IdAssingnment { Id = clientId }), SchemaId = MessageType.IdAssigning}));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void Inject<T>(T dependency)
|
|
||||||
// {
|
|
||||||
// switch (dependency)
|
|
||||||
// {
|
|
||||||
// case IInteractionModule interactionModule:
|
|
||||||
// _dataSource = interactionModule;
|
|
||||||
// break;
|
|
||||||
// case IExecuteModule executeModule:
|
|
||||||
// _executeModule = executeModule;
|
|
||||||
// break;
|
|
||||||
// case IMethodRepository methodRepository:
|
|
||||||
// _methodRepository = methodRepository;
|
|
||||||
// break;
|
|
||||||
// case IContextRepository contextRepository:
|
|
||||||
// _contextRepo = contextRepository;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
// using mROA.Abstract;
|
|
||||||
//
|
|
||||||
// namespace mROA.Implementation.Backend;
|
|
||||||
//
|
|
||||||
// public class StreamBasedInteractionModule : IInteractionModule
|
|
||||||
// {
|
|
||||||
// internal ISerialisationModule _serialisationModule;
|
|
||||||
// private readonly Dictionary<int, Stream> _streams = new();
|
|
||||||
// internal Action<int, byte[]>? _handler;
|
|
||||||
//
|
|
||||||
// public void RegisterSource(Stream stream)
|
|
||||||
// {
|
|
||||||
// var id = Random.Shared.Next();
|
|
||||||
// _streams.Add(id, stream);
|
|
||||||
// _ = ListenTo((id, stream), _handler!);
|
|
||||||
// _serialisationModule.SendWelcomeMessage(id);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public Stream GetSource(int clientId)
|
|
||||||
// {
|
|
||||||
// return _streams.GetValueOrDefault(clientId, Stream.Null);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void SendTo(int clientId, byte[] message)
|
|
||||||
// {
|
|
||||||
// if (!_streams.TryGetValue(clientId, out var stream))
|
|
||||||
// {
|
|
||||||
// throw new KeyNotFoundException($"Client {clientId} not found");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// stream.Write(BitConverter.GetBytes((ushort)message.Length), 0, sizeof(ushort));
|
|
||||||
// stream.Write(message, 0, message.Length);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private async Task ListenTo((int id, Stream stream) client, Action<int, byte[]> action)
|
|
||||||
// {
|
|
||||||
// TransmissionConfig.OwnershipRepository = new MultiClientOwnershipRepository();
|
|
||||||
// const int bufferSize = ushort.MaxValue;
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// byte[] buffer = new byte[bufferSize];
|
|
||||||
// while (client.stream.CanRead)
|
|
||||||
// {
|
|
||||||
// await client.stream.ReadExactlyAsync(buffer, 0, 2);
|
|
||||||
// var len = BitConverter.ToUInt16(buffer, 0);
|
|
||||||
// await client.stream.ReadExactlyAsync(buffer, 0, len);
|
|
||||||
// _ = Task.Run(() => action(client.id, buffer[..len]));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch (Exception)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine($"Client handling finished:{client.id}");
|
|
||||||
// _streams.Remove(client.id);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void Inject<T>(T dependency)
|
|
||||||
// {
|
|
||||||
// if (dependency is ISerialisationModule serialisationModule)
|
|
||||||
// {
|
|
||||||
// _handler = serialisationModule.HandleIncomingRequest;
|
|
||||||
// _serialisationModule = serialisationModule;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
@@ -62,10 +62,6 @@ namespace mROA.Implementation
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public object GetSingleObject(Type type, int ownerId)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
public int GetObjectIndex<T>(object o, IEndPointContext context)
|
public int GetObjectIndex<T>(object o, IEndPointContext context)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace mROA.Implementation.Frontend
|
|
||||||
{
|
|
||||||
// public class JsonFrontendSerialisationModule
|
|
||||||
// : ISerialisationModule.IFrontendSerialisationModule
|
|
||||||
// {
|
|
||||||
// private IInteractionModule.IFrontendInteractionModule? _interactionModule;
|
|
||||||
// public int ClientId => _interactionModule!.ClientId;
|
|
||||||
//
|
|
||||||
// public async Task<T> GetNextCommandExecution<T>(Guid requestId) where T : ICommandExecution
|
|
||||||
// {
|
|
||||||
// if (_interactionModule is null)
|
|
||||||
// throw new Exception("Interaction module not initialized");
|
|
||||||
//
|
|
||||||
// var receiveMessage = await _interactionModule.ReceiveMessage();
|
|
||||||
// var message = JsonSerializer.Deserialize<NetworkMessage>(receiveMessage)!;
|
|
||||||
//
|
|
||||||
// while (message.Id != requestId)
|
|
||||||
// {
|
|
||||||
// receiveMessage = await _interactionModule.ReceiveMessage();
|
|
||||||
// message = JsonSerializer.Deserialize<NetworkMessage>(receiveMessage)!;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// var parsed = JsonSerializer.Deserialize<T>(message.Data)!;
|
|
||||||
//
|
|
||||||
// if (message.SchemaId == MessageType.ErrorCommandExecution)
|
|
||||||
// {
|
|
||||||
// throw new RemoteException(JsonSerializer.Deserialize<ExceptionCommandExecution>(message.Data)!.Exception)
|
|
||||||
// { CallRequestId = requestId };
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return parsed;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public async Task<FinalCommandExecution<T>> GetFinalCommandExecution<T>(Guid requestId)
|
|
||||||
// {
|
|
||||||
// if (_interactionModule is null)
|
|
||||||
// throw new Exception("Interaction module not initialized");
|
|
||||||
//
|
|
||||||
// var receiveMessage = await _interactionModule.ReceiveMessage();
|
|
||||||
//
|
|
||||||
// var message = JsonSerializer.Deserialize<NetworkMessage>(receiveMessage)!;
|
|
||||||
// while (message.Id != requestId)
|
|
||||||
// {
|
|
||||||
// receiveMessage = await _interactionModule.ReceiveMessage();
|
|
||||||
//
|
|
||||||
// message = JsonSerializer.Deserialize<NetworkMessage>(receiveMessage)!;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (message.SchemaId == MessageType.ErrorCommandExecution)
|
|
||||||
// {
|
|
||||||
// throw new RemoteException(JsonSerializer.Deserialize<ExceptionCommandExecution>(message.Data)!.Exception)
|
|
||||||
// { CallRequestId = requestId };
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return JsonSerializer.Deserialize<FinalCommandExecution<T>>(message.Data)!;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void PostCallRequest(ICallRequest callRequest)
|
|
||||||
// {
|
|
||||||
// if (_interactionModule is null)
|
|
||||||
// throw new Exception("Interaction module not initialized");
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// var post = JsonSerializer.SerializeToUtf8Bytes(callRequest, callRequest.GetType());
|
|
||||||
// _interactionModule.PostMessage(JsonSerializer.SerializeToUtf8Bytes(new NetworkMessage
|
|
||||||
// {
|
|
||||||
// Id = callRequest.CallRequestId,
|
|
||||||
// Data = post,
|
|
||||||
// SchemaId = MessageType.CallRequest
|
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void Inject<T>(T dependency)
|
|
||||||
// {
|
|
||||||
// if (dependency is IInteractionModule.IFrontendInteractionModule interactionModule)
|
|
||||||
// _interactionModule = interactionModule;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public class RemoteException : Exception
|
|
||||||
{
|
|
||||||
public Guid CallRequestId;
|
|
||||||
private readonly string _error;
|
|
||||||
|
|
||||||
public RemoteException(string error)
|
|
||||||
{
|
|
||||||
_error = error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Message => $"Error in request {CallRequestId} : {_error}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace mROA.Implementation.Frontend
|
||||||
|
{
|
||||||
|
public class RemoteException : Exception
|
||||||
|
{
|
||||||
|
public Guid CallRequestId;
|
||||||
|
private readonly string _error;
|
||||||
|
|
||||||
|
public RemoteException(string error)
|
||||||
|
{
|
||||||
|
_error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Message => $"Error in request {CallRequestId} : {_error}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
@@ -59,9 +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.");
|
||||||
|
|
||||||
// await Task.Yield();
|
|
||||||
|
|
||||||
var multiClientOwnershipRepository =
|
var multiClientOwnershipRepository =
|
||||||
TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository;
|
TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository;
|
||||||
multiClientOwnershipRepository?.RegisterOwnership(_representationModule.Id);
|
multiClientOwnershipRepository?.RegisterOwnership(_representationModule.Id);
|
||||||
@@ -120,7 +117,6 @@ namespace mROA.Implementation.Frontend
|
|||||||
ExceptionCommandExecution => MessageType.ExceptionCommandExecution,
|
ExceptionCommandExecution => MessageType.ExceptionCommandExecution,
|
||||||
_ => MessageType.Unknown
|
_ => MessageType.Unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
_representationModule.PostCallMessage(request.Id, resultType, result, result.GetType());
|
_representationModule.PostCallMessage(request.Id, resultType, result, result.GetType());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
// public class StreamBasedFrontendInteractionModule : IInteractionModule.IFrontendInteractionModule
|
|
||||||
// {
|
|
||||||
// public Stream? ServerStream { get; set; }
|
|
||||||
// public int ClientId { get; set; }
|
|
||||||
//
|
|
||||||
// public NetworkMessage[] UnhandledMessages()
|
|
||||||
// {
|
|
||||||
// return Array.Empty<NetworkMessage>();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public NetworkMessage LastMessage()
|
|
||||||
// {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// public async Task<byte[]> ReceiveMessage()
|
|
||||||
// {
|
|
||||||
// if (ServerStream is null)
|
|
||||||
// throw new IOException("Server is not connected.");
|
|
||||||
//
|
|
||||||
// const int bufferSize = ushort.MaxValue;
|
|
||||||
//
|
|
||||||
// var buffer = new byte[bufferSize];
|
|
||||||
// if (!ServerStream.CanRead) throw new IOException("Server is not connected.");
|
|
||||||
//
|
|
||||||
// await ServerStream.ReadExactlyAsync(buffer, 0, 2);
|
|
||||||
// var len = BitConverter.ToUInt16(buffer, 0);
|
|
||||||
// await ServerStream.ReadExactlyAsync(buffer, 0, len);
|
|
||||||
//
|
|
||||||
// return buffer[..len];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void PostMessage(byte[] message)
|
|
||||||
// {
|
|
||||||
// if (ServerStream is null)
|
|
||||||
// throw new IOException("Server is not connected.");
|
|
||||||
//
|
|
||||||
// ServerStream.Write(BitConverter.GetBytes((ushort)message.Length), 0, sizeof(ushort));
|
|
||||||
// ServerStream.Write(message, 0, message.Length);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void Inject<T>(T dependency)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -86,13 +86,6 @@ namespace mROA.Implementation
|
|||||||
successResponse, errorResponse
|
successResponse, errorResponse
|
||||||
}, cancellationToken);
|
}, cancellationToken);
|
||||||
|
|
||||||
// if (cancellationToken.IsCancellationRequested)
|
|
||||||
// {
|
|
||||||
// await _representationModule.PostCallMessageAsync(request.Id, MessageType.CancelRequest, request.Id);
|
|
||||||
// localTokenSource.Cancel();
|
|
||||||
// cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (successResponse.IsCompletedSuccessfully)
|
if (successResponse.IsCompletedSuccessfully)
|
||||||
{
|
{
|
||||||
localTokenSource.Cancel();
|
localTokenSource.Cancel();
|
||||||
|
|||||||
Reference in New Issue
Block a user