9cad9ed0fc
v2-ci / build (push) Failing after 41s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
Adds <summary>/<param>/<returns>/<inheritdoc> where missing and removes project bookkeeping IDs (task/tracking refs) from shipped code comments, so the docs read cleanly and CommentChecker is quiet except for known false positives (PLC/protocol terms, event/IEqualityComparer inheritdoc). Doc/comment-only; no logic changed; solution builds clean.
49 lines
2.1 KiB
C#
49 lines
2.1 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Drivers;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Hubs;
|
|
|
|
/// <summary>
|
|
/// SignalR hub clients subscribe to for live driver-health updates. Clients invoke
|
|
/// <see cref="JoinDriver"/> once per page-load to receive the current snapshot + future
|
|
/// state transitions for one driver instance.
|
|
/// </summary>
|
|
[Authorize]
|
|
public sealed class DriverStatusHub : Hub
|
|
{
|
|
public const string Endpoint = "/hubs/driverstatus";
|
|
|
|
/// <summary>SignalR method name used to push <see cref="DriverHealthChanged"/> snapshots to clients.</summary>
|
|
public const string MethodName = "status";
|
|
|
|
private readonly IDriverStatusSnapshotStore _store;
|
|
|
|
/// <summary>Initializes a new instance of <see cref="DriverStatusHub"/>.</summary>
|
|
/// <param name="store">In-memory snapshot store supplying current state on join.</param>
|
|
public DriverStatusHub(IDriverStatusSnapshotStore store) => _store = store;
|
|
|
|
/// <summary>
|
|
/// Adds the calling connection to a per-driver-instance group. Immediately replies with
|
|
/// the current snapshot from the in-memory store so the client renders state without
|
|
/// waiting for the next change event.
|
|
/// </summary>
|
|
/// <param name="driverInstanceId">Identifier of the driver instance to join.</param>
|
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
|
public async Task JoinDriver(string driverInstanceId)
|
|
{
|
|
var groupName = GroupName(driverInstanceId);
|
|
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
|
|
|
|
if (_store.TryGet(driverInstanceId, out var snapshot))
|
|
{
|
|
await Clients.Caller.SendAsync(MethodName, snapshot);
|
|
}
|
|
}
|
|
|
|
/// <summary>Builds the SignalR group name for a given driver instance.</summary>
|
|
/// <param name="driverInstanceId">Identifier of the driver instance.</param>
|
|
/// <returns>The SignalR group name for the driver instance.</returns>
|
|
public static string GroupName(string driverInstanceId) => $"driver:{driverInstanceId}";
|
|
}
|