From 9599edbacdd321027bb7556eafb5b70ae8e04a40 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Thu, 6 Sep 2018 20:17:26 +0000 Subject: [PATCH] Rewrite of Bosmon MQTT --- BosmonMqtt/BosMonPluginClass.cs | 89 +++++++++ BosmonMqtt/BosmonMqtt.csproj | 22 ++- BosmonMqtt/Controller/MqttActionProvider.cs | 115 ++++++++++++ .../{ => Controller}/MqttEventProcessor.cs | 12 +- BosmonMqtt/Models/PluginConfiguration.cs | 6 - BosmonMqtt/Models/TelegramsEventConfig.cs | 99 ++++++++++ BosmonMqtt/MqttPlugin.cs | 143 +++++++-------- BosmonMqtt/Plugin.cs | 86 --------- BosmonMqtt/Views/ActionDialog.Designer.cs | 172 ++++++++++++++++++ BosmonMqtt/Views/ActionDialog.cs | 59 ++++++ BosmonMqtt/Views/ActionDialog.resx | 120 ++++++++++++ BosmonMqtt/Views/Config.cs | 6 - 12 files changed, 750 insertions(+), 179 deletions(-) create mode 100644 BosmonMqtt/BosMonPluginClass.cs create mode 100644 BosmonMqtt/Controller/MqttActionProvider.cs rename BosmonMqtt/{ => Controller}/MqttEventProcessor.cs (92%) create mode 100644 BosmonMqtt/Models/TelegramsEventConfig.cs delete mode 100644 BosmonMqtt/Plugin.cs create mode 100644 BosmonMqtt/Views/ActionDialog.Designer.cs create mode 100644 BosmonMqtt/Views/ActionDialog.cs create mode 100644 BosmonMqtt/Views/ActionDialog.resx diff --git a/BosmonMqtt/BosMonPluginClass.cs b/BosmonMqtt/BosMonPluginClass.cs new file mode 100644 index 0000000..089f293 --- /dev/null +++ b/BosmonMqtt/BosMonPluginClass.cs @@ -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 + } +} diff --git a/BosmonMqtt/BosmonMqtt.csproj b/BosmonMqtt/BosmonMqtt.csproj index ea1aea1..8e1de56 100644 --- a/BosmonMqtt/BosmonMqtt.csproj +++ b/BosmonMqtt/BosmonMqtt.csproj @@ -18,7 +18,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;COMPACT_FRAMEWORK prompt 4 x86 @@ -27,7 +27,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;MF_FRAMEWORK_VERSION_V4_2 prompt 4 x86 @@ -46,6 +46,9 @@ D:\Programme\BosMon\plugins\TelegramFilter.dll False + + D:\Programme\BosMon\plugins\TelegramsEvents.dll + @@ -201,11 +204,19 @@ lib\M2Mqtt\Utility\QueueExtension.cs - + + + + - + + Form + + + ActionDialog.cs + UserControl @@ -214,6 +225,9 @@ + + ActionDialog.cs + Config.cs diff --git a/BosmonMqtt/Controller/MqttActionProvider.cs b/BosmonMqtt/Controller/MqttActionProvider.cs new file mode 100644 index 0000000..8dee904 --- /dev/null +++ b/BosmonMqtt/Controller/MqttActionProvider.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/BosmonMqtt/MqttEventProcessor.cs b/BosmonMqtt/Controller/MqttEventProcessor.cs similarity index 92% rename from BosmonMqtt/MqttEventProcessor.cs rename to BosmonMqtt/Controller/MqttEventProcessor.cs index 7f00e7a..0a360ee 100644 --- a/BosmonMqtt/MqttEventProcessor.cs +++ b/BosmonMqtt/Controller/MqttEventProcessor.cs @@ -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 pfilter = new List(); - private List ffilter = new List(); - private List zfilter = new List(); + private readonly List pfilter = new List(); + private readonly List ffilter = new List(); + private readonly List zfilter = new List(); Thread connectionWatcher; public MqttEventProcessor(PluginConfiguration pluginconfiguration, IBosMonHost pluginHost) { diff --git a/BosmonMqtt/Models/PluginConfiguration.cs b/BosmonMqtt/Models/PluginConfiguration.cs index 641d1a2..52b8bbf 100644 --- a/BosmonMqtt/Models/PluginConfiguration.cs +++ b/BosmonMqtt/Models/PluginConfiguration.cs @@ -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(); } } diff --git a/BosmonMqtt/Models/TelegramsEventConfig.cs b/BosmonMqtt/Models/TelegramsEventConfig.cs new file mode 100644 index 0000000..f593e26 --- /dev/null +++ b/BosmonMqtt/Models/TelegramsEventConfig.cs @@ -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[] StringVariables { + get { + return Merge( + new TKeyVal[] { + new TKeyVal("title", "Mqtt-Post"), + new TKeyVal("desc", "Mqtt Nachricht die beim Event versendet wird."), + new TKeyVal("topic", ""), + new TKeyVal("message", "") + }, + base.StringVariables); + } + } + + + + public void Saved() { + this.ConfigChanged?.Invoke(this, new EventArgs()); + } + #endregion + } +} \ No newline at end of file diff --git a/BosmonMqtt/MqttPlugin.cs b/BosmonMqtt/MqttPlugin.cs index 7113fe0..34e4dc8 100644 --- a/BosmonMqtt/MqttPlugin.cs +++ b/BosmonMqtt/MqttPlugin.cs @@ -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; + + 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); + TelegramsEvents.Actions.ActionProviders.Add(new MqttActionProvider(this._mqtteventprocessor)); + } + + 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) { + } } - String IBosMonPlugin.PluginDescription { - get { - return "Sendet Telegramme nach MQTT"; + internal void Stop() { + if (!this.isInitialized) { + throw new BosMonInternalException("Not initialized"); } - } - 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) { - throw new BosMonArgumentNullException(); - } else if (this.plugin.ConfigurationStorage != null) { - throw new BosMonInternalException("ConfigStorage already set"); + try { + if (this.isStarted) { + this._configView.Dispose(); + this.PluginHost.UnRegisterConfigPage(this._configView); + this._events.TelegramEvent -= this._mqtteventprocessor.TelegramEvent; + this._mqtteventprocessor.Dispose(); + this.isStarted = false; } - this.plugin.ConfigurationStorage = value; + } catch (Exception ex) { + BosMon.Gui.BosMonErrorBox.Show(ex, "Fehler"); } } - #endregion - #region Plugin Einstiegspunkte - void IDisposable.Dispose() { - this.plugin.Dispose(true); - GC.SuppressFinalize(this); - } - void IBosMonPlugin.InitializePlugin() { - this.plugin.Init(); + internal void Dispose(Boolean dispose) { + if (!this.isDisposed) { + if (dispose) { + try { + //DeInitialize(); + } catch (Exception) { } + } + this.isDisposed = true; + } } - - void IBosMonPlugin.StartPlugin() { - this.plugin.Start(); - } - - void IBosMonPlugin.StopPlugin() { - this.plugin.Stop(); - } - #endregion } } diff --git a/BosmonMqtt/Plugin.cs b/BosmonMqtt/Plugin.cs deleted file mode 100644 index 136b246..0000000 --- a/BosmonMqtt/Plugin.cs +++ /dev/null @@ -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; - } - } - } -} diff --git a/BosmonMqtt/Views/ActionDialog.Designer.cs b/BosmonMqtt/Views/ActionDialog.Designer.cs new file mode 100644 index 0000000..92c7207 --- /dev/null +++ b/BosmonMqtt/Views/ActionDialog.Designer.cs @@ -0,0 +1,172 @@ +namespace BlubbFish.BosmonMqtt.Views { + partial class ActionDialog { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/BosmonMqtt/Views/ActionDialog.cs b/BosmonMqtt/Views/ActionDialog.cs new file mode 100644 index 0000000..ec82483 --- /dev/null +++ b/BosmonMqtt/Views/ActionDialog.cs @@ -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; + } + } + } +} diff --git a/BosmonMqtt/Views/ActionDialog.resx b/BosmonMqtt/Views/ActionDialog.resx new file mode 100644 index 0000000..5ea0895 --- /dev/null +++ b/BosmonMqtt/Views/ActionDialog.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BosmonMqtt/Views/Config.cs b/BosmonMqtt/Views/Config.cs index 60212d3..7d69a25 100644 --- a/BosmonMqtt/Views/Config.cs +++ b/BosmonMqtt/Views/Config.cs @@ -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; }));