[DW] Flex4Grid deleted

[NF] BosMon Mqtt Plugin created
This commit is contained in:
BlubbFish 2018-03-31 20:42:28 +00:00
commit ffdbb6eaa4
13 changed files with 1002 additions and 0 deletions

31
BosmonMqtt.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BosmonMqtt", "BosmonMqtt\BosmonMqtt.csproj", "{EE2F31C4-64D7-4788-AC68-33C5CC8EFCCD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt", "..\Librarys\mqtt\M2Mqtt\M2Mqtt.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EE2F31C4-64D7-4788-AC68-33C5CC8EFCCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE2F31C4-64D7-4788-AC68-33C5CC8EFCCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE2F31C4-64D7-4788-AC68-33C5CC8EFCCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE2F31C4-64D7-4788-AC68-33C5CC8EFCCD}.Release|Any CPU.Build.0 = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {768F1E16-781A-45A6-B11D-6B2D5E0008B1}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EE2F31C4-64D7-4788-AC68-33C5CC8EFCCD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BlubbFish.BosmonMqtt</RootNamespace>
<AssemblyName>BosmonMqtt</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="BosMonClasses">
<HintPath>D:\Programme\BosMon\BosMonClasses.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="TelegramFilter">
<HintPath>D:\Programme\BosMon\plugins\TelegramFilter.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="MqttEventProcessor.cs" />
<Compile Include="MqttPlugin.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="PluginConfiguration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Views\Config.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Views\Config.Designer.cs">
<DependentUpon>Config.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Views\Config.resx">
<DependentUpon>Config.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Librarys\mqtt\M2Mqtt\M2Mqtt.csproj">
<Project>{a11aef5a-b246-4fe8-8330-06db73cc8074}</Project>
<Name>M2Mqtt</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "D:\Programme\BosMon_dev\plugins\$(TargetFileName)"
copy "$(TargetDir)\M2Mqtt.dll" "D:\Programme\BosMon_dev\plugins\M2Mqtt.dll"
del "D:\Programme\BosMon_dev\config\bosmon.log"</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartAction>Program</StartAction>
<StartProgram>D:\Programme\BosMon_dev\BosMon.exe</StartProgram>
<StartWorkingDirectory>D:\Programme\BosMon_dev\</StartWorkingDirectory>
<StartArguments>-nosplashscreen -debug -configpath "D:\Programme\BosMon_dev\config"</StartArguments>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Text;
using BosMon.Data;
using BosMon.Data.Telegrams;
using BosMon.Prefs;
using TelegramFilter.Filter;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace BlubbFish.BosmonMqtt {
class MqttEventProcessor : IDisposable {
private PluginConfiguration pluginconfig;
private MqttClient client;
private FilterList filter;
private List<PocsagFilterItem> pfilter = new List<PocsagFilterItem>();
public MqttEventProcessor(PluginConfiguration pluginconfiguration) {
this.pluginconfig = pluginconfiguration;
this.Connect();
}
public void Connect() {
try {
this.client = new MqttClient(this.pluginconfig.Server, this.pluginconfig.Port, false, null);
if (this.pluginconfig.User == "" || this.pluginconfig.Password == "") {
this.client.Connect("bosmon-" + Guid.NewGuid().ToString());
} else {
this.client.Connect("bosmon-" + Guid.NewGuid().ToString(), this.pluginconfig.User, this.pluginconfig.Password);
}
this.client.Subscribe(new String[] { this.pluginconfig.Topic }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
} catch (Exception) {
}
this.filter = new FilterList(this.pluginconfig.PluginStorage.GetSection("filter"));
this.pfilter.Clear();
foreach (FilterItem item in this.filter) {
if(item.GetType() == typeof(PocsagFilterItem)) {
this.pfilter.Add(item as PocsagFilterItem);
}
}
}
internal void TelegramEvent(Object sender, TelegramEventArgs e) {
Telegram t = e.Telegram as Telegram;
if (this.client != null && this.client.IsConnected && this.filter != null) {
if (t.Type == PocsagTelegram.TYPE_POCSAG) {
PocsagTelegram p = t as PocsagTelegram;
foreach (PocsagFilterItem item in this.pfilter) {
if((item.IsMatching(p) && item.Negated)) {
return;
}
}
this.client.Publish(this.pluginconfig.Topic + p.Address+p.Func, Encoding.UTF8.GetBytes(p.Msg));
}
}
}
#region IDisposable Support
private Boolean disposedValue = false;
protected virtual void Dispose(Boolean disposing) {
if (!this.disposedValue) {
if (disposing) {
// TODO: verwalteten Zustand (verwaltete Objekte) entsorgen.
}
this.disposedValue = true;
}
}
public void Dispose() {
Dispose(true);
}
#endregion
}
}

89
BosmonMqtt/MqttPlugin.cs Normal file
View File

@ -0,0 +1,89 @@
using System;
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";
}
}
String IBosMonPlugin.PluginDescription {
get {
return "Sendet Telegramme nach MQTT";
}
}
Int32 IBosMonPlugin.PluginVersion {
get {
return 1;
}
}
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");
}
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
}
}

