From f3ece97ebf7746e8d4439601aab0ec75815f30cf Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Wed, 5 Feb 2025 00:08:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B3=D0=B5=D1=82=D0=B2=D0=B5=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mROA.Example/ITestController.cs | 1 + mROA.Example/TestController.cs | 5 ++ mROA.Example/TransmissionTestController.cs | 5 ++ mROA.Test/FrontendFinalTest.cs | 7 +-- mROA.Test/StreamTest.cs | 2 +- mROA/Abstract/IGatewayModule.cs | 7 +++ mROA/Abstract/IInteractionModule.cs | 1 + .../{ => Backend}/JsonSerialisationModule.cs | 0 .../Backend/NetworkGatewayModule.cs | 52 +++++++++++++++++++ .../StreamBasedInteractionModule.cs | 2 +- .../FrontendContextRepository.cs | 0 .../JsonFrontendSerialisationModule.cs | 0 .../StreamBasedFrontendInteractionModule.cs | 0 .../Test/ProgramlyInteractionChanel.cs | 5 ++ .../Implementation/TransmittedSharedObject.cs | 11 ---- 15 files changed, 80 insertions(+), 18 deletions(-) create mode 100644 mROA/Abstract/IGatewayModule.cs rename mROA/Implementation/{ => Backend}/JsonSerialisationModule.cs (100%) create mode 100644 mROA/Implementation/Backend/NetworkGatewayModule.cs rename mROA/Implementation/{ => Backend}/StreamBasedInteractionModule.cs (97%) rename mROA/Implementation/{ => Frontend}/FrontendContextRepository.cs (100%) rename mROA/Implementation/{ => Frontend}/JsonFrontendSerialisationModule.cs (100%) rename mROA/Implementation/{ => Frontend}/StreamBasedFrontendInteractionModule.cs (100%) diff --git a/mROA.Example/ITestController.cs b/mROA.Example/ITestController.cs index 66da71d..b56b427 100644 --- a/mROA.Example/ITestController.cs +++ b/mROA.Example/ITestController.cs @@ -12,4 +12,5 @@ public interface ITestController TransmittedSharedObject SharedObjectTransmitionTest(); int Parametrized(TestParameter parameter); TransmittedSharedObject GetTestParameter(); + string Alphabet(); } \ No newline at end of file diff --git a/mROA.Example/TestController.cs b/mROA.Example/TestController.cs index 09adf59..03e7db0 100644 --- a/mROA.Example/TestController.cs +++ b/mROA.Example/TestController.cs @@ -44,4 +44,9 @@ public class TestController : ITestController { return new TestParameterInstance(); } + + public string Alphabet() + { + return "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + } } \ No newline at end of file diff --git a/mROA.Example/TransmissionTestController.cs b/mROA.Example/TransmissionTestController.cs index e87693b..cebd1c1 100644 --- a/mROA.Example/TransmissionTestController.cs +++ b/mROA.Example/TransmissionTestController.cs @@ -44,4 +44,9 @@ public class TransmissionTestController : ITestController { return new TestParameterInstance(); } + + public string Alphabet() + { + return "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Reverse().ToString(); + } } \ No newline at end of file diff --git a/mROA.Test/FrontendFinalTest.cs b/mROA.Test/FrontendFinalTest.cs index b17028f..6538040 100644 --- a/mROA.Test/FrontendFinalTest.cs +++ b/mROA.Test/FrontendFinalTest.cs @@ -32,7 +32,6 @@ public class FrontendFinalTest _serialisationModule = new JsonSerialisationModule(_interactionModule, _methodRepository); _executeModule = new LaunchReadyExecutionModule(_methodRepository, _serialisationModule, _contextRepository); - TransmissionConfig.BackendRepository = _contextRepository; _frontendInteractionModule = new StreamBasedFrontendInteractionModule(); _frontendSerialisationModule = new JsonFrontendSerialisationModule(_frontendInteractionModule); @@ -40,9 +39,7 @@ public class FrontendFinalTest { typeof(ITestController), typeof(TestControllerRemoteEndpoint) }, {typeof(ITestParameter), typeof(TestParameterRemoteEndpoint)} }, _frontendSerialisationModule); - TransmissionConfig.FrontendRepository = _frontendContextRepository; - TransmissionConfig.SetupBackendRepository(); - + Task.Run(() => { TcpListener listener = new TcpListener(IPAddress.Loopback, 4567); @@ -52,7 +49,7 @@ public class FrontendFinalTest Console.WriteLine("Client connected"); - _interactionModule.RegisterClient(stream); + _interactionModule.RegisterSourse(stream); while (isTestNotFinished) ; }); diff --git a/mROA.Test/StreamTest.cs b/mROA.Test/StreamTest.cs index 418c83b..5bb7a91 100644 --- a/mROA.Test/StreamTest.cs +++ b/mROA.Test/StreamTest.cs @@ -37,7 +37,7 @@ public class StreamTest Console.WriteLine("Client connected"); - _interactionModule.RegisterClient(stream); + _interactionModule.RegisterSourse(stream); while (isTestNotFinished) ; }); diff --git a/mROA/Abstract/IGatewayModule.cs b/mROA/Abstract/IGatewayModule.cs new file mode 100644 index 0000000..fc29857 --- /dev/null +++ b/mROA/Abstract/IGatewayModule.cs @@ -0,0 +1,7 @@ +namespace mROA.Implementation; + +public interface IGatewayModule : IDisposable +{ + void Configure(IInteractionModule interactionModule); + void Run(); +} \ No newline at end of file diff --git a/mROA/Abstract/IInteractionModule.cs b/mROA/Abstract/IInteractionModule.cs index 2b33477..2673557 100644 --- a/mROA/Abstract/IInteractionModule.cs +++ b/mROA/Abstract/IInteractionModule.cs @@ -4,6 +4,7 @@ public interface IInteractionModule { void SetMessageHandler(Action handler); void SendTo(int clientId, byte[] message); + void RegisterSourse(Stream stream); public interface IFrontendInteractionModule { public Task ReceiveMessage(); diff --git a/mROA/Implementation/JsonSerialisationModule.cs b/mROA/Implementation/Backend/JsonSerialisationModule.cs similarity index 100% rename from mROA/Implementation/JsonSerialisationModule.cs rename to mROA/Implementation/Backend/JsonSerialisationModule.cs diff --git a/mROA/Implementation/Backend/NetworkGatewayModule.cs b/mROA/Implementation/Backend/NetworkGatewayModule.cs new file mode 100644 index 0000000..273a63c --- /dev/null +++ b/mROA/Implementation/Backend/NetworkGatewayModule.cs @@ -0,0 +1,52 @@ +using System.Net; +using System.Net.Sockets; + +namespace mROA.Implementation; + +public class NetworkGatewayModule : IGatewayModule +{ + private TcpListener _tcpListener; + private IInteractionModule _interactionModule; + + public NetworkGatewayModule(IPEndPoint endpoint) + { + _tcpListener = new TcpListener(endpoint); + } + + public void Configure(IInteractionModule interactionModule) + { + interactionModule = interactionModule; + } + + public void Run() + { + _tcpListener.Start(); + Console.WriteLine($"Listening on {_tcpListener.LocalEndpoint}"); + Console.WriteLine("Enter Ctrl-C to stop"); + while (true) + { + var key = Console.ReadKey(); + if (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control) + break; + } + + Task.Run(HandleIncomingConnections); + } + + public void Dispose() + { + _tcpListener.Stop(); + _tcpListener.Dispose(); + } + + private void HandleIncomingConnections() + { + while (true) + { + var client = _tcpListener.AcceptTcpClient(); + Console.WriteLine($"Client connected from {client.Client.RemoteEndPoint}"); + _interactionModule.RegisterSourse(client.GetStream()); + Console.WriteLine("Client registered"); + } + } +} \ No newline at end of file diff --git a/mROA/Implementation/StreamBasedInteractionModule.cs b/mROA/Implementation/Backend/StreamBasedInteractionModule.cs similarity index 97% rename from mROA/Implementation/StreamBasedInteractionModule.cs rename to mROA/Implementation/Backend/StreamBasedInteractionModule.cs index 4b7c2eb..584e73e 100644 --- a/mROA/Implementation/StreamBasedInteractionModule.cs +++ b/mROA/Implementation/Backend/StreamBasedInteractionModule.cs @@ -5,7 +5,7 @@ public class StreamBasedInteractionModule : IInteractionModule private Dictionary _streams = new(); private Action _handler; - public void RegisterClient(Stream stream) + public void RegisterSourse(Stream stream) { var id = Random.Shared.Next(); _streams.Add(id, stream); diff --git a/mROA/Implementation/FrontendContextRepository.cs b/mROA/Implementation/Frontend/FrontendContextRepository.cs similarity index 100% rename from mROA/Implementation/FrontendContextRepository.cs rename to mROA/Implementation/Frontend/FrontendContextRepository.cs diff --git a/mROA/Implementation/JsonFrontendSerialisationModule.cs b/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs similarity index 100% rename from mROA/Implementation/JsonFrontendSerialisationModule.cs rename to mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs diff --git a/mROA/Implementation/StreamBasedFrontendInteractionModule.cs b/mROA/Implementation/Frontend/StreamBasedFrontendInteractionModule.cs similarity index 100% rename from mROA/Implementation/StreamBasedFrontendInteractionModule.cs rename to mROA/Implementation/Frontend/StreamBasedFrontendInteractionModule.cs diff --git a/mROA/Implementation/Test/ProgramlyInteractionChanel.cs b/mROA/Implementation/Test/ProgramlyInteractionChanel.cs index d08a814..470de09 100644 --- a/mROA/Implementation/Test/ProgramlyInteractionChanel.cs +++ b/mROA/Implementation/Test/ProgramlyInteractionChanel.cs @@ -17,4 +17,9 @@ public class ProgramlyInteractionChanel : IInteractionModule Console.WriteLine("{0}: {1}", clientId, System.Text.Encoding.UTF8.GetString(message)); OutputBuffer.Add(System.Text.Encoding.UTF8.GetString(message)); } + + public void RegisterSourse(Stream stream) + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/mROA/Implementation/TransmittedSharedObject.cs b/mROA/Implementation/TransmittedSharedObject.cs index 366b05e..36b43f6 100644 --- a/mROA/Implementation/TransmittedSharedObject.cs +++ b/mROA/Implementation/TransmittedSharedObject.cs @@ -5,17 +5,6 @@ namespace mROA.Implementation; public static class TransmissionConfig { public static IContextRepository DefaultContextRepository { get; set; } - public static IContextRepository BackendRepository { get; set; } - public static IContextRepository FrontendRepository { get; set; } - - public static void SetupBackendRepository() - { - DefaultContextRepository = BackendRepository; - } - public static void SetupFrontendRepository() - { - DefaultContextRepository = FrontendRepository; - } } public class TransmittedSharedObject