public async void Process() { RequestSync requestSync = new RequestSync(); String requestJson = requestSync.GetJsonRequest(); //String requestJson = ""; HttpContent content = new StringContent(requestJson, Encoding.UTF8, "application/json"); HttpClient client = new HttpClient(); var response = await client.PostAsync("http://buyyourcity.ovh/api/sync", content); string responseJson = await response.Content.ReadAsStringAsync(); ResponseSync responseSync = JsonConvert.DeserializeObject <ResponseSync>(responseJson); //Save datas in DB. LocalDatabase db = new LocalDatabase(); syncOK = db.WriteSync(responseSync); Thread.Sleep(1000); Console.WriteLine("TRACE requestJson : " + requestJson); Console.WriteLine("TRACE responseJson : " + responseJson); Console.WriteLine("TRACE syncOK : " + syncOK); }
public Boolean WriteSync(ResponseSync responseSync) { try { db.DeleteAll <Categorie>(); db.DeleteAll <Client>(); db.DeleteAll <Constituer>(); db.DeleteAll <Couleur>(); db.DeleteAll <Date>(); db.DeleteAll <Devis>(); db.DeleteAll <Gamme>(); db.DeleteAll <Magasin>(); db.DeleteAll <Matiere>(); db.DeleteAll <Module>(); db.DeleteAll <Remise>(); db.DeleteAll <Sol>(); db.DeleteAll <Unite>(); db.DeleteAll <User>(); Console.WriteLine("TRACE count tableCategorie after delete : " + tableCategorie.Count()); Console.WriteLine("TRACE count tableUsers after delete : " + tableUser.Count()); db.Insert(responseSync.date); foreach (var categorie in responseSync.categories) { db.Insert(categorie); } foreach (var client in responseSync.clients) { db.Insert(client); } foreach (var constituer in responseSync.constituers) { db.Insert(constituer); } foreach (var couleur in responseSync.couleurs) { db.Insert(couleur); } foreach (var devis in responseSync.devis) { db.Insert(devis); } foreach (var gamme in responseSync.gammes) { db.Insert(gamme); } foreach (var magasin in responseSync.magasins) { db.Insert(magasin); } foreach (var matiere in responseSync.matieres) { db.Insert(matiere); } foreach (var module in responseSync.modules) { db.Insert(module); } foreach (var remise in responseSync.remises) { db.Insert(remise); } foreach (var sol in responseSync.sols) { sol.list_point_sol = "[{\"x\": \"2\", \"y\": \"5\"}, {\"x\": \"2\", \"y\": \"96\"}, {\"x\": \"92\", \"y\": \"97\"}, {\"x\": \"99\", \"y\": \"8\"}]"; db.Insert(sol); } foreach (var unite in responseSync.unites) { db.Insert(unite); } foreach (var user in responseSync.users) { db.Insert(user); } Console.WriteLine("TRACE count tableCategorie after fill with sync data : " + tableCategorie.Count()); Console.WriteLine("TRACE count tableUsers after fill with sync data : " + tableUser.Count()); return(true); }catch (Exception ex) { Console.WriteLine("WriteSync error : " + ex); return(false); } }