2using System.Collections.Generic;
5using System.Threading.Tasks;
24 private XmlDocument value;
25 private bool first =
true;
68 this.value =
new XmlDocument()
70 PreserveWhitespace =
false
72 this.value.LoadXml(s);
74 this.Timestamp = DateTime.UtcNow;
103 List<Field> Fields =
new List<Field>();
105 if (!(this.value.DocumentElement is
null))
106 this.AppendFields(
ThingReference, Fields, Request, this.value.DocumentElement, Prefix);
110 return Task.CompletedTask;
123 foreach (XmlAttribute Attribute
in Value.Attributes)
125 if (
string.IsNullOrEmpty(Prefix))
126 this.Add(
ThingReference, Fields, Attribute.Name, Attribute.Value, Request);
128 this.Add(
ThingReference, Fields, this.
Append(Prefix, Attribute.Name), Attribute.Value, Request);
131 Dictionary<string, int> Repetitions =
null;
134 foreach (XmlNode N
in Value)
136 if (N is XmlElement ChildElement)
138 s = ChildElement.LocalName;
140 if (Repetitions is
null)
141 Repetitions =
new Dictionary<string, int>();
143 if (Repetitions.TryGetValue(s, out
int i))
144 Repetitions[s] = i - 1;
150 foreach (XmlNode N
in Value)
152 if (N is XmlElement ChildElement)
154 s = ChildElement.LocalName;
156 if (Repetitions.TryGetValue(s, out
int i))
159 Repetitions[s] = i = 1;
161 Repetitions[s] = ++i;
164 s +=
", #" + i.ToString();
167 if (
string.IsNullOrEmpty(Prefix))
168 this.AppendFields(
ThingReference, Fields, Request, ChildElement, s);
170 this.AppendFields(
ThingReference, Fields, Request, ChildElement, Prefix +
", " + s);
172 else if (N is XmlText XmlText)
174 if (
string.IsNullOrEmpty(Prefix))
175 this.Add(
ThingReference, Fields,
"Value", XmlText.InnerText, Request);
177 this.Add(
ThingReference, Fields, Prefix, XmlText.InnerText, Request);
185 if (
int.TryParse(Value, out
int i))
187 else if (
long.TryParse(Value, out
long l))
195 else if (System.TimeSpan.TryParse(Value, out TimeSpan TimeSpan))
197 else if (System.DateTime.TryParse(Value, out DateTime DateTime))
199 if (DateTime.TimeOfDay == TimeSpan.Zero)
225 (n) => Task.FromResult<
string>(
this.xml),
228 XmlDocument Doc = new XmlDocument()
230 PreserveWhitespace = true
235 this.Topic.MqttClient.PUBLISH(
this.Topic.FullTopic,
this.QoS,
this.Retain, Encoding.UTF8.GetBytes(v));
236 return Task.CompletedTask;
246 this.Information(Output, this.xml);
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 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.
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 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....