Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ExternalWebNode.cs
2using System.Threading.Tasks;
6
8{
13 {
14 private static readonly Dictionary<string, KeyValuePair<Field[], ThingError[]>> sensorData = new Dictionary<string, KeyValuePair<Field[], ThingError[]>>();
15
20 : base()
21 {
22 }
23
27 public override Task<string> GetTypeNameAsync(Language Language)
28 {
29 return Language.GetStringAsync(typeof(LocalWebServerNode), 2, "External Web Node");
30 }
31
35 public override Task<bool> AcceptsChildAsync(INode Child)
36 {
37 return Task.FromResult(Child is ExternalWebNode);
38 }
39
45 public override Task<bool> AcceptsParentAsync(INode Parent)
46 {
47 return Task.FromResult(Parent is ExternalWebNode || Parent is LocalWebServerNode);
48 }
49
55 internal async Task NewSensorData(Field[] Fields, ThingError[] Errors)
56 {
57 bool PrevError;
58
59 lock (sensorData)
60 {
61 PrevError = sensorData.TryGetValue(this.NodeId, out KeyValuePair<Field[], ThingError[]> P)
62 && (P.Value?.Length ?? 0) > 0;
63
64 sensorData[this.NodeId] = new KeyValuePair<Field[], ThingError[]>(Fields, Errors);
65 }
66
67 if (!(Fields is null))
68 {
69 List<Field> MomentaryValues = null;
70
71 foreach (Field Field in Fields)
72 {
73 if (Field.Type.HasFlag(FieldType.Momentary))
74 {
75 MomentaryValues ??= new List<Field>();
76 MomentaryValues.Add(Field);
77 }
78 }
79
80 if (!(MomentaryValues is null))
81 await this.NewMomentaryValues(MomentaryValues.ToArray());
82 }
83
84 if (Errors is null)
85 {
86 if (PrevError)
87 await this.RemoveErrorAsync();
88 }
89 else
90 {
91 foreach (ThingError Error in Errors)
92 await this.LogErrorAsync(Error.ErrorMessage);
93 }
94 }
95
100 public async Task StartReadout(ISensorReadout Request)
101 {
102 KeyValuePair<Field[], ThingError[]> Data;
103 bool Found;
104
105 lock (sensorData)
106 {
107 Found = sensorData.TryGetValue(this.NodeId, out Data);
108 }
109
110 if (Found)
111 {
112 if (!(Data.Key is null))
113 await Request.ReportFields(Data.Value is null, Data.Key);
114
115 if (!(Data.Value is null))
116 await Request.ReportErrors(true, Data.Value);
117
118 if (Data.Key is null && Data.Value is null)
119 await Request.ReportErrors(true, new ThingError(this, "No Sensor Data reported."));
120 }
121 else
122 await Request.ReportErrors(true, new ThingError(this, "No Sensor Data reported."));
123 }
124 }
125}
Contains information about a language.
Definition: Language.cs:17
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Definition: Language.cs:209
Node representing an external web node.
override Task< bool > AcceptsChildAsync(INode Child)
TODO
override Task< string > GetTypeNameAsync(Language Language)
Type name representing data.
override Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a presumptive parent, i.e. can be added to that parent (if that parent accepts th...
async Task StartReadout(ISensorReadout Request)
Starts the readout of the sensor.
ExternalWebNode()
Node representing an external web node.
Node representing the local web server.
Base class for all metering nodes.
Definition: MeteringNode.cs:30
Task NewMomentaryValues(params Field[] Values)
Reports newly measured values.
virtual Task LogErrorAsync(string Body)
Logs an error message on the node.
INode Parent
Parent Node, or null if a root node.
virtual Task< bool > RemoveErrorAsync()
Removes error messages with an empty event ID from the node.
Base class for all sensor data fields.
Definition: Field.cs:20
FieldType Type
Field Type flags.
Definition: Field.cs:259
Contains information about an error on a thing
Definition: ThingError.cs:10
string ErrorMessage
Error message.
Definition: ThingError.cs:70
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
Interface for sensor nodes.
Definition: ISensor.cs:9
Interface for classes managing sensor data readouts.
Task ReportErrors(bool Done, params ThingError[] Errors)
Report error states to the client.
Task ReportFields(bool Done, params Field[] Fields)
Report read fields to the client.
FieldType
Field Type flags
Definition: FieldType.cs:10