добавление модуля гетвея
This commit is contained in:
@@ -12,4 +12,5 @@ public interface ITestController
|
||||
TransmittedSharedObject<ITestController> SharedObjectTransmitionTest();
|
||||
int Parametrized(TestParameter parameter);
|
||||
TransmittedSharedObject<ITestParameter> GetTestParameter();
|
||||
string Alphabet();
|
||||
}
|
||||
@@ -44,4 +44,9 @@ public class TestController : ITestController
|
||||
{
|
||||
return new TestParameterInstance();
|
||||
}
|
||||
|
||||
public string Alphabet()
|
||||
{
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
}
|
||||
}
|
||||
@@ -44,4 +44,9 @@ public class TransmissionTestController : ITestController
|
||||
{
|
||||
return new TestParameterInstance();
|
||||
}
|
||||
|
||||
public string Alphabet()
|
||||
{
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Reverse().ToString();
|
||||
}
|
||||
}
|
||||
@@ -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) ;
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ public class StreamTest
|
||||
|
||||
Console.WriteLine("Client connected");
|
||||
|
||||
_interactionModule.RegisterClient(stream);
|
||||
_interactionModule.RegisterSourse(stream);
|
||||
|
||||
while (isTestNotFinished) ;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace mROA.Implementation;
|
||||
|
||||
public interface IGatewayModule : IDisposable
|
||||
{
|
||||
void Configure(IInteractionModule interactionModule);
|
||||
void Run();
|
||||
}
|
||||
@@ -4,6 +4,7 @@ public interface IInteractionModule
|
||||
{
|
||||
void SetMessageHandler(Action<int, byte[]> handler);
|
||||
void SendTo(int clientId, byte[] message);
|
||||
void RegisterSourse(Stream stream);
|
||||
public interface IFrontendInteractionModule
|
||||
{
|
||||
public Task<byte[]> ReceiveMessage();
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ public class StreamBasedInteractionModule : IInteractionModule
|
||||
private Dictionary<int, Stream> _streams = new();
|
||||
private Action<int, byte[]> _handler;
|
||||
|
||||
public void RegisterClient(Stream stream)
|
||||
public void RegisterSourse(Stream stream)
|
||||
{
|
||||
var id = Random.Shared.Next();
|
||||
_streams.Add(id, stream);
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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<T>
|
||||
|
||||
Reference in New Issue
Block a user