Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FieldItem.cs
1using System;
2using System.Text;
3using System.Windows.Media;
5using Waher.Content;
7
9{
13 public class FieldItem : ColorableItem
14 {
15 private readonly Field field;
16 private readonly QuantityField quantityField;
17
23 : base(Colors.Black, Colors.White)
24 {
25 this.field = Field;
26 this.quantityField = Field as QuantityField;
27
28 FieldQoS QoS = Field.QoS;
29
30 if (QoS.HasFlag(FieldQoS.InvoiceConfirmed) || QoS.HasFlag(FieldQoS.Invoiced))
31 this.BackgroundColor = Colors.Gold;
32 else if (QoS.HasFlag(FieldQoS.EndOfSeries))
33 this.BackgroundColor = Colors.LightBlue;
34 else if (QoS.HasFlag(FieldQoS.Signed))
35 this.BackgroundColor = Colors.LightGreen;
36 else if (QoS.HasFlag(FieldQoS.Error))
37 this.BackgroundColor = Colors.LightPink;
38 else if (QoS.HasFlag(FieldQoS.PowerFailure) || QoS.HasFlag(FieldQoS.TimeOffset) || QoS.HasFlag(FieldQoS.Warning))
39 this.BackgroundColor = Colors.LightYellow;
40 else if (QoS.HasFlag(FieldQoS.Missing) || QoS.HasFlag(FieldQoS.InProgress))
41 this.BackgroundColor = Colors.LightGray;
42 else if (QoS.HasFlag(FieldQoS.AutomaticEstimate) || QoS.HasFlag(FieldQoS.ManualEstimate))
43 this.BackgroundColor = Colors.WhiteSmoke;
44 }
45
49 public Field Field => this.field;
50
54 public string Timestamp
55 {
56 get
57 {
58 return this.field.Timestamp.ToShortDateString() + ", " + this.field.Timestamp.ToLongTimeString();
59 }
60 }
61
65 public string FieldName => this.field.Name;
66
70 public string Value
71 {
72 get
73 {
74 if (!(this.quantityField is null))
75 return CommonTypes.Encode(this.quantityField.Value, this.quantityField.NrDecimals);
76 else
77 return this.field.ObjectValue?.ToString() ?? string.Empty;
78 }
79 }
80
84 public string Unit
85 {
86 get
87 {
88 if (!(this.quantityField is null))
89 return this.quantityField.Unit;
90 else
91 return string.Empty;
92 }
93 }
94
98 public string Status
99 {
100 get
101 {
102 if (this.statusString is null)
103 {
104 StringBuilder Output = null;
105
106 foreach (Enum Value in Enum.GetValues(typeof(FieldQoS)))
107 {
108 if (!this.field.QoS.HasFlag(Value))
109 continue;
110
111 if (Output is null)
112 Output = new StringBuilder();
113 else
114 Output.Append(", ");
115
116 switch ((FieldQoS)Value)
117 {
118 case FieldQoS.Missing: Output.Append("Missing"); break;
119 case FieldQoS.InProgress: Output.Append("In Progress"); break;
120 case FieldQoS.AutomaticEstimate: Output.Append("Automatic Estimate"); break;
121 case FieldQoS.ManualEstimate: Output.Append("Manual Estimate"); break;
122 case FieldQoS.ManualReadout: Output.Append("Manual Readout"); break;
123 case FieldQoS.AutomaticReadout: Output.Append("Automatic Readout"); break;
124 case FieldQoS.TimeOffset: Output.Append("Time Offset"); break;
125 case FieldQoS.Warning: Output.Append("Warning"); break;
126 case FieldQoS.Error: Output.Append("Error"); break;
127 case FieldQoS.Signed: Output.Append("Signed"); break;
128 case FieldQoS.Invoiced: Output.Append("Invoiced"); break;
129 case FieldQoS.EndOfSeries: Output.Append("End of Series"); break;
130 case FieldQoS.PowerFailure: Output.Append("Power Failure"); break;
131 case FieldQoS.InvoiceConfirmed: Output.Append("Invoice Confirmed"); break;
132 default: Output.Append(Value.ToString()); break;
133 }
134 }
135
136 this.statusString = Output.ToString();
137 }
138
139 return this.statusString;
140 }
141 }
142
143 private string statusString = null;
144
148 public string Type
149 {
150 get
151 {
152 if (this.typeString is null)
153 {
154 StringBuilder Output = null;
155
156 foreach (Enum Value in Enum.GetValues(typeof(FieldType)))
157 {
158 if (!this.field.Type.HasFlag(Value))
159 continue;
160
161 if (Output is null)
162 Output = new StringBuilder();
163 else
164 Output.Append(", ");
165
166 switch ((FieldType)Value)
167 {
168 case FieldType.Momentary: Output.Append("Momentary"); break;
169 case FieldType.Identity: Output.Append("Identity"); break;
170 case FieldType.Status: Output.Append("Status"); break;
171 case FieldType.Computed: Output.Append("Computed"); break;
172 case FieldType.Peak: Output.Append("Peak"); break;
173 case FieldType.Historical: Output.Append("Historical"); break;
174 default: Output.Append(Value.ToString()); break;
175 }
176 }
177
178 this.typeString = Output.ToString();
179 }
180
181 return this.typeString;
182 }
183 }
184
185 private string typeString = null;
186
187 public string Alignment
188 {
189 get
190 {
191 if (this.field is QuantityField ||
192 this.field is Int32Field ||
193 this.field is Int64Field)
194 {
195 return "Right";
196 }
197 else if (this.field is BooleanField)
198 return "Center";
199 else
200 return "Left";
201 }
202 }
203
204 }
205}
Represents one item in a sensor data readout.
Definition: FieldItem.cs:14
FieldItem(Field Field)
Represents one item in a sensor data readout.
Definition: FieldItem.cs:22
Abstract base class for selectable colorable item.
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:594
Represents a boolean value that can be either true or false.
Definition: BooleanField.cs:11
Base class for all sensor data fields.
Definition: Field.cs:20
FieldQoS QoS
Field Quality of Service flags.
Definition: Field.cs:269
Represents a 32-bit integer value.
Definition: Int32Field.cs:10
Represents a 64-bit integer value.
Definition: Int64Field.cs:10
Represents a physical quantity value.
FieldQoS
Field Quality of Service flags
Definition: FieldQoS.cs:10
FieldType
Field Type flags
Definition: FieldType.cs:10