fix(drivers): ILoggerFactory on FOCAS+TwinCAT factories; replace stale TODO(v3 WaveC); AbCip browsePageDelayMs form field; document Device1 + Modbus health (#608 #602 #596)

Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
This commit is contained in:
Joseph Doherty
2026-10-08 06:53:38 -04:00
parent 3baa332d6b
commit 9c39f2b6c4
17 changed files with 192 additions and 50 deletions
@@ -1,5 +1,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Logging;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Core.Hosting;
using ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Wire;
@@ -34,10 +35,12 @@ public static class FocasDriverFactoryExtensions
/// Throws if 'FOCAS' is already registered — single-instance per process.
/// </summary>
/// <param name="registry">The driver factory registry to register with.</param>
public static void Register(DriverFactoryRegistry registry)
/// <param name="loggerFactory">Optional logger factory; without it the driver and its wire client run on
/// the null logger and none of their diagnostics reach the node log (CONV-3).</param>
public static void Register(DriverFactoryRegistry registry, ILoggerFactory? loggerFactory = null)
{
ArgumentNullException.ThrowIfNull(registry);
registry.Register(DriverTypeName, CreateInstance);
registry.Register(DriverTypeName, (id, json) => CreateInstance(id, json, loggerFactory));
}
/// <summary>
@@ -46,18 +49,21 @@ public static class FocasDriverFactoryExtensions
/// <param name="driverInstanceId">The unique driver instance identifier.</param>
/// <param name="driverConfigJson">The driver configuration JSON string.</param>
/// <returns>A configured <see cref="FocasDriver"/> instance.</returns>
internal static FocasDriver CreateInstance(string driverInstanceId, string driverConfigJson)
/// <param name="loggerFactory">Optional logger factory for the driver and its wire client.</param>
internal static FocasDriver CreateInstance(string driverInstanceId, string driverConfigJson,
ILoggerFactory? loggerFactory = null)
{
var binding = ParseBinding(driverInstanceId, driverConfigJson);
var binding = ParseBinding(driverInstanceId, driverConfigJson, loggerFactory);
return new FocasDriver(
binding.Options,
driverInstanceId,
binding.ClientFactory,
loggerFactory?.CreateLogger<FocasDriver>(),
// Hand the driver the SAME parse it was built with, so InitializeAsync can re-derive EVERY
// config-derived dependency on a reinitialize — options AND the backend client factory
// together (#516). Re-parsing options alone would run a new device/tag set against the old
// backend, which is worse than not re-parsing at all.
rebind: json => ParseBinding(driverInstanceId, json));
rebind: json => ParseBinding(driverInstanceId, json, loggerFactory));
}
/// <summary>
@@ -68,8 +74,10 @@ public static class FocasDriverFactoryExtensions
/// </summary>
/// <param name="driverInstanceId">The unique driver instance identifier.</param>
/// <param name="driverConfigJson">The driver configuration JSON string.</param>
/// <param name="loggerFactory">Optional logger factory handed to the wire backend.</param>
/// <returns>The parsed options + backend factory.</returns>
internal static FocasDriverBinding ParseBinding(string driverInstanceId, string driverConfigJson)
internal static FocasDriverBinding ParseBinding(string driverInstanceId, string driverConfigJson,
ILoggerFactory? loggerFactory = null)
{
ArgumentException.ThrowIfNullOrWhiteSpace(driverInstanceId);
ArgumentException.ThrowIfNullOrWhiteSpace(driverConfigJson);
@@ -109,7 +117,7 @@ public static class FocasDriverFactoryExtensions
HandleRecycle = BuildHandleRecycle(dto.HandleRecycle),
};
return new FocasDriverBinding(options, BuildClientFactory(dto, driverInstanceId));
return new FocasDriverBinding(options, BuildClientFactory(dto, driverInstanceId, loggerFactory));
}
/// <summary>
@@ -131,14 +139,15 @@ public static class FocasDriverFactoryExtensions
/// </summary>
/// <param name="dto">The driver configuration DTO.</param>
/// <param name="driverInstanceId">The driver instance identifier for error reporting.</param>
/// <param name="loggerFactory">Optional logger factory for the wire client.</param>
/// <returns>A configured <see cref="IFocasClientFactory"/> instance.</returns>
internal static IFocasClientFactory BuildClientFactory(
FocasDriverConfigDto dto, string driverInstanceId)
FocasDriverConfigDto dto, string driverInstanceId, ILoggerFactory? loggerFactory = null)
{
var backend = (dto.Backend ?? "wire").Trim().ToLowerInvariant();
return backend switch
{
"wire" => new WireFocasClientFactory(),
"wire" => new WireFocasClientFactory(loggerFactory?.CreateLogger<FocasWireClient>()),
"unimplemented" or "none" or "stub" => new UnimplementedFocasClientFactory(),
_ => throw new InvalidOperationException(
$"FOCAS driver config for '{driverInstanceId}' has unknown Backend '{dto.Backend}'. " +