85
BosmonMqtt/Plugin.cs Normal file
View File

@ -0,0 +1,85 @@
using System;
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);
}
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;
}
}
}
}

View File

@ -0,0 +1,123 @@
using BosMon.Prefs;
using System;
using System.Text;
namespace BlubbFish.BosmonMqtt {
internal class PluginConfiguration : BosMonConfiguration, IBosMonConfigurationTemplate {
private String _server;
private String _user;
private String _pass;
private String _topic;
private Int32 _port;
public PluginConfiguration(IBosMonConfigurationStorage storage) : base(storage) {
this.PluginStorage = storage;
}
public IBosMonConfigurationStorage PluginStorage { get; private set; }
public String Server {
get {
return this._server;
}
set {
this._server = value;
WriteConfiguration();
}
}
public String User {
get {
return this._user;
}
set {
this._user = value;
WriteConfiguration();
}
}
public String Password {
get {
return Encoding.UTF8.GetString(Convert.FromBase64String(this._pass));
}
set {
this._pass = Convert.ToBase64String(Encoding.UTF8.GetBytes(value));
;
WriteConfiguration();
}
}
public String Topic {
get {
return this._topic;
}
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();
}
}
public Int32 Port {
get {
return this._port;
}
set {
this._port = value;
WriteConfiguration();
}
}
#region IBosMonConfigurationTemplate Config-Variablen
public override void ReadConfiguration() {
base.ReadConfiguration();
this._server = this.Storage.ReadString("server", "");
this._user = this.Storage.ReadString("user", "");
this._pass = this.Storage.ReadString("pass", "");
this._topic = this.Storage.ReadString("topic", "");
this._port = this.Storage.ReadInteger("port", 1883);
}
public override void WriteConfiguration() {
this.Storage.Write("server", this._server);
this.Storage.Write("user", this._user);
this.Storage.Write("pass", this._pass);
this.Storage.Write("topic", this._topic);
this.Storage.Write("port", this._port);
base.WriteConfiguration();
}
#endregion
#region IBosMonConfigurationTemplate Member
public override TKeyVal<String>[] StringVariables {
get {
return Merge(
new TKeyVal<String>[] {
new TKeyVal<String>("server", "localhost"),
new TKeyVal<String>("user", ""),
new TKeyVal<String>("pass", ""),
new TKeyVal<String>("topic", "/bosmon/messages/")
},
base.StringVariables);
}
}
public override TKeyVal<Int32>[] IntVariables {
get {
return Merge(new TKeyVal<Int32>[] {
new TKeyVal<Int32>("port",1883)
}, base.IntVariables);
}
}
public override TKeyVal<Boolean>[] Sections {
get {
return new TKeyVal<Boolean>[] {
new TKeyVal<Boolean>("filter", true)
};
}
}
#endregion
}
}

View File

@ -0,0 +1,39 @@
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("BosmonMqtt")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BosmonMqtt")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("BlubbFish")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("ee2f31c4-64d7-4788-ac68-33c5cc8efccd")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguage("de")]

232
BosmonMqtt/Views/Config.Designer.cs generated Normal file
View File

