diff --git a/IoT/Connector/Data/Mosquitto/ConnectorDataMosquitto.csproj b/ConnectorDataMosquitto/ConnectorDataMosquitto/ConnectorDataMosquitto.csproj similarity index 97% rename from IoT/Connector/Data/Mosquitto/ConnectorDataMosquitto.csproj rename to ConnectorDataMosquitto/ConnectorDataMosquitto/ConnectorDataMosquitto.csproj index b4bac7e..90b5ce8 100644 --- a/IoT/Connector/Data/Mosquitto/ConnectorDataMosquitto.csproj +++ b/ConnectorDataMosquitto/ConnectorDataMosquitto/ConnectorDataMosquitto.csproj @@ -1,54 +1,54 @@ - - - - - Debug - AnyCPU - {39235FAD-BA9D-4B51-82FC-6969967BEAE9} - Library - Properties - BlubbFish.Utils.IoT.Connector.Data - ConnectorDataMosquitto - v4.7.1 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - {b870e4d5-6806-4a0b-b233-8907eedc5afc} - Utils-IoT - - - + + + + + Debug + AnyCPU + {39235FAD-BA9D-4B51-82FC-6969967BEAE9} + Library + Properties + BlubbFish.Utils.IoT.Connector.Data + ConnectorDataMosquitto + v4.7.1 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + {b870e4d5-6806-4a0b-b233-8907eedc5afc} + Utils-IoT + + + \ No newline at end of file diff --git a/IoT/Connector/Data/Mosquitto/Mosquitto.cs b/ConnectorDataMosquitto/ConnectorDataMosquitto/Mosquitto.cs similarity index 97% rename from IoT/Connector/Data/Mosquitto/Mosquitto.cs rename to ConnectorDataMosquitto/ConnectorDataMosquitto/Mosquitto.cs index aa43517..9b460f3 100644 --- a/IoT/Connector/Data/Mosquitto/Mosquitto.cs +++ b/ConnectorDataMosquitto/ConnectorDataMosquitto/Mosquitto.cs @@ -1,125 +1,125 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text.RegularExpressions; - -namespace BlubbFish.Utils.IoT.Connector.Data { - public class Mosquitto : ADataBackend, IDisposable { - private Process p; - private String message; - - public override event MqttMessage MessageIncomming; - public override event MqttMessage MessageSending; - - public Mosquitto(Dictionary 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 - this.message = ""; - this.p = new Process(); - this.p.StartInfo.FileName = "mosquitto_sub"; - String topic = "#"; - String args = "-h " + this.settings["server"]+" "; - if(this.settings.ContainsKey("port")) { - args += "-p "+ this.settings["port"]+" "; - } - if (this.settings.ContainsKey("cafile")) { - args += "--cafile " + this.settings["cafile"] + " "; - } - if (this.settings.ContainsKey("cert")) { - args += "--cert " + this.settings["cert"] + " "; - } - if (this.settings.ContainsKey("key")) { - args += "--key " + this.settings["key"] + " "; - } - if(this.settings.ContainsKey("topic")) { - topic = this.settings["topic"]; - } - this.p.StartInfo.Arguments = args+"-t \""+ topic + "\" -v -d"; - this.p.StartInfo.CreateNoWindow = true; - this.p.StartInfo.UseShellExecute = false; - this.p.StartInfo.RedirectStandardOutput = true; - this.p.StartInfo.RedirectStandardError = true; - this.p.OutputDataReceived += this.P_OutputDataReceived; - this.p.ErrorDataReceived += this.P_ErrorDataReceived; - this.p.Start(); - this.p.BeginOutputReadLine(); - - } - - public override void Send(String topic, String data) { - Process send = new Process(); - send.StartInfo.FileName = "mosquitto_pub"; - String args = "-h " + this.settings["server"] + " "; - if (this.settings.ContainsKey("port")) { - args += "-p " + this.settings["port"] + " "; - } - if (this.settings.ContainsKey("cafile")) { - args += "--cafile " + this.settings["cafile"] + " "; - } - if (this.settings.ContainsKey("cert")) { - args += "--cert " + this.settings["cert"] + " "; - } - if (this.settings.ContainsKey("key")) { - args += "--key " + this.settings["key"] + " "; - } - send.StartInfo.Arguments = args + "-m \""+data.Replace("\"","\\\"")+"\" -t \""+topic+"\" -d"; - send.StartInfo.CreateNoWindow = true; - send.StartInfo.UseShellExecute = false; - send.StartInfo.RedirectStandardOutput = true; - send.StartInfo.RedirectStandardError = true; - send.Start(); - send.WaitForExit(); - MessageSending?.Invoke(this, new MqttEventArgs(data, topic)); - } - - private void P_ErrorDataReceived(Object sender, DataReceivedEventArgs e) { - if (e.Data != null) { - throw new NotImplementedException(e.Data); - } - } - - private void P_OutputDataReceived(Object sender, DataReceivedEventArgs e) { - if (e.Data != null) { - if (e.Data.StartsWith("Client mosqsub")) { - 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); - String topic = matches[0].Groups[1].Value; - String message = matches[0].Groups[2].Value.Trim(); - this.MessageIncomming?.Invoke(this, new MqttEventArgs(message, topic)); - } - this.message = e.Data + "\n"; - } else { - this.message += e.Data + "\n"; - } - } - } - - #region IDisposable Support - private Boolean disposedValue = false; // Dient zur Erkennung redundanter Aufrufe. - private readonly Dictionary settings; - - protected virtual void Dispose(Boolean disposing) { - if (!this.disposedValue) { - if (disposing) { - this.p.CancelOutputRead(); - if (!this.p.HasExited) { - this.p.Kill(); - } - this.p.Close(); - } - this.p = null; - this.disposedValue = true; - } - } - - ~Mosquitto() { - Dispose(false); - } - - public override void Dispose() { - Dispose(true); - GC.SuppressFinalize(this); - } - #endregion - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text.RegularExpressions; + +namespace BlubbFish.Utils.IoT.Connector.Data { + public class Mosquitto : ADataBackend, IDisposable { + private Process p; + private String message; + + public override event MqttMessage MessageIncomming; + public override event MqttMessage MessageSending; + + public Mosquitto(Dictionary 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 + this.message = ""; + this.p = new Process(); + this.p.StartInfo.FileName = "mosquitto_sub"; + String topic = "#"; + String args = "-h " + this.settings["server"]+" "; + if(this.settings.ContainsKey("port")) { + args += "-p "+ this.settings["port"]+" "; + } + if (this.settings.ContainsKey("cafile")) { + args += "--cafile " + this.settings["cafile"] + " "; + } + if (this.settings.ContainsKey("cert")) { + args += "--cert " + this.settings["cert"] + " "; + } + if (this.settings.ContainsKey("key")) { + args += "--key " + this.settings["key"] + " "; + } + if(this.settings.ContainsKey("topic")) { + topic = this.settings["topic"]; + } + this.p.StartInfo.Arguments = args+"-t \""+ topic + "\" -v -d"; + this.p.StartInfo.CreateNoWindow = true; + this.p.StartInfo.UseShellExecute = false; + this.p.StartInfo.RedirectStandardOutput = true; + this.p.StartInfo.RedirectStandardError = true; + this.p.OutputDataReceived += this.P_OutputDataReceived; + this.p.ErrorDataReceived += this.P_ErrorDataReceived; + this.p.Start(); + this.p.BeginOutputReadLine(); + + } + + public override void Send(String topic, String data) { + Process send = new Process(); + send.StartInfo.FileName = "mosquitto_pub"; + String args = "-h " + this.settings["server"] + " "; + if (this.settings.ContainsKey("port")) { + args += "-p " + this.settings["port"] + " "; + } + if (this.settings.ContainsKey("cafile")) { + args += "--cafile " + this.settings["cafile"] + " "; + } + if (this.settings.ContainsKey("cert")) { + args += "--cert " + this.settings["cert"] + " "; + } + if (this.settings.ContainsKey("key")) { + args += "--key " + this.settings["key"] + " "; + } + send.StartInfo.Arguments = args + "-m \""+data.Replace("\"","\\\"")+"\" -t \""+topic+"\" -d"; + send.StartInfo.CreateNoWindow = true; + send.StartInfo.UseShellExecute = false; + send.StartInfo.RedirectStandardOutput = true; + send.StartInfo.RedirectStandardError = true; + send.Start(); + send.WaitForExit(); + MessageSending?.Invoke(this, new MqttEventArgs(data, topic)); + } + + private void P_ErrorDataReceived(Object sender, DataReceivedEventArgs e) { + if (e.Data != null) { + throw new NotImplementedException(e.Data); + } + } + + private void P_OutputDataReceived(Object sender, DataReceivedEventArgs e) { + if (e.Data != null) { + if (e.Data.StartsWith("Client mosqsub")) { + 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); + String topic = matches[0].Groups[1].Value; + String message = matches[0].Groups[2].Value.Trim(); + this.MessageIncomming?.Invoke(this, new MqttEventArgs(message, topic)); + } + this.message = e.Data + "\n"; + } else { + this.message += e.Data + "\n"; + } + } + } + + #region IDisposable Support + private Boolean disposedValue = false; // Dient zur Erkennung redundanter Aufrufe. + private readonly Dictionary settings; + + protected virtual void Dispose(Boolean disposing) { + if (!this.disposedValue) { + if (disposing) { + this.p.CancelOutputRead(); + if (!this.p.HasExited) { + this.p.Kill(); + } + this.p.Close(); + } + this.p = null; + this.disposedValue = true; + } + } + + ~Mosquitto() { + Dispose(false); + } + + public override void Dispose() { + Dispose(true); + GC.SuppressFinalize(this); + } + #endregion + } +} diff --git a/IoT/Connector/Data/Mosquitto/Properties/AssemblyInfo.cs b/ConnectorDataMosquitto/ConnectorDataMosquitto/Properties/AssemblyInfo.cs similarity index 97% rename from IoT/Connector/Data/Mosquitto/Properties/AssemblyInfo.cs rename to ConnectorDataMosquitto/ConnectorDataMosquitto/Properties/AssemblyInfo.cs index 569c9b9..20dd49a 100644 --- a/IoT/Connector/Data/Mosquitto/Properties/AssemblyInfo.cs +++ b/ConnectorDataMosquitto/ConnectorDataMosquitto/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// Allgemeine Informationen über eine Assembly werden über die folgenden -// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -// die einer Assembly zugeordnet sind. -[assembly: AssemblyTitle("ConnectorDataMosquitto")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ConnectorDataMosquitto")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 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 -// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. -[assembly: ComVisible(false)] - -// 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")] - -// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -// -// Hauptversion -// Nebenversion -// Buildnummer -// Revision -// -// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, -// indem Sie "*" wie unten gezeigt eingeben: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("ConnectorDataMosquitto")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConnectorDataMosquitto")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 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 +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// 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")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]