Refactoring and add netcore
This commit is contained in:
parent
20f0390077
commit
8381edd133
@ -34,6 +34,11 @@
|
||||
<Compile Include="Mqtt.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="..\CONTRIBUTING.md" />
|
||||
<Content Include="..\LICENSE" />
|
||||
<Content Include="..\README.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj">
|
||||
<Project>{a11aef5a-b246-4fe8-8330-06db73cc8074}</Project>
|
||||
|
38
ConnectorDataMqtt/ConnectorDataMqtt_Core.csproj
Normal file
38
ConnectorDataMqtt/ConnectorDataMqtt_Core.csproj
Normal file
@ -0,0 +1,38 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<RootNamespace>BlubbFish.Utils.IoT.Connector.Data</RootNamespace>
|
||||
<AssemblyName>ConnectorDataMqtt</AssemblyName>
|
||||
<Company>BlubbFish</Company>
|
||||
<Authors>BlubbFish</Authors>
|
||||
<Version>1.1.0</Version>
|
||||
<Copyright>Copyright © BlubbFish 2017 - 27.05.2019</Copyright>
|
||||
<Description>ADataBackend Connector that connects to mqtt using M2Mqtt</Description>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<PackageProjectUrl>http://git.blubbfish.net/vs_utils/ConnectorDataMqtt</PackageProjectUrl>
|
||||
<RepositoryUrl>http://git.blubbfish.net/vs_utils/ConnectorDataMqtt.git</RepositoryUrl>
|
||||
<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>
|
||||
<NeutralLanguage>de-DE</NeutralLanguage>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Librarys\mqtt\M2Mqtt\M2Mqtt_Core.csproj" />
|
||||
<ProjectReference Include="..\..\Utils-IoT\Utils-IoT\Utils-IoT_Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="../CONTRIBUTING.md" />
|
||||
<Content Include="../LICENSE" />
|
||||
<Content Include="../README.md" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -61,23 +61,17 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
|
||||
private void Connect() {
|
||||
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Mqtt.Connect()");
|
||||
this.client.MqttMsgPublishReceived += this.Client_MqttMsgPublishReceived;
|
||||
if (this.settings.ContainsKey("user") && this.settings.ContainsKey("pass")) {
|
||||
this.client.Connect(Guid.NewGuid().ToString(), this.settings["user"], this.settings["pass"]);
|
||||
} else {
|
||||
this.client.Connect(Guid.NewGuid().ToString());
|
||||
}
|
||||
_ = 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.Subscripe();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Subscription
|
||||
private void Unsubscripe() {
|
||||
if(this.settings.ContainsKey("topic")) {
|
||||
this.client.Unsubscribe(this.settings["topic"].Split(';'));
|
||||
} else {
|
||||
this.client.Unsubscribe(new String[] { "#" });
|
||||
}
|
||||
}
|
||||
private void Unsubscripe() => _ = this.settings.ContainsKey("topic")
|
||||
? this.client.Unsubscribe(this.settings["topic"].Split(';'))
|
||||
: this.client.Unsubscribe(new String[] { "#" });
|
||||
|
||||
private void Subscripe() {
|
||||
if(this.settings.ContainsKey("topic")) {
|
||||
@ -86,34 +80,29 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
|
||||
for(Int32 i = 0; i < qos.Length; i++) {
|
||||
qos[i] = MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE;
|
||||
}
|
||||
this.client.Subscribe(this.settings["topic"].Split(';'), qos);
|
||||
_ = this.client.Subscribe(this.settings["topic"].Split(';'), qos);
|
||||
} else {
|
||||
this.client.Subscribe(new String[] { "#" }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
|
||||
_ = this.client.Subscribe(new String[] { "#" }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private async void Client_MqttMsgPublishReceived(Object sender, MqttMsgPublishEventArgs e) => await Task.Run(() => {
|
||||
this.NotifyClientIncomming(new DataEvent(Encoding.UTF8.GetString(e.Message), e.Topic, DateTime.Now));
|
||||
});
|
||||
private async void Client_MqttMsgPublishReceived(Object sender, MqttMsgPublishEventArgs e) => await Task.Run(() => this.NotifyClientIncomming(new DataEvent(Encoding.UTF8.GetString(e.Message), e.Topic, DateTime.Now)));
|
||||
|
||||
public override void Send(String topic, String data) {
|
||||
this.client.Publish(topic, Encoding.UTF8.GetBytes(data));
|
||||
_ = this.client.Publish(topic, Encoding.UTF8.GetBytes(data));
|
||||
this.NotifyClientSending(new DataEvent(data, topic, DateTime.Now));
|
||||
}
|
||||
|
||||
public void Send(String topic, Byte[] data) {
|
||||
_ = this.client.Publish(topic, data);
|
||||
this.NotifyClientSending(new DataEvent(Encoding.UTF8.GetString(data), topic, DateTime.Now));
|
||||
}
|
||||
|
||||
#region IDisposable Support
|
||||
private Boolean disposedValue = false;
|
||||
|
||||
public override Boolean IsConnected {
|
||||
get {
|
||||
if(this.client != null) {
|
||||
return this.client.IsConnected;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
public override Boolean IsConnected => this.client != null ? this.client.IsConnected : false;
|
||||
|
||||
protected virtual void Dispose(Boolean disposing) {
|
||||
if(!this.disposedValue) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
#if !NETCOREAPP
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@ -10,7 +11,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("BlubbFish")]
|
||||
[assembly: AssemblyProduct("ConnectorDataMqtt")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017 - 27.05.2019")]
|
||||
[assembly: AssemblyCopyright("Copyright © BlubbFish 2017 - 27.05.2019")]
|
||||
[assembly: AssemblyTrademark("© BlubbFish")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: NeutralResourcesLanguage("de-DE")]
|
||||
@ -35,7 +36,8 @@ using System.Runtime.InteropServices;
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0")]
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 1.1.0 Rewrite Module to reconnect itselfs, so you dont need to watch over the the state of the connection
|
||||
*/
|
||||
*/
|
||||
|
49
ConnectorDataMqtt_Core.sln
Normal file
49
ConnectorDataMqtt_Core.sln
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29519.87
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConnectorDataMqtt_Core", "ConnectorDataMqtt\ConnectorDataMqtt_Core.csproj", "{5D7A8892-6687-4FE2-85D1-12B49782EDF0}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utils-IoT_Core", "..\Utils-IoT\Utils-IoT\Utils-IoT_Core.csproj", "{45837342-5906-4906-AB49-971767D9E180}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "M2Mqtt_Core", "..\..\Librarys\mqtt\M2Mqtt\M2Mqtt_Core.csproj", "{05B829EF-6F4F-496D-8936-35D7F2179DF0}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "litjson_Core", "..\..\Librarys\litjson\litjson\litjson_Core.csproj", "{CA22D3E9-4195-453D-9CE0-3EBC672E6D06}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utils_Core", "..\Utils\Utils\Utils_Core.csproj", "{19424C4A-D024-484A-BE65-09C7C529A2C4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5D7A8892-6687-4FE2-85D1-12B49782EDF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5D7A8892-6687-4FE2-85D1-12B49782EDF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5D7A8892-6687-4FE2-85D1-12B49782EDF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5D7A8892-6687-4FE2-85D1-12B49782EDF0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{45837342-5906-4906-AB49-971767D9E180}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{45837342-5906-4906-AB49-971767D9E180}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{45837342-5906-4906-AB49-971767D9E180}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{45837342-5906-4906-AB49-971767D9E180}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{05B829EF-6F4F-496D-8936-35D7F2179DF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{05B829EF-6F4F-496D-8936-35D7F2179DF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{05B829EF-6F4F-496D-8936-35D7F2179DF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{05B829EF-6F4F-496D-8936-35D7F2179DF0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CA22D3E9-4195-453D-9CE0-3EBC672E6D06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CA22D3E9-4195-453D-9CE0-3EBC672E6D06}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CA22D3E9-4195-453D-9CE0-3EBC672E6D06}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CA22D3E9-4195-453D-9CE0-3EBC672E6D06}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{19424C4A-D024-484A-BE65-09C7C529A2C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{19424C4A-D024-484A-BE65-09C7C529A2C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{19424C4A-D024-484A-BE65-09C7C529A2C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{19424C4A-D024-484A-BE65-09C7C529A2C4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {92985FD1-A967-4AE1-B2E0-5E938C0A7D6A}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
Reference in New Issue
Block a user