Rewrite of Bosmon MQTT
This commit is contained in:
parent
b7afeb197c
commit
9599edbacd
89
BosmonMqtt/BosMonPluginClass.cs
Normal file
89
BosmonMqtt/BosMonPluginClass.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using BosMon.Exceptions;
|
||||
using BosMon.Plugins;
|
||||
using BosMon.Prefs;
|
||||
|
||||
namespace BlubbFish.BosmonMqtt {
|
||||
public class BosMonPluginClass : IBosMonPlugin {
|
||||
private readonly MqttPlugin plugin = new MqttPlugin();
|
||||
#region Plugin Eigenschaften
|
||||
String IBosMonPlugin.PluginName {
|
||||
get {
|
||||
return "MQTT-Bridge";
|
||||
}
|
||||
}
|
||||
|
||||
String IBosMonPlugin.PluginDescription {
|
||||
get {
|
||||
return "Sendet Telegramme nach MQTT";
|
||||
}
|
||||
}
|
||||
|
||||
Int32 IBosMonPlugin.PluginVersion {
|
||||
get {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
PluginType IBosMonPlugin.PluginType {
|
||||
get {
|
||||
return PluginType.Client;
|
||||
}
|
||||
}
|
||||
|
||||
Int32 IBosMonPlugin.PluginFlags {
|
||||
get {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
String[] IBosMonPlugin.StartPluginAfter {
|
||||
get {
|
||||
return new String[] { "TelegramsEvents" };
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Plugin Connectoren
|
||||
public IBosMonHost PluginHost {
|
||||
get {
|
||||
return this.plugin.PluginHost;
|
||||
}
|
||||
set {
|
||||
this.plugin.PluginHost = value ?? throw new BosMonArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
IBosMonConfigurationStorage IBosMonPlugin.ConfigurationStorage {
|
||||
get {
|
||||
return this.plugin.ConfigurationStorage;
|
||||
}
|
||||
set {
|
||||
if (value == null) {
|
||||
throw new BosMonArgumentNullException();
|
||||
} else if (this.plugin.ConfigurationStorage != null) {
|
||||
throw new BosMonInternalException("ConfigStorage already set");
|
||||
}
|
||||
this.plugin.ConfigurationStorage = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Plugin Einstiegspunkte
|
||||
void IDisposable.Dispose() {
|
||||
this.plugin.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
void IBosMonPlugin.InitializePlugin() {
|
||||
this.plugin.Init();
|
||||
}
|
||||
|
||||
void IBosMonPlugin.StartPlugin() {
|
||||
this.plugin.Start();
|
||||
}
|
||||
|
||||
void IBosMonPlugin.StopPlugin() {
|
||||
this.plugin.Stop();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG;COMPACT_FRAMEWORK</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -27,7 +27,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;MF_FRAMEWORK_VERSION_V4_2</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -46,6 +46,9 @@
|
||||
<HintPath>D:\Programme\BosMon\plugins\TelegramFilter.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="TelegramsEvents">
|
||||
<HintPath>D:\Programme\BosMon\plugins\TelegramsEvents.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\Librarys\litjson\litjson\IJsonWrapper.cs">
|
||||
@ -201,11 +204,19 @@
|
||||
<Compile Include="..\..\Librarys\mqtt\M2Mqtt\Utility\QueueExtension.cs">
|
||||
<Link>lib\M2Mqtt\Utility\QueueExtension.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="MqttEventProcessor.cs" />
|
||||
<Compile Include="Controller\MqttActionProvider.cs" />
|
||||
<Compile Include="Controller\MqttEventProcessor.cs" />
|
||||
<Compile Include="BosMonPluginClass.cs" />
|
||||
<Compile Include="Models\TelegramsEventConfig.cs" />
|
||||
<Compile Include="MqttPlugin.cs" />
|
||||
<Compile Include="Plugin.cs" />
|
||||
<Compile Include="Models\PluginConfiguration.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Views\ActionDialog.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Views\ActionDialog.Designer.cs">
|
||||
<DependentUpon>ActionDialog.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\Config.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
@ -214,6 +225,9 @@
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Views\ActionDialog.resx">
|
||||
<DependentUpon>ActionDialog.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Views\Config.resx">
|
||||
<DependentUpon>Config.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
115
BosmonMqtt/Controller/MqttActionProvider.cs
Normal file
115
BosmonMqtt/Controller/MqttActionProvider.cs
Normal file
@ -0,0 +1,115 @@
|
||||
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;
|
||||
using TelegramsEvents.Prefs;
|
||||
|
||||
namespace BlubbFish.BosmonMqtt.Controller {
|
||||
internal class MqttActionProvider : IActionProvider {
|
||||
private TelegramsEventsPlugin plugin;
|
||||
|
||||
//private TelegramsEventConfig eventconfig;
|
||||
|
||||
public MqttActionProvider(MqttEventProcessor mqtteventprocessor) {
|
||||
}
|
||||
|
||||
public String Name {
|
||||
get {
|
||||
return "Mqtt-Post";
|
||||
}
|
||||
}
|
||||
|
||||
public String Description {
|
||||
get {
|
||||
return "Send data over mqtt on an event";
|
||||
}
|
||||
}
|
||||
|
||||
public Image Image {
|
||||
get {
|
||||
return new Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
|
||||
}
|
||||
}
|
||||
|
||||
public System.Int32 ActionId {
|
||||
get {
|
||||
return 12345;
|
||||
}
|
||||
}
|
||||
|
||||
public IActionSettings CreateAction(IAlarmSettings alarmSettings) {
|
||||
return new MqttActionSettings(this, new BosMonConfiguration().Storage);
|
||||
}
|
||||
|
||||
public IActionSettings CreateAction(IAlarmSettings alarmSettings, IBosMonConfigurationStorage storage) {
|
||||
System.Windows.Forms.MessageBox.Show("test");
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
//throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -12,15 +12,15 @@ using TelegramFilter.Filter;
|
||||
using uPLibrary.Networking.M2Mqtt;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
|
||||
namespace BlubbFish.BosmonMqtt {
|
||||
namespace BlubbFish.BosmonMqtt.Controller {
|
||||
class MqttEventProcessor : IDisposable {
|
||||
private PluginConfiguration pluginconfig;
|
||||
private IBosMonHost pluginhost;
|
||||
private readonly PluginConfiguration pluginconfig;
|
||||
private readonly IBosMonHost pluginhost;
|
||||
private MqttClient client;
|
||||
private FilterList filter;
|
||||
private List<FilterItem> pfilter = new List<FilterItem>();
|
||||
private List<FilterItem> ffilter = new List<FilterItem>();
|
||||
private List<FilterItem> zfilter = new List<FilterItem>();
|
||||
private readonly List<FilterItem> pfilter = new List<FilterItem>();
|
||||
private readonly List<FilterItem> ffilter = new List<FilterItem>();
|
||||
private readonly List<FilterItem> zfilter = new List<FilterItem>();
|
||||
Thread connectionWatcher;
|
||||
|
||||
public MqttEventProcessor(PluginConfiguration pluginconfiguration, IBosMonHost pluginHost) {
|
@ -54,12 +54,6 @@ namespace BlubbFish.BosmonMqtt.Models {
|
||||
}
|
||||
set {
|
||||
this._topic = value;
|
||||
if (this._topic.Length > 0 && this._topic[0] != '/') {
|
||||
this._topic = "/" + this._topic;
|
||||
}
|
||||
if (this._topic.Length > 1 && this._topic[this._topic.Length-1] != '/') {
|
||||
this._topic = this._topic + "/";
|
||||
}
|
||||
WriteConfiguration();
|
||||
}
|
||||
}
|
||||
|
99
BosmonMqtt/Models/TelegramsEventConfig.cs
Normal file
99
BosmonMqtt/Models/TelegramsEventConfig.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using BosMon.Prefs;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace BlubbFish.BosmonMqtt.Models {
|
||||
internal class TelegramsEventConfig : BosMonConfiguration, IBosMonConfigurationTemplate {
|
||||
private String _title;
|
||||
private String _message;
|
||||
private String _topic;
|
||||
private String _desc;
|
||||
|
||||
public delegate void Change(Object sender, EventArgs e);
|
||||
public event Change ConfigChanged;
|
||||
|
||||
public TelegramsEventConfig(IBosMonConfigurationStorage storage) : base(storage) {
|
||||
this.PluginStorage = storage;
|
||||
}
|
||||
|
||||
#region öffentliche Eigenschaften
|
||||
public IBosMonConfigurationStorage PluginStorage { get; private set; }
|
||||
|
||||
public String Title {
|
||||
get {
|
||||
return this._title;
|
||||
}
|
||||
set {
|
||||
this._title = value;
|
||||
WriteConfiguration();
|
||||
}
|
||||
}
|
||||
public String Message {
|
||||
get {
|
||||
return this._message;
|
||||
}
|
||||
set {
|
||||
this._message = value;
|
||||
WriteConfiguration();
|
||||
}
|
||||
}
|
||||
public String Topic {
|
||||
get {
|
||||
return this._topic;
|
||||
}
|
||||
set {
|
||||
this._topic = value;
|
||||
WriteConfiguration();
|
||||
}
|
||||
}
|
||||
public String Desc {
|
||||
get {
|
||||
return this._desc;
|
||||
}
|
||||
set {
|
||||
this._desc = 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", "");
|
||||
}
|
||||
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();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBosMonConfigurationTemplate Member
|
||||
public override TKeyVal<String>[] StringVariables {
|
||||
get {
|
||||
return Merge(
|
||||
new TKeyVal<String>[] {
|
||||
new TKeyVal<String>("title", "Mqtt-Post"),
|
||||
new TKeyVal<String>("desc", "Mqtt Nachricht die beim Event versendet wird."),
|
||||
new TKeyVal<String>("topic", ""),
|
||||
new TKeyVal<String>("message", "")
|
||||
},
|
||||
base.StringVariables);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Saved() {
|
||||
this.ConfigChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,89 +1,90 @@
|
||||
using System;
|
||||
using BlubbFish.BosmonMqtt.Controller;
|
||||
using BlubbFish.BosmonMqtt.Models;
|
||||
using BlubbFish.BosmonMqtt.Views;
|
||||
using BosMon.Data.Processors;
|
||||
using BosMon.Exceptions;
|
||||
using BosMon.Plugins;
|
||||
using BosMon.Prefs;
|
||||
|
||||
namespace BlubbFish.BosmonMqtt {
|
||||
public class Class1 : IBosMonPlugin {
|
||||
private Plugin plugin = new Plugin();
|
||||
#region Plugin Eigenschaften
|
||||
String IBosMonPlugin.PluginName {
|
||||
get {
|
||||
return "MQTT-Bridge";
|
||||
}
|
||||
}
|
||||
class MqttPlugin {
|
||||
private PluginConfiguration pluginconfiguration;
|
||||
private Boolean isDisposed = false;
|
||||
private Boolean isInitialized = false;
|
||||
private ConfigView _configView;
|
||||
private MqttEventProcessor _mqtteventprocessor;
|
||||
private Boolean isStarted = false;
|
||||
private ITelegramEventProcessor _events;
|
||||
|
||||
String IBosMonPlugin.PluginDescription {
|
||||
get {
|
||||
return "Sendet Telegramme nach MQTT";
|
||||
}
|
||||
}
|
||||
internal IBosMonHost PluginHost { get; set; }
|
||||
internal IBosMonConfigurationStorage ConfigurationStorage { get; set; }
|
||||
|
||||
Int32 IBosMonPlugin.PluginVersion {
|
||||
get {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
PluginType IBosMonPlugin.PluginType {
|
||||
get {
|
||||
return PluginType.Client;
|
||||
}
|
||||
}
|
||||
|
||||
Int32 IBosMonPlugin.PluginFlags {
|
||||
get {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
String[] IBosMonPlugin.StartPluginAfter {
|
||||
get {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Plugin Connectoren
|
||||
public IBosMonHost PluginHost {
|
||||
get {
|
||||
return this.plugin.PluginHost;
|
||||
}
|
||||
set {
|
||||
this.plugin.PluginHost = value ?? throw new BosMonArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
IBosMonConfigurationStorage IBosMonPlugin.ConfigurationStorage {
|
||||
get {
|
||||
return this.plugin.ConfigurationStorage;
|
||||
}
|
||||
set {
|
||||
if (value == null) {
|
||||
internal void Init() {
|
||||
if (this.ConfigurationStorage == null || this.PluginHost == null) {
|
||||
throw new BosMonArgumentNullException();
|
||||
} else if (this.plugin.ConfigurationStorage != null) {
|
||||
throw new BosMonInternalException("ConfigStorage already set");
|
||||
}
|
||||
this.plugin.ConfigurationStorage = value;
|
||||
if (this.isInitialized) {
|
||||
throw new BosMonInternalException();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Plugin Einstiegspunkte
|
||||
void IDisposable.Dispose() {
|
||||
this.plugin.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
this.pluginconfiguration = new PluginConfiguration(this.ConfigurationStorage);
|
||||
this.isInitialized = true;
|
||||
this._configView = new ConfigView(this.pluginconfiguration);
|
||||
this._mqtteventprocessor = new MqttEventProcessor(this.pluginconfiguration, this.PluginHost);
|
||||
TelegramsEvents.Actions.ActionProviders.Add(new MqttActionProvider(this._mqtteventprocessor));
|
||||
}
|
||||
|
||||
void IBosMonPlugin.InitializePlugin() {
|
||||
this.plugin.Init();
|
||||
internal void Start() {
|
||||
if (!this.isInitialized) {
|
||||
throw new BosMonInternalException("Not initialized");
|
||||
}
|
||||
try {
|
||||
// ... Plugin starten ...
|
||||
this.PluginHost.RegisterConfigPage("Plugins", "Mqtt", this._configView);
|
||||
//this.PluginHost.RegisterEventProcessor("MqttEventProcessor", this._mqtteventprocessor);
|
||||
|
||||
this._events = this.PluginHost.GetEventProcessor("TelegramEventProcessor") as ITelegramEventProcessor;
|
||||
this._events.TelegramEvent += this._mqtteventprocessor.TelegramEvent;
|
||||
|
||||
|
||||
|
||||
// Es muss unbedingt darauf geachtet werden, dass das Plugin in dieser
|
||||
// Methode nicht blockiert, da sonst der Hauptthread von BosMon ebenfalls
|
||||
// blockiert wird.
|
||||
|
||||
this.isStarted = true;
|
||||
} catch (Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void IBosMonPlugin.StartPlugin() {
|
||||
this.plugin.Start();
|
||||
internal void Stop() {
|
||||
if (!this.isInitialized) {
|
||||
throw new BosMonInternalException("Not initialized");
|
||||
}
|
||||
|
||||
void IBosMonPlugin.StopPlugin() {
|
||||
this.plugin.Stop();
|
||||
try {
|
||||
if (this.isStarted) {
|
||||
this._configView.Dispose();
|
||||
this.PluginHost.UnRegisterConfigPage(this._configView);
|
||||
this._events.TelegramEvent -= this._mqtteventprocessor.TelegramEvent;
|
||||
this._mqtteventprocessor.Dispose();
|
||||
this.isStarted = false;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
BosMon.Gui.BosMonErrorBox.Show(ex, "Fehler");
|
||||
}
|
||||
}
|
||||
|
||||
internal void Dispose(Boolean dispose) {
|
||||
if (!this.isDisposed) {
|
||||
if (dispose) {
|
||||
try {
|
||||
//DeInitialize();
|
||||
} catch (Exception) { }
|
||||
}
|
||||
this.isDisposed = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,86 +0,0 @@
|
||||
using System;
|
||||
using BlubbFish.BosmonMqtt.Models;
|
||||
using BlubbFish.BosmonMqtt.Views;
|
||||
using BosMon.Data.Processors;
|
||||
using BosMon.Exceptions;
|
||||
using BosMon.Plugins;
|
||||
using BosMon.Prefs;
|
||||
|
||||
namespace BlubbFish.BosmonMqtt {
|
||||
class Plugin {
|
||||
private PluginConfiguration pluginconfiguration;
|
||||
private Boolean isDisposed = false;
|
||||
private Boolean isInitialized = false;
|
||||
private ConfigView _configView;
|
||||
private MqttEventProcessor _mqtteventprocessor;
|
||||
private Boolean isStarted = false;
|
||||
private ITelegramEventProcessor _events;
|
||||
|
||||
internal IBosMonHost PluginHost { get; set; }
|
||||
internal IBosMonConfigurationStorage ConfigurationStorage { get; set; }
|
||||
|
||||
internal void Init() {
|
||||
if (this.ConfigurationStorage == null || this.PluginHost == null) {
|
||||
throw new BosMonArgumentNullException();
|
||||
}
|
||||
if (this.isInitialized) {
|
||||
throw new BosMonInternalException();
|
||||
}
|
||||
this.pluginconfiguration = new PluginConfiguration(this.ConfigurationStorage);
|
||||
this.isInitialized = true;
|
||||
this._configView = new ConfigView(this.pluginconfiguration);
|
||||
this._mqtteventprocessor = new MqttEventProcessor(this.pluginconfiguration, this.PluginHost);
|
||||
}
|
||||
|
||||
internal void Start() {
|
||||
if (!this.isInitialized) {
|
||||
throw new BosMonInternalException("Not initialized");
|
||||
}
|
||||
try {
|
||||
// ... Plugin starten ...
|
||||
this.PluginHost.RegisterConfigPage("Plugins", "Mqtt", this._configView);
|
||||
//this.PluginHost.RegisterEventProcessor("MqttEventProcessor", this._mqtteventprocessor);
|
||||
|
||||
this._events = this.PluginHost.GetEventProcessor("TelegramEventProcessor") as ITelegramEventProcessor;
|
||||
this._events.TelegramEvent += this._mqtteventprocessor.TelegramEvent;
|
||||
|
||||
// Es muss unbedingt darauf geachtet werden, dass das Plugin in dieser
|
||||
// Methode nicht blockiert, da sonst der Hauptthread von BosMon ebenfalls
|
||||
// blockiert wird.
|
||||
|
||||
this.isStarted = true;
|
||||
} catch (Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
internal void Stop() {
|
||||
if (!this.isInitialized) {
|
||||
throw new BosMonInternalException("Not initialized");
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.isStarted) {
|
||||
this._configView.Dispose();
|
||||
this.PluginHost.UnRegisterConfigPage(this._configView);
|
||||
this._events.TelegramEvent -= this._mqtteventprocessor.TelegramEvent;
|
||||
this._mqtteventprocessor.Dispose();
|
||||
this.isStarted = false;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
BosMon.Gui.BosMonErrorBox.Show(ex, "Fehler");
|
||||
}
|
||||
}
|
||||
|
||||
internal void Dispose(Boolean dispose) {
|
||||
if (!this.isDisposed) {
|
||||
if (dispose) {
|
||||
try {
|
||||
//DeInitialize();
|
||||
} catch (Exception) { }
|
||||
}
|
||||
this.isDisposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
172
BosmonMqtt/Views/ActionDialog.Designer.cs
generated
Normal file
172
BosmonMqtt/Views/ActionDialog.Designer.cs
generated
Normal file
@ -0,0 +1,172 @@
|
||||
namespace BlubbFish.BosmonMqtt.Views {
|
||||
partial class ActionDialog {
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) {
|
||||
if (disposing && (components != null)) {
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent() {
|
||||
this.ButtonOk = new System.Windows.Forms.Button();
|
||||
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.TextBoxTopic = new System.Windows.Forms.TextBox();
|
||||
this.TextBoxMessage = new System.Windows.Forms.TextBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.TextBoxTitle = new System.Windows.Forms.TextBox();
|
||||
this.TextBoxDescription = new System.Windows.Forms.TextBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// ButtonOk
|
||||
//
|
||||
this.ButtonOk.Location = new System.Drawing.Point(12, 121);
|
||||
this.ButtonOk.Name = "ButtonOk";
|
||||
this.ButtonOk.Size = new System.Drawing.Size(75, 23);
|
||||
this.ButtonOk.TabIndex = 0;
|
||||
this.ButtonOk.Text = "OK";
|
||||
this.ButtonOk.UseVisualStyleBackColor = true;
|
||||
this.ButtonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
this.ButtonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.ButtonCancel.Location = new System.Drawing.Point(199, 121);
|
||||
this.ButtonCancel.Name = "ButtonCancel";
|
||||
this.ButtonCancel.Size = new System.Drawing.Size(75, 23);
|
||||
this.ButtonCancel.TabIndex = 1;
|
||||
this.ButtonCancel.Text = "Abbrechen";
|
||||
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(7, 67);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(37, 13);
|
||||
this.label1.TabIndex = 2;
|
||||
this.label1.Text = "Topic:";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(7, 93);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(56, 13);
|
||||
this.label2.TabIndex = 3;
|
||||
this.label2.Text = "Nachricht:";
|
||||
//
|
||||
// TextBoxTopic
|
||||
//
|
||||
this.TextBoxTopic.Location = new System.Drawing.Point(88, 64);
|
||||
this.TextBoxTopic.Name = "TextBoxTopic";
|
||||
this.TextBoxTopic.Size = new System.Drawing.Size(186, 20);
|
||||
this.TextBoxTopic.TabIndex = 4;
|
||||
this.TextBoxTopic.Tag = "topic";
|
||||
this.TextBoxTopic.Leave += new System.EventHandler(this.Settings_Changed);
|
||||
//
|
||||
// TextBoxMessage
|
||||
//
|
||||
this.TextBoxMessage.Location = new System.Drawing.Point(88, 90);
|
||||
this.TextBoxMessage.Name = "TextBoxMessage";
|
||||
this.TextBoxMessage.Size = new System.Drawing.Size(186, 20);
|
||||
this.TextBoxMessage.TabIndex = 5;
|
||||
this.TextBoxMessage.Tag = "message";
|
||||
this.TextBoxMessage.Leave += new System.EventHandler(this.Settings_Changed);
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(7, 15);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(30, 13);
|
||||
this.label3.TabIndex = 6;
|
||||
this.label3.Text = "Titel:";
|
||||
//
|
||||
// TextBoxTitle
|
||||
//
|
||||
this.TextBoxTitle.Location = new System.Drawing.Point(88, 12);
|
||||
this.TextBoxTitle.Name = "TextBoxTitle";
|
||||
this.TextBoxTitle.Size = new System.Drawing.Size(186, 20);
|
||||
this.TextBoxTitle.TabIndex = 7;
|
||||
this.TextBoxTitle.Tag = "title";
|
||||
this.TextBoxTitle.Leave += new System.EventHandler(this.Settings_Changed);
|
||||
//
|
||||
// TextBoxDescription
|
||||
//
|
||||
this.TextBoxDescription.Location = new System.Drawing.Point(88, 38);
|
||||
this.TextBoxDescription.Name = "TextBoxDescription";
|
||||
this.TextBoxDescription.Size = new System.Drawing.Size(186, 20);
|
||||
this.TextBoxDescription.TabIndex = 9;
|
||||
this.TextBoxDescription.Tag = "desc";
|
||||
this.TextBoxDescription.Leave += new System.EventHandler(this.Settings_Changed);
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(7, 41);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(75, 13);
|
||||
this.label4.TabIndex = 8;
|
||||
this.label4.Text = "Beschreibung:";
|
||||
//
|
||||
// ActionDialog
|
||||
//
|
||||
this.AcceptButton = this.ButtonOk;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.ButtonCancel;
|
||||
this.ClientSize = new System.Drawing.Size(286, 155);
|
||||
this.Controls.Add(this.TextBoxDescription);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.TextBoxTitle);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.TextBoxMessage);
|
||||
this.Controls.Add(this.TextBoxTopic);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.ButtonCancel);
|
||||
this.Controls.Add(this.ButtonOk);
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "ActionDialog";
|
||||
this.ShowIcon = false;
|
||||
this.ShowInTaskbar = false;
|
||||
this.Text = "Mqtt Nachriten Einstellungen";
|
||||
this.TopMost = true;
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button ButtonOk;
|
||||
private System.Windows.Forms.Button ButtonCancel;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.TextBox TextBoxTopic;
|
||||
private System.Windows.Forms.TextBox TextBoxMessage;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.TextBox TextBoxTitle;
|
||||
private System.Windows.Forms.TextBox TextBoxDescription;
|
||||
private System.Windows.Forms.Label label4;
|
||||
}
|
||||
}
|
59
BosmonMqtt/Views/ActionDialog.cs
Normal file
59
BosmonMqtt/Views/ActionDialog.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using BlubbFish.BosmonMqtt.Models;
|
||||
using BosMon.Utils;
|
||||
|
||||
namespace BlubbFish.BosmonMqtt.Views {
|
||||
internal partial class ActionDialog : Form {
|
||||
private TelegramsEventConfig eventconfig;
|
||||
private String _title;
|
||||
private String _desc;
|
||||
private String _message;
|
||||
private String _topic;
|
||||
|
||||
public ActionDialog(TelegramsEventConfig eventconfig) {
|
||||
InitializeComponent();
|
||||
this.eventconfig = eventconfig;
|
||||
this.DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
|
||||
public void LoadSettings() {
|
||||
this._title = this.eventconfig.Title;
|
||||
this._message = this.eventconfig.Message;
|
||||
this._topic = this.eventconfig.Topic;
|
||||
this._desc = this.eventconfig.Desc;
|
||||
this.TextBoxTitle.Text = this._title;
|
||||
this.TextBoxTopic.Text = this._topic;
|
||||
this.TextBoxMessage.Text = this._message;
|
||||
this.TextBoxDescription.Text = this._desc;
|
||||
}
|
||||
|
||||
private void ButtonOk_Click(Object sender, EventArgs e) {
|
||||
this.eventconfig.Title = this._title;
|
||||
this.eventconfig.Message = this._message;
|
||||
this.eventconfig.Topic = this._topic;
|
||||
this.eventconfig.Desc = this._desc;
|
||||
this.eventconfig.Saved();
|
||||
this.DialogResult = DialogResult.OK;
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void Settings_Changed(Object sender, EventArgs e) {
|
||||
TextBox t = sender as TextBox;
|
||||
switch (t.Tag) {
|
||||
case "title":
|
||||
this._title = t.Text;
|
||||
break;
|
||||
case "message":
|
||||
this._message = t.Text;
|
||||
break;
|
||||
case "topic":
|
||||
this._topic = t.Text;
|
||||
break;
|
||||
case "desc":
|
||||
this._desc = t.Text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
BosmonMqtt/Views/ActionDialog.resx
Normal file
120
BosmonMqtt/Views/ActionDialog.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?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>
|
||||
</root>
|
@ -48,12 +48,6 @@ namespace BlubbFish.BosmonMqtt.Views {
|
||||
break;
|
||||
case "topic":
|
||||
this._topic = t.Text;
|
||||
if (this._topic.Length > 0 && this._topic[0] != '/') {
|
||||
this._topic = "/" + this._topic;
|
||||
}
|
||||
if (this._topic.Length > 1 && this._topic[this._topic.Length - 1] != '/') {
|
||||
this._topic = this._topic + "/";
|
||||
}
|
||||
t.BeginInvoke((Action)(() => {
|
||||
t.Text = this._topic;
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user