change to netcore
This commit is contained in:
parent
8381edd133
commit
35ba2b8135
@ -15,6 +15,7 @@
|
|||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<PackageReleaseNotes>1.1.0 Rewrite Module to reconnect itselfs, so you dont need to watch over the the state of the connection</PackageReleaseNotes>
|
<PackageReleaseNotes>1.1.0 Rewrite Module to reconnect itselfs, so you dont need to watch over the the state of the connection</PackageReleaseNotes>
|
||||||
<NeutralLanguage>de-DE</NeutralLanguage>
|
<NeutralLanguage>de-DE</NeutralLanguage>
|
||||||
|
<PackageId>Mqtt.Data.Connector.IoT.Utils.BlubbFish</PackageId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -13,7 +13,7 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
|
|||||||
private Thread connectionWatcher;
|
private Thread connectionWatcher;
|
||||||
|
|
||||||
public Mqtt(Dictionary<String, String> settings) : base(settings) {
|
public Mqtt(Dictionary<String, String> settings) : base(settings) {
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Mqtt.Mqtt()");
|
Console.WriteLine("ConnectorDataMqtt_constr("+this.ToString()+")");
|
||||||
Int32 port = 1883;
|
Int32 port = 1883;
|
||||||
if(this.settings.ContainsKey("port")) {
|
if(this.settings.ContainsKey("port")) {
|
||||||
port = Int32.Parse(this.settings["port"]);
|
port = Int32.Parse(this.settings["port"]);
|
||||||
@ -22,6 +22,25 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
|
|||||||
this.ConnectionWatcher();
|
this.ConnectionWatcher();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override String ToString() {
|
||||||
|
String ret = "mqtt://";
|
||||||
|
if (this.settings.ContainsKey("user")) {
|
||||||
|
ret += this.settings["user"];
|
||||||
|
if (this.settings.ContainsKey("pass")) {
|
||||||
|
ret += ":" + this.settings["pass"];
|
||||||
|
}
|
||||||
|
ret += "@";
|
||||||
|
}
|
||||||
|
ret += this.settings["server"];
|
||||||
|
if (this.settings.ContainsKey("port")) {
|
||||||
|
ret += ":" + this.settings["port"];
|
||||||
|
}
|
||||||
|
if (this.settings.ContainsKey("topic")) {
|
||||||
|
ret += "/" + this.settings["topic"];
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#region ConectionManage
|
#region ConectionManage
|
||||||
private void ConnectionWatcher() {
|
private void ConnectionWatcher() {
|
||||||
this.connectionWatcher = new Thread(this.ConnectionWatcherRunner);
|
this.connectionWatcher = new Thread(this.ConnectionWatcherRunner);
|
||||||
@ -40,7 +59,7 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Reconnect() {
|
private void Reconnect() {
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Mqtt.Reconnect()");
|
Console.WriteLine("ConnectorDataMqtt_Reconnect(" + this.ToString() + ")");
|
||||||
if(this.IsConnected) {
|
if(this.IsConnected) {
|
||||||
this.Disconnect(true);
|
this.Disconnect(true);
|
||||||
} else {
|
} else {
|
||||||
@ -50,7 +69,7 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Disconnect(Boolean complete) {
|
private void Disconnect(Boolean complete) {
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Mqtt.Disconnect()");
|
Console.WriteLine("ConnectorDataMqtt_Disconnect(" + this.ToString() + ")");
|
||||||
this.client.MqttMsgPublishReceived -= this.Client_MqttMsgPublishReceived;
|
this.client.MqttMsgPublishReceived -= this.Client_MqttMsgPublishReceived;
|
||||||
this.Unsubscripe();
|
this.Unsubscripe();
|
||||||
if(complete) {
|
if(complete) {
|
||||||
@ -59,7 +78,7 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Connect() {
|
private void Connect() {
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Mqtt.Connect()");
|
Console.WriteLine("ConnectorDataMqtt_Connect(" + this.ToString() + ")");
|
||||||
this.client.MqttMsgPublishReceived += this.Client_MqttMsgPublishReceived;
|
this.client.MqttMsgPublishReceived += this.Client_MqttMsgPublishReceived;
|
||||||
_ = this.settings.ContainsKey("user") && this.settings.ContainsKey("pass")
|
_ = this.settings.ContainsKey("user") && this.settings.ContainsKey("pass")
|
||||||
? this.client.Connect(Guid.NewGuid().ToString(), this.settings["user"], this.settings["pass"])
|
? this.client.Connect(Guid.NewGuid().ToString(), this.settings["user"], this.settings["pass"])
|
||||||
@ -106,11 +125,10 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
|
|||||||
|
|
||||||
protected virtual void Dispose(Boolean disposing) {
|
protected virtual void Dispose(Boolean disposing) {
|
||||||
if(!this.disposedValue) {
|
if(!this.disposedValue) {
|
||||||
if(disposing) {try {
|
if(disposing) {
|
||||||
try {
|
try {
|
||||||
this.connectionWatcher.Abort();
|
this.connectionWatcher.Abort();
|
||||||
this.connectionWatcher = null;
|
this.connectionWatcher = null;
|
||||||
} catch { }
|
|
||||||
this.Disconnect(true);
|
this.Disconnect(true);
|
||||||
} catch (Exception) { }
|
} catch (Exception) { }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user