@ -0,0 +1,232 @@
namespace BlubbFish.BosmonMqtt.Views {
partial class ConfigView {
/// <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.label1 = new System.Windows.Forms.Label();
this.textServer = new System.Windows.Forms.TextBox();
this.textUser = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.textPass = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.textPort = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.labelStatus = new System.Windows.Forms.Label();
this.testButton = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.textTopic = new System.Windows.Forms.TextBox();
this.filterButton = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(6, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(55, 20);
this.label1.TabIndex = 0;
this.label1.Text = "Server:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// textServer
//
this.textServer.Location = new System.Drawing.Point(67, 16);
this.textServer.Name = "textServer";
this.textServer.Size = new System.Drawing.Size(317, 20);
this.textServer.TabIndex = 1;
this.textServer.Tag = "server";
this.textServer.Leave += new System.EventHandler(this.Settings_Changed);
//
// textUser
//
this.textUser.Location = new System.Drawing.Point(67, 68);
this.textUser.Name = "textUser";
this.textUser.Size = new System.Drawing.Size(317, 20);
this.textUser.TabIndex = 4;
this.textUser.Tag = "user";
this.textUser.Leave += new System.EventHandler(this.Settings_Changed);
//
// label3
//
this.label3.Location = new System.Drawing.Point(6, 67);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(55, 20);
this.label3.TabIndex = 3;
this.label3.Text = "Benutzer:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// textPass
//
this.textPass.Location = new System.Drawing.Point(67, 94);
this.textPass.Name = "textPass";
this.textPass.Size = new System.Drawing.Size(317, 20);
this.textPass.TabIndex = 6;
this.textPass.Tag = "pass";
this.textPass.UseSystemPasswordChar = true;
this.textPass.Leave += new System.EventHandler(this.Settings_Changed);
//
// label4
//
this.label4.Location = new System.Drawing.Point(6, 94);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(55, 20);
this.label4.TabIndex = 5;
this.label4.Text = "Passwort:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// groupBox1
//
this.groupBox1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.groupBox1.Controls.Add(this.textPort);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label7);
this.groupBox1.Controls.Add(this.labelStatus);
this.groupBox1.Controls.Add(this.testButton);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.textTopic);
this.groupBox1.Controls.Add(this.filterButton);
this.groupBox1.Controls.Add(this.textServer);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.textPass);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.textUser);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Location = new System.Drawing.Point(3, 3);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(390, 250);
this.groupBox1.TabIndex = 7;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Einstellungen";
//
// textPort
//
this.textPort.Location = new System.Drawing.Point(67, 42);
this.textPort.MaxLength = 5;
this.textPort.Name = "textPort";
this.textPort.Size = new System.Drawing.Size(317, 20);
this.textPort.TabIndex = 15;
this.textPort.Tag = "port";
this.textPort.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Check_Numbers);
this.textPort.Leave += new System.EventHandler(this.Settings_Changed);
//
// label2
//
this.label2.Location = new System.Drawing.Point(6, 42);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(55, 20);
this.label2.TabIndex = 14;
this.label2.Text = "Port:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label7
//
this.label7.Location = new System.Drawing.Point(141, 151);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(243, 29);
this.label7.TabIndex = 13;
this.label7.Text = "Wurden Filter eingetragen, so werden nur Telegramme gesendet, die explizit erlaub" +
"t sind.";
//
// labelStatus
//
this.labelStatus.AutoSize = true;
this.labelStatus.Location = new System.Drawing.Point(67, 227);
this.labelStatus.Name = "labelStatus";
this.labelStatus.Size = new System.Drawing.Size(131, 13);
this.labelStatus.TabIndex = 12;
this.labelStatus.Text = "Verbindung nicht getestet.";
//
// testButton
//
this.testButton.Location = new System.Drawing.Point(67, 197);
this.testButton.Name = "testButton";
this.testButton.Size = new System.Drawing.Size(200, 23);
this.testButton.TabIndex = 11;
this.testButton.Text = "Einstellungen Testen";
this.testButton.UseVisualStyleBackColor = true;
this.testButton.Click += new System.EventHandler(this.Setting_Test);
//
// label5
//
this.label5.Location = new System.Drawing.Point(6, 120);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(55, 20);
this.label5.TabIndex = 9;
this.label5.Text = "Topic:";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// textTopic
//
this.textTopic.Location = new System.Drawing.Point(67, 120);
this.textTopic.Name = "textTopic";
this.textTopic.Size = new System.Drawing.Size(317, 20);
this.textTopic.TabIndex = 10;
this.textTopic.Tag = "topic";
this.textTopic.Leave += new System.EventHandler(this.Settings_Changed);
//
// filterButton
//
this.filterButton.Location = new System.Drawing.Point(9, 153);
this.filterButton.Name = "filterButton";
this.filterButton.Size = new System.Drawing.Size(125, 23);
this.filterButton.TabIndex = 8;
this.filterButton.Text = "Filter...";
this.filterButton.UseVisualStyleBackColor = true;
this.filterButton.Click += new System.EventHandler(this.Filter_Click);
//
// ConfigView
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.Controls.Add(this.groupBox1);
this.Name = "ConfigView";
this.Size = new System.Drawing.Size(396, 256);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textServer;
private System.Windows.Forms.TextBox textUser;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textPass;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button filterButton;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textTopic;
private System.Windows.Forms.Label labelStatus;
private System.Windows.Forms.Button testButton;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox textPort;
private System.Windows.Forms.Label label2;
}
}

