From 6d9607081c412ddf0785536631ac5c038cfdb850 Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Thu, 13 Mar 2025 08:43:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=B5=D0=BC=D0=BA=D0=B0=20=D1=81=20?= =?UTF-8?q?=D1=87=D0=B0=D1=82=D0=BE=D0=BC=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example.Backend/Printer.cs | 2 +- Example.Events.Backend/Chat.cs | 18 +++++++++++++++ Example.Events.Backend/ChatFactory.cs | 22 ++++++++++++++++++ Example.Events.Shared/IChat.cs | 13 +++++++++++ Example.Events.Shared/IChatFactory.cs | 12 ++++++++++ Example.Shared/Example.Shared.csproj | 6 ++--- Example.Shared/ILoadTest.cs | 3 +-- Example.Shared/IPrinterFactory.cs | 2 +- mROA.Cbor/CborSerializationToolkit.cs | 7 ++++++ mROA.Codegen/mROASourceGenerator.cs | 9 ++++---- mROA.sln | 33 ++++++++++++++++++++++++--- 11 files changed, 112 insertions(+), 15 deletions(-) create mode 100644 Example.Events.Backend/Chat.cs create mode 100644 Example.Events.Backend/ChatFactory.cs create mode 100644 Example.Events.Shared/IChat.cs create mode 100644 Example.Events.Shared/IChatFactory.cs diff --git a/Example.Backend/Printer.cs b/Example.Backend/Printer.cs index 2bfc5a1..f4073bf 100644 --- a/Example.Backend/Printer.cs +++ b/Example.Backend/Printer.cs @@ -27,7 +27,7 @@ namespace Example.Backend // throw new Exception("The method or operation is not implemented."); var page = new Page { Text = text }; Console.WriteLine($"Request id : :{context.RequestId}"); - OnPrint?.Invoke(page, new RequestContext(context.RequestId, -1000)); + OnPrint?.Invoke(page, context); Resource /= 1.5; return page; } diff --git a/Example.Events.Backend/Chat.cs b/Example.Events.Backend/Chat.cs new file mode 100644 index 0000000..2239d59 --- /dev/null +++ b/Example.Events.Backend/Chat.cs @@ -0,0 +1,18 @@ +using Example.Events.Shared; +using mROA.Implementation; + +namespace Example.Events.Backend; + +public class Chat : IChat +{ + public void PostSymbol(string symbol, RequestContext context) + { + OnCharPosted?.Invoke(symbol, context); + } + + public event Action? OnCharPosted; + + public void OnCharPostedExternal(string p0, RequestContext p1) + { + } +} \ No newline at end of file diff --git a/Example.Events.Backend/ChatFactory.cs b/Example.Events.Backend/ChatFactory.cs new file mode 100644 index 0000000..90a4c65 --- /dev/null +++ b/Example.Events.Backend/ChatFactory.cs @@ -0,0 +1,22 @@ +using Example.Events.Shared; +using mROA.Implementation.Attributes; + +namespace Example.Events.Backend; + +[SharedObjectSingleton] +public class ChatFactory : IChatFactory +{ + private static readonly Dictionary Chats = new(); + + public IChat GetChat(Guid id) + { + if (Chats.TryGetValue(id, out var chat)) + { + return chat; + } + + var created = new Chat(); + Chats.Add(id, created); + return created; + } +} \ No newline at end of file diff --git a/Example.Events.Shared/IChat.cs b/Example.Events.Shared/IChat.cs new file mode 100644 index 0000000..a37b06a --- /dev/null +++ b/Example.Events.Shared/IChat.cs @@ -0,0 +1,13 @@ +using System; +using mROA.Implementation; +using mROA.Implementation.Attributes; + +namespace Example.Events.Shared +{ + [SharedObjectInterface] + public partial interface IChat : IShared + { + void PostSymbol(string symbol, RequestContext context = default); + event Action OnCharPosted; + } +} \ No newline at end of file diff --git a/Example.Events.Shared/IChatFactory.cs b/Example.Events.Shared/IChatFactory.cs new file mode 100644 index 0000000..b73949b --- /dev/null +++ b/Example.Events.Shared/IChatFactory.cs @@ -0,0 +1,12 @@ +using System; +using mROA.Implementation; +using mROA.Implementation.Attributes; + +namespace Example.Events.Shared +{ + [SharedObjectInterface] + public interface IChatFactory : IShared + { + IChat GetChat(Guid id); + } +} \ No newline at end of file diff --git a/Example.Shared/Example.Shared.csproj b/Example.Shared/Example.Shared.csproj index f2050a6..98d21fd 100644 --- a/Example.Shared/Example.Shared.csproj +++ b/Example.Shared/Example.Shared.csproj @@ -2,17 +2,15 @@ net9.0 - enable - 9 - + - + diff --git a/Example.Shared/ILoadTest.cs b/Example.Shared/ILoadTest.cs index 8234f1f..227af99 100644 --- a/Example.Shared/ILoadTest.cs +++ b/Example.Shared/ILoadTest.cs @@ -15,5 +15,4 @@ namespace Example.Shared Task AsyncTest(CancellationToken token = default); } -} - +} \ No newline at end of file diff --git a/Example.Shared/IPrinterFactory.cs b/Example.Shared/IPrinterFactory.cs index 884293d..60d4d0e 100644 --- a/Example.Shared/IPrinterFactory.cs +++ b/Example.Shared/IPrinterFactory.cs @@ -4,7 +4,7 @@ using mROA.Implementation.Attributes; namespace Example.Shared { [SharedObjectInterface] - public interface IPrinterFactory : IShared + public interface IPrinterFactory : IShared { IPrinter Create(string printerName); void Register(IPrinter printer); diff --git a/mROA.Cbor/CborSerializationToolkit.cs b/mROA.Cbor/CborSerializationToolkit.cs index 341b49d..47d1fc0 100644 --- a/mROA.Cbor/CborSerializationToolkit.cs +++ b/mROA.Cbor/CborSerializationToolkit.cs @@ -62,6 +62,13 @@ namespace mROA.Cbor if (nonCasted is PreParsedValue preParsed) return preParsed.ToObject(type, context); + + + if (type == typeof(Guid)) + { + return new Guid((byte[])nonCasted); + } + return Convert.ChangeType(nonCasted, type); } diff --git a/mROA.Codegen/mROASourceGenerator.cs b/mROA.Codegen/mROASourceGenerator.cs index 651dd1b..b58c2de 100644 --- a/mROA.Codegen/mROASourceGenerator.cs +++ b/mROA.Codegen/mROASourceGenerator.cs @@ -283,8 +283,8 @@ namespace {classSymbol.ContainingNamespace.ToDisplayString()} {{ BindAction = (instance, context, representationProducer, index) => {{ - var module = representationProducer.Produce(context.OwnerId); - + var ownerId = context.OwnerId; + var module = representationProducer.Produce(ownerId); {string.Join("\r\n", singleEventBinder)} }} }}"; @@ -471,14 +471,15 @@ namespace {classSymbol.ContainingNamespace.ToDisplayString()} var requestIndex = parameters.FindIndex(i => i.Name == "RequestContext"); if (requestIndex != -1) { - callFilter = $"\n\r\t\t\tif(context.OwnerId == p{requestIndex}.OwnerId) return;"; + callFilter = $"\n\r\t\t\tif(ownerId == p{requestIndex}.OwnerId) return;"; } var eventBinderCode = $@" (instance as {baseType.ToDisplayString()}).{eventSymbol.Name} += ({parametersDeclaration}) => {{ + Console.WriteLine($""Try to send to {{ownerId}} with hash code {{context.GetHashCode()}}""); + {callFilter} Console.WriteLine(""Sending event...""); -{callFilter} var request = new DefaultCallRequest {{ CommandId = {index}, ObjectId = new ComplexObjectIdentifier(index, context.HostId), Parameters = new object[] {{ {transferParameters} }} diff --git a/mROA.sln b/mROA.sln index 6899901..1cfa5fa 100644 --- a/mROA.sln +++ b/mROA.sln @@ -21,6 +21,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Benchmark", "mROA.Benc EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Cbor", "mROA.Cbor\mROA.Cbor.csproj", "{6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TotalDemo", "TotalDemo", "{FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Events", "Events", "{032E1288-4D26-4FA5-ABB6-E7D738F319DE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Events.Shared", "Example.Events.Shared\Example.Events.Shared.csproj", "{6342C7FC-12B4-4BC6-BA25-159B1400D952}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Events.Backend", "Example.Events.Backend\Example.Events.Backend.csproj", "{B63F58B2-8D86-42F3-96A5-470CB449BFD3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Events.Client", "Example.Events.Client\Example.Events.Client.csproj", "{98451C0E-E179-4F5F-9F1A-8B353EDE2EBC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -59,13 +69,30 @@ Global {6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}.Debug|Any CPU.Build.0 = Debug|Any CPU {6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}.Release|Any CPU.ActiveCfg = Release|Any CPU {6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}.Release|Any CPU.Build.0 = Release|Any CPU + {6342C7FC-12B4-4BC6-BA25-159B1400D952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6342C7FC-12B4-4BC6-BA25-159B1400D952}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6342C7FC-12B4-4BC6-BA25-159B1400D952}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6342C7FC-12B4-4BC6-BA25-159B1400D952}.Release|Any CPU.Build.0 = Release|Any CPU + {B63F58B2-8D86-42F3-96A5-470CB449BFD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B63F58B2-8D86-42F3-96A5-470CB449BFD3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B63F58B2-8D86-42F3-96A5-470CB449BFD3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B63F58B2-8D86-42F3-96A5-470CB449BFD3}.Release|Any CPU.Build.0 = Release|Any CPU + {98451C0E-E179-4F5F-9F1A-8B353EDE2EBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {98451C0E-E179-4F5F-9F1A-8B353EDE2EBC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {98451C0E-E179-4F5F-9F1A-8B353EDE2EBC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {98451C0E-E179-4F5F-9F1A-8B353EDE2EBC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {A9BB364E-0BA6-40B9-A293-757BC48EFC06} = {EAE92F5A-664C-41AB-8811-5885524B5347} - {E7703F5B-F2A6-4A88-AA57-EBB1E38D533E} = {EAE92F5A-664C-41AB-8811-5885524B5347} - {9BD25A13-3165-47C0-9EAA-5C59EC490E32} = {EAE92F5A-664C-41AB-8811-5885524B5347} + {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E} = {EAE92F5A-664C-41AB-8811-5885524B5347} + {A9BB364E-0BA6-40B9-A293-757BC48EFC06} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E} + {9BD25A13-3165-47C0-9EAA-5C59EC490E32} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E} + {E7703F5B-F2A6-4A88-AA57-EBB1E38D533E} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E} + {032E1288-4D26-4FA5-ABB6-E7D738F319DE} = {EAE92F5A-664C-41AB-8811-5885524B5347} + {6342C7FC-12B4-4BC6-BA25-159B1400D952} = {032E1288-4D26-4FA5-ABB6-E7D738F319DE} + {B63F58B2-8D86-42F3-96A5-470CB449BFD3} = {032E1288-4D26-4FA5-ABB6-E7D738F319DE} + {98451C0E-E179-4F5F-9F1A-8B353EDE2EBC} = {032E1288-4D26-4FA5-ABB6-E7D738F319DE} EndGlobalSection EndGlobal