diff --git a/Example.Events.Backend/Program.cs b/Example.Events.Backend/Program.cs index 3bd1f89..d42eb89 100644 --- a/Example.Events.Backend/Program.cs +++ b/Example.Events.Backend/Program.cs @@ -14,7 +14,6 @@ class Program static void Main(string[] args) { var builder = new FullMixBuilder(); - // builder.UseJsonSerialisation(); builder.Modules.Add(new CborSerializationToolkit()); builder.Modules.Add(new BackendIdentityGenerator()); builder.UseNetworkGateway(IPEndPoint.Parse("192.168.1.101:6000"), typeof(NextGenerationInteractionModule), diff --git a/mROA/Implementation/Backend/BasicExecutionModule.cs b/mROA/Implementation/Backend/BasicExecutionModule.cs index 8b056ba..e36ac30 100644 --- a/mROA/Implementation/Backend/BasicExecutionModule.cs +++ b/mROA/Implementation/Backend/BasicExecutionModule.cs @@ -183,25 +183,6 @@ namespace mROA.Implementation.Backend 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 { Id = command.Id @@ -245,24 +226,6 @@ namespace mROA.Implementation.Backend multiClientOwnershipRepository?.FreeOwnership(); }); - - // result.ContinueWith(t => - // { - // var finalResult = t.GetType().GetProperty("Result")?.GetValue(t); - // var payload = new FinalCommandExecution - // { - // 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 { Id = command.Id diff --git a/mROA/Implementation/Backend/JsonSerialisationModule.cs b/mROA/Implementation/Backend/JsonSerialisationModule.cs deleted file mode 100644 index 557331a..0000000 --- a/mROA/Implementation/Backend/JsonSerialisationModule.cs +++ /dev/null @@ -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(message)!; -// Console.WriteLine(Encoding.Default.GetString(input.Data)); -// if (input.SchemaId == MessageType.CallRequest) -// { -// var command = JsonSerializer.Deserialize(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 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; -// } -// } -// } \ No newline at end of file diff --git a/mROA/Implementation/Backend/StreamBasedInteractionModule.cs b/mROA/Implementation/Backend/StreamBasedInteractionModule.cs deleted file mode 100644 index 0427209..0000000 --- a/mROA/Implementation/Backend/StreamBasedInteractionModule.cs +++ /dev/null @@ -1,66 +0,0 @@ -// using mROA.Abstract; -// -// namespace mROA.Implementation.Backend; -// -// public class StreamBasedInteractionModule : IInteractionModule -// { -// internal ISerialisationModule _serialisationModule; -// private readonly Dictionary _streams = new(); -// internal Action? _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 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 dependency) -// { -// if (dependency is ISerialisationModule serialisationModule) -// { -// _handler = serialisationModule.HandleIncomingRequest; -// _serialisationModule = serialisationModule; -// } -// } -// -// } \ No newline at end of file diff --git a/mROA/Implementation/ComplexContextRepository.cs b/mROA/Implementation/ComplexContextRepository.cs index 536a36c..8f44c78 100644 --- a/mROA/Implementation/ComplexContextRepository.cs +++ b/mROA/Implementation/ComplexContextRepository.cs @@ -62,10 +62,6 @@ namespace mROA.Implementation throw new NotImplementedException(); } - // public object GetSingleObject(Type type, int ownerId) - // { - // } - public int GetObjectIndex(object o, IEndPointContext context) { throw new NotImplementedException(); diff --git a/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs b/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs deleted file mode 100644 index 98bae9a..0000000 --- a/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs +++ /dev/null @@ -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 GetNextCommandExecution(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(receiveMessage)!; -// -// while (message.Id != requestId) -// { -// receiveMessage = await _interactionModule.ReceiveMessage(); -// message = JsonSerializer.Deserialize(receiveMessage)!; -// } -// -// var parsed = JsonSerializer.Deserialize(message.Data)!; -// -// if (message.SchemaId == MessageType.ErrorCommandExecution) -// { -// throw new RemoteException(JsonSerializer.Deserialize(message.Data)!.Exception) -// { CallRequestId = requestId }; -// } -// -// return parsed; -// } -// -// public async Task> GetFinalCommandExecution(Guid requestId) -// { -// if (_interactionModule is null) -// throw new Exception("Interaction module not initialized"); -// -// var receiveMessage = await _interactionModule.ReceiveMessage(); -// -// var message = JsonSerializer.Deserialize(receiveMessage)!; -// while (message.Id != requestId) -// { -// receiveMessage = await _interactionModule.ReceiveMessage(); -// -// message = JsonSerializer.Deserialize(receiveMessage)!; -// } -// -// if (message.SchemaId == MessageType.ErrorCommandExecution) -// { -// throw new RemoteException(JsonSerializer.Deserialize(message.Data)!.Exception) -// { CallRequestId = requestId }; -// } -// -// return JsonSerializer.Deserialize>(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 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}"; - } -} \ No newline at end of file diff --git a/mROA/Implementation/Frontend/RemoteException.cs b/mROA/Implementation/Frontend/RemoteException.cs new file mode 100644 index 0000000..093d9c1 --- /dev/null +++ b/mROA/Implementation/Frontend/RemoteException.cs @@ -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}"; + } +} \ No newline at end of file diff --git a/mROA/Implementation/Frontend/RequestExtractor.cs b/mROA/Implementation/Frontend/RequestExtractor.cs index cb87c79..0788ba9 100644 --- a/mROA/Implementation/Frontend/RequestExtractor.cs +++ b/mROA/Implementation/Frontend/RequestExtractor.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using mROA.Abstract; @@ -59,9 +58,7 @@ namespace mROA.Implementation.Frontend throw new NullReferenceException("Representation module is null."); if (_methodRepository == null) throw new NullReferenceException("Method repository is null."); - - // await Task.Yield(); - + var multiClientOwnershipRepository = TransmissionConfig.OwnershipRepository as MultiClientOwnershipRepository; multiClientOwnershipRepository?.RegisterOwnership(_representationModule.Id); @@ -120,7 +117,6 @@ namespace mROA.Implementation.Frontend ExceptionCommandExecution => MessageType.ExceptionCommandExecution, _ => MessageType.Unknown }; - _representationModule.PostCallMessage(request.Id, resultType, result, result.GetType()); } else diff --git a/mROA/Implementation/Frontend/StreamBasedFrontendInteractionModule.cs b/mROA/Implementation/Frontend/StreamBasedFrontendInteractionModule.cs deleted file mode 100644 index a94a374..0000000 --- a/mROA/Implementation/Frontend/StreamBasedFrontendInteractionModule.cs +++ /dev/null @@ -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(); -// } -// -// public NetworkMessage LastMessage() -// { -// return null; -// } -// -// -// -// public async Task 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 dependency) -// { -// } -// } \ No newline at end of file diff --git a/mROA/Implementation/RemoteObjectBase.cs b/mROA/Implementation/RemoteObjectBase.cs index 225a010..a35e734 100644 --- a/mROA/Implementation/RemoteObjectBase.cs +++ b/mROA/Implementation/RemoteObjectBase.cs @@ -86,13 +86,6 @@ namespace mROA.Implementation successResponse, errorResponse }, cancellationToken); - // if (cancellationToken.IsCancellationRequested) - // { - // await _representationModule.PostCallMessageAsync(request.Id, MessageType.CancelRequest, request.Id); - // localTokenSource.Cancel(); - // cancellationToken.ThrowIfCancellationRequested(); - // } - if (successResponse.IsCompletedSuccessfully) { localTokenSource.Cancel();