From 5718f9c313bed63365304a1e11cb7687991c7f7a Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Thu, 27 Feb 2025 08:40:22 +0300 Subject: [PATCH] cbor works --- Example.Backend/Example.Backend.csproj | 4 ++ Example.Backend/Program.cs | 2 +- Example.Frontend/Example.Frontend.csproj | 8 ++++ mROA.Cbor/mROA.Cbor.csproj | 8 ++++ mROA/Abstract/ICommandExecution.cs | 2 - .../Backend/BasicExecutionModule.cs | 47 ++++++++++--------- .../CommandExecution/AsyncCommandExecution.cs | 2 - .../ExceptionCommandExecution.cs | 2 - .../CommandExecution/FinalCommandExecution.cs | 5 -- .../TypedFinalCommandExecution.cs | 13 ----- 10 files changed, 45 insertions(+), 48 deletions(-) delete mode 100644 mROA/Implementation/CommandExecution/TypedFinalCommandExecution.cs diff --git a/Example.Backend/Example.Backend.csproj b/Example.Backend/Example.Backend.csproj index 4f357b7..b951e33 100644 --- a/Example.Backend/Example.Backend.csproj +++ b/Example.Backend/Example.Backend.csproj @@ -14,6 +14,10 @@ + + + + diff --git a/Example.Backend/Program.cs b/Example.Backend/Program.cs index 30b50f6..7c5bcc9 100644 --- a/Example.Backend/Program.cs +++ b/Example.Backend/Program.cs @@ -34,7 +34,7 @@ class Program })); builder.SetupMethodsRepository(new CoCodegenMethodRepository()); builder.Modules.Add(new CreativeRepresentationModuleProducer( - new IInjectableModule[] { builder.GetModule()! }, + new IInjectableModule[] { builder.GetModule()! }, typeof(RepresentationModule))); builder.Modules.Add(new CancellationRepository()); diff --git a/Example.Frontend/Example.Frontend.csproj b/Example.Frontend/Example.Frontend.csproj index 35760b9..207a2b2 100644 --- a/Example.Frontend/Example.Frontend.csproj +++ b/Example.Frontend/Example.Frontend.csproj @@ -9,6 +9,14 @@ 9 + + + + + + + + diff --git a/mROA.Cbor/mROA.Cbor.csproj b/mROA.Cbor/mROA.Cbor.csproj index 7f66dce..a2dbaf9 100644 --- a/mROA.Cbor/mROA.Cbor.csproj +++ b/mROA.Cbor/mROA.Cbor.csproj @@ -5,6 +5,14 @@ enable + + + + + + + + diff --git a/mROA/Abstract/ICommandExecution.cs b/mROA/Abstract/ICommandExecution.cs index 210b976..5037a4e 100644 --- a/mROA/Abstract/ICommandExecution.cs +++ b/mROA/Abstract/ICommandExecution.cs @@ -5,7 +5,5 @@ namespace mROA.Abstract public interface ICommandExecution { Guid Id { get; set; } - int ClientId { get; set; } - int CommandId { get; } } } \ No newline at end of file diff --git a/mROA/Implementation/Backend/BasicExecutionModule.cs b/mROA/Implementation/Backend/BasicExecutionModule.cs index 3173d37..c1522ca 100644 --- a/mROA/Implementation/Backend/BasicExecutionModule.cs +++ b/mROA/Implementation/Backend/BasicExecutionModule.cs @@ -43,8 +43,7 @@ namespace mROA.Implementation.Backend _cancellationRepo.FreeCancelation(command.Id); return new FinalCommandExecution { - Id = command.Id, - CommandId = command.CommandId + Id = command.Id }; } @@ -76,7 +75,7 @@ namespace mROA.Implementation.Backend #endif contextRepository.ClearObject(command.ObjectId); } - + return result; } catch (Exception e) @@ -84,8 +83,6 @@ namespace mROA.Implementation.Backend Console.WriteLine(e); throw; } - - } private static ICommandExecution Execute(MethodInfo currentCommand, object context, object? parameter, @@ -98,19 +95,26 @@ namespace mROA.Implementation.Backend : new[] { parameter }; var finalResult = currentCommand.Invoke(context, finalParameter); - - return new TypedFinalCommandExecution + + if (currentCommand.ReturnType.Name == "Void") { - CommandId = command.CommandId, Result = finalResult, - Id = command.Id, - Type = currentCommand.ReturnType + return new FinalCommandExecution + { + Id = command.Id + }; + } + + return new FinalCommandExecution + { + Result = finalResult, + Id = command.Id }; } catch (Exception e) { return new ExceptionCommandExecution { - Id = command.Id, CommandId = command.CommandId, + Id = command.Id, Exception = e.ToString() }; } @@ -139,17 +143,16 @@ namespace mROA.Implementation.Backend { if (token.IsCancellationRequested) return; - + var payload = new FinalCommandExecution { - Id = command.Id, - CommandId = command.CommandId + 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(); @@ -157,14 +160,14 @@ namespace mROA.Implementation.Backend return new AsyncCommandExecution { - Id = command.Id, CommandId = command.CommandId + Id = command.Id }; } catch (Exception e) { return new ExceptionCommandExecution { - Id = command.Id, CommandId = command.CommandId, + Id = command.Id, Exception = e.ToString() }; } @@ -190,12 +193,10 @@ namespace mROA.Implementation.Backend result.ContinueWith(t => { var finalResult = t.GetType().GetProperty("Result")?.GetValue(t); - var payload = new TypedFinalCommandExecution + var payload = new FinalCommandExecution { Id = command.Id, - Result = finalResult, - CommandId = command.CommandId, - Type = finalResult?.GetType() + Result = finalResult }; _cancellationRepo.FreeCancelation(command.Id); @@ -208,14 +209,14 @@ namespace mROA.Implementation.Backend return new AsyncCommandExecution { - Id = command.Id, CommandId = command.CommandId + Id = command.Id }; } catch (Exception e) { return new ExceptionCommandExecution { - Id = command.Id, CommandId = command.CommandId, + Id = command.Id, Exception = e.ToString() }; } diff --git a/mROA/Implementation/CommandExecution/AsyncCommandExecution.cs b/mROA/Implementation/CommandExecution/AsyncCommandExecution.cs index fcddf6e..7dea41d 100644 --- a/mROA/Implementation/CommandExecution/AsyncCommandExecution.cs +++ b/mROA/Implementation/CommandExecution/AsyncCommandExecution.cs @@ -6,7 +6,5 @@ namespace mROA.Implementation.CommandExecution public class AsyncCommandExecution : ICommandExecution { public Guid Id { get; set; } - public int ClientId { get; set; } - public int CommandId { get; set; } } } \ No newline at end of file diff --git a/mROA/Implementation/CommandExecution/ExceptionCommandExecution.cs b/mROA/Implementation/CommandExecution/ExceptionCommandExecution.cs index c9d32ab..82a63de 100644 --- a/mROA/Implementation/CommandExecution/ExceptionCommandExecution.cs +++ b/mROA/Implementation/CommandExecution/ExceptionCommandExecution.cs @@ -7,8 +7,6 @@ namespace mROA.Implementation.CommandExecution public class ExceptionCommandExecution : ICommandExecution { public Guid Id { get; set; } - public int ClientId { get; set; } - public int CommandId { get; set; } public string Exception { get; set; } public RemoteException GetException() diff --git a/mROA/Implementation/CommandExecution/FinalCommandExecution.cs b/mROA/Implementation/CommandExecution/FinalCommandExecution.cs index 331928d..2a99331 100644 --- a/mROA/Implementation/CommandExecution/FinalCommandExecution.cs +++ b/mROA/Implementation/CommandExecution/FinalCommandExecution.cs @@ -1,7 +1,6 @@ using System; using System.Text.Json.Serialization; using mROA.Abstract; -using mROA.Implementation.Attributes; // ReSharper disable UnusedAutoPropertyAccessor.Global @@ -10,10 +9,6 @@ namespace mROA.Implementation.CommandExecution public class FinalCommandExecution : ICommandExecution { public Guid Id { get; set; } - [SerializationIgnore] - public int ClientId { get; set; } - [SerializationIgnore] - public int CommandId { get; set; } } public class FinalCommandExecution : FinalCommandExecution diff --git a/mROA/Implementation/CommandExecution/TypedFinalCommandExecution.cs b/mROA/Implementation/CommandExecution/TypedFinalCommandExecution.cs deleted file mode 100644 index 47ff4b1..0000000 --- a/mROA/Implementation/CommandExecution/TypedFinalCommandExecution.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Text.Json.Serialization; -using mROA.Implementation.Attributes; - -namespace mROA.Implementation.CommandExecution -{ - public class TypedFinalCommandExecution : FinalCommandExecution - { - [SerializationIgnore] - // ReSharper disable once UnusedAutoPropertyAccessor.Global - public Type? Type { get; set; } - } -} \ No newline at end of file