move Mosquitto to ConnectorDataMosquitto

This commit is contained in:
Philip Schell 2019-02-14 11:49:55 +01:00
parent b5c31cff84
commit 28b7ff4d00
3 changed files with 214 additions and 214 deletions

View File

@ -1,54 +1,54 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{39235FAD-BA9D-4B51-82FC-6969967BEAE9}</ProjectGuid> <ProjectGuid>{39235FAD-BA9D-4B51-82FC-6969967BEAE9}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BlubbFish.Utils.IoT.Connector.Data</RootNamespace> <RootNamespace>BlubbFish.Utils.IoT.Connector.Data</RootNamespace>
<AssemblyName>ConnectorDataMosquitto</AssemblyName> <AssemblyName>ConnectorDataMosquitto</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Mosquitto.cs" /> <Compile Include="Mosquitto.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\Utils-IoT.csproj"> <ProjectReference Include="..\..\..\Utils-IoT.csproj">
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project> <Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
<Name>Utils-IoT</Name> <Name>Utils-IoT</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -1,125 +1,125 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace BlubbFish.Utils.IoT.Connector.Data { namespace BlubbFish.Utils.IoT.Connector.Data {
public class Mosquitto : ADataBackend, IDisposable { public class Mosquitto : ADataBackend, IDisposable {
private Process p; private Process p;
private String message; private String message;
public override event MqttMessage MessageIncomming; public override event MqttMessage MessageIncomming;
public override event MqttMessage MessageSending; public override event MqttMessage MessageSending;
public Mosquitto(Dictionary<String, String> mqtt_settings) { public Mosquitto(Dictionary<String, String> mqtt_settings) {
this.settings = mqtt_settings; this.settings = mqtt_settings;
//mosquitto_sub --cafile ca.pem --cert cert.pem --key cert.key -h swb.broker.flex4grid.eu -p 8883 -t "#" -v -d //mosquitto_sub --cafile ca.pem --cert cert.pem --key cert.key -h swb.broker.flex4grid.eu -p 8883 -t "#" -v -d
this.message = ""; this.message = "";
this.p = new Process(); this.p = new Process();
this.p.StartInfo.FileName = "mosquitto_sub"; this.p.StartInfo.FileName = "mosquitto_sub";
String topic = "#"; String topic = "#";
String args = "-h " + this.settings["server"]+" "; String args = "-h " + this.settings["server"]+" ";
if(this.settings.ContainsKey("port")) { if(this.settings.ContainsKey("port")) {
args += "-p "+ this.settings["port"]+" "; args += "-p "+ this.settings["port"]+" ";
} }
if (this.settings.ContainsKey("cafile")) { if (this.settings.ContainsKey("cafile")) {
args += "--cafile " + this.settings["cafile"] + " "; args += "--cafile " + this.settings["cafile"] + " ";
} }
if (this.settings.ContainsKey("cert")) { if (this.settings.ContainsKey("cert")) {
args += "--cert " + this.settings["cert"] + " "; args += "--cert " + this.settings["cert"] + " ";
} }
if (this.settings.ContainsKey("key")) { if (this.settings.ContainsKey("key")) {
args += "--key " + this.settings["key"] + " "; args += "--key " + this.settings["key"] + " ";
} }
if(this.settings.ContainsKey("topic")) { if(this.settings.ContainsKey("topic")) {
topic = this.settings["topic"]; topic = this.settings["topic"];
} }
this.p.StartInfo.Arguments = args+"-t \""+ topic + "\" -v -d"; this.p.StartInfo.Arguments = args+"-t \""+ topic + "\" -v -d";
this.p.StartInfo.CreateNoWindow = true; this.p.StartInfo.CreateNoWindow = true;
this.p.StartInfo.UseShellExecute = false; this.p.StartInfo.UseShellExecute = false;
this.p.StartInfo.RedirectStandardOutput = true; this.p.StartInfo.RedirectStandardOutput = true;
this.p.StartInfo.RedirectStandardError = true; this.p.StartInfo.RedirectStandardError = true;
this.p.OutputDataReceived += this.P_OutputDataReceived; this.p.OutputDataReceived += this.P_OutputDataReceived;
this.p.ErrorDataReceived += this.P_ErrorDataReceived; this.p.ErrorDataReceived += this.P_ErrorDataReceived;
this.p.Start(); this.p.Start();
this.p.BeginOutputReadLine(); this.p.BeginOutputReadLine();
} }
public override void Send(String topic, String data) { public override void Send(String topic, String data) {
Process send = new Process(); Process send = new Process();
send.StartInfo.FileName = "mosquitto_pub"; send.StartInfo.FileName = "mosquitto_pub";
String args = "-h " + this.settings["server"] + " "; String args = "-h " + this.settings["server"] + " ";
if (this.settings.ContainsKey("port")) { if (this.settings.ContainsKey("port")) {
args += "-p " + this.settings["port"] + " "; args += "-p " + this.settings["port"] + " ";
} }
if (this.settings.ContainsKey("cafile")) { if (this.settings.ContainsKey("cafile")) {
args += "--cafile " + this.settings["cafile"] + " "; args += "--cafile " + this.settings["cafile"] + " ";
} }
if (this.settings.ContainsKey("cert")) { if (this.settings.ContainsKey("cert")) {
args += "--cert " + this.settings["cert"] + " "; args += "--cert " + this.settings["cert"] + " ";
} }
if (this.settings.ContainsKey("key")) { if (this.settings.ContainsKey("key")) {
args += "--key " + this.settings["key"] + " "; args += "--key " + this.settings["key"] + " ";
} }
send.StartInfo.Arguments = args + "-m \""+data.Replace("\"","\\\"")+"\" -t \""+topic+"\" -d"; send.StartInfo.Arguments = args + "-m \""+data.Replace("\"","\\\"")+"\" -t \""+topic+"\" -d";
send.StartInfo.CreateNoWindow = true; send.StartInfo.CreateNoWindow = true;
send.StartInfo.UseShellExecute = false; send.StartInfo.UseShellExecute = false;
send.StartInfo.RedirectStandardOutput = true; send.StartInfo.RedirectStandardOutput = true;
send.StartInfo.RedirectStandardError = true; send.StartInfo.RedirectStandardError = true;
send.Start(); send.Start();
send.WaitForExit(); send.WaitForExit();
MessageSending?.Invoke(this, new MqttEventArgs(data, topic)); MessageSending?.Invoke(this, new MqttEventArgs(data, topic));
} }
private void P_ErrorDataReceived(Object sender, DataReceivedEventArgs e) { private void P_ErrorDataReceived(Object sender, DataReceivedEventArgs e) {
if (e.Data != null) { if (e.Data != null) {
throw new NotImplementedException(e.Data); throw new NotImplementedException(e.Data);
} }
} }
private void P_OutputDataReceived(Object sender, DataReceivedEventArgs e) { private void P_OutputDataReceived(Object sender, DataReceivedEventArgs e) {
if (e.Data != null) { if (e.Data != null) {
if (e.Data.StartsWith("Client mosqsub")) { if (e.Data.StartsWith("Client mosqsub")) {
if (this.message != "" && this.message.IndexOf(" received PUBLISH ") > 0) { if (this.message != "" && this.message.IndexOf(" received PUBLISH ") > 0) {
MatchCollection matches = (new Regex("^Client mosqsub[\\|/].*received PUBLISH \\(.*,.*,.*,.*, '(.*)'.*\\)\\)\n[^ ]* (.*)$", RegexOptions.IgnoreCase | RegexOptions.Singleline)).Matches(this.message); MatchCollection matches = (new Regex("^Client mosqsub[\\|/].*received PUBLISH \\(.*,.*,.*,.*, '(.*)'.*\\)\\)\n[^ ]* (.*)$", RegexOptions.IgnoreCase | RegexOptions.Singleline)).Matches(this.message);
String topic = matches[0].Groups[1].Value; String topic = matches[0].Groups[1].Value;
String message = matches[0].Groups[2].Value.Trim(); String message = matches[0].Groups[2].Value.Trim();
this.MessageIncomming?.Invoke(this, new MqttEventArgs(message, topic)); this.MessageIncomming?.Invoke(this, new MqttEventArgs(message, topic));
} }
this.message = e.Data + "\n"; this.message = e.Data + "\n";
} else { } else {
this.message += e.Data + "\n"; this.message += e.Data + "\n";
} }
} }
} }
#region IDisposable Support #region IDisposable Support
private Boolean disposedValue = false; // Dient zur Erkennung redundanter Aufrufe. private Boolean disposedValue = false; // Dient zur Erkennung redundanter Aufrufe.
private readonly Dictionary<String, String> settings; private readonly Dictionary<String, String> settings;
protected virtual void Dispose(Boolean disposing) { protected virtual void Dispose(Boolean disposing) {
if (!this.disposedValue) { if (!this.disposedValue) {
if (disposing) { if (disposing) {
this.p.CancelOutputRead(); this.p.CancelOutputRead();
if (!this.p.HasExited) { if (!this.p.HasExited) {
this.p.Kill(); this.p.Kill();
} }
this.p.Close(); this.p.Close();
} }
this.p = null; this.p = null;
this.disposedValue = true; this.disposedValue = true;
} }
} }
~Mosquitto() { ~Mosquitto() {
Dispose(false); Dispose(false);
} }
public override void Dispose() { public override void Dispose() {
Dispose(true); Dispose(true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
#endregion #endregion
} }
} }

View File

@ -1,36 +1,36 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden // Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind. // die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("ConnectorDataMosquitto")] [assembly: AssemblyTitle("ConnectorDataMosquitto")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConnectorDataMosquitto")] [assembly: AssemblyProduct("ConnectorDataMosquitto")]
[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly // Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von // für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. // COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("39235fad-ba9d-4b51-82fc-6969967beae9")] [assembly: Guid("39235fad-ba9d-4b51-82fc-6969967beae9")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
// //
// Hauptversion // Hauptversion
// Nebenversion // Nebenversion
// Buildnummer // Buildnummer
// Revision // Revision
// //
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben: // indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]