2using System.Collections;
3using System.Collections.Generic;
4using System.Threading.Tasks;
23 private string userName =
string.Empty;
24 private string password =
string.Empty;
25 private string willTopic =
string.Empty;
26 private string willData =
string.Empty;
27 private string brokerKey =
null;
28 private string connectionSubscription =
"#";
29 private bool willRetain =
false;
30 private bool trustServer =
false;
46 [Header(44,
"Trust Server", 80)]
47 [ToolTip(45,
"If the remote server certificate should be trusted even if it is not valid.")]
50 get => this.trustServer;
51 set => this.trustServer = value;
58 [Header(3,
"User Name:")]
59 [ToolTip(4,
"User name used during authentication process.")]
60 [DefaultValueStringEmpty]
64 set => this.userName = value;
71 [Header(5,
"Password:")]
72 [ToolTip(6,
"Password used during authentication process. NOTE: Will be sent in clear text. Don't reuse passwords.")]
74 [DefaultValueStringEmpty]
78 set => this.password = value;
85 [Header(46,
"Connection Subscription:")]
86 [ToolTip(47,
"Subscription topic executed when connecting. Empty means no subscription will be performed. Multiple subjects can be comma-separated.")]
90 get => this.connectionSubscription;
91 set => this.connectionSubscription = value;
97 [Page(10,
"Last Will and Testament")]
98 [Header(11,
"Will Topic:")]
99 [ToolTip(12,
"When the connection is lost, a Last Will and Testament can be published on this topic to alert subscribers you've lost connection.")]
100 [DefaultValueStringEmpty]
103 get => this.willTopic;
104 set => this.willTopic = value;
110 [Page(10,
"Last Will and Testament")]
111 [Header(13,
"Will Data:")]
112 [ToolTip(14,
"When the connection is lost, this content will be published on the topic defined above.")]
113 [DefaultValueStringEmpty]
116 get => this.willData;
117 set => this.willData = value;
123 [Page(10,
"Last Will and Testament")]
124 [Header(15,
"Retain Will on topic.")]
125 [ToolTip(16,
"If the content published on the will should be retained on the topic.")]
126 [DefaultValue(
false)]
129 get => this.willRetain;
130 set => this.willRetain = value;
136 [Page(10,
"Last Will and Testament")]
137 [Header(17,
"Quality of Service:")]
138 [ToolTip(18,
"The quality of service used when sending the last will and testament.")]
146 set => this.willQoS = value;
170 if (!
string.IsNullOrEmpty(this.brokerKey))
173 return base.DestroyAsync();
184 string PrevKey = this.brokerKey;
186 this.connectionSubscription);
188 if (PrevKey != this.brokerKey && !
string.IsNullOrEmpty(PrevKey))
191 return this.brokerKey;
202 return base.NodeUpdated();
212 this.connectionSubscription, this.willTopic, this.willData, this.willRetain, this.willQoS);
223 return await base.RemoveAsync(Child);
226 #region ICommunicationLayer
239 this.
GetBroker().Result.Client?.Add(Sniffer);
247 this.
GetBroker().Result.Client?.AddRange(Sniffers);
255 return this.
GetBroker().Result.Client?.Remove(Sniffer) ??
false;
271 get {
return this.
GetBroker().Result.Client?.HasSniffers ??
false; }
282 IEnumerator IEnumerable.GetEnumerator()
284 return this.
GetBroker().Result.Client?.GetEnumerator() ??
new ISniffer[0].GetEnumerator();
295 if (!(Client is
null))
307 if (!(Client is
null))
319 if (!(Client is
null))
331 if (!(Client is
null))
343 if (!(Client is
null))
355 if (!(Client is
null))
367 if (!(Client is
null))
368 await Client.Error(
Error);
379 if (!(Client is
null))
391 if (!(Client is
null))
404 if (!(Client is
null))
417 if (!(Client is
null))
430 if (!(Client is
null))
443 if (!(Client is
null))
456 if (!(Client is
null))
469 if (!(Client is
null))
482 if (!(Client is
null))
483 await Client.Error(Timestamp,
Error);
491 public async Task
Exception(DateTime Timestamp,
string Exception)
495 if (!(Client is
null))
496 await Client.
Exception(Timestamp, Exception);
504 public async Task
Exception(DateTime Timestamp, Exception Exception)
508 if (!(Client is
null))
509 await Client.
Exception(Timestamp, Exception);
524 List<ICommand> Result =
new List<ICommand>();
526 Result.AddRange(await base.Commands);
527 Result.Add(
new ReconnectCommand((await this.
GetBroker()).Client));
540 LinkedList<Parameter> Result = await base.GetDisplayableParametersAsync(
Language, Caller) as LinkedList<Parameter>;
544 Broker.Client.
State.ToString() ??
string.Empty));
Task TransmitBinary(byte[] Data)
Called when binary data has been transmitted.
Task Exception(Exception Exception)
Called to inform the viewer of an exception state.
Task Information(string Comment)
Called to inform the viewer of something.
Task TransmitText(string Text)
Called when text has been transmitted.
Task ReceiveText(string Text)
Called when text has been received.
Task ReceiveBinary(byte[] Data)
Called when binary data has been received.
Task Warning(string Warning)
Called to inform the viewer of a warning state.
Manages an MQTT connection. Implements MQTT v3.1.1, as defined in http://docs.oasis-open....
MqttState State
Current state of connection.
Typed enumerator of sniffers.
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 ...
string Host
Host name or IP address.
Node representing a port on an IP Host machine.
bool Tls
If connection is encrypted using TLS or not.
MQTT Broker connection object.
Static class managing connections to MQTT brokers.
static async Task< MqttBroker > GetBroker(MqttBrokerNode Node, string Key, string Host, int Port, bool Tls, bool TrustServer, string UserName, string Password, string ConnectionSubscription, string WillTopic, string WillData, bool WillRetain, MqttQualityOfService WillQoS)
TODO
static string GetKey(string Host, int Port, bool Tls, bool TrustServer, string UserName, string Password, string ConnectionSubscription)
Gets sort key for MQTT broker
static Task DestroyBroker(string Key)
TODO
Node representing a connection to an MQTT broker.
override Task DestroyAsync()
TODO
string ConnectionSubscription
Startup subscription
ISniffer[] Sniffers
Registered sniffers.
async Task ReceiveBinary(DateTime Timestamp, byte[] Data)
Called when binary data has been received.
override async Task< bool > RemoveAsync(INode Child)
TODO
async Task Warning(string Warning)
Called to inform the viewer of a warning state.
async Task ReceiveText(string Text)
Called when text has been received.
async Task Exception(string Exception)
Called to inform the viewer of an exception state.
async override Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
async Task Error(string Error)
Called to inform the viewer of an error state.
void Add(ISniffer Sniffer)
ICommunicationLayer.Add
async Task Exception(DateTime Timestamp, string Exception)
Called to inform the viewer of an exception state.
void AddRange(IEnumerable< ISniffer > Sniffers)
ICommunicationLayer.AddRange
override Task< bool > AcceptsChildAsync(INode Child)
TODO
async Task ReceiveText(DateTime Timestamp, string Text)
Called when text has been received.
Task< MqttBroker > GetBroker()
Gets the corresponding broker node.
IEnumerator< ISniffer > GetEnumerator()
IEnumerable<T>.GetEnumerator()
async Task TransmitBinary(DateTime Timestamp, byte[] Data)
Called when binary data has been transmitted.
override Task NodeUpdated()
TODO
async Task Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
bool HasSniffers
If there are sniffers registered on the object.
async Task< IEnumerable< ICommand > > GetCommands()
TODO
async Task TransmitText(DateTime Timestamp, string Text)
Called when text has been transmitted.
bool TrustServer
If connection is encrypted using TLS or not.
async Task TransmitBinary(byte[] Data)
Called when binary data has been transmitted.
async Task Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
bool Remove(ISniffer Sniffer)
ICommunicationLayer.Remove
async Task Exception(Exception Exception)
Called to inform the viewer of an exception state.
override Task< string > GetTypeNameAsync(Language Language)
Type name representing data.
async Task ReceiveBinary(byte[] Data)
Called when binary data has been received.
override Task< IEnumerable< ICommand > > Commands
TODO
MqttQualityOfService WillQoS
TODO
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
async Task TransmitText(string Text)
Called when text has been transmitted.
async Task Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
async Task Information(string Comment)
Called to inform the viewer of something.
MqttBrokerNode()
Node representing a connection to an MQTT broker.
async Task Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
A Metering node representing an MQTT topic
Tokens available in request.
Interface for observable classes implementing communication protocols.
Interface for sniffers. Sniffers can be added to ICommunicationLayer classes to eavesdrop on communic...
Interface for nodes that are published through the concentrator interface.
MqttQualityOfService
MQTT Quality of Service level.