//Requisita o endereço REST para Sincronizar a classe específica no banco SQLite local private static async void requestRestAndSync <T>() where T : new() { var holder = RestHolder <T> .instance; if (holder.LockSyncThread) { return; } holder.LockSyncThread = true; try { //Pega o DateTime da ultima requisição desta Uri DateTime lastRequest = Prefs.getDateTime(holder.SyncUri); //Request e Sync long unixTimestamp = lastRequest.Ticks - new DateTime(1970, 1, 1).Ticks; Stopwatch stopwatch = new Stopwatch(); StringBuilder log = new StringBuilder(); stopwatch.Start(); string content = await RestService.GetAsync(holder.SyncUri + (unixTimestamp / TimeSpan.TicksPerMillisecond)); log = log.AppendFormat("\n-------- REST REQUEST TIME <{1}> {0} ------- ", stopwatch.Elapsed, typeof(T).Name); stopwatch.Restart(); List <T> entities = JsonConvert.DeserializeObject <List <T> >(content); log = log.AppendFormat("\n-------- Deserialize TIME <{1}> {0} ------- ", stopwatch.Elapsed, typeof(T).Name); stopwatch.Restart(); SQLiteRepository.SyncEntities <T>(entities); log = log.AppendFormat("\n-------- SYNC TIME <{1}> {0} -------", stopwatch.Elapsed, typeof(T).Name); //Seta o DateTime da ultima requisição para AGORA Prefs.setDateTime(holder.SyncUri, DateTime.Now); holder.LockSyncThread = false; Debug.WriteLine(log); } catch (Exception e) { holder.LockSyncThread = false; Console.WriteLine(e.Message); } }