public static HotspotEventsRec JsonToHotspotEventsRec(string txt) { try { var retval = new HotspotEventsRec(); var jHotspotEvents = JObject.Parse(txt); foreach (var jRec in jHotspotEvents["area_events"]) { var rec = new HotspotEvent(); rec.Hotspot = IntToId((int)jRec["area"]["id"]); rec.Object = IntToId((int)jRec["object"]["id"]); rec.Time = DoubleToTime((double)jRec["time"]); rec.Type = IntToType((int)jRec["type"]); retval.HotspotEvents.Add(rec); } return(retval); } catch (Exception ex) { var newEx = new Exception("Invalid JSON data format returned for 'State'.", ex); throw newEx; } }
public static EventsRec JsonToEventsRec(string txt) { try { var retval = new EventsRec(); var jHotspotEvents = JObject.Parse(txt); // Parse out HOTSPOT Events foreach (var jRec in jHotspotEvents["area_events"]) { var rec = new HotspotEvent(); rec.Hotspot = IntToId((int)jRec["area"]["id"]); rec.Object = IntToId((int)jRec["object"]["id"]); rec.Time = DoubleToTime((double)jRec["time"]); rec.Type = IntToType((int)jRec["type"]); retval.HotspotEvents.Add(rec); } // Parse out BORDER Events foreach (var jRec in jHotspotEvents["line_events"]) { var rec = new BorderEvent(); rec.Border = IntToId((int)jRec["line"]["id"]); rec.Direction = IntToDirection((int)jRec["direction"]); rec.Object = IntToId((int)jRec["object"]["id"]); rec.Time = DoubleToTime((double)jRec["time"]); retval.BorderEvents.Add(rec); } return(retval); } catch (Exception ex) { var newEx = new Exception("Invalid JSON data format returned for 'State'.", ex); throw newEx; } }