public int ExecAPIs() { if (!itsRunning) { itsRunning = true; PopulateSync(); try { controller.ExecRestApis(); } //O XGH só existe quando é encontrado. Se ta funcionando NAO RELA A MAO. catch (InvalidLoginException invalid) { try { InvokeOnMainThread(delegate { model.db.RemoveUser(invalid.userID); }); } catch (InvalidOperationException) { return(-99); } } #if !DEBUG catch (Exception ex) { MetricsManager.TrackEvent("SyncDataFail"); MetricsManager.TrackEvent(ex.Message); } #endif var NewPdvs = new List <string>(); InvokeOnMainThread(delegate { NewPdvs = controller.GetNovosPdvsNotification(); if (NewPdvs.Count > 0) { var content = new UNMutableNotificationContent { Title = "Novos PDVs", Subtitle = "Roteiro Atualizado", Body = "Existem " + NewPdvs.Count + " novos PDVs cadastrados", Badge = NewPdvs.Count }; var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(1, false); var requestID = "newPdvs"; var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger); UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) => { }); } }); itsRunning = false; return(NewPdvs.Count); } return(0); }
static void ExecAPIs(bool isToUpdateImage) { itsRunning = true; PopulateSync(); try { controller.ExecRestApis(); if (isToUpdateImage) { UploadImages(); } } catch (InvalidLoginException invalid) { try { model.db.RemoveUser(invalid.userID); } catch (InvalidOperationException) { Process.GetCurrentProcess().CloseMainWindow(); } } catch (Exception ex) { #if !DEBUG MetricsManager.TrackEvent("SyncDataFail"); MetricsManager.TrackEvent(ex.Message); #endif #if DEBUG throw ex; #endif } var NewPdvs = new List <string>(); NewPdvs = controller.GetNovosPdvsNotification(); if (NewPdvs.Count > 0) { var content = new UNMutableNotificationContent { Title = "Novos PDVs", Subtitle = "Roteiro Atualizado", Body = "Existem " + NewPdvs.Count + " novos PDVs cadastrados", Badge = NewPdvs.Count }; var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(1, false); var requestID = "newPdvs"; var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger); UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) => { }); } itsRunning = false; }
public static void ExecSync() { var difTime = (DateTime.Now - lastHitSync).TotalSeconds; if (difTime >= 11) { lastHitSync = DateTime.Now; itsRunning = true; MetricsManager.TrackEvent("PerformSync"); model = new SyncronizerModel { versionName = GetVersionName(), db = new SyncronizerDA(SQLite_Android.DB.dataBase), dbCache = new CacheDA(SQLite_Android.DB.dataBase) }; controller = new SyncronizerCon(model); try { UploadImages(); controller.ExecRestApis(); } catch (InvalidLoginException invalid) { try { model.db.RemoveUser(invalid.userID); } catch (InvalidOperationException) { } finally { context.SendBroadcast(new Intent(MenuPDVsModel.ACTION_FINISHED_SYNC)); } } catch (Java.Lang.Exception) { MetricsManager.TrackEvent("SyncDataFail"); } finally { context.SendBroadcast(new Intent(MenuPDVsModel.ACTION_FINISHED_SYNC)); } itsRunning = false; if (string.IsNullOrEmpty(controller.exceptionMessage) || controller.exceptionMessage == "Socket closed") { AddNotificationPdv(controller.GetNovosPdvsNotification()); } else if (controller.invalidException != null) { try { model.db.RemoveUser(controller.invalidException.userID); } catch (InvalidOperationException) { } finally { context.SendBroadcast(new Intent(MenuPDVsModel.ACTION_FINISHED_SYNC)); } } else { context.SendBroadcast(new Intent(MenuPDVsModel.ACTION_FINISHED_SYNC)); if (!controller.exceptionMessage.ToUpper().Contains("RESET BY PEER") || controller.exceptionMessage.ToUpper().Contains("SOCKET") || controller.exceptionMessage.ToUpper().Contains("TIMEOUT") || controller.exceptionMessage.ToUpper().Contains("TIME OUT")) { MetricsManager.TrackEvent("SyncDataFail"); MetricsManager.TrackEvent(controller.exceptionMessage); #if DEBUG Console.WriteLine(controller.exceptionMessage); throw new Exception(controller.exceptionMessage); #endif } } } }