Esempio n. 1
0
        public HttpStatusCode GetAllEvents(DateTime start, DateTime end, out EventsRec rec)
        {
            ValidateIsBound();

            var    client       = new MoveRestClient(_device, _port, _username, _password);
            string body         = null;
            var    responseCode = client.GetAllEvents(start, end, out body);
            string msg          = (body.Length > _DATA_PREVIEW_SIZE) ? body.Substring(0, _DATA_PREVIEW_SIZE) : body;

            Trace.TraceInformation("\nRaw JSON data:  {0}", msg);

            rec = JsonHelper.JsonToEventsRec(body);
            return(responseCode);
        }
Esempio n. 2
0
        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;
            }
        }