/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { bool dbExist = await CheckDbAsync("Tips.db3"); if (!dbExist) { await CreateDatabaseAsync(); } SQLiteAsyncConnection conn = new SQLiteAsyncConnection("Tips.db3"); var query = conn.Table<Tips>(); tips = await query.ToListAsync(); string title1res = tips[tips.Count - 1].title1; string title2res = tips[tips.Count - 1].title2; string title3res = tips[tips.Count - 1].title3; string desc1res = tips[tips.Count - 1].desc1; string desc2res = tips[tips.Count - 1].desc2; string desc3res = tips[tips.Count - 1].desc3; Tips l = new Tips { title1 = title1res, title2 = title2res, title3 = title3res, desc1 = desc1res, desc2 = desc2res, desc3 = desc3res }; t.Add(l); TipsList.ItemsSource = t; }
public async void Parse3() { Uri uri = new Uri("https://api.parse.com/1/classes/Tips"); Debug.WriteLine(uri); HttpClient cl = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri); request.Headers.Add("X-Parse-Application-Id", "7EjTEqzbb1zfFWz6BJArdZVKkPag6qUuKTCE7rz3"); request.Headers.Add("X-Parse-REST-API-Key", "L3IEKFEazzTxzWVZim6oSVwCTvMPWwiI7IyQYnz3"); HttpResponseMessage response = await cl.SendAsync(request); var data = await response.Content.ReadAsStringAsync(); var parsedObject = JsonConvert.DeserializeObject<JObject>(data); JObject jsonObject = new JObject(); jsonObject["results"] = parsedObject["results"]; bool dbExist = await CheckDbAsync("Tips.db3"); if (!dbExist) { await CreateDatabaseAsync3(); } else { conn = new SQLiteAsyncConnection("Tips.db3"); } // await DropTableAsync3(); var listT = new List<Tips>(); foreach (var dataset in jsonObject["results"]) { string title1 = Convert.ToString(dataset["Title1"]); string title2 = Convert.ToString(dataset["Title2"]); string title3 = Convert.ToString(dataset["Title3"]); string Desc1 = Convert.ToString(dataset["Desc1"]); string Desc2 = Convert.ToString(dataset["Desc2"]); string Desc3 = Convert.ToString(dataset["Desc3"]); string Id = Convert.ToString(dataset["objectId"]); Tips t = new Tips(); t.desc1 = Desc1; t.desc2 = Desc2; t.desc3 = Desc3; t.title1 = title1; t.title2 = title2; t.title3 = title3; t.Id= Id; listT.Add(t); } // await DropTableAsync3(); await conn.InsertAllAsync(listT); int i = 0; foreach (Tips t in listT) { Debug.WriteLine("Compteur =" + i); i++; Debug.WriteLine(t.desc1); } }