2using System.Collections.Generic;
5using System.Threading.Tasks;
40 private string[] fields;
44 private string responseVariable;
77 public override async Task
FromXml(XmlElement Definition)
81 this.responseVariable =
XML.
Attribute(Definition,
"responseVariable");
85 await base.FromXml(Definition);
87 List<ThingReference> Nodes =
null;
88 List<string> Fields =
null;
95 Nodes =
new List<ThingReference>();
97 Nodes.Add(NodeRef.ThingReference);
102 Fields =
new List<string>();
104 Fields.Add(FieldRef.Name);
110 this.nodeReferences = Nodes?.ToArray();
111 this.fields = Fields?.ToArray();
124 throw new Exception(
"Actor not an XMPP Sensor Client.");
129 ??
throw new Exception(
"No connection in roster with Bare JID: " + To);
132 throw new Exception(
"Contact not online: " + To);
137 TaskCompletionSource<bool> T =
new TaskCompletionSource<bool>();
138 Dictionary<string, Field> FieldsAsObject = this.responseType == SensorDataResponseType.Object ?
new Dictionary<string, Field>() :
null;
139 List<Field> FieldsAsArray = this.responseType == SensorDataResponseType.Array ?
new List<Field>() :
null;
140 List<ThingError> Errors =
new List<ThingError>();
143 Request.OnErrorsReceived += (Sender, NewErrors) =>
147 Errors.AddRange(NewErrors);
150 return Task.CompletedTask;
153 Request.OnFieldsReceived += (Sender, NewFields) =>
157 lock (FieldsAsObject)
159 foreach (
Field F
in NewFields)
160 FieldsAsObject[F.Name] = F;
167 FieldsAsArray.AddRange(NewFields);
171 return Task.CompletedTask;
174 Request.OnStateChanged += (Sender, NewState) =>
179 T.TrySetResult(
true);
184 T.TrySetResult(
false);
188 return Task.CompletedTask;
193 StringBuilder sb =
new StringBuilder();
195 sb.AppendLine(
"Sensor Data readout failed. Errors reported: ");
201 throw new Exception(sb.ToString());
204 Variables[this.responseVariable] = (object)FieldsAsObject ?? FieldsAsArray.ToArray();
215 public override void ExportPlantUml(StreamWriter Output,
int Indentation,
char QuoteChar)
217 base.ExportPlantUml(Output, Indentation, QuoteChar);
219 Indent(Output, Indentation);
221 Output.Write(this.actor.
Value);
222 Output.Write(
".ReadSensorData");
227 XMPP.Activities.SendMessage.AppendArgument(Output, Indentation,
"To", this.to.
Value,
true, QuoteChar);
229 Output.WriteLine(
");");
Root node of a simulation model
ISimulationNode[] Children
Child nodes.
async Task< object > GetActorObjectAsync(StringAttribute Actor, Variables Variables)
Gets an actor object, given a string representation, possibly containing script, of the actor.
static void Indent(StreamWriter Output, int Indentation)
Adds indentation to the current row.
Contains the value of a string attribute, possibly with embedded script.
async Task< string > GetValueAsync(Variables Variables)
Gets the value of the attribute.
string Value
String value, from definition
Waher.Things.SensorData.FieldType Type
Field Type
Sends a custom IQ request to a recipient
override string LocalName
Local name of XML element defining contents of class.
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
ReadSensor(ISimulationNode Parent, Model Model)
Sends a custom IQ request to a recipient
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
override async Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
Abstract base class for IoT XMPP activity nodes.
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Maintains information about an item in the roster.
bool HasLastPresence
If the roster item has received presence from an online resource having the given bare JID.
string LastPresenceFullJid
Full JID of last resource sending online presence.
PresenceEventArgs LastPresence
Last presence received from a resource having this bare JID.
Implements an XMPP sensor client interface.
Task< SensorDataClientRequest > RequestReadout(string Destination, FieldType Types)
Requests a sensor data readout.
Manages a sensor data client request.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
static readonly Regex BareJidRegEx
Regular expression for Bare JIDs
XmppClient Client
XMPP Client.
Base class for all sensor data fields.
Contains information about an error on a thing
string ErrorMessage
Error message.
Contains a reference to a thing
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
ISimulationNode Parent
Parent node in the simulation model.
SensorDataResponseType
How sensor data is to be returned.
SensorDataReadoutState
Sensor Data Readout States.
FieldType
Field Type flags