5using System.Threading.Tasks;
24 private XmlDocument value;
25 private bool first =
true;
70 this.Timestamp = DateTime.UtcNow;
99 List<Field> Fields =
new List<Field>();
101 if (!(this.value.DocumentElement is
null))
102 this.AppendFields(
ThingReference, Fields, Request, this.value.DocumentElement, Prefix);
106 return Task.CompletedTask;
119 foreach (XmlAttribute Attribute
in Value.Attributes)
121 if (
string.IsNullOrEmpty(Prefix))
122 this.Add(
ThingReference, Fields, Attribute.Name, Attribute.Value, Request);
124 this.Add(
ThingReference, Fields, this.
Append(Prefix, Attribute.Name), Attribute.Value, Request);
127 Dictionary<string, int> Repetitions =
null;
130 foreach (XmlNode N
in Value)
132 if (N is XmlElement ChildElement)
134 s = ChildElement.LocalName;
136 if (Repetitions is
null)
137 Repetitions =
new Dictionary<string, int>();
139 if (Repetitions.TryGetValue(s, out
int i))
140 Repetitions[s] = i - 1;
146 foreach (XmlNode N
in Value)
148 if (N is XmlElement ChildElement)
150 s = ChildElement.LocalName;
152 if (Repetitions.TryGetValue(s, out
int i))
155 Repetitions[s] = i = 1;
157 Repetitions[s] = ++i;
160 s +=
", #" + i.ToString();
163 if (
string.IsNullOrEmpty(Prefix))
164 this.AppendFields(
ThingReference, Fields, Request, ChildElement, s);
166 this.AppendFields(
ThingReference, Fields, Request, ChildElement, Prefix +
", " + s);
168 else if (N is XmlText XmlText)
170 if (
string.IsNullOrEmpty(Prefix))
171 this.Add(
ThingReference, Fields,
"Value", XmlText.InnerText, Request);
173 this.Add(
ThingReference, Fields, Prefix, XmlText.InnerText, Request);
181 if (
int.TryParse(Value, out
int i))
183 else if (
long.TryParse(Value, out
long l))
191 else if (
System.TimeSpan.TryParse(Value, out TimeSpan TimeSpan))
193 else if (
System.DateTime.TryParse(Value, out DateTime DateTime))
195 if (DateTime.TimeOfDay == TimeSpan.Zero)
221 (n) => Task.FromResult<
string>(
this.xml),
224 XmlDocument Doc = XML.ParseXml(v, true);
227 this.Topic.MqttClient.PUBLISH(this.Topic.FullTopic, this.QoS, this.Retain, Encoding.UTF8.GetBytes(v));
228 return Task.CompletedTask;
Helps with parsing of commong data types.
static bool TryParseRfc822(string s, out DateTimeOffset Value)
Parses a date and time value encoded according to RFC 822, §5.
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Helps with common XML-related tasks.
static XmlDocument ParseXml(string Xml)
Parses an XML Document from its string representation.
static bool IsValidXml(string Xml)
Checks if a string is valid XML
Information about content received from the MQTT server.
string DataString
String representation of UTF-8 encoded binary data.
MqttHeader Header
MQTT Header
Implements an XMPP sensor client interface.
static readonly string[] NamespacesSensorData
Supported sensor-data namespaces.
static SensorData ParseFields(XmlElement Content)
Parses sensor data field definitions.
Contains personal sensor data.
IEnumerable< Field > Fields
Sensor data fields.
Contains information about a language.
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 ...
Abstract base class for control parameters.
Multi-line text control parameter.
Abstract base class for MQTT data encapsulations.
void Information(ICommunicationLayer Output, string Info)
Outputs information to sniffer.
MqttTopic Topic
Topic used
DateTime Timestamp
Timestamp of data reception.
string Append(string Prefix, string Name)
Appends a name to a topic name.
Represents an MQTT topic with XML data.
XmlData()
Represents an MQTT topic with XML data.
override void SnifferOutput(ICommunicationLayer Output)
Outputs the parsed data to the sniffer.
override bool IsControllable
TODO
override ControlParameter[] GetControlParameters()
TODO
override IMqttData CreateNew(MqttTopic Topic, MqttContent Content)
Creates a new instance of the data.
override Grade DefaultSupport
Default support.
override Task StartReadout(ThingReference ThingReference, ISensorReadout Request, string Prefix, bool Last)
Starts a readout of the data.
override Task< string > GetTypeName(Language Language)
Type name representing data.
XmlData(MqttTopic Topic, string Xml, XmlDocument Value)
Represents an MQTT topic with XML data.
override Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
A Metering node representing an MQTT topic
Represents a boolean value that can be either true or false.
Represents a date and optional time value.
Represents a duration value. Duration values adhere to the type specified by xsd:duration.
Represents a 32-bit integer value.
Represents a 64-bit integer value.
Represents a physical quantity value.
Represents a string value.
Represents a time value. Time values adhere to the type specified by xsd:time.
Contains a reference to a thing
Interface for observable classes implementing communication protocols.
Interface for classes managing sensor data readouts.
Task ReportFields(bool Done, params Field[] Fields)
Report read fields to the client.
Interface for MQTT Data encapsulations
Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
DataProcessingResult
Results from processing an incoming message.
FieldQoS
Field Quality of Service flags
FieldType
Field Type flags
Represents a duration value, as defined by the xsd:duration data type: http://www....