Esempio n. 1
0
        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);
        }
 public static void ExecSyncUI()
 {
     MetricsManager.TrackEvent("UIPerformSync");
     model = new SyncronizerModel
     {
         versionName = GetVersionName(),
         db          = new SyncronizerDA(SQLite_Android.DB.dataBase),
         dbCache     = new CacheDA(SQLite_Android.DB.dataBase)
     };
     controller = new SyncronizerCon(model);
     controller.ExecRestApis();
 }
Esempio n. 3
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;
        }
        void ExecLogin()
        {
            model.empresa  = txtEmpresaLogin.Text;
            model.login    = txtUsuarioLogin.Text;
            model.password = txtSenhaLogin.Text;

            var bounds = UIScreen.MainScreen.Bounds;

            loadingOverlay = new LoadingOverlay(bounds);
            loadingOverlay.ExecOverLay();
            View.Add(loadingOverlay);

            new Thread(new ThreadStart(delegate
            {
                try
                {
                    SyncronizerModel modelSync;
                    SyncronizerCon controllerSync;
                    var infoUser = controller.DoLogin(model.empresa, model.login, model.password);
                    infoUser     = GetAvatarDeUsuario(infoUser);
                    GetLogoEmpresa(infoUser.SERVIDOR.Substring(0, infoUser.SERVIDOR.IndexOf(".",
                                                                                            StringComparison.CurrentCulture)), infoUser);
                    InvokeOnMainThread(() =>
                    {
                        controller.InsertNewUser(infoUser);
                        modelSync = new SyncronizerModel()
                        {
                            db      = new SyncronizerDA(Sqlite_IOS.DB.dataBase),
                            dbCache = new CacheDA(Sqlite_IOS.DB.dataBase)
                        };
                        controllerSync = new SyncronizerCon(modelSync);
                        controllerSync.ExecRestApis();
#if !DEBUG
                        BITHockeyManager.SharedHockeyManager.UserId    = infoUser.ID;
                        BITHockeyManager.SharedHockeyManager.UserEmail = infoUser.SERVIDOR;
                        BITHockeyManager.SharedHockeyManager.StartManager();
#endif
                        MoveToFeedPDV();
                    });
                }
                catch (InvalidLoginException loginError)
                {
                    InvokeOnMainThread(() =>
                    {
                        var alert = UIAlertController.Create(loginError.Message, null, UIAlertControllerStyle.Alert);
                        alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                        alert.View.TintColor = UIColor.FromRGB(10, 88, 90);
                        PresentViewController(alert, true, null);
                    });
                }
                catch (Exception ex)
                {
                    var exi = ex.Message;
                    InvokeOnMainThread(() =>
                    {
                        var alert = UIAlertController.Create(
                            "Ocorreu um erro inesperado, verifique sua conexão e os dados de login",
                            null, UIAlertControllerStyle.Alert);
                        alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                        alert.View.TintColor = UIColor.FromRGB(10, 88, 90);
                        PresentViewController(alert, true, null);
                    });
                }
                finally
                {
                    InvokeOnMainThread(() =>
                    {
                        loadingOverlay.Hide();
                    });
                }
            })).Start();
        }
        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
                    }
                }
            }
        }