Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MqttTimTopicNode.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
10
12{
17 {
18 private string timId;
19 private byte[] timIdBin;
20
25 {
26 }
27
31 [Page(1, "IEEE 1451")]
32 [Header(5, "TIM ID:", 200)]
33 [ToolTip(6, "TIM unique identifier.")]
34 [Required]
35 [RegularExpression("[A-Fa-f0-9]{32}")]
36 public string TimId
37 {
38 get => this.timId;
39 set
40 {
41 this.timIdBin = Hashes.StringToBinary(value);
42 this.timId = value;
43 }
44 }
45
49 public byte[] TimIdBinary => this.timIdBin;
50
54 public override string LocalId
55 {
56 get
57 {
58 if (!string.IsNullOrEmpty(this.EntityName))
59 return this.EntityName;
60 else
61 return this.NodeId;
62 }
63 }
64
68 public override Task<string> GetTypeNameAsync(Language Language)
69 {
70 return Language.GetStringAsync(typeof(Ieee1451Parser), 6, "IEEE 1451.0 TIM");
71 }
72
79 public override async Task<IEnumerable<Parameter>> GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
80 {
81 LinkedList<Parameter> Parameters = (LinkedList<Parameter>)await base.GetDisplayableParametersAsync(Language, Caller);
82
83 Parameters.AddLast(new StringParameter("TimId",
84 await Language.GetStringAsync(typeof(MqttNcapTopicNode), 7, "TIM ID"),
85 this.TimId));
86
87 Parameters.AddLast(new StringParameter("NcapId",
88 await Language.GetStringAsync(typeof(MqttNcapTopicNode), 4, "NCAP ID"),
89 this.NcapId));
90
91 return Parameters;
92 }
93
97 public override Task<bool> AcceptsParentAsync(INode Parent)
98 {
99 return Task.FromResult(Parent is MqttNcapTopicNode);
100 }
101
105 public override Task<bool> AcceptsChildAsync(INode Child)
106 {
107 return Task.FromResult(Child is MqttChannelTopicNode);
108 }
109
116 {
117 if (Topic.CurrentParentTopic?.Node is MqttNcapTopicNode &&
118 !(Topic.CurrentParentTopic?.Node is MqttTimTopicNode) &&
119 Guid.TryParse(Topic.CurrentSegment, out _))
120 {
121 return Grade.Excellent;
122 }
123 else
124 return Grade.NotAtAll;
125 }
126
132 public override async Task<IMqttTopicNode> CreateNew(MqttTopicRepresentation Topic)
133 {
134 return new MqttTimTopicNode()
135 {
136 NodeId = await GetUniqueNodeId("TIM-" + Topic.CurrentSegment),
138 TimId = Topic.CurrentSegment,
139 NcapId = Topic.Segments[Topic.SegmentIndex - 1]
140 };
141 }
142 }
143}
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
Contains methods for simple hash calculations.
Definition: Hashes.cs:59
static byte[] StringToBinary(string s)
Parses a hex string.
Definition: Hashes.cs:102
Topic node representing an IEEE 1451.0 Channel.
Topic node representing an IEEE 1451.0 NCAP.
Topic node representing an IEEE 1451.0 TIM.
override Task< bool > AcceptsChildAsync(INode Child)
If the node accepts a given child.
override Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a given parent.
override async Task< IMqttTopicNode > CreateNew(MqttTopicRepresentation Topic)
Creates a new node of the same type.
override Grade Supports(MqttTopicRepresentation Topic)
How well the topic node supports an MQTT topic
override async Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
MqttTimTopicNode()
Topic node representing an IEEE 1451.0 TIM.
override Task< string > GetTypeNameAsync(Language Language)
Diaplayable type name for node.
Static class for IEEE 1451-related parsing tasks.
static async Task< string > GetUniqueNodeId(string NodeId)
Gets a Node ID, based on NodeId that is not already available in the database.
string LocalTopic
Local Topic segment
Contains information about an MQTT topic
string CurrentSegment
Current segment being processed.
MqttTopic CurrentParentTopic
Current parent topic.
string[] Segments
Segments in topic string.
Tokens available in request.
Definition: RequestOrigin.cs:9
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
new INode Parent
Parent Node, or null if a root node.
Grade
Grade enumeration
Definition: Grade.cs:7