Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MqttEventSinkNode.cs
2using System.Threading.Tasks;
3using System.Xml;
4using Waher.Content;
7using Waher.Things;
10
12{
17 {
22 : base()
23 {
24 }
25
39 string SinkId, string Broker, int Port, bool Tls, string UserName,
40 string Password, string Topic)
41 : base(Source, Parent, SinkId)
42 {
43 this.Broker = Broker;
44 this.Port = Port;
45 this.Tls = Tls;
46 this.UserName = UserName;
47 this.Password = Password;
48 this.Topic = Topic;
49 }
50
54 [Page(7, "Configuration")]
55 [Header(159, "Broker:")]
56 [ToolTip(160, "Host name of broker.")]
57 [Required]
58 public string Broker { get; set; }
59
63 [Page(7, "Configuration")]
64 [Header(161, "Port:")]
65 [ToolTip(162, "Port number of the broker.")]
66 [Required]
67 [Range(1, 65535)]
68 public int Port { get; set; }
69
73 [Page(7, "Configuration")]
74 [Header(163, "Use Encryption (TLS)")]
75 [ToolTip(164, "If TLS is used to connect to the broker.")]
76 [Required]
77 public bool Tls { get; set; }
78
82 [Page(7, "Configuration")]
83 [Header(165, "User Name:")]
84 [ToolTip(166, "User name to use when connecting to the broker.")]
85 public string UserName { get; set; }
86
90 [Page(7, "Configuration")]
91 [Header(167, "Password:")]
92 [ToolTip(168, "Password to use when connecting to the broker.")]
93 [Text(TextPosition.AfterField, 169, "Note: Leave User Name and Password empty to either connect anonymously, or authenticate using mTLS where such is supported.")]
94 public string Password { get; set; }
95
99 [Page(7, "Configuration")]
100 [Header(170, "Topic:")]
101 [ToolTip(171, "Topic to publish events to.")]
102 [Required]
103 public string Topic { get; set; }
104
109 public override Task<string> GetTypeNameAsync(Language Language)
110 {
111 return Language.GetStringAsync(typeof(GatewayConfigSource), 172, "MQTT Event Sink");
112 }
113
120 public override async Task<IEnumerable<Parameter>> GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
121 {
122 LinkedList<Parameter> Parameters = (LinkedList<Parameter>)await base.GetDisplayableParametersAsync(Language, Caller);
124
125 Parameters.AddLast(new StringParameter("Broker", await Namespace.GetStringAsync(173, "Broker"), this.Broker));
126 Parameters.AddLast(new Int32Parameter("Port", await Namespace.GetStringAsync(45, "Port Number"), this.Port));
127 Parameters.AddLast(new BooleanParameter("Tls", await Namespace.GetStringAsync(36, "Encrypted"), this.Tls));
128 Parameters.AddLast(new StringParameter("Topic", await Namespace.GetStringAsync(174, "Topic"), this.Topic));
129
130 return Parameters;
131 }
132
137 public override void Export(XmlWriter Output)
138 {
139 Output.WriteStartElement("MqttEventSink");
140 Output.WriteAttributeString("id", this.SinkId);
141 Output.WriteAttributeString("broker", this.Broker);
142 Output.WriteAttributeString("port", this.Port.ToString());
143 Output.WriteAttributeString("tls", CommonTypes.Encode(this.Tls));
144
145 if (!string.IsNullOrEmpty(this.UserName))
146 Output.WriteAttributeString("username", this.UserName);
147
148 if (!string.IsNullOrEmpty(this.Password))
149 Output.WriteAttributeString("password", this.Password);
150
151 Output.WriteAttributeString("topic", this.Topic);
152 Output.WriteEndElement();
153 }
154 }
155}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:15
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:596
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
async Task< Namespace > GetNamespaceAsync(string Name)
Gets the namespace object, given its name, if available.
Definition: Language.cs:99
Contains information about a namespace in a language.
Definition: Namespace.cs:17
Task< LanguageString > GetStringAsync(int Id)
Gets the string object, given its ID, if available.
Definition: Namespace.cs:65
Abstract base class for gateway configuration nodes.
virtual INode Parent
Parent Node, or null if a root node.
GatewayConfigSource Source
Source hosting the node.
Abstract base class for event sink nodes.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
override void Export(XmlWriter Output)
Exports the event sink definition to XML.
MqttEventSinkNode(GatewayConfigSource Source, ConfigurationNode Parent, string SinkId, string Broker, int Port, bool Tls, string UserName, string Password, string Topic)
Representation of a MqttEventSink
override async Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
Tokens available in request.
Definition: RequestOrigin.cs:9
TextPosition
Where the instructions are to be place.
Definition: TextAttribute.cs:9