4using System.Threading.Tasks;
24 private string userName =
string.Empty;
25 private string password =
string.Empty;
26 private string willTopic =
string.Empty;
27 private string willData =
string.Empty;
28 private string brokerKey =
null;
29 private string connectionSubscription =
"#";
30 private bool willRetain =
false;
31 private bool trustServer =
false;
47 [Header(44,
"Trust Server", 80)]
48 [ToolTip(45,
"If the remote server certificate should be trusted even if it is not valid.")]
51 get => this.trustServer;
52 set => this.trustServer = value;
59 [Header(3,
"User Name:")]
60 [ToolTip(4,
"User name used during authentication process.")]
61 [DefaultValueStringEmpty]
65 set => this.userName = value;
72 [Header(5,
"Password:")]
73 [ToolTip(6,
"Password used during authentication process. NOTE: Will be sent in clear text. Don't reuse passwords.")]
79 set => this.password = value;
91 [Header(46,
"Connection Subscription:")]
92 [ToolTip(47,
"Subscription topic executed when connecting. Empty means no subscription will be performed. Multiple subjects can be comma-separated.")]
96 get => this.connectionSubscription;
97 set => this.connectionSubscription = value;
103 [Page(10,
"Last Will and Testament")]
104 [Header(11,
"Will Topic:")]
105 [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.")]
106 [DefaultValueStringEmpty]
109 get => this.willTopic;
110 set => this.willTopic = value;
116 [Page(10,
"Last Will and Testament")]
117 [Header(13,
"Will Data:")]
118 [ToolTip(14,
"When the connection is lost, this content will be published on the topic defined above.")]
119 [DefaultValueStringEmpty]
122 get => this.willData;
123 set => this.willData = value;
129 [Page(10,
"Last Will and Testament")]
130 [Header(15,
"Retain Will on topic.")]
131 [ToolTip(16,
"If the content published on the will should be retained on the topic.")]
132 [DefaultValue(
false)]
135 get => this.willRetain;
136 set => this.willRetain = value;
142 [Page(10,
"Last Will and Testament")]
143 [Header(17,
"Quality of Service:")]
144 [ToolTip(18,
"The quality of service used when sending the last will and testament.")]
152 set => this.willQoS = value;
176 if (!
string.IsNullOrEmpty(this.brokerKey))
179 return base.DestroyAsync();
190 string PrevKey = this.brokerKey;
192 this.connectionSubscription);
194 if (PrevKey != this.brokerKey && !
string.IsNullOrEmpty(PrevKey))
197 return this.brokerKey;
208 return base.NodeUpdated();
218 this.connectionSubscription, this.willTopic, this.willData, this.willRetain, this.willQoS);
238 return await base.RemoveAsync(Child);
241 #region ICommunicationLayer
254 this.
GetBroker().Result.Client?.Add(Sniffer);
262 this.
GetBroker().Result.Client?.AddRange(Sniffers);
270 return this.
GetBroker().Result.Client?.Remove(Sniffer) ??
false;
278 get {
return this.
GetBroker().Result.Client?.Sniffers ?? Array.Empty<
ISniffer>(); }
286 get {
return this.
GetBroker().Result.Client?.HasSniffers ??
false; }
297 IEnumerator IEnumerable.GetEnumerator()
332 public void ReceiveBinary(
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count)
369 public void TransmitBinary(
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count)
428 Client?.Error(
Error);
472 public void ReceiveBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data)
474 this.
ReceiveBinary(Timestamp, ConstantBuffer, Data, 0, Data.Length);
486 public void ReceiveBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count)
490 Client?.
ReceiveBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
514 this.
TransmitBinary(Timestamp, ConstantBuffer, Data, 0, Data.Length);
526 public void TransmitBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count)
530 Client?.
TransmitBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
590 Client?.Error(Timestamp,
Error);
598 public void Exception(DateTime Timestamp,
string Exception)
610 public void Exception(DateTime Timestamp, Exception Exception)
629 List<ICommand> Result =
new List<ICommand>();
631 Result.AddRange(await base.Commands);
632 Result.Add(
new ReconnectCommand((await this.
GetBroker()).Client));
645 LinkedList<Parameter> Result = await base.GetDisplayableParametersAsync(
Language, Caller) as LinkedList<Parameter>;
649 Broker.Client.
State.ToString() ??
string.Empty));
void TransmitText(string Text)
Called when text has been transmitted.
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
void ReceiveText(string Text)
Called when text has been received.
void Warning(string Warning)
Called to inform the viewer of a warning state.
void TransmitBinary(int Count)
Called when binary data has been transmitted.
void ReceiveBinary(int Count)
Called when binary data has been received.
void Information(string Comment)
Called to inform the viewer of something.
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)
Gets an MQTT Broker object, according to connection parameters. If one is not in memory,...
static string GetKey(string Host, int Port, bool Tls, bool TrustServer, string UserName, string Password, string ConnectionSubscription)
Gets sort key for MQTT broker
static MqttBroker GetCachedBroker(string Key)
Gets an MQTT Broker object, if available in the cache.
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.
void TransmitText(string Text)
Called when text has been transmitted.
void Warning(string Warning)
Called to inform the viewer of a warning state.
override async Task< bool > RemoveAsync(INode Child)
TODO
void Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
void Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
void ReceiveBinary(int Count)
Called when binary data has been received.
void ReceiveText(string Text)
Called when text has been received.
async override Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
void TransmitText(DateTime Timestamp, string Text)
Called when text has been transmitted.
void Add(ISniffer Sniffer)
ICommunicationLayer.Add
void ReceiveText(DateTime Timestamp, string Text)
Called when text has been received.
void Exception(DateTime Timestamp, string Exception)
Called to inform the viewer of an exception state.
void AddRange(IEnumerable< ISniffer > Sniffers)
ICommunicationLayer.AddRange
void Information(string Comment)
Called to inform the viewer of something.
string[] EncryptedProperties
Array of properties that are encrypted.
override Task< bool > AcceptsChildAsync(INode Child)
TODO
void ReceiveBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
void TransmitBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
void TransmitBinary(DateTime Timestamp, int Count)
Called when binary data has been transmitted.
Task< MqttBroker > GetBroker()
Gets the corresponding broker node.
IEnumerator< ISniffer > GetEnumerator()
IEnumerable<T>.GetEnumerator()
MqttBroker GetCachedBroker()
Gets the corresponding broker node, if available in the cache.
void Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
void Error(string Error)
Called to inform the viewer of an error state.
void TransmitBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
override Task NodeUpdated()
TODO
void Exception(string Exception)
Called to inform the viewer of an exception state.
bool HasSniffers
If there are sniffers registered on the object.
async Task< IEnumerable< ICommand > > GetCommands()
TODO
bool TrustServer
If connection is encrypted using TLS or not.
void ReceiveBinary(DateTime Timestamp, int Count)
Called when binary data has been received.
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
bool Remove(ISniffer Sniffer)
ICommunicationLayer.Remove
override Task< string > GetTypeNameAsync(Language Language)
Type name representing data.
void TransmitBinary(int Count)
Called when binary data has been transmitted.
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
override Task< IEnumerable< ICommand > > Commands
TODO
MqttQualityOfService WillQoS
TODO
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
MqttBrokerNode()
Node representing a connection to an MQTT broker.
void Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
void ReceiveBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
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 objects containing encrypted properties. Mark the properties that are encrypted with th...
Interface for nodes that are published through the concentrator interface.
MqttQualityOfService
MQTT Quality of Service level.