-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.DemoTypes.cs
More file actions
128 lines (110 loc) · 5.31 KB
/
Copy pathMainWindow.DemoTypes.cs
File metadata and controls
128 lines (110 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System.Globalization;
using ArIED61850Tester.Models;
namespace ArIED61850Tester;
public partial class MainWindow
{
private static string ToggleDemoValue(string value)
{
var normalized = value.Trim();
if (normalized.Equals("false", StringComparison.OrdinalIgnoreCase)) return "true";
if (normalized.Equals("true", StringComparison.OrdinalIgnoreCase)) return "false";
if (normalized.Contains("Closed", StringComparison.OrdinalIgnoreCase)) return "Open [01]";
if (normalized.Contains("Open", StringComparison.OrdinalIgnoreCase)) return "Closed [10]";
if (normalized.Equals("Remote", StringComparison.OrdinalIgnoreCase)) return "Local";
if (normalized.Equals("Local", StringComparison.OrdinalIgnoreCase)) return "Remote";
return normalized;
}
private static string BuildSidecarRoot(string reference)
{
foreach (var suffix in new[] { ".stVal", ".mag.f", ".general" })
{
if (reference.EndsWith(suffix, StringComparison.OrdinalIgnoreCase))
return reference[..^suffix.Length];
}
var lastDot = reference.LastIndexOf('.');
return lastDot > 0 ? reference[..lastDot] : reference;
}
private static string FormatDemoAnalog(double value, string unit)
{
var decimals = Math.Abs(value) < 10 ? "0.00" : "0.0";
return string.IsNullOrWhiteSpace(unit)
? value.ToString(decimals, CultureInfo.InvariantCulture)
: $"{value.ToString(decimals, CultureInfo.InvariantCulture)} {unit}";
}
private static DemoSignalSeed Position(string name, string path, string initial)
=> new(name, path, "ST", "Dbpos", "Status", string.Empty, initial, DemoValueKind.Discrete, 0, 0, new[] { "Open [01]", "Closed [10]" }, true);
private static DemoSignalSeed Boolean(string name, string path, bool initial, bool eventEligible)
=> new(name, path, "ST", "BOOLEAN", "Status", string.Empty, initial ? "true" : "false", DemoValueKind.Discrete, 0, 0, new[] { "false", "true" }, eventEligible);
private static DemoSignalSeed State(string name, string path, string[] values, string initial, bool eventEligible)
=> new(name, path, "ST", "INT32", "Status", string.Empty, initial, DemoValueKind.Discrete, 0, 0, values, eventEligible);
private static DemoSignalSeed Counter(string name, string path, int initial)
=> new(name, path, "ST", "INT32", "Counter", string.Empty, initial.ToString(CultureInfo.InvariantCulture), DemoValueKind.Counter, initial, 0, null, false);
private static DemoSignalSeed Analog(string name, string path, string unit, double baseValue, double variation)
=> new(name, path, "MX", "FLOAT32", "Measurement", unit, FormatDemoAnalog(baseValue, unit), DemoValueKind.Analog, baseValue, variation, null, false);
private enum DemoDeviceRole { Bcu, Ocr, LineDiff, Distance, TrafoDiff, BusbarDiff, CapBank, Coupler }
private enum DemoValueKind { Discrete, Analog, Counter }
private sealed record DemoDeviceSpec(string Name, string Description, string IpAddress, string ModelSummary, DemoDeviceRole Role);
private sealed record DemoSignalSeed(
string Name,
string Path,
string FunctionalConstraint,
string DataType,
string Category,
string Unit,
string InitialValue,
DemoValueKind Kind,
double BaseValue,
double Variation,
string[]? DiscreteValues,
bool EventEligible);
private sealed record DemoPointState(
Iec61850MonitorDevice Device,
SignalDefinition Signal,
Iec61850MonitorPoint Point,
DemoSignalSeed Seed);
private sealed record DemoGooseStreamSpec(
string StreamKey,
string IedName,
string AppId,
string SourceMac,
string DestinationMac,
int Vlan,
string ControlBlock,
string DataSet,
IReadOnlyList<DemoGooseLeafState> Leaves);
private sealed class DemoGooseLeafState
{
public DemoGooseLeafState(string name, string path, string typeText, string value)
{
Name = name;
Path = path;
TypeText = typeText;
Value = value;
PreviousValue = value;
}
public string Name { get; }
public string Path { get; }
public string TypeText { get; }
public string Value { get; set; }
public string PreviousValue { get; set; }
}
private sealed class DemoGooseStreamState
{
public DemoGooseStreamState(DemoGooseStreamSpec spec, int stateNumber, int sequenceNumber, long packetCount)
{
Spec = spec;
StateNumber = stateNumber;
SequenceNumber = sequenceNumber;
PacketCount = packetCount;
Leaves = spec.Leaves.Select(leaf => new DemoGooseLeafState(leaf.Name, leaf.Path, leaf.TypeText, leaf.Value)).ToList();
LastTimelineTimestamp = DateTimeOffset.Now.AddSeconds(-8);
}
public DemoGooseStreamSpec Spec { get; }
public GooseStreamRow Row { get; set; } = null!;
public List<DemoGooseLeafState> Leaves { get; }
public int StateNumber { get; set; }
public int SequenceNumber { get; set; }
public long PacketCount { get; set; }
public DateTimeOffset LastTimelineTimestamp { get; set; }
}
}