refactor(historian): align ServerHistorianOptions with AlarmHistorian (Port default, Validate list, log context)
This commit is contained in:
@@ -30,7 +30,7 @@ public sealed class ServerHistorianOptions
|
||||
public string Host { get; init; } = "localhost";
|
||||
|
||||
/// <summary>TCP port the Wonderware historian sidecar listens on.</summary>
|
||||
public int Port { get; init; }
|
||||
public int Port { get; init; } = 32569;
|
||||
|
||||
/// <summary>When <c>true</c>, the client connects over TLS.</summary>
|
||||
public bool UseTls { get; init; }
|
||||
@@ -44,12 +44,14 @@ public sealed class ServerHistorianOptions
|
||||
/// <summary>Returns operator-facing misconfiguration warnings for an <c>Enabled</c> historian
|
||||
/// (empty when disabled or correctly configured). Pure — the registration logs each entry.</summary>
|
||||
/// <returns>Zero or more human-readable warning messages.</returns>
|
||||
public IEnumerable<string> Validate()
|
||||
public IReadOnlyList<string> Validate()
|
||||
{
|
||||
if (!Enabled) yield break;
|
||||
var warnings = new List<string>();
|
||||
if (!Enabled) return warnings;
|
||||
if (string.IsNullOrWhiteSpace(SharedSecret))
|
||||
yield return "ServerHistorian:SharedSecret is empty while the historian is enabled — the Wonderware sidecar Hello frame will carry an empty secret.";
|
||||
warnings.Add("ServerHistorian:SharedSecret is empty while the historian is enabled — the Wonderware sidecar Hello frame will carry an empty secret.");
|
||||
if (Port <= 0)
|
||||
yield return $"ServerHistorian:Port is {Port} — must be > 0; the read client cannot dial the sidecar.";
|
||||
warnings.Add($"ServerHistorian:Port is {Port} — must be > 0; the read client cannot dial the sidecar.");
|
||||
return warnings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public static class ServiceCollectionExtensions
|
||||
if (opts is not { Enabled: true }) return services; // leave the Null default from AddOtOpcUaRuntime
|
||||
|
||||
foreach (var warning in opts.Validate())
|
||||
Serilog.Log.Logger.ForContext<ServerHistorianOptions>().Warning("ServerHistorian config: {ServerHistorianConfigWarning}", warning);
|
||||
Serilog.Log.Logger.ForContext<IHistorianDataSource>().Warning("ServerHistorian config: {ServerHistorianConfigWarning}", warning);
|
||||
|
||||
// Last-registration-wins over the TryAddSingleton Null default seeded by AddOtOpcUaRuntime.
|
||||
services.AddSingleton<IHistorianDataSource>(sp => dataSourceFactory(opts, sp));
|
||||
|
||||
Reference in New Issue
Block a user