3using System.Threading.Tasks;
14 private static readonly Dictionary<string, MqttBroker> brokers =
new Dictionary<string, MqttBroker>();
27 public static string GetKey(
string Host,
int Port,
bool Tls,
bool TrustServer,
string UserName,
string Password,
string ConnectionSubscription)
29 StringBuilder sb =
new StringBuilder();
32 sb.AppendLine(Port.ToString());
33 sb.AppendLine(Tls.ToString());
34 sb.AppendLine(TrustServer.ToString());
35 sb.AppendLine(UserName);
36 sb.AppendLine(Password);
37 sb.AppendLine(ConnectionSubscription);
50 if (brokers.TryGetValue(Key, out
MqttBroker Broker))
62 public static async Task<MqttBroker>
GetBroker(
MqttBrokerNode Node,
string Key,
string Host,
int Port,
bool Tls,
bool TrustServer,
63 string UserName,
string Password,
string ConnectionSubscription,
string WillTopic,
string WillData,
bool WillRetain,
70 if (!brokers.TryGetValue(Key, out Broker))
74 if (!(Broker is
null))
76 await Broker.
SetWill(WillTopic, WillData, WillRetain, WillQoS);
81 Broker =
new MqttBroker(Node, Host, Port, Tls, TrustServer, UserName, Password, ConnectionSubscription,
82 WillTopic, WillData, WillRetain, WillQoS);
89 if (brokers.TryGetValue(Key, out Result))
93 brokers[Key] = Result = Broker;
98 if (!(Obsolete is
null))
114 if (!brokers.TryGetValue(Key, out Broker))
115 return Task.CompletedTask;
Contains methods for simple hash calculations.
static string ComputeSHA1HashString(byte[] Data)
Computes the SHA-1 hash of a block of binary data.
MQTT Broker connection object.
bool Remove(string LocalTopic)
Removes a child topic
Task DisposeAsync()
Closes the connection and disposes of all resources.
async Task SetWill(string WillTopic, string WillData, bool WillRetain, MqttQualityOfService WillQoS)
TODO
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.
MqttQualityOfService
MQTT Quality of Service level.