merge(deferred-10): aggregated live alarm stream for Alarm Summary

Merges plan #10 (feat/live-alarm-stream) into main alongside plan #22.

Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
Joseph Doherty
2026-07-10 13:01:04 -04:00
36 changed files with 3327 additions and 53 deletions
@@ -127,6 +127,26 @@ public sealed class AlarmSummaryService : IAlarmSummaryService
}
}
/// <inheritdoc/>
public AlarmSummaryResult BuildFromLiveAlarms(IReadOnlyList<AlarmStateChanged> alarms)
{
ArgumentNullException.ThrowIfNull(alarms);
// Flatten one row per alarm (instance from the alarm itself, mirroring
// FetchInstanceAsync) and apply the SAME deterministic instance-then-name
// sort as GetSiteAlarmsAsync so the live and poll paths render identically.
var orderedRows = alarms
.Select(alarm => new AlarmSummaryRow(alarm.InstanceUniqueName, alarm))
.OrderBy(r => r.InstanceUniqueName, StringComparer.OrdinalIgnoreCase)
.ThenBy(r => r.Alarm.AlarmName, StringComparer.OrdinalIgnoreCase)
.ToList();
// The live cache is alarm-only, so it cannot enumerate "not reporting"
// instances — left empty here; the periodic poll (GetSiteAlarmsAsync)
// remains the authority for that list.
return new AlarmSummaryResult(orderedRows, Array.Empty<string>());
}
/// <inheritdoc/>
public AlarmRollup ComputeRollup(IReadOnlyList<AlarmSummaryRow> rows)
{
@@ -42,6 +42,28 @@ public interface IAlarmSummaryService
/// </returns>
Task<AlarmSummaryResult> GetSiteAlarmsAsync(int siteId, CancellationToken cancellationToken = default);
/// <summary>
/// Builds an <see cref="AlarmSummaryResult"/> directly from an in-memory live
/// snapshot (plan #10, Task 5) — the current alarms served by
/// <see cref="ZB.MOM.WW.ScadaBridge.Communication.ISiteAlarmLiveCache.GetCurrentAlarms"/>
/// — instead of fanning out per-instance snapshot Asks. Each
/// <see cref="AlarmStateChanged"/> is flattened to one
/// <see cref="AlarmSummaryRow"/> (instance taken from
/// <see cref="AlarmStateChanged.InstanceUniqueName"/>) and ordered with the SAME
/// deterministic instance-then-alarm-name sort as
/// <see cref="GetSiteAlarmsAsync"/>, so the two paths are interchangeable.
/// </summary>
/// <remarks>
/// The live cache carries only alarm state, so it cannot know which Enabled
/// instances are silent-but-reporting versus not reporting at all;
/// <see cref="AlarmSummaryResult.NotReportingInstances"/> is therefore always
/// empty on this path. The page keeps its periodic <see cref="GetSiteAlarmsAsync"/>
/// poll as the authority for "not reporting" (and as a live-stream safety net).
/// </remarks>
/// <param name="alarms">The current live alarm snapshot for a site.</param>
/// <returns>An <see cref="AlarmSummaryResult"/> whose <see cref="AlarmSummaryResult.NotReportingInstances"/> is empty.</returns>
AlarmSummaryResult BuildFromLiveAlarms(IReadOnlyList<AlarmStateChanged> alarms);
/// <summary>
/// Pure roll-up over a set of <see cref="AlarmSummaryRow"/>s. Exposed so the
/// page (and tests) can recompute the headline tiles without re-querying.