예제 #1
0
        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["lastchecktips"].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=Tips"));

            var result = await response.Content.ReadAsStringAsync();

            result = result.Trim(new Char[] { '"' });
            Debug.WriteLine(result);

            DatabaseTip Db_Helper = new DatabaseTip();
            try
            {
                List<Tips> newprobs = JsonConvert.DeserializeObject<List<Tips>>(result);
                foreach (Tips prob in newprobs)
                {
                    try
                    {
                        Db_Helper.InsertTip(prob);
                    }
                    catch
                    {
                        Debug.WriteLine("DB error for item of id: " + prob.Id);
                    }
                }
                localSettings.Containers["userInfo"].Values["lastchecktips"] = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");
                progressbar.Text = "New items";
            }
            catch
            {
                Debug.WriteLine("No new items");
                progressbar.Text = "No New items";
            }
            finally
            {
                ReadTips dbtips = new ReadTips();
                DB_TipList = dbtips.GetAllTips();
                listBox.ItemsSource = DB_TipList.OrderByDescending(i => i.Id).ToList();
            }
            progressbar.HideAsync();
        }
예제 #2
0
 private void ReadTips_Loaded(object sender, RoutedEventArgs e)
 {
     ReadTips dbtips = new ReadTips();
     DB_TipList = dbtips.GetAllTips();
     listBox.ItemsSource = DB_TipList.OrderByDescending(i => i.Id).ToList();
 }