diff --git a/Mqtt-SWB-Dashboard/Helper/Household.cs b/Mqtt-SWB-Dashboard/Helper/Household.cs index a8454cd..3d4ed48 100644 --- a/Mqtt-SWB-Dashboard/Helper/Household.cs +++ b/Mqtt-SWB-Dashboard/Helper/Household.cs @@ -7,19 +7,19 @@ using LitJson; namespace Mqtt_SWB_Dashboard.Helper { class Household { - public Dictionary Devices { get; private set; } + public SortedDictionary Devices { get; private set; } public DateTime Active { get; private set; } public Boolean Connected { get; private set; } public Household(String did, Device device) { this.Active = DateTime.Now; - this.Devices = new Dictionary { + this.Devices = new SortedDictionary { { did, device } }; } public Household(JsonData data) { - this.Devices = new Dictionary(); + this.Devices = new SortedDictionary(); if (data.Keys.Contains("Devices")) { foreach (KeyValuePair item in data["Devices"]) { this.Devices.Add(item.Key, new Device(item.Value)); diff --git a/Mqtt-SWB-Dashboard/MainWindow.xaml.cs b/Mqtt-SWB-Dashboard/MainWindow.xaml.cs index 8ded6e8..bad72f7 100644 --- a/Mqtt-SWB-Dashboard/MainWindow.xaml.cs +++ b/Mqtt-SWB-Dashboard/MainWindow.xaml.cs @@ -20,13 +20,18 @@ namespace Mqtt_SWB_Dashboard { System.Threading.Thread.CurrentThread.CurrentUICulture = info; LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(System.Windows.Markup.XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))); - String broker = InIReader.GetInstance("settings.ini").GetValue("general", "broker"); - this.Dispatcher.BeginInvoke((Action)(() => { - this.connectedTo.Text = "Connected to: "+broker; - })); - this.s = new Stats(new Mosquitto(broker)); - this.s.UpdatedConsumption += this.S_UpdatedConsumption; - this.S_UpdatedConsumption(this.s, null); + try { + String broker = InIReader.GetInstance("settings.ini").GetValue("general", "broker"); + this.Dispatcher.BeginInvoke((Action)(() => { + this.connectedTo.Text = "Connected to: " + broker; + })); + this.s = new Stats(new Mosquitto(broker)); + 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) { diff --git a/Mqtt-SWB-Dashboard/Stats.cs b/Mqtt-SWB-Dashboard/Stats.cs index 1cba0fb..f86b8eb 100644 --- a/Mqtt-SWB-Dashboard/Stats.cs +++ b/Mqtt-SWB-Dashboard/Stats.cs @@ -8,8 +8,8 @@ using Mqtt_SWB_Dashboard.Helper; namespace Mqtt_SWB_Dashboard { internal class Stats : IDisposable { - private Dictionary households = new Dictionary(); - private Dictionary raspis = new Dictionary(); + private SortedDictionary households = new SortedDictionary(); + private SortedDictionary raspis = new SortedDictionary(); private Mosquitto mosquitto; public delegate void UpdateMessage(Stats sender, EventArgs e); @@ -290,10 +290,14 @@ namespace Mqtt_SWB_Dashboard { if (!this.disposedValue) { if (disposing) { this.mosquitto.MessageIncomming -= this.Mosquitto_MessageIncomming; - String households = JsonMapper.ToJson(this.households); - File.WriteAllText("household.json", households); - String raspis = JsonMapper.ToJson(this.raspis); - File.WriteAllText("raspi.json", raspis); + JsonWriter writer = new JsonWriter { + PrettyPrint = true + }; + JsonMapper.ToJson(this.households, writer); + File.WriteAllText("household.json", writer.ToString()); + writer.Reset(); + JsonMapper.ToJson(this.raspis, writer); + File.WriteAllText("raspi.json", writer.ToString()); this.mosquitto.Dispose(); } this.mosquitto = null; diff --git a/Mqtt-SWB-Dashboard/bin/Release/Mqtt-SWB-Dashboard.exe b/Mqtt-SWB-Dashboard/bin/Release/Mqtt-SWB-Dashboard.exe index df6f886..b775cc4 100644 Binary files a/Mqtt-SWB-Dashboard/bin/Release/Mqtt-SWB-Dashboard.exe and b/Mqtt-SWB-Dashboard/bin/Release/Mqtt-SWB-Dashboard.exe differ