ProjectsOld/Mqtt-SWB-Dashboard/Mqtt-SWB-Dashboard/MainWindow.xaml.cs
2017-12-18 23:30:48 +01:00

61 lines
2.5 KiB
C#

using System;
using System.Globalization;
using System.Windows;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Connector;
namespace Mqtt_SWB_Dashboard {
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
private Stats s;
public MainWindow() {
InitializeComponent();
CultureInfo info = new CultureInfo("de-DE");
info.NumberFormat.NumberDecimalSeparator = ".";
CultureInfo.DefaultThreadCurrentCulture = info;
CultureInfo.DefaultThreadCurrentUICulture = info;
System.Threading.Thread.CurrentThread.CurrentCulture = info;
System.Threading.Thread.CurrentThread.CurrentUICulture = info;
LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(System.Windows.Markup.XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
try {
String broker = InIReader.GetInstance("settings.ini").GetValue("mqtt", "server");
this.Dispatcher.BeginInvoke((Action)(() => {
this.connectedTo.Text = "Connected to: " + broker;
}));
this.s = new Stats(ADataBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("mqtt")));
this.s.UpdatedConsumption += this.S_UpdatedConsumption;
this.S_UpdatedConsumption(this.s, null);
} catch(Exception e) {
MessageBox.Show(e.Message+"\n"+e.StackTrace, "Some Shit goes fucking wrong!");
Application.Current.Shutdown(1);
}
}
private void S_UpdatedConsumption(Stats sender, EventArgs e) {
this.Dispatcher.BeginInvoke((Action)(() => {
this.countRaspis.Text = sender.GetNumberRaspis();
this.maxRaspi.Text = sender.GetMostRaspiUptime();
this.avgUptime.Text = sender.GetAvgRaspiUptime();
this.countColum.Text = sender.GetCurrentColum();
Tuple<Int32, Int32> devices = sender.GetNumberDevices();
this.countDevices.Text = devices.Item1 + " / " + devices.Item2;
Tuple<Int32, Int32, Int32> houses = sender.GetNumberHouseholds();
this.countHouses.Text = houses.Item1 + " / " + houses.Item2 + " / " + houses.Item3;
Tuple<Double, Double> power = sender.GetCurrentPower();
this.countPower.Text = power.Item1 + "W / " + power.Item2 + "W";
((Models.PowerChartModel)this.DataContext).AddPower(power, houses, devices);
}));
}
private void OnClosed(Object sender, EventArgs e) {
if (this.s != null) {
this.s.Dispose();
}
}
}
}