refactor(scripted-alarms): review-fix polish for T5/T7/T8 (observer isolation, warning hoist, doc)
This commit is contained in:
@@ -206,6 +206,13 @@ public sealed record EquipmentScriptedAlarmPlan(
|
||||
/// <see cref="DependencyRefs"/> (an interface-typed list) BY REFERENCE, flagging every alarm as
|
||||
/// "changed" on every parse (fresh list instances). Compare it element-wise so a no-op redeploy
|
||||
/// diffs empty (mirrors <see cref="EquipmentVirtualTagPlan"/>).</summary>
|
||||
/// <remarks>
|
||||
/// <b>DependencyRefs equality is order-sensitive</b> (SequenceEqual).
|
||||
/// <see cref="Phase7Composer.MergeAlarmDependencyRefs"/> is the canonical, deterministic
|
||||
/// producer of that order (predicate <c>ctx.GetTag</c> reads first, then first-seen message
|
||||
/// template tokens). Downstream byte-parity between the live composer and the artifact-decode
|
||||
/// mirror depends on both sides calling <c>MergeAlarmDependencyRefs</c> with identical inputs.
|
||||
/// </remarks>
|
||||
public bool Equals(EquipmentScriptedAlarmPlan? other) =>
|
||||
other is not null &&
|
||||
ScriptedAlarmId == other.ScriptedAlarmId &&
|
||||
@@ -419,37 +426,37 @@ public static class Phase7Composer
|
||||
// template tokens; the reserved {{equip}} double-brace form is excluded). Enabled is carried
|
||||
// (never dropped) — the runtime host decides whether to host a disabled alarm. Ordered by
|
||||
// EquipmentId then ScriptedAlarmId so the upcoming artifact byte-parity test is reliable.
|
||||
var equipmentScriptedAlarms = scriptedAlarms
|
||||
//
|
||||
// Eager foreach (not lazy LINQ Select) so the Trace.TraceWarning fires exactly once per
|
||||
// compose call; a lazy select would re-fire on every re-enumeration of the LINQ chain.
|
||||
var equipmentScriptedAlarms = new List<EquipmentScriptedAlarmPlan>();
|
||||
foreach (var a in scriptedAlarms
|
||||
.OrderBy(a => a.EquipmentId, StringComparer.Ordinal)
|
||||
.ThenBy(a => a.ScriptedAlarmId, StringComparer.Ordinal)
|
||||
.Select(a =>
|
||||
.ThenBy(a => a.ScriptedAlarmId, StringComparer.Ordinal))
|
||||
{
|
||||
if (!scriptsById.TryGetValue(a.PredicateScriptId, out var s))
|
||||
{
|
||||
if (!scriptsById.TryGetValue(a.PredicateScriptId, out var s))
|
||||
{
|
||||
Trace.TraceWarning(
|
||||
"Phase7Composer: scripted alarm '{0}' (equipment '{1}') references predicate " +
|
||||
"script '{2}' which is not in the supplied scripts — skipping.",
|
||||
a.ScriptedAlarmId, a.EquipmentId, a.PredicateScriptId);
|
||||
return null;
|
||||
}
|
||||
var source = s.SourceCode;
|
||||
return new EquipmentScriptedAlarmPlan(
|
||||
ScriptedAlarmId: a.ScriptedAlarmId,
|
||||
EquipmentId: a.EquipmentId,
|
||||
Name: a.Name,
|
||||
AlarmType: a.AlarmType,
|
||||
Severity: a.Severity,
|
||||
MessageTemplate: a.MessageTemplate,
|
||||
PredicateScriptId: a.PredicateScriptId,
|
||||
PredicateSource: source,
|
||||
DependencyRefs: MergeAlarmDependencyRefs(source, a.MessageTemplate),
|
||||
HistorizeToAveva: a.HistorizeToAveva,
|
||||
Retain: a.Retain,
|
||||
Enabled: a.Enabled);
|
||||
})
|
||||
.Where(p => p is not null)
|
||||
.Select(p => p!)
|
||||
.ToList();
|
||||
Trace.TraceWarning(
|
||||
"Phase7Composer: scripted alarm '{0}' (equipment '{1}') references predicate " +
|
||||
"script '{2}' which is not in the supplied scripts — skipping.",
|
||||
a.ScriptedAlarmId, a.EquipmentId, a.PredicateScriptId);
|
||||
continue;
|
||||
}
|
||||
var source = s.SourceCode;
|
||||
equipmentScriptedAlarms.Add(new EquipmentScriptedAlarmPlan(
|
||||
ScriptedAlarmId: a.ScriptedAlarmId,
|
||||
EquipmentId: a.EquipmentId,
|
||||
Name: a.Name,
|
||||
AlarmType: a.AlarmType,
|
||||
Severity: a.Severity,
|
||||
MessageTemplate: a.MessageTemplate,
|
||||
PredicateScriptId: a.PredicateScriptId,
|
||||
PredicateSource: source,
|
||||
DependencyRefs: MergeAlarmDependencyRefs(source, a.MessageTemplate),
|
||||
HistorizeToAveva: a.HistorizeToAveva,
|
||||
Retain: a.Retain,
|
||||
Enabled: a.Enabled));
|
||||
}
|
||||
|
||||
return new Phase7CompositionResult(areas, lines, nodes, plans, alarms, galaxyTags)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user