117
BosmonMqtt/Views/Config.cs Normal file
View File

@ -0,0 +1,117 @@
using System;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using BosMon.Prefs;
using BosMon.Utils;
using TelegramFilter.Filter;
using TelegramFilter.Gui;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace BlubbFish.BosmonMqtt.Views {
internal partial class ConfigView : UserControl {
private PluginConfiguration pluginconfig;
private EditFilterListDlg filter;
internal ConfigView(PluginConfiguration pluginconfiguration) {
InitializeComponent();
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) {
this.filter.ShowDialog();
}
private void Settings_Changed(Object sender, EventArgs e) {
TextBox t = (TextBox)sender;
switch (t.Tag) {
case "server":
this.pluginconfig.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;
case "port":
if (Int32.TryParse(t.Text, out Int32 port)) {
this.pluginconfig.Port = port;
}
break;
}
}
private void Check_Numbers(Object sender, KeyPressEventArgs e) {
e.Handled = !Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar);
}
private void Setting_Test(Object sender, EventArgs e) {
try {
this.labelStatus.BeginInvoke((Action)(() => {
this.labelStatus.Text = "Baue Verbindung auf.";
this.labelStatus.ForeColor = Color.DarkOrange;
}));
MqttClient client = new MqttClient(this.pluginconfig.Server, this.pluginconfig.Port, false, null);
if (this.pluginconfig.User == "" || this.pluginconfig.Password == "") {
client.Connect("bosmon-" + Guid.NewGuid().ToString());
} else {
client.Connect("bosmon-" + Guid.NewGuid().ToString(), this.pluginconfig.User, this.pluginconfig.Password);
}
this.labelStatus.BeginInvoke((Action)(() => {
this.labelStatus.Text = "Subscribe Topic.";
this.labelStatus.ForeColor = Color.DarkOrange;
}));
client.Subscribe(new String[] { this.pluginconfig.Topic }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
this.labelStatus.BeginInvoke((Action)(() => {
this.labelStatus.Text = "Schicke Testnachricht.";
this.labelStatus.ForeColor = Color.DarkOrange;
}));
client.MqttMsgPublishReceived += this.Client_MqttMsgPublishReceived;
client.Publish(this.pluginconfig.Topic, Encoding.UTF8.GetBytes("BosMon Connection Test"));
this.labelStatus.BeginInvoke((Action)(() => {
this.labelStatus.Text = "Warte auf Testnachricht.";
this.labelStatus.ForeColor = Color.DarkOrange;
}));
for(Int32 i=0;i<=20;i++) {
Thread.Sleep(100);
if (this._testMessageRecieved) {
break;
}
}
if(!this._testMessageRecieved) {
throw new Exception();
}
this.labelStatus.BeginInvoke((Action)(() => {
this.labelStatus.Text = "Verbindung erfolgreich!";
this.labelStatus.ForeColor = Color.DarkGreen;
}));
} catch(Exception) {
this.labelStatus.BeginInvoke((Action)(() => {
this.labelStatus.Text += " Fehler!";
this.labelStatus.ForeColor = Color.Red;
}));
}
}
private Boolean _testMessageRecieved = false;
private void Client_MqttMsgPublishReceived(Object sender, MqttMsgPublishEventArgs e) {
if(Encoding.UTF8.GetString(e.Message) == "BosMon Connection Test") {
this._testMessageRecieved = true;
}
}
}
}

View 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>

Binary file not shown.

Binary file not shown.