[NF] Verbindungsüberwachung eingebaut
[NF] Globale Aktivierung des Plugins hinzugefügt
This commit is contained in:
parent
ffdbb6eaa4
commit
01140f1700
@ -51,7 +51,7 @@
|
|||||||
<Compile Include="MqttEventProcessor.cs" />
|
<Compile Include="MqttEventProcessor.cs" />
|
||||||
<Compile Include="MqttPlugin.cs" />
|
<Compile Include="MqttPlugin.cs" />
|
||||||
<Compile Include="Plugin.cs" />
|
<Compile Include="Plugin.cs" />
|
||||||
<Compile Include="PluginConfiguration.cs" />
|
<Compile Include="Models\PluginConfiguration.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Views\Config.cs">
|
<Compile Include="Views\Config.cs">
|
||||||
<SubType>UserControl</SubType>
|
<SubType>UserControl</SubType>
|
||||||
|
@ -2,18 +2,22 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace BlubbFish.BosmonMqtt {
|
namespace BlubbFish.BosmonMqtt.Models {
|
||||||
internal class PluginConfiguration : BosMonConfiguration, IBosMonConfigurationTemplate {
|
internal class PluginConfiguration : BosMonConfiguration, IBosMonConfigurationTemplate {
|
||||||
private String _server;
|
private String _server;
|
||||||
private String _user;
|
private String _user;
|
||||||
private String _pass;
|
private String _pass;
|
||||||
private String _topic;
|
private String _topic;
|
||||||
private Int32 _port;
|
private Int32 _port;
|
||||||
|
private Boolean _enable;
|
||||||
|
public delegate void Change(Object sender, EventArgs e);
|
||||||
|
public event Change ConfigChanged;
|
||||||
|
|
||||||
public PluginConfiguration(IBosMonConfigurationStorage storage) : base(storage) {
|
public PluginConfiguration(IBosMonConfigurationStorage storage) : base(storage) {
|
||||||
this.PluginStorage = storage;
|
this.PluginStorage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region öffentliche Eigenschaften
|
||||||
public IBosMonConfigurationStorage PluginStorage { get; private set; }
|
public IBosMonConfigurationStorage PluginStorage { get; private set; }
|
||||||
|
|
||||||
public String Server {
|
public String Server {
|
||||||
@ -69,6 +73,17 @@ namespace BlubbFish.BosmonMqtt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean Enable {
|
||||||
|
get {
|
||||||
|
return this._enable;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this._enable = value;
|
||||||
|
WriteConfiguration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region IBosMonConfigurationTemplate Config-Variablen
|
#region IBosMonConfigurationTemplate Config-Variablen
|
||||||
public override void ReadConfiguration() {
|
public override void ReadConfiguration() {
|
||||||
base.ReadConfiguration();
|
base.ReadConfiguration();
|
||||||
@ -77,6 +92,7 @@ namespace BlubbFish.BosmonMqtt {
|
|||||||
this._pass = this.Storage.ReadString("pass", "");
|
this._pass = this.Storage.ReadString("pass", "");
|
||||||
this._topic = this.Storage.ReadString("topic", "");
|
this._topic = this.Storage.ReadString("topic", "");
|
||||||
this._port = this.Storage.ReadInteger("port", 1883);
|
this._port = this.Storage.ReadInteger("port", 1883);
|
||||||
|
this._enable = this.Storage.ReadBoolean("enable", false);
|
||||||
}
|
}
|
||||||
public override void WriteConfiguration() {
|
public override void WriteConfiguration() {
|
||||||
this.Storage.Write("server", this._server);
|
this.Storage.Write("server", this._server);
|
||||||
@ -84,9 +100,11 @@ namespace BlubbFish.BosmonMqtt {
|
|||||||
this.Storage.Write("pass", this._pass);
|
this.Storage.Write("pass", this._pass);
|
||||||
this.Storage.Write("topic", this._topic);
|
this.Storage.Write("topic", this._topic);
|
||||||
this.Storage.Write("port", this._port);
|
this.Storage.Write("port", this._port);
|
||||||
|
this.Storage.Write("enable", this._enable);
|
||||||
base.WriteConfiguration();
|
base.WriteConfiguration();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IBosMonConfigurationTemplate Member
|
#region IBosMonConfigurationTemplate Member
|
||||||
public override TKeyVal<String>[] StringVariables {
|
public override TKeyVal<String>[] StringVariables {
|
||||||
get {
|
get {
|
||||||
@ -107,6 +125,13 @@ namespace BlubbFish.BosmonMqtt {
|
|||||||
}, base.IntVariables);
|
}, base.IntVariables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public override TKeyVal<Boolean>[] BoolVariables {
|
||||||
|
get {
|
||||||
|
return Merge(new TKeyVal<Boolean>[] {
|
||||||
|
new TKeyVal<Boolean>("enable", false)
|
||||||
|
}, base.BoolVariables);
|
||||||
|
}
|
||||||
|
}
|
||||||
public override TKeyVal<Boolean>[] Sections {
|
public override TKeyVal<Boolean>[] Sections {
|
||||||
get {
|
get {
|
||||||
return new TKeyVal<Boolean>[] {
|
return new TKeyVal<Boolean>[] {
|
||||||
@ -115,6 +140,10 @@ namespace BlubbFish.BosmonMqtt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Saved() {
|
||||||
|
this.ConfigChanged?.Invoke(this, new EventArgs());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using BlubbFish.BosmonMqtt.Models;
|
||||||
using BosMon.Data;
|
using BosMon.Data;
|
||||||
using BosMon.Data.Telegrams;
|
using BosMon.Data.Telegrams;
|
||||||
using BosMon.Prefs;
|
using BosMon.Plugins;
|
||||||
|
using BosMon.Utils;
|
||||||
using TelegramFilter.Filter;
|
using TelegramFilter.Filter;
|
||||||
using uPLibrary.Networking.M2Mqtt;
|
using uPLibrary.Networking.M2Mqtt;
|
||||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||||
@ -11,16 +14,78 @@ using uPLibrary.Networking.M2Mqtt.Messages;
|
|||||||
namespace BlubbFish.BosmonMqtt {
|
namespace BlubbFish.BosmonMqtt {
|
||||||
class MqttEventProcessor : IDisposable {
|
class MqttEventProcessor : IDisposable {
|
||||||
private PluginConfiguration pluginconfig;
|
private PluginConfiguration pluginconfig;
|
||||||
|
private IBosMonHost pluginhost;
|
||||||
private MqttClient client;
|
private MqttClient client;
|
||||||
private FilterList filter;
|
private FilterList filter;
|
||||||
private List<PocsagFilterItem> pfilter = new List<PocsagFilterItem>();
|
private List<PocsagFilterItem> pfilter = new List<PocsagFilterItem>();
|
||||||
|
Thread connectionWatcher;
|
||||||
|
|
||||||
public MqttEventProcessor(PluginConfiguration pluginconfiguration) {
|
public MqttEventProcessor(PluginConfiguration pluginconfiguration, IBosMonHost pluginHost) {
|
||||||
this.pluginconfig = pluginconfiguration;
|
this.pluginconfig = pluginconfiguration;
|
||||||
|
this.pluginhost = pluginHost;
|
||||||
|
this.Connect();
|
||||||
|
if(this.pluginconfig.Enable) {
|
||||||
|
this.ConnectionWatcherStart();
|
||||||
|
}
|
||||||
|
this.pluginconfig.ConfigChanged += this.Pluginconfig_ConfigChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConnectionWatcherRunner() {
|
||||||
|
while(true) {
|
||||||
|
try {
|
||||||
|
Thread.Sleep(10000);
|
||||||
|
if(!this.client.IsConnected) {
|
||||||
|
this.Reconnect();
|
||||||
|
}
|
||||||
|
} catch(Exception) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConnectionWatcherStart() {
|
||||||
|
if(this.connectionWatcher == null) {
|
||||||
|
this.connectionWatcher = new Thread(this.ConnectionWatcherRunner);
|
||||||
|
}
|
||||||
|
if(this.connectionWatcher.ThreadState == ThreadState.Running || this.connectionWatcher.ThreadState == ThreadState.WaitSleepJoin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.connectionWatcher.Start();
|
||||||
|
this.Log("ConnectionWatcherStart", "Überwachungsthread gestartet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConnectionWatcherStop() {
|
||||||
|
if(this.connectionWatcher == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.connectionWatcher.Abort();
|
||||||
|
Thread.Sleep(100);
|
||||||
|
this.connectionWatcher = null;
|
||||||
|
} catch (Exception) { }
|
||||||
|
this.Log("ConnectionWatcherStop", "Überwachungsthread gestoppt.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Pluginconfig_ConfigChanged(Object sender, EventArgs e) {
|
||||||
|
this.Reconnect();
|
||||||
|
if (this.pluginconfig.Enable) {
|
||||||
|
this.ConnectionWatcherStart();
|
||||||
|
}
|
||||||
|
if(!this.pluginconfig.Enable) {
|
||||||
|
this.ConnectionWatcherStop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Reconnect() {
|
||||||
|
if (this.pluginconfig.Enable) {
|
||||||
|
this.Log("Reconnect", "Reconnect ausgelößt.");
|
||||||
|
}
|
||||||
|
this.Disconnect();
|
||||||
this.Connect();
|
this.Connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Connect() {
|
|
||||||
|
|
||||||
|
private void Connect() {
|
||||||
|
if (this.pluginconfig.Enable) {
|
||||||
try {
|
try {
|
||||||
this.client = new MqttClient(this.pluginconfig.Server, this.pluginconfig.Port, false, null);
|
this.client = new MqttClient(this.pluginconfig.Server, this.pluginconfig.Port, false, null);
|
||||||
if (this.pluginconfig.User == "" || this.pluginconfig.Password == "") {
|
if (this.pluginconfig.User == "" || this.pluginconfig.Password == "") {
|
||||||
@ -30,18 +95,31 @@ namespace BlubbFish.BosmonMqtt {
|
|||||||
}
|
}
|
||||||
this.client.Subscribe(new String[] { this.pluginconfig.Topic }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
|
this.client.Subscribe(new String[] { this.pluginconfig.Topic }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
|
||||||
} catch (Exception) {
|
} catch (Exception) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.filter = new FilterList(this.pluginconfig.PluginStorage.GetSection("filter"));
|
this.filter = new FilterList(this.pluginconfig.PluginStorage.GetSection("filter"));
|
||||||
this.pfilter.Clear();
|
|
||||||
foreach (FilterItem item in this.filter) {
|
foreach (FilterItem item in this.filter) {
|
||||||
if (item.GetType() == typeof(PocsagFilterItem)) {
|
if (item.GetType() == typeof(PocsagFilterItem)) {
|
||||||
this.pfilter.Add(item as PocsagFilterItem);
|
this.pfilter.Add(item as PocsagFilterItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.Log("Connect", "Erfolgreich verbunden.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Disconnect() {
|
||||||
|
this.pfilter.Clear();
|
||||||
|
if (this.client != null && this.client.IsConnected) {
|
||||||
|
this.client.Unsubscribe(new String[] { this.pluginconfig.Topic });
|
||||||
|
this.client.Disconnect();
|
||||||
|
this.Log("Disconnect", "Verbindung getrennt.");
|
||||||
|
}
|
||||||
|
this.client = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void TelegramEvent(Object sender, TelegramEventArgs e) {
|
internal void TelegramEvent(Object sender, TelegramEventArgs e) {
|
||||||
|
if (this.pluginconfig.Enable) {
|
||||||
|
try {
|
||||||
Telegram t = e.Telegram as Telegram;
|
Telegram t = e.Telegram as Telegram;
|
||||||
if (this.client != null && this.client.IsConnected && this.filter != null) {
|
if (this.client != null && this.client.IsConnected && this.filter != null) {
|
||||||
if (t.Type == PocsagTelegram.TYPE_POCSAG) {
|
if (t.Type == PocsagTelegram.TYPE_POCSAG) {
|
||||||
@ -54,6 +132,13 @@ namespace BlubbFish.BosmonMqtt {
|
|||||||
this.client.Publish(this.pluginconfig.Topic + p.Address + p.Func, Encoding.UTF8.GetBytes(p.Msg));
|
this.client.Publish(this.pluginconfig.Topic + p.Address + p.Func, Encoding.UTF8.GetBytes(p.Msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Log(String method, String text) {
|
||||||
|
BosMonLog.Logger.WriteLine(LogSeverity.Info, "BosmonMqtt.MqttEventProcessor", method, text);
|
||||||
|
this.pluginhost.AddMessage(DateTime.Now.Ticks, MessageType.Message, "BosmonMqtt " + text);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IDisposable Support
|
#region IDisposable Support
|
||||||
@ -63,7 +148,8 @@ namespace BlubbFish.BosmonMqtt {
|
|||||||
protected virtual void Dispose(Boolean disposing) {
|
protected virtual void Dispose(Boolean disposing) {
|
||||||
if (!this.disposedValue) {
|
if (!this.disposedValue) {
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
// TODO: verwalteten Zustand (verwaltete Objekte) entsorgen.
|
this.ConnectionWatcherStop();
|
||||||
|
this.Disconnect();
|
||||||
}
|
}
|
||||||
this.disposedValue = true;
|
this.disposedValue = true;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using BlubbFish.BosmonMqtt.Models;
|
||||||
using BlubbFish.BosmonMqtt.Views;
|
using BlubbFish.BosmonMqtt.Views;
|
||||||
using BosMon.Data.Processors;
|
using BosMon.Data.Processors;
|
||||||
using BosMon.Exceptions;
|
using BosMon.Exceptions;
|
||||||
@ -28,7 +29,7 @@ namespace BlubbFish.BosmonMqtt {
|
|||||||
this.pluginconfiguration = new PluginConfiguration(this.ConfigurationStorage);
|
this.pluginconfiguration = new PluginConfiguration(this.ConfigurationStorage);
|
||||||
this.isInitialized = true;
|
this.isInitialized = true;
|
||||||
this._configView = new ConfigView(this.pluginconfiguration);
|
this._configView = new ConfigView(this.pluginconfiguration);
|
||||||
this._mqtteventprocessor = new MqttEventProcessor(this.pluginconfiguration);
|
this._mqtteventprocessor = new MqttEventProcessor(this.pluginconfiguration, this.PluginHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Start() {
|
internal void Start() {
|
||||||
|
19
BosmonMqtt/Views/Config.Designer.cs
generated
19
BosmonMqtt/Views/Config.Designer.cs
generated
@ -38,6 +38,7 @@
|
|||||||
this.label5 = new System.Windows.Forms.Label();
|
this.label5 = new System.Windows.Forms.Label();
|
||||||
this.textTopic = new System.Windows.Forms.TextBox();
|
this.textTopic = new System.Windows.Forms.TextBox();
|
||||||
this.filterButton = new System.Windows.Forms.Button();
|
this.filterButton = new System.Windows.Forms.Button();
|
||||||
|
this.boxEnable = new System.Windows.Forms.CheckBox();
|
||||||
this.groupBox1.SuspendLayout();
|
this.groupBox1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -113,7 +114,7 @@
|
|||||||
this.groupBox1.Controls.Add(this.label1);
|
this.groupBox1.Controls.Add(this.label1);
|
||||||
this.groupBox1.Controls.Add(this.textUser);
|
this.groupBox1.Controls.Add(this.textUser);
|
||||||
this.groupBox1.Controls.Add(this.label3);
|
this.groupBox1.Controls.Add(this.label3);
|
||||||
this.groupBox1.Location = new System.Drawing.Point(3, 3);
|
this.groupBox1.Location = new System.Drawing.Point(3, 30);
|
||||||
this.groupBox1.Name = "groupBox1";
|
this.groupBox1.Name = "groupBox1";
|
||||||
this.groupBox1.Size = new System.Drawing.Size(390, 250);
|
this.groupBox1.Size = new System.Drawing.Size(390, 250);
|
||||||
this.groupBox1.TabIndex = 7;
|
this.groupBox1.TabIndex = 7;
|
||||||
@ -196,18 +197,31 @@
|
|||||||
this.filterButton.UseVisualStyleBackColor = true;
|
this.filterButton.UseVisualStyleBackColor = true;
|
||||||
this.filterButton.Click += new System.EventHandler(this.Filter_Click);
|
this.filterButton.Click += new System.EventHandler(this.Filter_Click);
|
||||||
//
|
//
|
||||||
|
// boxEnable
|
||||||
|
//
|
||||||
|
this.boxEnable.AutoSize = true;
|
||||||
|
this.boxEnable.Location = new System.Drawing.Point(3, 7);
|
||||||
|
this.boxEnable.Name = "boxEnable";
|
||||||
|
this.boxEnable.Size = new System.Drawing.Size(218, 17);
|
||||||
|
this.boxEnable.TabIndex = 8;
|
||||||
|
this.boxEnable.Text = "Aktiviert oder Deaktiviert das Mqtt-Plugin";
|
||||||
|
this.boxEnable.UseVisualStyleBackColor = true;
|
||||||
|
this.boxEnable.CheckedChanged += new System.EventHandler(this.Enabled_Changed);
|
||||||
|
//
|
||||||
// ConfigView
|
// ConfigView
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.AutoSize = true;
|
this.AutoSize = true;
|
||||||
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
||||||
|
this.Controls.Add(this.boxEnable);
|
||||||
this.Controls.Add(this.groupBox1);
|
this.Controls.Add(this.groupBox1);
|
||||||
this.Name = "ConfigView";
|
this.Name = "ConfigView";
|
||||||
this.Size = new System.Drawing.Size(396, 256);
|
this.Size = new System.Drawing.Size(396, 283);
|
||||||
this.groupBox1.ResumeLayout(false);
|
this.groupBox1.ResumeLayout(false);
|
||||||
this.groupBox1.PerformLayout();
|
this.groupBox1.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,5 +242,6 @@
|
|||||||
private System.Windows.Forms.Label label7;
|
private System.Windows.Forms.Label label7;
|
||||||
private System.Windows.Forms.TextBox textPort;
|
private System.Windows.Forms.TextBox textPort;
|
||||||
private System.Windows.Forms.Label label2;
|
private System.Windows.Forms.Label label2;
|
||||||
|
private System.Windows.Forms.CheckBox boxEnable;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,8 @@ using System.Drawing;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using BosMon.Prefs;
|
using BlubbFish.BosmonMqtt.Models;
|
||||||
|
using BosMon.Gui;
|
||||||
using BosMon.Utils;
|
using BosMon.Utils;
|
||||||
using TelegramFilter.Filter;
|
using TelegramFilter.Filter;
|
||||||
using TelegramFilter.Gui;
|
using TelegramFilter.Gui;
|
||||||
@ -11,19 +12,19 @@ using uPLibrary.Networking.M2Mqtt;
|
|||||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||||
|
|
||||||
namespace BlubbFish.BosmonMqtt.Views {
|
namespace BlubbFish.BosmonMqtt.Views {
|
||||||
internal partial class ConfigView : UserControl {
|
internal partial class ConfigView : UserControl, IPreferencesUserControl {
|
||||||
private PluginConfiguration pluginconfig;
|
private PluginConfiguration pluginconfig;
|
||||||
private EditFilterListDlg filter;
|
private EditFilterListDlg filter;
|
||||||
|
private String _server;
|
||||||
|
private String _port;
|
||||||
|
private String _user;
|
||||||
|
private String _pass;
|
||||||
|
private String _topic;
|
||||||
|
private Boolean _enable;
|
||||||
|
|
||||||
internal ConfigView(PluginConfiguration pluginconfiguration) {
|
internal ConfigView(PluginConfiguration pluginconfiguration) {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.pluginconfig = pluginconfiguration;
|
this.pluginconfig = pluginconfiguration;
|
||||||
this.filter = new EditFilterListDlg(new FilterList(this.pluginconfig.PluginStorage.GetSection("filter")));
|
|
||||||
this.textServer.Text = this.pluginconfig.Server;
|
|
||||||
this.textUser.Text = this.pluginconfig.User;
|
|
||||||
this.textPass.Text = this.pluginconfig.Password;
|
|
||||||
this.textTopic.Text = this.pluginconfig.Topic;
|
|
||||||
this.textPort.Text = this.pluginconfig.Port.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Filter_Click(Object sender, EventArgs e) {
|
private void Filter_Click(Object sender, EventArgs e) {
|
||||||
@ -31,30 +32,47 @@ namespace BlubbFish.BosmonMqtt.Views {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Settings_Changed(Object sender, EventArgs e) {
|
private void Settings_Changed(Object sender, EventArgs e) {
|
||||||
TextBox t = (TextBox)sender;
|
TextBox t = sender as TextBox;
|
||||||
switch (t.Tag) {
|
switch (t.Tag) {
|
||||||
case "server":
|
case "server":
|
||||||
this.pluginconfig.Server = t.Text;
|
this._server = t.Text;
|
||||||
break;
|
|
||||||
case "user":
|
|
||||||
this.pluginconfig.User = t.Text;
|
|
||||||
break;
|
|
||||||
case "pass":
|
|
||||||
this.pluginconfig.Password = t.Text;
|
|
||||||
break;
|
|
||||||
case "topic":
|
|
||||||
this.pluginconfig.Topic = t.Text;
|
|
||||||
t.BeginInvoke((Action)(() => {
|
|
||||||
t.Text = this.pluginconfig.Topic;
|
|
||||||
}));
|
|
||||||
break;
|
break;
|
||||||
case "port":
|
case "port":
|
||||||
if (Int32.TryParse(t.Text, out Int32 port)) {
|
this._port = t.Text;
|
||||||
this.pluginconfig.Port = port;
|
break;
|
||||||
|
case "user":
|
||||||
|
this._user = t.Text;
|
||||||
|
break;
|
||||||
|
case "pass":
|
||||||
|
this._pass = t.Text;
|
||||||
|
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;
|
||||||
|
}));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void Enabled_Changed(Object sender, EventArgs e) {
|
||||||
|
CheckBox t = sender as CheckBox;
|
||||||
|
this._enable = t.Checked;
|
||||||
|
this.boxEnable.BeginInvoke((Action)(() => {
|
||||||
|
this.textServer.Enabled = this._enable;
|
||||||
|
this.textPort.Enabled = this._enable;
|
||||||
|
this.textUser.Enabled = this._enable;
|
||||||
|
this.textPass.Enabled = this._enable;
|
||||||
|
this.textTopic.Enabled = this._enable;
|
||||||
|
this.filterButton.Enabled = this._enable;
|
||||||
|
this.testButton.Enabled = this._enable;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
private void Check_Numbers(Object sender, KeyPressEventArgs e) {
|
private void Check_Numbers(Object sender, KeyPressEventArgs e) {
|
||||||
e.Handled = !Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar);
|
e.Handled = !Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar);
|
||||||
@ -66,23 +84,29 @@ namespace BlubbFish.BosmonMqtt.Views {
|
|||||||
this.labelStatus.Text = "Baue Verbindung auf.";
|
this.labelStatus.Text = "Baue Verbindung auf.";
|
||||||
this.labelStatus.ForeColor = Color.DarkOrange;
|
this.labelStatus.ForeColor = Color.DarkOrange;
|
||||||
}));
|
}));
|
||||||
MqttClient client = new MqttClient(this.pluginconfig.Server, this.pluginconfig.Port, false, null);
|
if (!Int32.TryParse(this._port, out Int32 port)) {
|
||||||
|
this.labelStatus.BeginInvoke((Action)(() => {
|
||||||
|
this.labelStatus.Text = "Fehler beim Parsen des Ports.";
|
||||||
|
}));
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
MqttClient client = new MqttClient(this._server, port, false, null);
|
||||||
if (this.pluginconfig.User == "" || this.pluginconfig.Password == "") {
|
if (this.pluginconfig.User == "" || this.pluginconfig.Password == "") {
|
||||||
client.Connect("bosmon-" + Guid.NewGuid().ToString());
|
client.Connect("bosmon-" + Guid.NewGuid().ToString());
|
||||||
} else {
|
} else {
|
||||||
client.Connect("bosmon-" + Guid.NewGuid().ToString(), this.pluginconfig.User, this.pluginconfig.Password);
|
client.Connect("bosmon-" + Guid.NewGuid().ToString(), this._user, this._pass);
|
||||||
}
|
}
|
||||||
this.labelStatus.BeginInvoke((Action)(() => {
|
this.labelStatus.BeginInvoke((Action)(() => {
|
||||||
this.labelStatus.Text = "Subscribe Topic.";
|
this.labelStatus.Text = "Subscribe Topic.";
|
||||||
this.labelStatus.ForeColor = Color.DarkOrange;
|
this.labelStatus.ForeColor = Color.DarkOrange;
|
||||||
}));
|
}));
|
||||||
client.Subscribe(new String[] { this.pluginconfig.Topic }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
|
client.Subscribe(new String[] { this._topic }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
|
||||||
this.labelStatus.BeginInvoke((Action)(() => {
|
this.labelStatus.BeginInvoke((Action)(() => {
|
||||||
this.labelStatus.Text = "Schicke Testnachricht.";
|
this.labelStatus.Text = "Schicke Testnachricht.";
|
||||||
this.labelStatus.ForeColor = Color.DarkOrange;
|
this.labelStatus.ForeColor = Color.DarkOrange;
|
||||||
}));
|
}));
|
||||||
client.MqttMsgPublishReceived += this.Client_MqttMsgPublishReceived;
|
client.MqttMsgPublishReceived += this.Client_MqttMsgPublishReceived;
|
||||||
client.Publish(this.pluginconfig.Topic, Encoding.UTF8.GetBytes("BosMon Connection Test"));
|
client.Publish(this._topic, Encoding.UTF8.GetBytes("BosMon Connection Test"));
|
||||||
this.labelStatus.BeginInvoke((Action)(() => {
|
this.labelStatus.BeginInvoke((Action)(() => {
|
||||||
this.labelStatus.Text = "Warte auf Testnachricht.";
|
this.labelStatus.Text = "Warte auf Testnachricht.";
|
||||||
this.labelStatus.ForeColor = Color.DarkOrange;
|
this.labelStatus.ForeColor = Color.DarkOrange;
|
||||||
@ -113,5 +137,58 @@ namespace BlubbFish.BosmonMqtt.Views {
|
|||||||
this._testMessageRecieved = true;
|
this._testMessageRecieved = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void LoadSettings() {
|
||||||
|
this.filter = new EditFilterListDlg(new FilterList(this.pluginconfig.PluginStorage.GetSection("filter")));
|
||||||
|
this._server = this.pluginconfig.Server;
|
||||||
|
this._port = this.pluginconfig.Port.ToString();
|
||||||
|
this._user = this.pluginconfig.User;
|
||||||
|
this._pass = this.pluginconfig.Password;
|
||||||
|
this._topic = this.pluginconfig.Topic;
|
||||||
|
this._enable = this.pluginconfig.Enable;
|
||||||
|
|
||||||
|
this.textServer.BeginInvoke((Action)(() => {
|
||||||
|
this.textServer.Text = this._server;
|
||||||
|
}));
|
||||||
|
this.textPort.BeginInvoke((Action)(() => {
|
||||||
|
this.textPort.Text = this._port;
|
||||||
|
}));
|
||||||
|
this.textUser.BeginInvoke((Action)(() => {
|
||||||
|
this.textUser.Text = this._user;
|
||||||
|
}));
|
||||||
|
this.textPass.BeginInvoke((Action)(() => {
|
||||||
|
this.textPass.Text = this._pass;
|
||||||
|
}));
|
||||||
|
this.textTopic.BeginInvoke((Action)(() => {
|
||||||
|
this.textTopic.Text = this._topic;
|
||||||
|
}));
|
||||||
|
this.boxEnable.BeginInvoke((Action)(() => {
|
||||||
|
this.boxEnable.Checked = this._enable;
|
||||||
|
this.textServer.Enabled = this._enable;
|
||||||
|
this.textPort.Enabled = this._enable;
|
||||||
|
this.textUser.Enabled = this._enable;
|
||||||
|
this.textPass.Enabled = this._enable;
|
||||||
|
this.textTopic.Enabled = this._enable;
|
||||||
|
this.filterButton.Enabled = this._enable;
|
||||||
|
this.testButton.Enabled = this._enable;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean SaveSettings() {
|
||||||
|
if (Int32.TryParse(this._port, out Int32 port)) {
|
||||||
|
this.pluginconfig.Port = port;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.pluginconfig.Server = this._server;
|
||||||
|
this.pluginconfig.User = this._user;
|
||||||
|
this.pluginconfig.Password = this._pass;
|
||||||
|
this.pluginconfig.Topic = this._topic;
|
||||||
|
this.pluginconfig.Enable = this._enable;
|
||||||
|
this.pluginconfig.Saved();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetSettings() { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user