Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GuidData.cs
1using System;
2using System.Text;
3using System.Threading.Tasks;
10
12{
16 public class GuidData : MqttData
17 {
18 private Guid value;
19
23 public GuidData()
24 : base()
25 {
26 }
27
33 public GuidData(MqttTopic Topic, Guid Value)
34 : base(Topic)
35 {
36 this.value = Value;
37 }
38
45 public override Task<DataProcessingResult> DataReported(MqttTopic Topic, MqttContent Content)
46 {
47 if (Guid.TryParse(Content.DataString, out Guid Value))
48 {
49 this.value = Value;
50 this.Timestamp = DateTime.UtcNow;
51 this.QoS = Content.Header.QualityOfService;
52 this.Retain = Content.Header.Retain;
53
54 return Task.FromResult(DataProcessingResult.ProcessedNewMomentaryValues);
55 }
56 else
57 return Task.FromResult(DataProcessingResult.Incompatible);
58 }
59
63 public override Task<string> GetTypeName(Language Language)
64 {
65 return Language.GetStringAsync(typeof(MqttTopicNode), 36, "GUID");
66 }
67
75 public override Task StartReadout(ThingReference ThingReference, ISensorReadout Request, string Prefix, bool Last)
76 {
77 Request.ReportFields(Last, new StringField(ThingReference, this.Timestamp, this.Append(Prefix, "Value"),
78 this.value.ToString(), FieldType.Momentary, FieldQoS.AutomaticReadout));
79
80 return Task.CompletedTask;
81 }
82
86 public override bool IsControllable => true;
87
92 {
93 return new ControlParameter[]
94 {
95 new StringControlParameter("Value", "Publish", "Value:", "GUID value of topic.", @"^[{(]?[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}[)}]?$",
96 (n) => Task.FromResult<string>(this.value.ToString()),
97 (n, v) =>
98 {
99 this.value = Guid.Parse(v);
100 this.Topic.MqttClient.PUBLISH(this.Topic.FullTopic, this.QoS, this.Retain, Encoding.UTF8.GetBytes(v));
101 return Task.CompletedTask;
102 })
103 };
104 }
105
109 public override void SnifferOutput(ICommunicationLayer Output)
110 {
111 this.Information(Output, this.value.ToString());
112 }
113
117 public override Grade DefaultSupport => Grade.Excellent;
118
126 {
127 IMqttData Result = new GuidData(Topic, default);
128 Result.DataReported(Topic, Content);
129 return Result;
130 }
131 }
132}
Information about content received from the MQTT server.
Definition: MqttContent.cs:9
string DataString
String representation of UTF-8 encoded binary data.
Definition: MqttContent.cs:56
MqttHeader Header
MQTT Header
Definition: MqttContent.cs:35
Contains information about a language.
Definition: Language.cs:17
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 ...
Definition: Language.cs:209
Abstract base class for control parameters.
Represents an MQTT topic with GUID data.
Definition: GuidData.cs:17
override Task< string > GetTypeName(Language Language)
Type name representing data.
Definition: GuidData.cs:63
override Task StartReadout(ThingReference ThingReference, ISensorReadout Request, string Prefix, bool Last)
Starts a readout of the data.
Definition: GuidData.cs:75
GuidData()
Represents an MQTT topic with GUID data.
Definition: GuidData.cs:23
GuidData(MqttTopic Topic, Guid Value)
Represents an MQTT topic with GUID data.
Definition: GuidData.cs:33
override Grade DefaultSupport
Default support.
Definition: GuidData.cs:117
override Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
Definition: GuidData.cs:45
override IMqttData CreateNew(MqttTopic Topic, MqttContent Content)
Creates a new instance of the data.
Definition: GuidData.cs:125
override void SnifferOutput(ICommunicationLayer Output)
Outputs the parsed data to the sniffer.
Definition: GuidData.cs:109
override ControlParameter[] GetControlParameters()
TODO
Definition: GuidData.cs:91
Abstract base class for MQTT data encapsulations.
Definition: MqttData.cs:18
void Information(ICommunicationLayer Output, string Info)
Outputs information to sniffer.
Definition: MqttData.cs:91
DateTime Timestamp
Timestamp of data reception.
Definition: MqttData.cs:39
string Append(string Prefix, string Name)
Appends a name to a topic name.
Definition: MqttData.cs:100
MQTT Topic information.
Definition: MqttTopic.cs:19
A Metering node representing an MQTT topic
Represents a string value.
Definition: StringField.cs:10
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
Definition: IMqttData.cs:38
Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
Grade
Grade enumeration
Definition: Grade.cs:7
DataProcessingResult
Results from processing an incoming message.
Definition: IMqttData.cs:17
FieldQoS
Field Quality of Service flags
Definition: FieldQoS.cs:10
FieldType
Field Type flags
Definition: FieldType.cs:10
MqttQualityOfService QualityOfService
Quality of Service level.
Definition: MqttHeader.cs:16