[NF] Sortiere JSON Ausgabe und Formatiere sie schön
This commit is contained in:
parent
66a517b935
commit
a0efb63b99
@ -7,19 +7,19 @@ using LitJson;
|
||||
namespace Mqtt_SWB_Dashboard.Helper {
|
||||
class Household {
|
||||
|
||||
public Dictionary<String, Device> Devices { get; private set; }
|
||||
public SortedDictionary<String, Device> 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<String, Device> {
|
||||
this.Devices = new SortedDictionary<String, Device> {
|
||||
{ did, device }
|
||||
};
|
||||
}
|
||||
|
||||
public Household(JsonData data) {
|
||||
this.Devices = new Dictionary<String, Device>();
|
||||
this.Devices = new SortedDictionary<String, Device>();
|
||||
if (data.Keys.Contains("Devices")) {
|
||||
foreach (KeyValuePair<String, JsonData> item in data["Devices"]) {
|
||||
this.Devices.Add(item.Key, new Device(item.Value));
|
||||
|
@ -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) {
|
||||
|
@ -8,8 +8,8 @@ using Mqtt_SWB_Dashboard.Helper;
|
||||
|
||||
namespace Mqtt_SWB_Dashboard {
|
||||
internal class Stats : IDisposable {
|
||||
private Dictionary<String, Household> households = new Dictionary<String, Household>();
|
||||
private Dictionary<String, Raspi> raspis = new Dictionary<String, Raspi>();
|
||||
private SortedDictionary<String, Household> households = new SortedDictionary<String, Household>();
|
||||
private SortedDictionary<String, Raspi> raspis = new SortedDictionary<String, Raspi>();
|
||||
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;
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user