Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FieldModel.cs
1using System.ComponentModel;
2using Waher.Events;
4
6{
11 public class FieldModel(Field Field) : INotifyPropertyChanged
12 {
13 private Field field = Field;
14
18 public string Name => this.field.Name;
19
23 public bool Writable => this.field.Writable;
24
28 public FieldQoS QoS => this.field.QoS;
29
33 public FieldType Type => this.field.Type;
34
38 public DateTime Timestamp => this.field.Timestamp;
39
43 public string ValueString
44 {
45 get
46 {
47 if (this.field is DateTimeField DT)
48 return DT.Value.ToShortDateString() + ", " + DT.Value.ToLongTimeString();
49 else if (this.field is DateField D)
50 return D.Value.ToShortDateString();
51 else
52 return this.field.ValueString;
53 }
54 }
55
60 {
61 get
62 {
63 if (this.field is Int32Field ||
64 this.field is Int64Field ||
65 this.field is QuantityField)
66 {
67 return TextAlignment.End;
68 }
69 else if (this.field is BooleanField ||
70 this.field is DateField ||
71 this.field is DateTimeField ||
72 this.field is DurationField ||
73 this.field is TimeField)
74 {
75 return TextAlignment.Center;
76 }
77 else
78 return TextAlignment.Start;
79 }
80 }
81
85 public Field Field
86 {
87 get => this.field;
88 set
89 {
90 bool NameChanged = this.field.Name != value.Name;
91 bool WritableChanged = this.field.Writable != value.Writable;
92 bool QoSChanged = this.field.QoS != value.QoS;
93 bool TypeChanged = this.field.Type != value.Type;
94 bool TimestampChanged = this.field.Timestamp != value.Timestamp;
95 bool ValueStringChanged = this.field.ValueString != value.ValueString;
96
97 this.field = value;
98
99 if (NameChanged)
100 this.RaisePropertyChanged(nameof(this.Name));
101
102 if (WritableChanged)
103 this.RaisePropertyChanged(nameof(this.Writable));
104
105 if (QoSChanged)
106 this.RaisePropertyChanged(nameof(this.QoS));
107
108 if (TypeChanged)
109 this.RaisePropertyChanged(nameof(this.Type));
110
111 if (TimestampChanged)
112 this.RaisePropertyChanged(nameof(this.Timestamp));
113
114 if (ValueStringChanged)
115 this.RaisePropertyChanged(nameof(this.ValueString));
116 }
117 }
118
119 private void RaisePropertyChanged(string Name)
120 {
121 try
122 {
123 this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(Name));
124 }
125 catch (Exception ex)
126 {
127 Log.Exception(ex);
128 }
129 }
130
134 public event PropertyChangedEventHandler? PropertyChanged;
135 }
136}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Definition: Log.cs:1647
Represents a boolean value that can be either true or false.
Definition: BooleanField.cs:11
Represents a date value.
Definition: DateField.cs:11
Represents a date and optional time value.
Represents a duration value. Duration values adhere to the type specified by xsd:duration.
Base class for all sensor data fields.
Definition: Field.cs:20
FieldQoS QoS
Field Quality of Service flags.
Definition: Field.cs:269
FieldType Type
Field Type flags.
Definition: Field.cs:259
abstract string ValueString
String representation of field value.
Definition: Field.cs:399
string Name
Unlocalized field name.
Definition: Field.cs:279
DateTime Timestamp
Timestamp of field value.
Definition: Field.cs:202
bool Writable
If the field corresponds to a control parameter with the same name.
Definition: Field.cs:301
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.
Represents a time value. Time values adhere to the type specified by xsd:time.
Definition: TimeField.cs:14
TextAlignment
Text alignment of contents.
HorizontalAlignment
Horizontal alignment
Definition: Cell.cs:14
FieldQoS
Field Quality of Service flags
Definition: FieldQoS.cs:10
FieldType
Field Type flags
Definition: FieldType.cs:10