public string GetItem(string name) { Client.DefaultRequestHeaders.Add("Accept", "application/json"); var uri = new Uri(string.Format("{0}://{1}:{2}/{3}", Settings.Protocol, Settings.Server, Settings.Port.ToString(), Common.Constants.Api.Items + name)); Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Debug("Kala", "GetItem() - URI: " + uri.ToString())); try { var response = Client.GetAsync(uri).Result; if (!response.IsSuccessStatusCode) { return(null); } string resultString = response.Content.ReadAsStringAsync().Result; Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Debug("Kala", @"Content Response: '" + resultString.ToString() + "'")); Models.Item updatedItem = JsonConvert.DeserializeObject <Models.Item>(resultString); if (updatedItem.TransformedState != null) { return(updatedItem.TransformedState.ToString()); } else if (updatedItem.State != null) { return(updatedItem.State.ToString()); } } catch (Exception ex) { Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Error("Kala", "GetItem() - Failed: " + ex.ToString())); } return(null); }
//Update stored list public static void Calendar_Update(Models.Item item) { CrossLogger.Current.Debug("Calendar", "Update" + item.ToString()); //Loop and update with new data foreach (Models.calItems itemCal in itemCalendar) { if (itemCal.Link.Equals(item.link)) { itemCal.State = item.state; } } lock (itemCalendar) { Create_Calendar(); } }