Example #1
0
        //Requisita o endereço REST para Sincronizar a classe específica no banco SQLite local
        private static async void requestRestAndSyncDeleted <T>() where T : new()
        {
            var holder = RestHolder <T> .instance;

            if (holder.LockSyncDeletedThread)
            {
                return;
            }
            holder.LockSyncDeletedThread = true;

            try
            {
                //Pega o DateTime da ultima requisição desta Uri
                DateTime lastRequest = Prefs.getDateTime(holder.SyncDeletedUri);

                //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.SyncDeletedUri + (unixTimestamp / TimeSpan.TicksPerMillisecond));

                log = log.AppendFormat("\n-------- REST REQUEST TIME <{1}> {0} ------- ", stopwatch.Elapsed, typeof(T).Name);

                stopwatch.Restart();
                List <long> deletedIds = JsonConvert.DeserializeObject <List <long> >(content);
                log = log.AppendFormat("\n-------- Deserialize TIME <{1}> {0} ------- ", stopwatch.Elapsed, typeof(T).Name);

                stopwatch.Restart();
                SQLiteRepository.SyncDeletedEntities <T>(deletedIds);
                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.SyncDeletedUri, DateTime.Now);
                holder.LockSyncDeletedThread = false;

                Debug.WriteLine(log);
            }
            catch (Exception e)
            {
                holder.LockSyncDeletedThread = false;
                Console.WriteLine(e.Message);
            }
        }