Skip to content

Commit

Permalink
update factory and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Scretch9 committed Dec 13, 2023
1 parent 3ca2855 commit ed571b5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/FieldElementSubsystems.Test/Point/PointTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ private static Mock<IPointToInterlockingConnection> CreateDefaultMockConnection(
"INTERLOCKING",
"http://localhost:50051",
true,
false
false,
ConnectionProtocol.EulynxBaseline4R1
));
mockConnection.Setup(x => x.TimeoutToken).Returns(() => CancellationToken.None);
mockConnection
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace EulynxLive.FieldElementSubsystems.Configuration;

public enum ConnectionProtocol {
EulynxBaseline4R1,
EulynxBaseline4R2
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public record PointConfiguration(
string RemoteId,
string RemoteEndpoint,
bool? AllPointMachinesCrucial = null,
bool? SimulateRandomTimeouts = null
bool? SimulateRandomTimeouts = null,
ConnectionProtocol? ConnectionProtocol = null
);
29 changes: 26 additions & 3 deletions src/Point/Connections/ConnectionFactory.cs
Original file line number Diff line number Diff line change
@@ -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<T> (IServiceProvider x) where T : IPointToInterlockingConnection {
public class ConnectionFactory{
private IConfiguration _configuration { get; }
private ILogger<ConnectionFactory> _logger { get; }

public ConnectionFactory(ILogger<ConnectionFactory> logger, IConfiguration configuration){
_logger = logger;
_configuration = configuration;
}

return ActivatorUtilities.CreateInstance<T>(x, CancellationToken.None);
public IPointToInterlockingConnection CreateConnection(IServiceProvider x) {
var connectionProtocol = _configuration.GetSection("ConnectionSettings").Get<PointConfiguration>()?.ConnectionProtocol;
switch (connectionProtocol){
case ConnectionProtocol.EulynxBaseline4R1:
return new EulynxBaseline4R1.PointToInterlockingConnection(x.GetRequiredService<ILogger<EulynxBaseline4R1.PointToInterlockingConnection>>(), _configuration, CancellationToken.None);
case ConnectionProtocol.EulynxBaseline4R2:
return new EulynxBaseline4R2.PointToInterlockingConnection(x.GetRequiredService<ILogger<EulynxBaseline4R2.PointToInterlockingConnection>>(), _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<ILogger<EulynxBaseline4R2.PointToInterlockingConnection>>(), _configuration, CancellationToken.None);
}
}
}
23 changes: 22 additions & 1 deletion src/Point/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions src/Point/Startup.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,7 +21,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddGrpc();
services.AddGrpcReflection();

services.AddSingleton(ConnectionFactory.CreateConnection<EulynxBaseline4R1.PointToInterlockingConnection>);
services.AddSingleton(x => new ConnectionFactory(x.GetRequiredService<ILogger<ConnectionFactory>>(), x.GetRequiredService<IConfiguration>()).CreateConnection(x));

// In production, the React files will be served from this directory
services.AddSpaStaticFiles(configuration =>
Expand Down

0 comments on commit ed571b5

Please sign in to comment.