From 2f65fb24c0165f0a4ab730839fda53fb7ccaf33c Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Wed, 7 May 2025 09:03:20 +0300 Subject: [PATCH] Event binding bug found --- Example.Frontend/Program.cs | 9 ++++----- mROA.Cbor/CborSerializationToolkit.cs | 3 ++- mROA/Abstract/IFrontendBridge.cs | 3 ++- mROA/Implementation/Backend/ContextRepository.cs | 6 +++--- mROA/Implementation/Frontend/NetworkFrontendBridge.cs | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Example.Frontend/Program.cs b/Example.Frontend/Program.cs index f85e261..129e91d 100644 --- a/Example.Frontend/Program.cs +++ b/Example.Frontend/Program.cs @@ -16,11 +16,11 @@ using mROA.Implementation.Frontend; class Program { - public static void Main(string[] args) + public static async Task Main(string[] args) { var builder = new FullMixBuilder(); new RemoteTypeBinder(); - // builder.Modules.Add(new JsonSerializationToolkit()); + builder.Modules.Add(new CborSerializationToolkit()); builder.Modules.Add(new EndPointContext()); builder.Modules.Add(new RemoteContextRepository()); @@ -39,7 +39,7 @@ class Program builder.Build(); var frontendBridge = builder.GetModule()!; - frontendBridge.Connect(); + await frontendBridge.Connect(); _ = builder.GetModule()!.StartExtraction(); _ = builder.GetModule().Start(serverEndPoint); Console.WriteLine(builder.GetModule().HostId); @@ -87,8 +87,7 @@ class Program Console.WriteLine("Names: " + string.Join(", ", names)); - var page = disposingPrinter.Print("Test Page", false, default, CancellationToken.None).GetAwaiter() - .GetResult(); + var page = await disposingPrinter.Print("Test Page", false, default, CancellationToken.None); Console.WriteLine("Page printed"); DemoCheck.TaskExecution = true; Console.WriteLine(page.ToString()); diff --git a/mROA.Cbor/CborSerializationToolkit.cs b/mROA.Cbor/CborSerializationToolkit.cs index 425cbe3..672f38d 100644 --- a/mROA.Cbor/CborSerializationToolkit.cs +++ b/mROA.Cbor/CborSerializationToolkit.cs @@ -213,7 +213,8 @@ namespace mROA.Cbor if (obj is IShared) { - var generic = obj.GetType().GetInterfaces().FirstOrDefault(i => typeof(IShared).IsAssignableFrom(i)); + var interfaces = obj.GetType().GetInterfaces(); + var generic = interfaces.FirstOrDefault(i => typeof(IShared).IsAssignableFrom(i)); var sharedShell = typeof(SharedObjectShellShell<>).MakeGenericType(generic); var so = Activator.CreateInstance(sharedShell, obj, context) as diff --git a/mROA/Abstract/IFrontendBridge.cs b/mROA/Abstract/IFrontendBridge.cs index 53217d7..7ce7460 100644 --- a/mROA/Abstract/IFrontendBridge.cs +++ b/mROA/Abstract/IFrontendBridge.cs @@ -1,10 +1,11 @@ using System; +using System.Threading.Tasks; namespace mROA.Abstract { public interface IFrontendBridge : IInjectableModule, IDisposable { - void Connect(); + Task Connect(); void Obstacle(); void Disconnect(); } diff --git a/mROA/Implementation/Backend/ContextRepository.cs b/mROA/Implementation/Backend/ContextRepository.cs index 13541c5..8b7e738 100644 --- a/mROA/Implementation/Backend/ContextRepository.cs +++ b/mROA/Implementation/Backend/ContextRepository.cs @@ -32,9 +32,9 @@ namespace mROA.Implementation.Backend public int ResisterObject(object o, IEndPointContext context) { var last = _storage.Place(o); - - EventBinders.OfType>().FirstOrDefault() - ?.BindEvents((T)o, context, _representationModuleProducer!, last); + + var binder = EventBinders.OfType>().FirstOrDefault(); + binder?.BindEvents((T)o, context, _representationModuleProducer!, last); return last; } diff --git a/mROA/Implementation/Frontend/NetworkFrontendBridge.cs b/mROA/Implementation/Frontend/NetworkFrontendBridge.cs index 04d6248..8611418 100644 --- a/mROA/Implementation/Frontend/NetworkFrontendBridge.cs +++ b/mROA/Implementation/Frontend/NetworkFrontendBridge.cs @@ -40,7 +40,7 @@ namespace mROA.Implementation.Frontend } } - public void Connect() + public async Task Connect() { if (_interactionModule is null) throw new Exception("Interaction module was not injected"); @@ -57,7 +57,7 @@ namespace mROA.Implementation.Frontend .Wait(); _currentExtractor.SingleReceive(); - var idMessage = _interactionModule.GetNextMessageReceiving(false).GetAwaiter().GetResult(); + var idMessage = await _interactionModule.GetNextMessageReceiving(false); if (idMessage.MessageType != EMessageType.IdAssigning) {