示例#1
0
        public async Task putLightState(LightModel lm)
        {
            try
            {
                //var jsonString = "{\"on\":"+ lm.on + "}";
                var jsn = JsonConvert.SerializeObject(lm);

                var httpContent = new StringContent(jsn, Encoding.UTF8, "application/json");

                var client   = new HttpClient();
                var response = await client.PutAsync(baseUrl + lm.key + "/state", httpContent);

                if (!response.IsSuccessStatusCode)
                {
                    await new MessageDialog("Failed request").ShowAsync();
                    return;
                }

                string json = await response.Content.ReadAsStringAsync();
            }
            catch (OperationCanceledException)
            {
                await new MessageDialog("Operation time out").ShowAsync();
            }
        }
示例#2
0
        public async Task putLightState(LightModel lm)
        {
            try
            {
                //var jsonString = "{\"on\":"+ lm.on + "}";
                var jsn = JsonConvert.SerializeObject(lm);

                var httpContent = new StringContent(jsn, Encoding.UTF8, "application/json");

                var client = new HttpClient();
                var response = await client.PutAsync(baseUrl+lm.key+"/state", httpContent);

                if (!response.IsSuccessStatusCode)
                {
                    await new MessageDialog("Failed request").ShowAsync();
                    return;
                }

                string json = await response.Content.ReadAsStringAsync();

            }
            catch (OperationCanceledException)
            {
                await new MessageDialog("Operation time out").ShowAsync();
            }
        }
示例#3
0
 public void UpdateLight(LightModel model)
 {
     var item = rows.FirstOrDefault(r => r == model);
     if (item != null)
     {
         item = model;
     }
 }
示例#4
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            payload = e.Parameter as Payload;
            lightModel = payload.lm;
            lightViewModel = payload.lvm;

            this.DataContext = lightModel;
        }
示例#5
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            payload        = e.Parameter as Payload;
            lightModel     = payload.lm;
            lightViewModel = payload.lvm;

            this.DataContext = lightModel;
        }
示例#6
0
        public void UpdateLight(LightModel model)
        {
            var item = rows.FirstOrDefault(r => r == model);

            if (item != null)
            {
                item = model;
            }
        }
示例#7
0
        private void listView_ItemClick(object sender, ItemClickEventArgs e)
        {
            LightModel selectedLight = (LightModel)e.ClickedItem;

            Payload payload = new Payload();

            payload.lvm = lightsList;
            payload.lm  = selectedLight;

            Frame.Navigate(typeof(LightDetailPage), payload);
        }
示例#8
0
        public void parseJson(string jsonString)
        {
            JObject jsonObject = JObject.Parse(jsonString);

            //LightViewModel lightVM = new LightViewModel();

            foreach (var light in jsonObject)
            {
                LightModel lightModel = new LightModel();
                lightModel.key  = int.Parse(light.Key);
                lightModel.name = (string)light.Value["name"];
                lightModel.on   = (bool)light.Value["state"]["on"];
                lightModel.bri  = (int)light.Value["state"]["bri"];

                if (light.Value["state"]["sat"] != null)
                {
                    lightModel.sat = (int)light.Value["state"]["sat"];
                    lightModel.hue = (int)light.Value["state"]["hue"];
                }


                lvm.AddLight(lightModel);
            }
        }
示例#9
0
        public void parseJson(string jsonString)
        {

            JObject jsonObject = JObject.Parse(jsonString);
            //LightViewModel lightVM = new LightViewModel();

            foreach (var light in jsonObject)
            {
                LightModel lightModel = new LightModel();
                lightModel.key = int.Parse(light.Key);
                lightModel.name = (string)light.Value["name"];
                lightModel.on = (bool)light.Value["state"]["on"];
                lightModel.bri = (int)light.Value["state"]["bri"];

                if (light.Value["state"]["sat"] != null)
                { 
                    lightModel.sat = (int)light.Value["state"]["sat"];
                    lightModel.hue = (int)light.Value["state"]["hue"];
                }


                lvm.AddLight(lightModel);
            }
        }
示例#10
0
 public void AddLight(LightModel model)
 {
     rows.Add(model);
 }
示例#11
0
 public void AddLight(LightModel model)
 {
     rows.Add(model);
 }