[NF] Now Possible to generate MQTT Alert Messages

This commit is contained in:
BlubbFish 2018-10-08 14:17:52 +00:00
parent 9599edbacd
commit 0c9610ec9f
12 changed files with 388 additions and 101 deletions

View File

@ -21,7 +21,7 @@ namespace BlubbFish.BosmonMqtt {
Int32 IBosMonPlugin.PluginVersion {
get {
return 4;
return 5;
}
}

View File

@ -27,7 +27,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;MF_FRAMEWORK_VERSION_V4_2</DefineConstants>
<DefineConstants>TRACE;COMPACT_FRAMEWORK</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
@ -205,12 +205,18 @@
<Link>lib\M2Mqtt\Utility\QueueExtension.cs</Link>
</Compile>
<Compile Include="Controller\MqttActionProvider.cs" />
<Compile Include="Controller\MqttActionSettings.cs" />
<Compile Include="Controller\MqttEventProcessor.cs" />
<Compile Include="BosMonPluginClass.cs" />
<Compile Include="Models\TelegramsEventConfig.cs" />
<Compile Include="MqttPlugin.cs" />
<Compile Include="Models\PluginConfiguration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Views\ActionDialog.cs">
<SubType>Form</SubType>
</Compile>
@ -225,6 +231,10 @@
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Views\ActionDialog.resx">
<DependentUpon>ActionDialog.cs</DependentUpon>
</EmbeddedResource>
@ -232,7 +242,9 @@
<DependentUpon>Config.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Resources\mqtt.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "D:\Programme\BosMon_dev\plugins\$(TargetFileName)"

View File

@ -1,8 +1,6 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using BlubbFish.BosmonMqtt.Models;
using BlubbFish.BosmonMqtt.Views;
using BosMon.Prefs;
using TelegramsEvents;
using TelegramsEvents.Actions;
@ -10,11 +8,9 @@ using TelegramsEvents.Prefs;
namespace BlubbFish.BosmonMqtt.Controller {
internal class MqttActionProvider : IActionProvider {
private TelegramsEventsPlugin plugin;
//private TelegramsEventConfig eventconfig;
public MqttActionProvider(MqttEventProcessor mqtteventprocessor) {
public MqttActionProvider(MqttEventProcessor mqttEventProcessor) {
this.MqttEventProcessor = mqttEventProcessor;
}
public String Name {
@ -31,7 +27,7 @@ namespace BlubbFish.BosmonMqtt.Controller {
public Image Image {
get {
return new Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
return Properties.Resources.ActionProviderIcon;
}
}
@ -41,75 +37,22 @@ namespace BlubbFish.BosmonMqtt.Controller {
}
}
public MqttEventProcessor MqttEventProcessor { get; }
public IActionSettings CreateAction(IAlarmSettings alarmSettings) {
return new MqttActionSettings(this, new BosMonConfiguration().Storage);
return new MqttActionSettings(this);
}
public IActionSettings CreateAction(IAlarmSettings alarmSettings, IBosMonConfigurationStorage storage) {
System.Windows.Forms.MessageBox.Show("test");
throw new System.NotImplementedException();
return new MqttActionSettings(this, storage);
}
public void Dispose() {
//throw new System.NotImplementedException();
}
public void Dispose() { }
public DialogResult EditAction(IActionSettings item) {
return item.EditAction();
}
public void Init(IBosMonConfigurationStorage storage, TelegramsEventsPlugin plugin) {
this.plugin = plugin;
//this.eventconfig = new TelegramsEventConfig(storage);
//plugin
}
}
class MqttActionSettings : IActionSettings {
private readonly MqttActionProvider mqttActionProvider;
private TelegramsEventConfig eventconfig;
public MqttActionSettings(MqttActionProvider mqttActionProvider, IBosMonConfigurationStorage storage) {
this.mqttActionProvider = mqttActionProvider;
this.Enabled = true;
this.Storage = storage;
}
public Boolean Enabled { get; set; }
public String Name { get { return this.eventconfig.Title; } }
public String Description { get { return this.eventconfig.Desc; } }
public IActionProvider ActionProvider { get { return this.mqttActionProvider; } }
public Int32 Id { get { return 456548; } }
public IBosMonConfigurationStorage Storage {
get {
return this.eventconfig.PluginStorage;
}
set {
this.eventconfig = new TelegramsEventConfig(value);
}
}
public Object Clone() {
throw new System.NotImplementedException();
}
public DialogResult EditAction() {
ActionDialog a = new ActionDialog(this.eventconfig);
a.LoadSettings();
return a.ShowDialog();
}
public void ExecuteAction(System.Int32 id, System.String description, AlarmEventArgs args) {
throw new System.NotImplementedException();
}
public void Init(IBosMonConfigurationStorage storage, TelegramsEventsPlugin plugin) { }
}
}

View File

@ -0,0 +1,77 @@
using System;
using System.Windows.Forms;
using BlubbFish.BosmonMqtt.Models;
using BlubbFish.BosmonMqtt.Views;
using BosMon.Prefs;
using TelegramsEvents;
using TelegramsEvents.Actions;
using TelegramsEvents.Prefs;
namespace BlubbFish.BosmonMqtt.Controller {
class MqttActionSettings : IActionSettings {
private readonly MqttActionProvider mqttActionProvider;
public MqttActionSettings(MqttActionProvider mqttActionProvider) {
this.mqttActionProvider = mqttActionProvider;
this.Eventconfig = new TelegramsEventConfig(this.ActionProvider.ActionId) {
Enabled = true
};
}
public MqttActionSettings(MqttActionProvider mqttActionProvider, IBosMonConfigurationStorage storage) {
this.mqttActionProvider = mqttActionProvider;
this.Eventconfig = new TelegramsEventConfig(storage);
}
public Boolean Enabled {
get {
return this.Eventconfig.Enabled;
}
set {
this.Eventconfig.Enabled = value;
}
}
public String Name { get { return this.Eventconfig.Title; } }
public String Description { get { return this.Eventconfig.Desc; } }
public IActionProvider ActionProvider { get { return this.mqttActionProvider; } }
public Int32 Id { get { return this.ActionProvider.ActionId; } }
public TelegramsEventConfig Eventconfig { get; set; }
public IBosMonConfigurationStorage Storage {
get {
return this.Eventconfig.PluginStorage;
}
set {
this.Eventconfig.PluginStorage = value;
}
}
public Object Clone() {
return new MqttActionSettings(this.mqttActionProvider) {
Eventconfig = new TelegramsEventConfig(this.ActionProvider.ActionId) {
Desc = this.Eventconfig.Desc,
Enabled = this.Eventconfig.Enabled,
Message = this.Eventconfig.Message,
Title = this.Eventconfig.Title,
Topic = this.Eventconfig.Topic
}
};
}
public DialogResult EditAction() {
ActionDialog a = new ActionDialog(this.Eventconfig);
a.LoadSettings();
return a.ShowDialog();
}
public void ExecuteAction(Int32 id, String description, AlarmEventArgs args) {
this.mqttActionProvider.MqttEventProcessor.Send(this.Eventconfig.Topic, this.Eventconfig.Message);
}
}
}

View File

@ -153,13 +153,19 @@ namespace BlubbFish.BosmonMqtt.Controller {
text = JsonMapper.ToJson(z);
topic = this.pluginconfig.Topic + "zveidmf/" + z.Address;
}
this.client.Publish(topic, Encoding.UTF8.GetBytes(text));
this.Send(topic, text);
}
}
} catch (Exception) { }
} catch { }
}
}
internal void Send(String topic, String text) {
try {
this.client.Publish(topic, Encoding.UTF8.GetBytes(text));
} catch { }
}
private Boolean FilterMatch(Telegram t) {
if (t.Type == PocsagTelegram.TYPE_POCSAG) {
return this.FilterMatchType(this.pfilter, t);

View File

@ -4,74 +4,113 @@ using System.Text;
namespace BlubbFish.BosmonMqtt.Models {
internal class TelegramsEventConfig : BosMonConfiguration, IBosMonConfigurationTemplate {
private String _title;
private String _message;
private String _topic;
private String _desc;
private Boolean hasStorage = false;
private String title;
private String message;
private String topic;
private Boolean enabled;
private String desc;
private Int32 actionId;
public delegate void Change(Object sender, EventArgs e);
public event Change ConfigChanged;
public TelegramsEventConfig(IBosMonConfigurationStorage storage) : base(storage) {
this.PluginStorage = storage;
this.hasStorage = true;
this.ReadConfiguration();
}
public TelegramsEventConfig(Int32 actionId) {
this.actionId = actionId;
}
#region öffentliche Eigenschaften
public IBosMonConfigurationStorage PluginStorage { get; private set; }
public IBosMonConfigurationStorage PluginStorage {
get {
if (this.hasStorage) {
return this.Storage;
} else {
return null;
}
}
set {
this.Storage = value;
if(!this.hasStorage && this.Storage != null) {
this.hasStorage = true;
this.WriteConfiguration();
}
}
}
public String Title {
get {
return this._title;
return this.title;
}
set {
this._title = value;
this.title = value;
WriteConfiguration();
}
}
public String Message {
get {
return this._message;
return this.message;
}
set {
this._message = value;
this.message = value;
WriteConfiguration();
}
}
public String Topic {
get {
return this._topic;
return this.topic;
}
set {
this._topic = value;
this.topic = value;
WriteConfiguration();
}
}
public String Desc {
get {
return this._desc;
return this.desc;
}
set {
this._desc = value;
this.desc = value;
WriteConfiguration();
}
}
public Boolean Enabled {
get {
return this.enabled;
}
set {
this.enabled = value;
WriteConfiguration();
}
}
#endregion
#region IBosMonConfigurationTemplate Config-Variablen
public override void ReadConfiguration() {
base.ReadConfiguration();
this._title = this.Storage.ReadString("title", "");
this._desc = this.Storage.ReadString("desc", "");
this._message = this.Storage.ReadString("message", "");
this._topic = this.Storage.ReadString("topic", "");
if (this.hasStorage) {
base.ReadConfiguration();
this.title = this.Storage.ReadString("title", "");
this.desc = this.Storage.ReadString("desc", "");
this.message = this.Storage.ReadString("message", "");
this.topic = this.Storage.ReadString("topic", "");
this.enabled = this.Storage.ReadBoolean("enabled", true);
this.actionId = this.Storage.ReadInteger("actionId");
}
}
public override void WriteConfiguration() {
this.Storage.Write("title", this._title);
this.Storage.Write("desc", this._desc);
this.Storage.Write("message", this._message);
this.Storage.Write("topic", this._topic);
base.WriteConfiguration();
if (this.hasStorage) {
this.Storage.Write("title", this.title);
this.Storage.Write("desc", this.desc);
this.Storage.Write("message", this.message);
this.Storage.Write("topic", this.topic);
this.Storage.Write("actionId", this.actionId);
this.Storage.Write("enabled", this.enabled);
base.WriteConfiguration();
}
}
#endregion
@ -89,7 +128,21 @@ namespace BlubbFish.BosmonMqtt.Models {
}
}
public override TKeyVal<Int32>[] IntVariables {
get {
return Merge(new TKeyVal<Int32>[] {
new TKeyVal<Int32>("actionId", 12345)
}, base.IntVariables);
}
}
public override TKeyVal<Boolean>[] BoolVariables {
get {
return Merge(new TKeyVal<Boolean>[] {
new TKeyVal<Boolean>("enabled", true)
}, base.BoolVariables);
}
}
public void Saved() {
this.ConfigChanged?.Invoke(this, new EventArgs());

View File

@ -11,7 +11,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BosmonMqtt")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyCopyright("Copyright © 2018 - 08.10.2018")]
[assembly: AssemblyTrademark("BlubbFish")]
[assembly: AssemblyCulture("")]
@ -33,7 +33,7 @@ using System.Runtime.InteropServices;
// 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.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.4.0")]
[assembly: AssemblyFileVersion("1.4.0")]
[assembly: NeutralResourcesLanguage("de")]

View File

@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.42000
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.
// </auto-generated>
//------------------------------------------------------------------------------
namespace BlubbFish.BosmonMqtt.Properties {
using System;
/// <summary>
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
/// </summary>
// Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
// mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BlubbFish.BosmonMqtt.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap ActionProviderIcon {
get {
object obj = ResourceManager.GetObject("ActionProviderIcon", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ActionProviderIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\mqtt.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,7 +1,6 @@
using System;
using System.Windows.Forms;
using BlubbFish.BosmonMqtt.Models;
using BosMon.Utils;
namespace BlubbFish.BosmonMqtt.Views {
internal partial class ActionDialog : Form {