Beispiel #1
0
        public bool read(Device dev)
        {
            if (dev == null)
            {
                return(false);
            }
            var result = false;

            try
            {
                HttpResponseMessage response = GetResponse(dev);
                if (response == null)
                {
                    return(result);
                }
                result = response.IsSuccessStatusCode;
                if (result)
                {
                    var content = response.Content.ReadAsStringAsync();
                    content.Wait();
                    result = Interfaces.UpdateDevice(dev, content.Result, silence_io: false, update_id: false);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Server Input Error: " + e.Message);
            }

            return(result);
        }
Beispiel #2
0
        /**
         * Given relevant information string, attempts to create a device capable of communicating with a device through the server.
         * \param[in] info JSON string representing the device, which came from the server
         * \param[in] frame TimeFrame for timestamping data for this device
         */
        public Device CreateDevice(string info, TimeFrame frame)
        {
            var inp  = new ServerInput(_server.ToString());
            var outp = new ServerOutput(_server.ToString());

            return(Interfaces.DeserializeDevice(info, inp, outp, frame));
        }
Beispiel #3
0
        /**
         * Given relevant configuration strings, attempts to create a device capable of communicating with the device inside
         * the house.
         * \param[in] info JSON string representing the device configuration.
         * \param[in] house_json JSON string representing the house configuration.
         * \param[in] frame TimeFrame for the Device to use for time stamping
         * \param[out] Instance of Device representing the requested device, or null if the inputs are invalid.
         */
        public static Device CreateDevice(FullID id, string house_json, string device_json, TimeFrame frame)
        {
            var inp    = new HouseInput(house_json, device_json);
            var outp   = new HouseOutput(house_json, device_json);
            var device = Interfaces.DeserializeDevice(device_json, inp, outp, frame);

            if (device != null)
            {
                device.ID = id;
            }
            return(device);
        }
Beispiel #4
0
        protected bool read_driver(Device dev)
        {
            var response = false;

            try {
                UInt64 devID = 0;
                try
                {
                    var dev_info = JObject.Parse(_deviceInfo);
                    devID = dev_info.GetValue("ID").ToObject <UInt64>();
                }
                catch (JsonException ex)
                {
                    return(false);
                }

                var query = _Http_Client.GetAsync(String.Format("api/device/{0}", devID));

                query.Wait();

                response = query.Result.IsSuccessStatusCode;
                if (response)
                {
                    var data = query.Result.Content.ReadAsStringAsync();
                    data.Wait();
                    Interfaces.UpdateDevice(dev, data.Result, silence_io: true);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("HouseInput failed: " + ex.Message);
                response = false;
            }

            return(response);
        }