From 22cf8ede0ae801b8fa2786aca196efcb32d9bb0c Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Wed, 12 Mar 2025 10:28:05 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D1=83=D0=BC=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=20=D0=BE=D1=82=D1=80=D0=B8=D1=86=D0=B0=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=BC=20=D0=B0=D0=B9=D0=B4=D0=B8=D1=88=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=BC=20=D1=81=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0=20=D0=B3=D0=BB=D0=BE=D0=B1=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B8=20=D0=BA=D0=B0=D0=B6=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=BE=D0=BD=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=81=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example.Frontend/ClientBasedPrinter.cs | 1 + Example.Frontend/DemoCheck.cs | 37 +++++++++++++++++++ Example.Frontend/Program.cs | 20 ++++++++-- .../Backend/NetworkGatewayModule.cs | 2 +- .../Implementation/ComplexObjectIdentifier.cs | 7 ++-- .../Frontend/NetworkFrontendBridge.cs | 2 +- .../{IdAssingnment.cs => IdAssignment.cs} | 2 +- mROA/Implementation/SharedObjectShell.cs | 4 +- 8 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 Example.Frontend/DemoCheck.cs rename mROA/Implementation/{IdAssingnment.cs => IdAssignment.cs} (72%) diff --git a/Example.Frontend/ClientBasedPrinter.cs b/Example.Frontend/ClientBasedPrinter.cs index 0686390..6afc7a3 100644 --- a/Example.Frontend/ClientBasedPrinter.cs +++ b/Example.Frontend/ClientBasedPrinter.cs @@ -17,6 +17,7 @@ namespace Example.Frontend public string GetName() { Console.WriteLine("ClientBasedPrinter called from server!!!!!!!!!!! Vova likes that:)"); + DemoCheck.BackwardCall = true; return "ClientBasedPrinter from mroa"; } diff --git a/Example.Frontend/DemoCheck.cs b/Example.Frontend/DemoCheck.cs new file mode 100644 index 0000000..efc95aa --- /dev/null +++ b/Example.Frontend/DemoCheck.cs @@ -0,0 +1,37 @@ +using System; +using System.Linq; + +namespace Example.Frontend +{ + public static class DemoCheck + { + public static bool ClientBasedImplementation; + public static bool TaskCancelation; + public static bool Dispose; + public static bool PropertySet; + public static bool PropertyGet; + public static bool TaskExecution; + public static bool BackwardCall; + public static bool BasicNonParamsCall; + public static bool EventCallback; + public static bool CreatingPrinter; + + public static void Show() + { + Console.WriteLine("======================== Demo summary ========================"); + var fields = typeof(DemoCheck).GetFields().OrderBy(i => i.Name).ToList(); + foreach (var field in fields) + { + var value = (bool)field.GetValue(null)!; + if (value) + { + Console.BackgroundColor = ConsoleColor.Green; + }else Console.BackgroundColor = ConsoleColor.Gray; + + Console.Write($"{field.Name}"); + Console.BackgroundColor = ConsoleColor.Black; + Console.WriteLine(); + } + } + } +} \ No newline at end of file diff --git a/Example.Frontend/Program.cs b/Example.Frontend/Program.cs index c47bec3..156026d 100644 --- a/Example.Frontend/Program.cs +++ b/Example.Frontend/Program.cs @@ -48,25 +48,32 @@ class Program //правильный порядок команд 8-5-10-7 using (var disposingPrinter = factory.Create("Test")) { - disposingPrinter.OnPrint += (_, _) => { Console.WriteLine("New page creater. Called from event!!!"); }; + DemoCheck.CreatingPrinter = true; + disposingPrinter.OnPrint += (_, _) => + { + Console.WriteLine("New page creater. Called from event!!!"); + DemoCheck.EventCallback = true; + }; Console.WriteLine("Printer created"); Thread.Sleep(100); var name = disposingPrinter.GetName(); + DemoCheck.BasicNonParamsCall = true; Console.WriteLine("Printer name : {0}", name); Thread.Sleep(100); factory.Register(new ClientBasedPrinter()); + DemoCheck.ClientBasedImplementation = true; Console.WriteLine("Registered printer"); Thread.Sleep(100); - var registred = factory.GetFirstPrinter(); + var registered = factory.GetFirstPrinter(); Console.WriteLine("First printer"); Thread.Sleep(100); - Console.WriteLine(registred); + Console.WriteLine(registered); Console.WriteLine("Collecting all printers"); var names = factory.CollectAllNames(); Thread.Sleep(100); @@ -76,11 +83,15 @@ class Program var page = disposingPrinter.Print("Test Page", false, default, CancellationToken.None).GetAwaiter() .GetResult(); Console.WriteLine("Page printed"); + DemoCheck.TaskExecution = true; Console.WriteLine(page.ToString()); Console.WriteLine($"Printer resource : {disposingPrinter.Resource}"); + DemoCheck.PropertyGet = true; + Console.WriteLine("Restoring resource"); disposingPrinter.Resource = 100; + DemoCheck.PropertySet = true; Console.WriteLine($"Printer resource again : {disposingPrinter.Resource}"); var data = page.GetData(); @@ -88,6 +99,7 @@ class Program Console.WriteLine("Dispose printer"); } + DemoCheck.Dispose = true; var loadSingleton = context.GetSingleObject(typeof(ILoadTest), 0) as ILoadTest; @@ -100,6 +112,8 @@ class Program Thread.Sleep(5000); cts.Cancel(); Console.WriteLine($"Token state {cts.Token.IsCancellationRequested}"); + DemoCheck.TaskCancelation = true; + DemoCheck.Show(); Console.ReadKey(); // // const int iterations = 10000; diff --git a/mROA/Implementation/Backend/NetworkGatewayModule.cs b/mROA/Implementation/Backend/NetworkGatewayModule.cs index 81d6266..61e19c7 100644 --- a/mROA/Implementation/Backend/NetworkGatewayModule.cs +++ b/mROA/Implementation/Backend/NetworkGatewayModule.cs @@ -87,7 +87,7 @@ namespace mROA.Implementation.Backend interaction.PostMessage(new NetworkMessage { Id = Guid.NewGuid(), SchemaId = MessageType.IdAssigning, - Data = _serialization.Serialize(new IdAssingnment { Id = interaction.ConnectionId }) + Data = _serialization.Serialize(new IdAssignment { Id = -interaction.ConnectionId }) }); _hub.RegisterInteraction(interaction); Console.WriteLine("Client registered"); diff --git a/mROA/Implementation/ComplexObjectIdentifier.cs b/mROA/Implementation/ComplexObjectIdentifier.cs index 15ede59..37d87a2 100644 --- a/mROA/Implementation/ComplexObjectIdentifier.cs +++ b/mROA/Implementation/ComplexObjectIdentifier.cs @@ -7,18 +7,19 @@ namespace mROA.Implementation { public int ContextId; public int OwnerId; - public ComplexObjectIdentifier(int contextId, int ownerId) { ContextId = contextId; OwnerId = ownerId; } - public static ComplexObjectIdentifier Singleton(int ownerId) => new() { ContextId = -1, OwnerId = ownerId }; - public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = -1 }; + public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = 0 }; public static ComplexObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat }; + public int ClientId => Math.Abs(OwnerId); + public bool IsSererStored => OwnerId > 0; + public bool IsClientStored => OwnerId < 0; public override string ToString() { return $"{{ {nameof(ContextId)}: {ContextId}, {nameof(OwnerId)}: {OwnerId} }}"; diff --git a/mROA/Implementation/Frontend/NetworkFrontendBridge.cs b/mROA/Implementation/Frontend/NetworkFrontendBridge.cs index 5616e5b..2bff07f 100644 --- a/mROA/Implementation/Frontend/NetworkFrontendBridge.cs +++ b/mROA/Implementation/Frontend/NetworkFrontendBridge.cs @@ -46,7 +46,7 @@ namespace mROA.Implementation.Frontend } - var assignment = _serialization.Deserialize(welcomeMessage.Data)!; + var assignment = _serialization.Deserialize(welcomeMessage.Data)!; TransmissionConfig.OwnershipRepository = new StaticOwnershipRepository(assignment.Id); } } diff --git a/mROA/Implementation/IdAssingnment.cs b/mROA/Implementation/IdAssignment.cs similarity index 72% rename from mROA/Implementation/IdAssingnment.cs rename to mROA/Implementation/IdAssignment.cs index dfb634b..427124b 100644 --- a/mROA/Implementation/IdAssingnment.cs +++ b/mROA/Implementation/IdAssignment.cs @@ -1,6 +1,6 @@ namespace mROA.Implementation { - public class IdAssingnment + public class IdAssignment { public int Id { get; set; } } diff --git a/mROA/Implementation/SharedObjectShell.cs b/mROA/Implementation/SharedObjectShell.cs index 14ee815..0fe0450 100644 --- a/mROA/Implementation/SharedObjectShell.cs +++ b/mROA/Implementation/SharedObjectShell.cs @@ -51,7 +51,7 @@ namespace mROA.Implementation } else { - _identifier.OwnerId = EndPointContext.HostId; + _identifier.OwnerId = EndPointContext.OwnerId; _identifier.ContextId = EndPointContext.RealRepository.GetObjectIndex(Value, EndPointContext); } } @@ -71,7 +71,7 @@ namespace mROA.Implementation { get { - _identifier.OwnerId = _identifier.OwnerId == -1 ? EndPointContext.OwnerId : _identifier.OwnerId; + _identifier.OwnerId = _identifier.OwnerId == 0 ? EndPointContext.OwnerId : _identifier.OwnerId; return _identifier; } set