Adds the draft-editor tab + page surface for authoring Phase 7 virtual tags and scripted alarms, plus the /alarms/historian operator diagnostics page. Monaco loads from CDN via a progressive-enhancement JS shim — the textarea works immediately so the page is functional even if the CDN is unreachable. ## New services (Admin) - ScriptService — CRUD for Script entity. SHA-256 SourceHash recomputed on save so Core.Scripting's CompiledScriptCache hits on re-publish of unchanged source + misses when the source actually changes. - VirtualTagService — CRUD for VirtualTag, with Enabled toggle. - ScriptedAlarmService — CRUD for ScriptedAlarm + lookup of persistent ScriptedAlarmState (logical-id-keyed per plan decision #14). - ScriptTestHarnessService — pre-publish dry-run. Enforces plan decision #22: only inputs the DependencyExtractor identifies can be supplied. Missing / extra synthetic inputs surface as dedicated outcomes. Captures SetVirtualTag writes + Serilog events from the script so the operator can see both the output + the log output before publishing. - HistorianDiagnosticsService — surfaces the local-process IAlarmHistorianSink state on /alarms/historian. Null sink reports Disabled + swallows retry. Live SqliteStoreAndForwardSink reports real queue depth + last-error + drain state and routes the Retry-dead-lettered button through. ## New UI - ScriptsTab.razor (inside DraftEditor tabs) — list + create/edit/delete scripts with Monaco editor + dependency preview + test-harness run panel showing output + writes + log emissions. - ScriptEditor.razor — reusable Monaco-backed textarea. Loads editor from CDN via wwwroot/js/monaco-loader.js. Textarea stays authoritative for Blazor binding; Monaco mirrors into it on every keystroke. - AlarmsHistorian.razor (/alarms/historian) — queue depth + dead-letter depth + drain state badge + last-error banner + Retry-dead-lettered button. - DraftEditor.razor — new "Scripts" tab. ## DI wiring All five services registered in Program.cs. Null historian sink bound at Admin composition time (real SqliteStoreAndForwardSink lives in the Server process). ## Tests — 13/13 Phase7ServicesTests covers: - ScriptService: Add generates logical id + hash, Update recomputes hash on source change, Update same-source keeps hash (cache-hit preservation), Delete is idempotent - VirtualTagService: round-trips trigger flags, Enabled toggle works - ScriptedAlarmService: HistorizeToAveva defaults true per plan decision #15 - ScriptTestHarness: successful run captures output + writes, rejects missing / extra inputs, rejects non-literal paths, compile errors surface as Threw - HistorianDiagnosticsService: null sink reports Disabled + retry returns 0
33 lines
1.4 KiB
C#
33 lines
1.4 KiB
C#
using ZB.MOM.WW.OtOpcUa.Core.AlarmHistorian;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Admin.Services;
|
|
|
|
/// <summary>
|
|
/// Surfaces the local-node historian queue health on the Admin UI's
|
|
/// <c>/alarms/historian</c> diagnostics page (Phase 7 plan decisions #16/#21).
|
|
/// Exposes queue depth / drain state / last-error, and lets the operator retry
|
|
/// dead-lettered rows without restarting the node.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The sink injected here is the server-process <see cref="IAlarmHistorianSink"/>.
|
|
/// When <see cref="NullAlarmHistorianSink"/> is bound (historian disabled for this
|
|
/// deployment), <see cref="TryRetryDeadLettered"/> silently returns 0 and
|
|
/// <see cref="GetStatus"/> reports <see cref="HistorianDrainState.Disabled"/>.
|
|
/// </remarks>
|
|
public sealed class HistorianDiagnosticsService(IAlarmHistorianSink sink)
|
|
{
|
|
public HistorianSinkStatus GetStatus() => sink.GetStatus();
|
|
|
|
/// <summary>
|
|
/// Operator action from the UI's "Retry dead-lettered" button. Returns the number
|
|
/// of rows revived so the UI can flash a confirmation. When the live sink doesn't
|
|
/// implement retry (test doubles, Null sink), returns 0.
|
|
/// </summary>
|
|
public int TryRetryDeadLettered()
|
|
{
|
|
if (sink is SqliteStoreAndForwardSink concrete)
|
|
return concrete.RetryDeadLettered();
|
|
return 0;
|
|
}
|
|
}
|