[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 {
|
namespace Mqtt_SWB_Dashboard.Helper {
|
||||||
class Household {
|
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 DateTime Active { get; private set; }
|
||||||
public Boolean Connected { get; private set; }
|
public Boolean Connected { get; private set; }
|
||||||
|
|
||||||
public Household(String did, Device device) {
|
public Household(String did, Device device) {
|
||||||
this.Active = DateTime.Now;
|
this.Active = DateTime.Now;
|
||||||
this.Devices = new Dictionary<String, Device> {
|
this.Devices = new SortedDictionary<String, Device> {
|
||||||
{ did, device }
|
{ did, device }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Household(JsonData data) {
|
public Household(JsonData data) {
|
||||||
this.Devices = new Dictionary<String, Device>();
|
this.Devices = new SortedDictionary<String, Device>();
|
||||||
if (data.Keys.Contains("Devices")) {
|
if (data.Keys.Contains("Devices")) {
|
||||||
foreach (KeyValuePair<String, JsonData> item in data["Devices"]) {
|
foreach (KeyValuePair<String, JsonData> item in data["Devices"]) {
|
||||||
this.Devices.Add(item.Key, new Device(item.Value));
|
this.Devices.Add(item.Key, new Device(item.Value));
|
||||||
|
@ -20,13 +20,18 @@ namespace Mqtt_SWB_Dashboard {
|
|||||||
System.Threading.Thread.CurrentThread.CurrentUICulture = info;
|
System.Threading.Thread.CurrentThread.CurrentUICulture = info;
|
||||||
LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(System.Windows.Markup.XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
|
LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(System.Windows.Markup.XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
|
||||||
|
|
||||||
String broker = InIReader.GetInstance("settings.ini").GetValue("general", "broker");
|
try {
|
||||||
this.Dispatcher.BeginInvoke((Action)(() => {
|
String broker = InIReader.GetInstance("settings.ini").GetValue("general", "broker");
|
||||||
this.connectedTo.Text = "Connected to: "+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 = new Stats(new Mosquitto(broker));
|
||||||
this.S_UpdatedConsumption(this.s, null);
|
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) {
|
private void S_UpdatedConsumption(Stats sender, EventArgs e) {
|
||||||
|
@ -8,8 +8,8 @@ using Mqtt_SWB_Dashboard.Helper;
|
|||||||
|
|
||||||
namespace Mqtt_SWB_Dashboard {
|
namespace Mqtt_SWB_Dashboard {
|
||||||
internal class Stats : IDisposable {
|
internal class Stats : IDisposable {
|
||||||
private Dictionary<String, Household> households = new Dictionary<String, Household>();
|
private SortedDictionary<String, Household> households = new SortedDictionary<String, Household>();
|
||||||
private Dictionary<String, Raspi> raspis = new Dictionary<String, Raspi>();
|
private SortedDictionary<String, Raspi> raspis = new SortedDictionary<String, Raspi>();
|
||||||
private Mosquitto mosquitto;
|
private Mosquitto mosquitto;
|
||||||
|
|
||||||
public delegate void UpdateMessage(Stats sender, EventArgs e);
|
public delegate void UpdateMessage(Stats sender, EventArgs e);
|
||||||
@ -290,10 +290,14 @@ namespace Mqtt_SWB_Dashboard {
|
|||||||
if (!this.disposedValue) {
|
if (!this.disposedValue) {
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
this.mosquitto.MessageIncomming -= this.Mosquitto_MessageIncomming;
|
this.mosquitto.MessageIncomming -= this.Mosquitto_MessageIncomming;
|
||||||
String households = JsonMapper.ToJson(this.households);
|
JsonWriter writer = new JsonWriter {
|
||||||
File.WriteAllText("household.json", households);
|
PrettyPrint = true
|
||||||
String raspis = JsonMapper.ToJson(this.raspis);
|
};
|
||||||
File.WriteAllText("raspi.json", raspis);
|
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.Dispose();
|
||||||
}
|
}
|
||||||
this.mosquitto = null;
|
this.mosquitto = null;
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user