示例#1
0
        public void VerifyDeviceBuilders()
        {
            const string valid_string = "{class: \"LightSwitch\", enabled: true, Brightness: 1.0}";
            var          intf         = new Interfaces("http://localhost");

            var dev = intf.CreateDevice(valid_string, null);

            Assert.IsNotNull(dev);
            Assert.AreEqual(dev.Input.GetType(), typeof(ServerInput));
            Assert.AreEqual(dev.Output.GetType(), typeof(ServerOutput));

            dev.resetIO();
            Assert.AreEqual(dev.Input.GetType(), typeof(NullDeviceInput));
            Assert.AreEqual(dev.Output.GetType(), typeof(NullDeviceOutput));
        }
示例#2
0
        // add any other JArrays containing blobs here

        ////////////////////////////////////////////////////////////////////////////////////////
        //
        // deviceBlobs methods

        /*************** DEBUG MODE METHOD *************/

        static public bool AddDeviceBlob_DEBUG(JObject blob)
        {
            Uri        storageURL  = new Uri(DeviceRepository.storageURL);
            Interfaces check       = new Interfaces(storageURL);
            string     blob_string = blob.ToString();
            Device     dev         = check.CreateDevice(blob_string, new TimeFrame());
            ulong      devID       = (ulong)blob["deviceID"];
            ulong      roomID      = (ulong)blob["roomID"];
            ulong      houseID     = (ulong)blob["houseID"];

            FullID fullID = new FullID();

            fullID.DeviceID = devID;
            fullID.RoomID   = roomID;
            fullID.HouseID  = houseID;

            deviceBlobs.Add(fullID, dev);
            //if (deviceBlobs.Contains(fullID, dev))
            //{
            //    return true;
            //}

            return(true);
        }
示例#3
0
        /*************** END DEBUG MODE METHOD *************/

        static public bool AddDeviceBlob(JObject blob)
        {
            Uri        storageURL  = new Uri(DeviceRepository.storageURL);
            Interfaces check       = new Interfaces(storageURL);
            string     blob_string = blob.ToString();
            Device     dev         = check.CreateDevice(blob_string, new TimeFrame());
            ulong      devID       = (ulong)blob["deviceID"];
            ulong      roomID      = (ulong)blob["roomID"];
            ulong      houseID     = (ulong)blob["houseID"];

            FullID fullID = new FullID();

            fullID.DeviceID = devID;
            fullID.RoomID   = roomID;
            fullID.HouseID  = houseID;

            bool notify = false;

            deviceBlobs.Add(fullID, dev);
            //if (deviceBlobs.Contains(fullID, dev))
            //{
            //    notify = true;
            //}

            if (!notify)
            {
                return(true);
            }

            WebRequest request = WebRequest.Create(DeviceRepository.decisionURL + "BH/" + houseID);

            request.Method = "GET";
            string userid = "";

            try
            {
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    var     stream  = response.GetResponseStream();
                    var     reader  = new StreamReader(stream);
                    string  str     = reader.ReadToEnd();
                    JObject jobject = JObject.Parse(str);
                    userid = (string)jobject["userID"];
                }
            }

            catch (WebException we)
            {
                return(true);
            }

            request        = WebRequest.Create(DeviceRepository.decisionURL + "BU/" + userid);
            request.Method = "GET";
            string endpoint = "";

            try
            {
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    var     stream  = response.GetResponseStream();
                    var     reader  = new StreamReader(stream);
                    string  str     = reader.ReadToEnd();
                    JObject jobject = JObject.Parse(str);
                    endpoint = (string)jobject["endPointArn"];

                    // of the array is one line of the file.
                    //string[] lines = System.IO.File.ReadAllLines(@"C:\keys.txt");
                    string accK = "";
                    string secK = "";
                    NotificationManager notificationManager = new NotificationManager(accK, secK, Amazon.RegionEndpoint.USEast1);
                    notificationManager.init();
                    notificationManager.PublishNotification(endpoint, "Device Updated");
                }
            }

            catch (WebException we)
            {
                return(true);
            }


            return(true);
        }