Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ReportFields.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Threading.Tasks;
5using System.Xml;
9using Waher.Events;
11using Waher.Script;
12using Waher.Things;
14
16{
21 {
22 private FieldNode[] fields;
23 private string eventArgs;
24 private bool more;
25
32 : base(Parent, Model)
33 {
34 }
35
39 public override string LocalName => nameof(ReportFields);
40
48 {
49 return new ReportFields(Parent, Model);
50 }
51
56 public override async Task FromXml(XmlElement Definition)
57 {
58 this.eventArgs = XML.Attribute(Definition, "eventArgs", "e");
59 this.more = XML.Attribute(Definition, "more", false);
60
61 await base.FromXml(Definition);
62
63 List<FieldNode> Fields = new List<FieldNode>();
64
65 foreach (ISimulationNode Node in this.Children)
66 {
67 if (Node is FieldNode Field)
68 Fields.Add(Field);
69 }
70
71 this.fields = Fields.ToArray();
72 }
73
79 public override Task<LinkedListNode<IActivityNode>> Execute(Variables Variables)
80 {
81 if (!Variables.TryGetVariable(this.eventArgs, out Variable v) ||
82 !(v.ValueObject is SensorDataServerRequest e))
83 {
84 throw new Exception("Sensor data event arguments not found.");
85 }
86
87 LinkedList<Field> Fields = new LinkedList<Field>();
88
89 foreach (FieldNode Field in this.fields)
90 {
91 try
92 {
93 Field.AddFields(Fields, Variables);
94 }
95 catch (Exception ex)
96 {
97 ex = Log.UnnestException(ex);
98 e.ReportErrors(false, new ThingError(Field.ThingReference, DateTime.Now, ex.Message));
99 }
100 }
101
102 e.ReportFields(!this.more, Fields);
103
104 return Task.FromResult<LinkedListNode<IActivityNode>>(null);
105 }
106
113 public override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
114 {
115 Indent(Output, Indentation);
116 Output.Write(":ReportFields(");
118 Output.WriteLine(");");
119 }
120
121 }
122}
Root node of a simulation model
Definition: Model.cs:49
static void Indent(StreamWriter Output, int Indentation)
Adds indentation to the current row.
Abstract base class for sensor data field nodes.
Definition: FieldNode.cs:16
Reports new momentary sensor data fields.
static string Join(string[] References)
Joins an array of references, and delimits them with ", ".
static string[] GetThingReferences(FieldNode[] FieldNodes)
Gets referenced thing references
override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
override async Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Definition: ReportFields.cs:56
ReportFields(ISimulationNode Parent, Model Model)
Reports sensor data fields.
Definition: ReportFields.cs:31
override string LocalName
Local name of XML element defining contents of class.
Definition: ReportFields.cs:39
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: ReportFields.cs:47
override Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
Definition: ReportFields.cs:79
Abstract base class for IoT XMPP activity nodes.
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Definition: XML.cs:914
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Definition: Log.cs:818
Contains information about a variable.
Definition: Variable.cs:10
Collection of variables.
Definition: Variables.cs:25
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Definition: Variables.cs:52
Base class for all sensor data fields.
Definition: Field.cs:20
Contains information about an error on a thing
Definition: ThingError.cs:10
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
ISimulationNode Parent
Parent node in the simulation model.