добавление модуля гетвея
This commit is contained in:
@@ -12,4 +12,5 @@ public interface ITestController
|
|||||||
TransmittedSharedObject<ITestController> SharedObjectTransmitionTest();
|
TransmittedSharedObject<ITestController> SharedObjectTransmitionTest();
|
||||||
int Parametrized(TestParameter parameter);
|
int Parametrized(TestParameter parameter);
|
||||||
TransmittedSharedObject<ITestParameter> GetTestParameter();
|
TransmittedSharedObject<ITestParameter> GetTestParameter();
|
||||||
|
string Alphabet();
|
||||||
}
|
}
|
||||||
@@ -44,4 +44,9 @@ public class TestController : ITestController
|
|||||||
{
|
{
|
||||||
return new TestParameterInstance();
|
return new TestParameterInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Alphabet()
|
||||||
|
{
|
||||||
|
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -44,4 +44,9 @@ public class TransmissionTestController : ITestController
|
|||||||
{
|
{
|
||||||
return new TestParameterInstance();
|
return new TestParameterInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Alphabet()
|
||||||
|
{
|
||||||
|
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Reverse().ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,6 @@ public class FrontendFinalTest
|
|||||||
_serialisationModule = new JsonSerialisationModule(_interactionModule, _methodRepository);
|
_serialisationModule = new JsonSerialisationModule(_interactionModule, _methodRepository);
|
||||||
|
|
||||||
_executeModule = new LaunchReadyExecutionModule(_methodRepository, _serialisationModule, _contextRepository);
|
_executeModule = new LaunchReadyExecutionModule(_methodRepository, _serialisationModule, _contextRepository);
|
||||||
TransmissionConfig.BackendRepository = _contextRepository;
|
|
||||||
|
|
||||||
_frontendInteractionModule = new StreamBasedFrontendInteractionModule();
|
_frontendInteractionModule = new StreamBasedFrontendInteractionModule();
|
||||||
_frontendSerialisationModule = new JsonFrontendSerialisationModule(_frontendInteractionModule);
|
_frontendSerialisationModule = new JsonFrontendSerialisationModule(_frontendInteractionModule);
|
||||||
@@ -40,8 +39,6 @@ public class FrontendFinalTest
|
|||||||
{ typeof(ITestController), typeof(TestControllerRemoteEndpoint) },
|
{ typeof(ITestController), typeof(TestControllerRemoteEndpoint) },
|
||||||
{typeof(ITestParameter), typeof(TestParameterRemoteEndpoint)}
|
{typeof(ITestParameter), typeof(TestParameterRemoteEndpoint)}
|
||||||
}, _frontendSerialisationModule);
|
}, _frontendSerialisationModule);
|
||||||
TransmissionConfig.FrontendRepository = _frontendContextRepository;
|
|
||||||
TransmissionConfig.SetupBackendRepository();
|
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
@@ -52,7 +49,7 @@ public class FrontendFinalTest
|
|||||||
|
|
||||||
Console.WriteLine("Client connected");
|
Console.WriteLine("Client connected");
|
||||||
|
|
||||||
_interactionModule.RegisterClient(stream);
|
_interactionModule.RegisterSourse(stream);
|
||||||
|
|
||||||
while (isTestNotFinished) ;
|
while (isTestNotFinished) ;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class StreamTest
|
|||||||
|
|
||||||
Console.WriteLine("Client connected");
|
Console.WriteLine("Client connected");
|
||||||
|
|
||||||
_interactionModule.RegisterClient(stream);
|
_interactionModule.RegisterSourse(stream);
|
||||||
|
|
||||||
while (isTestNotFinished) ;
|
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 SetMessageHandler(Action<int, byte[]> handler);
|
||||||
void SendTo(int clientId, byte[] message);
|
void SendTo(int clientId, byte[] message);
|
||||||
|
void RegisterSourse(Stream stream);
|
||||||
public interface IFrontendInteractionModule
|
public interface IFrontendInteractionModule
|
||||||
{
|
{
|
||||||
public Task<byte[]> ReceiveMessage();
|
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 Dictionary<int, Stream> _streams = new();
|
||||||
private Action<int, byte[]> _handler;
|
private Action<int, byte[]> _handler;
|
||||||
|
|
||||||
public void RegisterClient(Stream stream)
|
public void RegisterSourse(Stream stream)
|
||||||
{
|
{
|
||||||
var id = Random.Shared.Next();
|
var id = Random.Shared.Next();
|
||||||
_streams.Add(id, stream);
|
_streams.Add(id, stream);
|
||||||
@@ -17,4 +17,9 @@ public class ProgramlyInteractionChanel : IInteractionModule
|
|||||||
Console.WriteLine("{0}: {1}", clientId, System.Text.Encoding.UTF8.GetString(message));
|
Console.WriteLine("{0}: {1}", clientId, System.Text.Encoding.UTF8.GetString(message));
|
||||||
OutputBuffer.Add(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 class TransmissionConfig
|
||||||
{
|
{
|
||||||
public static IContextRepository DefaultContextRepository { get; set; }
|
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>
|
public class TransmittedSharedObject<T>
|
||||||
|
|||||||
Reference in New Issue
Block a user