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(); } }
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(); } }
public void UpdateLight(LightModel model) { var item = rows.FirstOrDefault(r => r == model); if (item != null) { item = model; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { payload = e.Parameter as Payload; lightModel = payload.lm; lightViewModel = payload.lvm; this.DataContext = lightModel; }
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); }
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); } }
public void AddLight(LightModel model) { rows.Add(model); }