fix(dcl): feed ScadaBridge:MxGateway:ClientNamePrefix into the MxGateway client-name fallback (review 2026-10-21 02/U1, 08/O2)

This commit is contained in:
Joseph Doherty
2026-10-22 06:29:05 -04:00
parent f18d3adbfc
commit 3543a7f295
6 changed files with 71 additions and 6 deletions
@@ -29,6 +29,7 @@ public class MxGatewayDataConnection
private readonly ILogger<MxGatewayDataConnection> _logger;
private readonly ISecretResolver? _secretResolver;
private readonly int _supervisoryAdviseParallelism;
private readonly string _clientNamePrefix;
private IMxGatewayClient? _client;
private ConnectionHealth _status = ConnectionHealth.Disconnected;
private CancellationTokenSource? _eventLoopCts;
@@ -79,16 +80,25 @@ public class MxGatewayDataConnection
/// Maximum in-flight supervisory advise commands on the bulk-subscribe path when the
/// endpoint has no write-user context (<c>DataConnectionOptions.MxSupervisoryAdviseParallelism</c>).
/// </param>
/// <param name="clientNamePrefix">
/// Gateway client registration name used when the connection's own <c>ClientName</c> is blank
/// (<c>ScadaBridge:MxGateway:ClientNamePrefix</c>, default <c>scadabridge</c>). Null or blank
/// keeps the <c>scadabridge</c> default.
/// </param>
public MxGatewayDataConnection(
IMxGatewayClientFactory clientFactory,
ILogger<MxGatewayDataConnection> logger,
ISecretResolver? secretResolver = null,
int supervisoryAdviseParallelism = 16)
int supervisoryAdviseParallelism = 16,
string? clientNamePrefix = null)
{
_clientFactory = clientFactory;
_logger = logger;
_secretResolver = secretResolver;
_supervisoryAdviseParallelism = Math.Max(1, supervisoryAdviseParallelism);
_clientNamePrefix = string.IsNullOrWhiteSpace(clientNamePrefix)
? new MxGatewayGlobalOptions().ClientNamePrefix
: clientNamePrefix.Trim();
}
/// <inheritdoc />
@@ -177,7 +187,7 @@ public class MxGatewayDataConnection
await _client.ConnectAsync(new MxGatewayConnectionOptions(
cfg.Endpoint,
apiKey,
string.IsNullOrWhiteSpace(cfg.ClientName) ? "scadabridge" : cfg.ClientName,
string.IsNullOrWhiteSpace(cfg.ClientName) ? _clientNamePrefix : cfg.ClientName,
cfg.WriteUserId,
cfg.UseTls,
string.IsNullOrWhiteSpace(cfg.CaFile) ? null : cfg.CaFile,
@@ -35,11 +35,13 @@ public class DataConnectionFactory : IDataConnectionFactory
/// construction without it keeps literal-key behaviour.
/// </param>
/// <param name="dataConnectionOptions">Optional data connection options, such as the MxGateway supervisory-advise parallelism; defaults apply when null.</param>
/// <param name="mxGatewayGlobalOptions">Optional MxGateway global options (the client-name fallback); defaults apply when null.</param>
public DataConnectionFactory(
ILoggerFactory loggerFactory,
IOptions<OpcUaGlobalOptions> opcUaGlobalOptions,
ISecretResolver? secretResolver = null,
IOptions<DataConnectionOptions>? dataConnectionOptions = null)
IOptions<DataConnectionOptions>? dataConnectionOptions = null,
IOptions<MxGatewayGlobalOptions>? mxGatewayGlobalOptions = null)
{
_loggerFactory = loggerFactory;
_secretResolver = secretResolver;
@@ -48,6 +50,9 @@ public class DataConnectionFactory : IDataConnectionFactory
// DataConnectionOptions is consumed by the actor, which is constructed elsewhere.
var supervisoryAdviseParallelism =
(dataConnectionOptions?.Value ?? new DataConnectionOptions()).MxSupervisoryAdviseParallelism;
// The client registration name a connection with a blank ClientName falls back to
// (review 2026-10-21 02/U1 — the option was bound and validated but never read).
var mxClientNamePrefix = (mxGatewayGlobalOptions?.Value ?? new MxGatewayGlobalOptions()).ClientNamePrefix;
// Register built-in protocols.
// Pass the ILoggerFactory into RealOpcUaClientFactory so
@@ -64,7 +69,8 @@ public class DataConnectionFactory : IDataConnectionFactory
new RealMxGatewayClientFactory(_loggerFactory),
_loggerFactory.CreateLogger<MxGatewayDataConnection>(),
_secretResolver,
supervisoryAdviseParallelism));
supervisoryAdviseParallelism,
mxClientNamePrefix));
}
/// <summary>
@@ -6,6 +6,10 @@ namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer;
/// </summary>
public class MxGatewayGlobalOptions
{
/// <summary>Prefix used to derive a per-connection client registration name when the connection's ClientName is blank.</summary>
/// <summary>
/// Gateway client registration name used by any MxGateway connection whose own ClientName is
/// blank (e.g. set per site to tell sites apart on a shared gateway). The default keeps the
/// historical <c>scadabridge</c> name.
/// </summary>
public string ClientNamePrefix { get; set; } = "scadabridge";
}