Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Base64Ncap.cs
1using System;
2using System.Threading.Tasks;
8
10{
14 public class Base64Ncap : Ncap
15 {
16 private bool firstMessage = true;
17
21 public Base64Ncap()
22 : base()
23 {
24 }
25
31 public Base64Ncap(MqttTopic Topic, byte[] Value)
32 : base(Topic, Value)
33 {
34 }
35
42 public override async Task<DataProcessingResult> DataReported(MqttTopic Topic, MqttContent Content)
43 {
44 string s = Content.DataString;
45
46 if (!Base64Data.RegEx.IsMatch(s))
47 return this.firstMessage ? DataProcessingResult.Incompatible : DataProcessingResult.Processed;
48
49 try
50 {
51 this.firstMessage = false;
52 return await this.DataReported(Topic, Content, Convert.FromBase64String(s));
53 }
54 catch (Exception)
55 {
56 return DataProcessingResult.Processed;
57 }
58 }
59
63 public override Task<string> GetTypeName(Language Language)
64 {
65 return Language.GetStringAsync(typeof(RootTopic), 12, "IEEE 1451.1.6 NCAP (BASE64)");
66 }
67
71 public override void SnifferOutput(ICommunicationLayer Output)
72 {
73 }
74
81 public override IMqttData CreateNew(MqttTopic Topic, MqttContent Content)
82 {
83 IMqttData Result = new Base64Ncap(Topic, default);
84 Result.DataReported(Topic, Content);
85 return Result;
86 }
87 }
88}
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
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
Base64-encoded IEEE 1451.1.6 NCAP.
Definition: Base64Ncap.cs:15
override void SnifferOutput(ICommunicationLayer Output)
Outputs the parsed data to the sniffer.
Definition: Base64Ncap.cs:71
override async Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
Definition: Base64Ncap.cs:42
Base64Ncap(MqttTopic Topic, byte[] Value)
Base64-encoded IEEE 1451.1.6 NCAP.
Definition: Base64Ncap.cs:31
Base64Ncap()
Base64-encoded IEEE 1451.1.6 NCAP.
Definition: Base64Ncap.cs:21
override Task< string > GetTypeName(Language Language)
Type name representing data.
Definition: Base64Ncap.cs:63
override IMqttData CreateNew(MqttTopic Topic, MqttContent Content)
Creates a new instance of the data.
Definition: Base64Ncap.cs:81
Abstract base class for IEEE 1451.1.6 NCAPs.
Definition: Ncap.cs:22
IEEE 1451.1.6 root topic node
Definition: RootTopic.cs:13
Represents an MQTT topic with base64-encoded binary data.
Definition: Base64Data.cs:19
static readonly Regex RegEx
Parsed regular expression for BASE64-encoded data.
Definition: Base64Data.cs:28
MQTT Topic information.
Definition: MqttTopic.cs:19
Interface for observable classes implementing communication protocols.
Interface for MQTT Data encapsulations
Definition: IMqttData.cs:38
Task< DataProcessingResult > DataReported(MqttTopic Topic, MqttContent Content)
Called when new data has been published.
DataProcessingResult
Results from processing an incoming message.
Definition: IMqttData.cs:17