From ed571b5fb28b63eb4403b64d42db614143a35eff Mon Sep 17 00:00:00 2001 From: Benedikt Schenkel Date: Wed, 13 Dec 2023 11:47:51 +0100 Subject: [PATCH] update factory and readme --- .../Point/PointTest.cs | 3 +- .../Configuration/ConnectionProtocol.cs | 6 ++++ .../Configuration/PointConfiguration.cs | 3 +- src/Point/Connections/ConnectionFactory.cs | 29 +++++++++++++++++-- src/Point/README.md | 23 ++++++++++++++- src/Point/Startup.cs | 4 +-- 6 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 src/FieldElementSubsystems/Configuration/ConnectionProtocol.cs diff --git a/src/FieldElementSubsystems.Test/Point/PointTest.cs b/src/FieldElementSubsystems.Test/Point/PointTest.cs index b26cdf7..37af51b 100644 --- a/src/FieldElementSubsystems.Test/Point/PointTest.cs +++ b/src/FieldElementSubsystems.Test/Point/PointTest.cs @@ -20,7 +20,8 @@ private static Mock CreateDefaultMockConnection( "INTERLOCKING", "http://localhost:50051", true, - false + false, + ConnectionProtocol.EulynxBaseline4R1 )); mockConnection.Setup(x => x.TimeoutToken).Returns(() => CancellationToken.None); mockConnection diff --git a/src/FieldElementSubsystems/Configuration/ConnectionProtocol.cs b/src/FieldElementSubsystems/Configuration/ConnectionProtocol.cs new file mode 100644 index 0000000..6bf38fa --- /dev/null +++ b/src/FieldElementSubsystems/Configuration/ConnectionProtocol.cs @@ -0,0 +1,6 @@ +namespace EulynxLive.FieldElementSubsystems.Configuration; + +public enum ConnectionProtocol { + EulynxBaseline4R1, + EulynxBaseline4R2 +} diff --git a/src/FieldElementSubsystems/Configuration/PointConfiguration.cs b/src/FieldElementSubsystems/Configuration/PointConfiguration.cs index 17a073c..4118a8e 100644 --- a/src/FieldElementSubsystems/Configuration/PointConfiguration.cs +++ b/src/FieldElementSubsystems/Configuration/PointConfiguration.cs @@ -6,5 +6,6 @@ public record PointConfiguration( string RemoteId, string RemoteEndpoint, bool? AllPointMachinesCrucial = null, - bool? SimulateRandomTimeouts = null + bool? SimulateRandomTimeouts = null, + ConnectionProtocol? ConnectionProtocol = null ); diff --git a/src/Point/Connections/ConnectionFactory.cs b/src/Point/Connections/ConnectionFactory.cs index 9bdd9f1..23da160 100644 --- a/src/Point/Connections/ConnectionFactory.cs +++ b/src/Point/Connections/ConnectionFactory.cs @@ -1,10 +1,33 @@ +using EulynxLive.FieldElementSubsystems.Configuration; using EulynxLive.FieldElementSubsystems.Interfaces; +using EulynxBaseline4R1 = EulynxLive.FieldElementSubsystems.Connections.EulynxBaseline4R1; +using EulynxBaseline4R2 = EulynxLive.FieldElementSubsystems.Connections.EulynxBaseline4R2; + namespace EulynxLive.Point.Connections; -public static class ConnectionFactory{ - public static IPointToInterlockingConnection CreateConnection (IServiceProvider x) where T : IPointToInterlockingConnection { +public class ConnectionFactory{ + private IConfiguration _configuration { get; } + private ILogger _logger { get; } + + public ConnectionFactory(ILogger logger, IConfiguration configuration){ + _logger = logger; + _configuration = configuration; + } - return ActivatorUtilities.CreateInstance(x, CancellationToken.None); + public IPointToInterlockingConnection CreateConnection(IServiceProvider x) { + var connectionProtocol = _configuration.GetSection("ConnectionSettings").Get()?.ConnectionProtocol; + switch (connectionProtocol){ + case ConnectionProtocol.EulynxBaseline4R1: + return new EulynxBaseline4R1.PointToInterlockingConnection(x.GetRequiredService>(), _configuration, CancellationToken.None); + case ConnectionProtocol.EulynxBaseline4R2: + return new EulynxBaseline4R2.PointToInterlockingConnection(x.GetRequiredService>(), _configuration, CancellationToken.None); + default: + if (connectionProtocol != null) + _logger.LogWarning($"Unknown connection protocol {connectionProtocol}. Using EulynxBaseline4R2."); + else + _logger.LogWarning($"No connection protocol specified. Using EulynxBaseline4R2."); + return new EulynxBaseline4R2.PointToInterlockingConnection(x.GetRequiredService>(), _configuration, CancellationToken.None); + } } } diff --git a/src/Point/README.md b/src/Point/README.md index bd20a0e..b22eda3 100644 --- a/src/Point/README.md +++ b/src/Point/README.md @@ -6,4 +6,25 @@ EULYNX Point Simulator - https://dotnet.microsoft.com/ - https://nodejs.org/en/ -Then, execute `dotnet run` in this directory and open http://localhost:5000 in the browser. +Then, execute `dotnet run` in this directory and open http://localhost:5101 in the browser. + +## Arguments + +The `PointSettings` command-line arguments are used to configure the point simulator. + +| Argument | Description | +|---|---| +| `--PointSettings:LocalId` | The local point ID. | +| `--PointSettings:LocalRastaId` | The local Rasta ID. | +| `--PointSettings:RemoteId` | The remote point ID. | +| `--PointSettings:RemoteEndpoint` | The remote endpoint URL. | +| `--PointSettings:ConnectionProtocol` | The protocol to use when connecting to an endpoint. | + +For example, to set the local point ID to `W1`, the local Rasta ID to `96`, the remote point ID to `INTERLOCKING`, and the remote endpoint URL to `http://localhost:5100` using `EulynxBaseline4R1`, you would use the following command: +``` +dotnet run --PointSettings:LocalId W1 --PointSettings:LocalRastaId 96 --PointSettings:RemoteId INTERLOCKING --PointSettings:RemoteEndpoint http://localhost:5100 --PointSettings:ConnectionProtocol EulynxBaseline4R1 +``` + +### Available Connection Protocols: +- EulynxBaseline4R1 +- EulynxBaseline4R2 diff --git a/src/Point/Startup.cs b/src/Point/Startup.cs index 9905df9..378bc3e 100644 --- a/src/Point/Startup.cs +++ b/src/Point/Startup.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer; using EulynxLive.Point.Services; using EulynxLive.FieldElementSubsystems.Interfaces; -using EulynxBaseline4R1 = EulynxLive.FieldElementSubsystems.Connections.EulynxBaseline4R1; -using EulynxBaseline4R2 = EulynxLive.FieldElementSubsystems.Connections.EulynxBaseline4R2; using EulynxLive.Point.Connections; namespace EulynxLive.Point @@ -23,7 +21,7 @@ public void ConfigureServices(IServiceCollection services) services.AddGrpc(); services.AddGrpcReflection(); - services.AddSingleton(ConnectionFactory.CreateConnection); + services.AddSingleton(x => new ConnectionFactory(x.GetRequiredService>(), x.GetRequiredService()).CreateConnection(x)); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration =>