2using System.Collections.Generic;
3using System.Threading.Tasks;
20 private readonly SortedDictionary<string, MqttTopic> topics =
new SortedDictionary<string, MqttTopic>();
25 private readonly
string localTopic;
26 private readonly
string fullTopic;
27 private long dataCount = 0;
28 private Exception ex =
null;
29 private DateTime exTP = DateTime.MinValue;
44 if (this.nodeReference is
null && !(
Node is
null))
75 if (this.topics is
null)
83 Result =
new MqttTopic[this.topics.Count];
84 this.topics.Values.CopyTo(Result, 0);
93 MqttTopic Topic = await this.GetLocalTopic(Representation, CreateNew, IgnoreGuids,
Broker);
97 else if (Representation.
MoveNext(Topic))
98 return await Topic.GetTopic(Representation, CreateNew, IgnoreGuids,
Broker);
110 if (this.topics.TryGetValue(CurrentSegment, out Topic))
114 if (IgnoreGuids && Guid.TryParse(CurrentSegment.Replace(
'_',
'-'), out Guid _))
117 if (this.node.HasChildren)
125 if (this.topics.TryGetValue(CurrentSegment, out Topic2))
130 this.topics[CurrentSegment] = Topic;
145 AddNode = await AddNode.
CreateNew(Representation);
150 if (this.topics.TryGetValue(CurrentSegment, out Topic2))
153 this.topics[CurrentSegment] = Topic;
156 await this.node.AddAsync(AddNode);
178 int Len = Content.
Data.Length;
185 this.dataCount += Len;
187 bool NewMomentaryValues;
191 if (this.data is
null)
200 NewMomentaryValues =
false;
204 NewMomentaryValues =
false;
208 NewMomentaryValues =
true;
217 NewMomentaryValues =
false;
220 if (this.broker.Client?.HasSniffers ??
false)
223 if (NewMomentaryValues)
231 this.node.NewMomentaryValues(e.Fields);
236 while (!(Parent is
null))
238 foreach (
Field F
in e.Fields)
240 if (F.Name ==
"Value")
241 F.Name = Current.localTopic;
243 F.Name = Current.localTopic +
", " + F.Name;
249 Parent = Parent.parent;
252 return Task.CompletedTask;
256 return Task.CompletedTask;
263 await this.Exception(ex);
292 this.exTP = DateTime.MinValue;
294 return this.node.RemoveErrorAsync(
"Error");
297 private Task Exception(Exception ex)
300 this.exTP = DateTime.UtcNow;
302 return this.node.LogErrorAsync(
"Error", ex.Message);
310 return this.fullTopic;
321 return this.
StartReadout(this.nodeReference, Request,
string.Empty, DoneAfter);
331 MqttTopic[] ChildNodes = this.GetChildNodes();
333 if (!(ChildNodes is
null) && ChildNodes.Length > 0)
335 foreach (
MqttTopic ChildTopic
in ChildNodes)
338 string.IsNullOrEmpty(Prefix) ? ChildTopic.
LocalTopic : Prefix +
", " + ChildTopic.
LocalTopic,
false);
342 if (!(this.ex is
null))
344 else if (this.data is
null)
346 this.data = await this.node.GetDefaultDataObject();
348 if (this.data is
null)
359 await this.node.RemoveErrorAsync(
"Readout");
364 await this.node.LogErrorAsync(
"Readout", ex.Message);
385 if (!(this.data is
null))
391 if (this.dataCount > 0)
Manages an MQTT connection. Implements MQTT v3.1.1, as defined in http://docs.oasis-open....
Information about content received from the MQTT server.
Manages a chat sensor data readout request.
Static class that dynamically manages types and interfaces available in the runtime environment.
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.
Represents an MQTT topic with binary data.
MQTT Broker connection object.
async Task DataReported(MqttContent Content)
Called when new data has been published.
MqttBroker Broker
MQTT Broker
void SetData< T >(T Data)
Sets the parsed data of a topic.
string FullTopic
Full topic name
async Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(LinkedList< Parameter > Parameters, Language Language, RequestOrigin _)
TODO
ControlParameter[] GetControlParameters()
TODO
async Task StartReadout(ThingReference ThingReference, ISensorReadout Request, string Prefix, bool Last)
TODO
MqttTopic(IMqttTopicNode Node, string FullTopic, string LocalTopic, MqttTopic Parent, MqttBroker Broker)
MQTT Topic information.
IMqttData FindDataType(MqttContent Content)
FInds best implementation to process binary data.
override string ToString()
TODO
string LocalTopic
Local topic name.
IMqttTopicNode Node
Reference to the MQTT Topic Node
bool Remove(string LocalTopic)
Removes a child topic
IMqttData Data
Current parsed data.
Task StartReadout(ISensorReadout Request, bool DoneAfter)
Starts the readout of the sensor.
A Metering node representing an MQTT topic
Contains information about an MQTT topic
bool MoveNext(MqttTopic NewParent)
Moves to the next segment.
string CurrentSegment
Current segment being processed.
string ProcessedSegments
Processed segments
Tokens available in request.
Base class for all sensor data fields.
Contains information about an error on a thing
Contains a reference to a thing
Interface for nodes that are published through the concentrator interface.
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
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.
Interface for thing references.
string Partition
Optional partition in which the Node ID is unique.
string SourceId
Optional ID of source containing node.
void NewMomentaryValues(params Field[] Values)
Reports newly measured values.
new string NodeId
ID of node.
Interface for MQTT Topic nodes.
string LocalTopic
Local Topic segment
Task< IMqttTopicNode > CreateNew(MqttTopicRepresentation Topic)
Creates a new node of the same type.
Interface for MQTT Data encapsulations
Task< string > GetTypeName(Language Language)
Type name representing data.
ControlParameter[] GetControlParameters()
Gets an array of control parameters
bool IsControllable
If data can be controlled (written)
Task StartReadout(ThingReference ThingReference, ISensorReadout Request, string Prefix, bool Last)
Starts a readout of the data.
Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
IMqttData CreateNew(MqttTopic Topic, MqttContent Content)
Creates a new instance of the data.
void SnifferOutput(ICommunicationLayer Output)
Outputs the parsed data to the sniffer.
DataProcessingResult
Results from processing an incoming message.
FieldType
Field Type flags