Adds a new HiLo alarm trigger type with four configurable setpoints
(LoLo / Lo / Hi / HiHi). Each setpoint carries an optional priority,
deadband (for hysteresis), and operator message. The site runtime emits
AlarmStateChanged with an AlarmLevel field so consumers can differentiate
warning vs critical bands.
Plumbing:
- new AlarmLevel enum + AlarmStateChanged.Level/Message init properties
- AlarmTriggerEditor (Blazor) gets a HiLo render with severity tinting
- AlarmTriggerConfigCodec extracted from the editor for testability
- sitestream.proto carries level + message over gRPC
- SemanticValidator enforces numeric attribute, setpoint ordering,
non-negative deadband
- on-trigger scripts get an Alarm global (Name/Level/Priority/Message)
so notification routing can branch by severity
- per-instance InstanceAlarmOverride entity + EF migration + flattening
step + CLI commands; HiLo overrides merge setpoint-by-setpoint, binary
types whole-replace
- DebugView shows a Level badge + per-band message tooltip
- App.razor auto-reloads on permanent Blazor circuit failure
- docker/regen-proto.sh automates the proto regen workflow (the linux/arm64
protoc segfault means generated files are checked in for now)
136 lines
4.0 KiB
C#
136 lines
4.0 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using ScadaLink.Commons.Entities.Instances;
|
|
using ScadaLink.Commons.Entities.Sites;
|
|
using ScadaLink.Commons.Entities.Templates;
|
|
|
|
namespace ScadaLink.ConfigurationDatabase.Configurations;
|
|
|
|
public class InstanceConfiguration : IEntityTypeConfiguration<Instance>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Instance> builder)
|
|
{
|
|
builder.HasKey(i => i.Id);
|
|
|
|
builder.Property(i => i.UniqueName)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(i => i.State)
|
|
.HasConversion<string>()
|
|
.HasMaxLength(50);
|
|
|
|
builder.HasOne<Template>()
|
|
.WithMany()
|
|
.HasForeignKey(i => i.TemplateId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne<Site>()
|
|
.WithMany()
|
|
.HasForeignKey(i => i.SiteId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne<Area>()
|
|
.WithMany()
|
|
.HasForeignKey(i => i.AreaId)
|
|
.OnDelete(DeleteBehavior.SetNull)
|
|
.IsRequired(false);
|
|
|
|
builder.HasMany(i => i.AttributeOverrides)
|
|
.WithOne()
|
|
.HasForeignKey(o => o.InstanceId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder.HasMany(i => i.AlarmOverrides)
|
|
.WithOne()
|
|
.HasForeignKey(o => o.InstanceId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder.HasMany(i => i.ConnectionBindings)
|
|
.WithOne()
|
|
.HasForeignKey(b => b.InstanceId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder.HasIndex(i => new { i.SiteId, i.UniqueName }).IsUnique();
|
|
}
|
|
}
|
|
|
|
public class InstanceAttributeOverrideConfiguration : IEntityTypeConfiguration<InstanceAttributeOverride>
|
|
{
|
|
public void Configure(EntityTypeBuilder<InstanceAttributeOverride> builder)
|
|
{
|
|
builder.HasKey(o => o.Id);
|
|
|
|
builder.Property(o => o.AttributeName)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.Property(o => o.OverrideValue)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.HasIndex(o => new { o.InstanceId, o.AttributeName }).IsUnique();
|
|
}
|
|
}
|
|
|
|
public class InstanceAlarmOverrideConfiguration : IEntityTypeConfiguration<InstanceAlarmOverride>
|
|
{
|
|
public void Configure(EntityTypeBuilder<InstanceAlarmOverride> builder)
|
|
{
|
|
builder.HasKey(o => o.Id);
|
|
|
|
builder.Property(o => o.AlarmCanonicalName)
|
|
.IsRequired()
|
|
.HasMaxLength(400); // Larger than attribute names to fit composed paths.
|
|
|
|
builder.Property(o => o.TriggerConfigurationOverride)
|
|
.HasMaxLength(4000);
|
|
|
|
builder.HasIndex(o => new { o.InstanceId, o.AlarmCanonicalName }).IsUnique();
|
|
}
|
|
}
|
|
|
|
public class InstanceConnectionBindingConfiguration : IEntityTypeConfiguration<InstanceConnectionBinding>
|
|
{
|
|
public void Configure(EntityTypeBuilder<InstanceConnectionBinding> builder)
|
|
{
|
|
builder.HasKey(b => b.Id);
|
|
|
|
builder.Property(b => b.AttributeName)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.HasOne<DataConnection>()
|
|
.WithMany()
|
|
.HasForeignKey(b => b.DataConnectionId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasIndex(b => new { b.InstanceId, b.AttributeName }).IsUnique();
|
|
}
|
|
}
|
|
|
|
public class AreaConfiguration : IEntityTypeConfiguration<Area>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Area> builder)
|
|
{
|
|
builder.HasKey(a => a.Id);
|
|
|
|
builder.Property(a => a.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(200);
|
|
|
|
builder.HasOne<Site>()
|
|
.WithMany()
|
|
.HasForeignKey(a => a.SiteId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
// Self-referencing parent area
|
|
builder.HasOne<Area>()
|
|
.WithMany(a => a.Children)
|
|
.HasForeignKey(a => a.ParentAreaId)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.IsRequired(false);
|
|
|
|
builder.HasIndex(a => new { a.SiteId, a.ParentAreaId, a.Name }).IsUnique();
|
|
}
|
|
}
|