73 lines
2.6 KiB
C#
73 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using BlubbFish.Utils;
|
|
using Dashboard.Tracings;
|
|
using BlubbFish.Utils.IoT.Sensor;
|
|
using BlubbFish.Utils.IoT.Connector;
|
|
|
|
namespace Dashboard {
|
|
public partial class Dashboard : Form {
|
|
private Dictionary<String, ASensor> sensors = new Dictionary<String, ASensor>();
|
|
private ADataBackend mqtt;
|
|
|
|
public Dashboard(Boolean debug) {
|
|
InitializeComponent();
|
|
this.mqtt = ADataBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("mqtt"));
|
|
|
|
this.GenerateSensors();
|
|
this.GenerateForms();
|
|
|
|
this.FormClosed += this.Dashboard_FormClosed;
|
|
this.SizeChanged += this.Dashboard_SizeChanged;
|
|
|
|
if (debug) {
|
|
this.mqtt.MessageIncomming += this.Instance_MessageIncomming;
|
|
this.mqtt.MessageSending += this.Instance_MessageSending;
|
|
}
|
|
}
|
|
|
|
private void Dashboard_SizeChanged(Object sender, EventArgs e) {
|
|
this.flowLayoutPanel2.Size = new System.Drawing.Size(this.Size.Width - 40, this.Size.Width - 76);
|
|
}
|
|
|
|
private void GenerateSensors() {
|
|
InIReader ini = InIReader.GetInstance("sensor.ini");
|
|
List<String> sensorini = ini.GetSections(false);
|
|
foreach(String sensor in sensorini) {
|
|
this.sensors.Add(sensor.ToLower(), ASensor.GetInstance(this.mqtt, ini.GetSection(sensor), sensor));
|
|
}
|
|
}
|
|
|
|
private void GenerateForms() {
|
|
InIReader ini = InIReader.GetInstance("tracings.ini");
|
|
List<String> tracingini = ini.GetSections();
|
|
foreach(String tracing in tracingini) {
|
|
this.flowLayoutPanel2.Controls.Add(ATracings.GetInstance(ini.GetValue(tracing, "type").ToLower(), this.sensors, ini.GetSection(tracing)).GetPanel());
|
|
}
|
|
}
|
|
|
|
private void Dashboard_FormClosed(Object sender, FormClosedEventArgs e) {
|
|
this.Dispose();
|
|
}
|
|
private new void Dispose() {
|
|
foreach (KeyValuePair<String, ASensor> item in this.sensors) {
|
|
item.Value.Dispose();
|
|
}
|
|
this.sensors.Clear();
|
|
this.mqtt.MessageIncomming -= this.Instance_MessageIncomming;
|
|
this.mqtt.MessageSending -= this.Instance_MessageSending;
|
|
this.mqtt.Dispose();
|
|
this.Dispose(true);
|
|
}
|
|
|
|
private void Instance_MessageIncomming(Object sender, MqttEventArgs e) {
|
|
Console.WriteLine("Received = " + e.Message + " on topic " + e.Topic+" at "+DateTime.Now.ToUniversalTime());
|
|
}
|
|
|
|
private void Instance_MessageSending(Object sender, MqttEventArgs e) {
|
|
Console.WriteLine("Sended = " + e.Message + " on topic " + e.Topic + " at " + DateTime.Now.ToUniversalTime());
|
|
}
|
|
}
|
|
}
|