async private void GetDataFromWeb() { progressbar.Text = "Fetching new data"; progressbar.ShowAsync(); var client = new HttpClient(); Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; if (!localSettings.Containers.ContainsKey("userInfo")) { MessageDialog msgbox = new MessageDialog("Please log-in first. Go to settings from the main menu."); await msgbox.ShowAsync(); return; } var lastcheck = localSettings.Containers["userInfo"].Values["lastcheckexamples"].ToString(); Debug.WriteLine(System.Uri.EscapeUriString(lastcheck)); var response = await client.GetAsync(new Uri("http://codeinn-acecoders.rhcloud.com:8000/query/data?Timestamp=" + System.Uri.EscapeUriString(lastcheck) + "&Table=Examples")); var result = await response.Content.ReadAsStringAsync(); result = result.Trim(new Char[] { '"' }); Debug.WriteLine(result); DatabaseExample Db_Helper = new DatabaseExample(); try { List<Examples> newex = JsonConvert.DeserializeObject<List<Examples>>(result); foreach (Examples ex in newex) { try { Db_Helper.InsertExample(ex); } catch { Debug.WriteLine("DB error for item of id: " + ex.Id); } } localSettings.Containers["userInfo"].Values["lastcheckexamples"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); progressbar.Text = "New items"; } catch { Debug.WriteLine("No new items"); progressbar.Text = "No New items"; } finally { ReadExamples dbproblems = new ReadExamples(); DB_ExampleList = dbproblems.GetAllExamples(); listBox.ItemsSource = DB_ExampleList.OrderByDescending(i => i.Id).ToList(); } progressbar.HideAsync(); }
private void ReadExamples_Loaded(object sender, RoutedEventArgs e) { ReadExamples dbproblems = new ReadExamples(); DB_ExampleList = dbproblems.GetAllExamples(); listBox.ItemsSource = DB_ExampleList.OrderBy(i => i.Id).ToList(); }