From 59d1f15bc23901ea64f81c664b4b4a5484ceffec Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Thu, 31 Aug 2017 14:24:21 +0000 Subject: [PATCH] [BF] Typo [NF] Nun mit Beispieldateien [NF] Benutzen einer Fabrik --- Mqtt-Dashboard/Dashboard.csproj | 15 ++++++-------- Mqtt-Dashboard/Form1.cs | 20 ++----------------- Mqtt-Dashboard/Sensor/ASensor.cs | 12 +++++++++++ Mqtt-Dashboard/Sensor/Luminanz.cs | 20 +++++++++++++++++++ Mqtt-Dashboard/Sensor/Pir.cs | 16 +++++++++++++++ Mqtt-Dashboard/Sensor/Temperatur.cs | 20 +++++++++++++++++++ Mqtt-Dashboard/Tracings/ATracings.cs | 10 ++++++++++ Mqtt-Dashboard/Tracings/PowerMeter.cs | 4 ++-- Mqtt-Dashboard/Tracings/Switcher.cs | 3 +-- .../{sensor.ini => sensor.ini.example} | 0 .../{settings.ini => settings.ini.example} | 0 .../{tracings.ini => tracings.ini.example} | 0 12 files changed, 89 insertions(+), 31 deletions(-) create mode 100644 Mqtt-Dashboard/Sensor/Luminanz.cs create mode 100644 Mqtt-Dashboard/Sensor/Pir.cs create mode 100644 Mqtt-Dashboard/Sensor/Temperatur.cs rename Mqtt-Dashboard/{sensor.ini => sensor.ini.example} (100%) rename Mqtt-Dashboard/{settings.ini => settings.ini.example} (100%) rename Mqtt-Dashboard/{tracings.ini => tracings.ini.example} (100%) diff --git a/Mqtt-Dashboard/Dashboard.csproj b/Mqtt-Dashboard/Dashboard.csproj index 94b8c73..7a8bf7a 100644 --- a/Mqtt-Dashboard/Dashboard.csproj +++ b/Mqtt-Dashboard/Dashboard.csproj @@ -59,8 +59,11 @@ + + + @@ -89,15 +92,9 @@ Settings.settings True - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - + + + diff --git a/Mqtt-Dashboard/Form1.cs b/Mqtt-Dashboard/Form1.cs index 7df74d4..d6e23b7 100644 --- a/Mqtt-Dashboard/Form1.cs +++ b/Mqtt-Dashboard/Form1.cs @@ -7,7 +7,6 @@ using Dashboard.Tracings; using BlubbFish.Utils; using System.Collections.Generic; using System.Threading; -using Dashboard.tracings; namespace Dashboard { public partial class Dashboard : Form { @@ -32,35 +31,20 @@ namespace Dashboard { private void Dashboard_SizeChanged(Object sender, EventArgs e) { this.flowLayoutPanel2.Size = new System.Drawing.Size(this.Size.Width - 40, this.Size.Width - 76); - //this.Size.Height } private void GenerateSensors() { InIReader ini = InIReader.GetInstance("sensor.ini"); List sensorini = ini.GetSections(); foreach(String sensor in sensorini) { - ASensor s; - switch(ini.GetValue(sensor, "type").ToLower()) { - case "power": s = new Power(ini.GetSection(sensor)); break; - case "switch": s = new Switch(ini.GetSection(sensor)); break; - default: throw new ArgumentException("sensor.ini: " + sensor + " section has a missconfiguration in type"); - } - this.sensors.Add(sensor.ToLower().Substring(1, sensor.Length - 2), s); + this.sensors.Add(sensor.ToLower().Substring(1, sensor.Length - 2), ASensor.GetInstance(ini.GetValue(sensor, "type").ToLower(), ini.GetSection(sensor))); } } private void GenerateForms() { InIReader ini = InIReader.GetInstance("tracings.ini"); List tracingini = ini.GetSections(); foreach(String tracing in tracingini) { - ATracings t; - switch(ini.GetValue(tracing, "type").ToLower()) { - case "graph": t = new Graph(this.sensors[ini.GetValue(tracing, "sensor").ToLower()],ini.GetSection(tracing)); break; - case "meter": t = new Meter(this.sensors[ini.GetValue(tracing, "sensor").ToLower()], ini.GetSection(tracing)); break; - case "powermeter": t = new PowerMeter(this.sensors[ini.GetValue(tracing, "sensor").ToLower()], ini.GetSection(tracing)); break; - case "switcher": t = new Switcher(this.sensors[ini.GetValue(tracing, "sensor").ToLower()], ini.GetSection(tracing)); break; - default: throw new ArgumentException("tracings.ini: " + tracing + " section has a missconfiguration in type"); - } - this.flowLayoutPanel2.Controls.Add(t.GetPanel()); + this.flowLayoutPanel2.Controls.Add(ATracings.GetInstance(ini.GetValue(tracing, "type").ToLower(), this.sensors[ini.GetValue(tracing, "sensor").ToLower()], ini.GetSection(tracing)).GetPanel()); } } private void SensorPolling() { diff --git a/Mqtt-Dashboard/Sensor/ASensor.cs b/Mqtt-Dashboard/Sensor/ASensor.cs index be70005..4cbe6ef 100644 --- a/Mqtt-Dashboard/Sensor/ASensor.cs +++ b/Mqtt-Dashboard/Sensor/ASensor.cs @@ -37,6 +37,18 @@ namespace Dashboard.Sensor { } protected abstract void UpdateValue(MqttMsgPublishEventArgs e); public Int32 GetInt { get; protected set; } + + internal static ASensor GetInstance(String v, Dictionary dictionary) { + string object_sensor = "Dashboard.Sensor." + char.ToUpper(v[0]) + v.Substring(1); + Type t = null; + try { + t = Type.GetType(object_sensor, true); + } catch(TypeLoadException) { + throw new ArgumentException("sensor.ini: " + v + " is not a Sensor"); + } + return (ASensor)t.GetConstructor(new Type[] { typeof(Dictionary) }).Invoke(new object[] { dictionary }); + } + public Single GetFloat { get; protected set; } public Boolean GetBool { get; protected set; } public Types Datatypes { get; protected set; } diff --git a/Mqtt-Dashboard/Sensor/Luminanz.cs b/Mqtt-Dashboard/Sensor/Luminanz.cs new file mode 100644 index 0000000..7e9d0a6 --- /dev/null +++ b/Mqtt-Dashboard/Sensor/Luminanz.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using uPLibrary.Networking.M2Mqtt.Messages; + +namespace Dashboard.Sensor { + class Luminanz : ASensor { + public Luminanz(Dictionary settings) : base(settings) { + this.GetBool = true; + this.GetFloat = 0.0f; + this.GetInt = 0; + this.Datatypes = Types.Int; + } + + protected override void UpdateValue(MqttMsgPublishEventArgs e) { + this.GetInt = Int32.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US")); + } + } +} diff --git a/Mqtt-Dashboard/Sensor/Pir.cs b/Mqtt-Dashboard/Sensor/Pir.cs new file mode 100644 index 0000000..f6804c6 --- /dev/null +++ b/Mqtt-Dashboard/Sensor/Pir.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using uPLibrary.Networking.M2Mqtt.Messages; + +namespace Dashboard.Sensor { + class Pir : ASensor { + public Pir(Dictionary settings) : base(settings) { + this.Datatypes = Types.Bool; + } + + protected override void UpdateValue(MqttMsgPublishEventArgs e) { + this.GetBool = (Encoding.UTF8.GetString(e.Message).ToLower() == "on") ? true : false; + } + } +} \ No newline at end of file diff --git a/Mqtt-Dashboard/Sensor/Temperatur.cs b/Mqtt-Dashboard/Sensor/Temperatur.cs new file mode 100644 index 0000000..b86a283 --- /dev/null +++ b/Mqtt-Dashboard/Sensor/Temperatur.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using uPLibrary.Networking.M2Mqtt.Messages; + +namespace Dashboard.Sensor { + class Temperatur : ASensor { + public Temperatur(Dictionary settings) : base(settings) { + this.GetBool = true; + this.GetFloat = 0.0f; + this.GetInt = 0; + this.Datatypes = Types.Float; + } + + protected override void UpdateValue(MqttMsgPublishEventArgs e) { + this.GetFloat = Single.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US")); + } + } +} \ No newline at end of file diff --git a/Mqtt-Dashboard/Tracings/ATracings.cs b/Mqtt-Dashboard/Tracings/ATracings.cs index cbd2283..00cff63 100644 --- a/Mqtt-Dashboard/Tracings/ATracings.cs +++ b/Mqtt-Dashboard/Tracings/ATracings.cs @@ -15,5 +15,15 @@ namespace Dashboard.Tracings { } protected abstract void SensorUpdate(Object sender, EventArgs e); public abstract Panel GetPanel(); + internal static ATracings GetInstance(String v, ASensor aSensor, Dictionary dictionary) { + string object_sensor = "Dashboard.Tracings." + char.ToUpper(v[0]) + v.Substring(1); + Type t = null; + try { + t = Type.GetType(object_sensor, true); + } catch(TypeLoadException) { + throw new ArgumentException("tracings.ini: " + v + " is not a Tracing"); + } + return (ATracings)t.GetConstructor(new Type[] { typeof(ASensor), typeof(Dictionary) }).Invoke(new object[] { aSensor, dictionary }); + } } } \ No newline at end of file diff --git a/Mqtt-Dashboard/Tracings/PowerMeter.cs b/Mqtt-Dashboard/Tracings/PowerMeter.cs index 816d97b..6d1719e 100644 --- a/Mqtt-Dashboard/Tracings/PowerMeter.cs +++ b/Mqtt-Dashboard/Tracings/PowerMeter.cs @@ -8,8 +8,8 @@ using System.Windows.Forms; using Dashboard.Sensor; namespace Dashboard.Tracings { - class PowerMeter : Meter { - public PowerMeter(ASensor sensor, Dictionary settings) : base(sensor, settings) { + class Powermeter : Meter { + public Powermeter(ASensor sensor, Dictionary settings) : base(sensor, settings) { } protected override void SensorUpdate(Object sender, EventArgs e) { String value = ""; diff --git a/Mqtt-Dashboard/Tracings/Switcher.cs b/Mqtt-Dashboard/Tracings/Switcher.cs index 0fe31f1..9fca61f 100644 --- a/Mqtt-Dashboard/Tracings/Switcher.cs +++ b/Mqtt-Dashboard/Tracings/Switcher.cs @@ -4,9 +4,8 @@ using System.Globalization; using System.Windows.Forms; using Dashboard.Connector; using Dashboard.Sensor; -using Dashboard.Tracings; -namespace Dashboard.tracings { +namespace Dashboard.Tracings { class Switcher : ATracings { private Label label; private Button button1; diff --git a/Mqtt-Dashboard/sensor.ini b/Mqtt-Dashboard/sensor.ini.example similarity index 100% rename from Mqtt-Dashboard/sensor.ini rename to Mqtt-Dashboard/sensor.ini.example diff --git a/Mqtt-Dashboard/settings.ini b/Mqtt-Dashboard/settings.ini.example similarity index 100% rename from Mqtt-Dashboard/settings.ini rename to Mqtt-Dashboard/settings.ini.example diff --git a/Mqtt-Dashboard/tracings.ini b/Mqtt-Dashboard/tracings.ini.example similarity index 100% rename from Mqtt-Dashboard/tracings.ini rename to Mqtt-Dashboard/tracings.ini.example