Esempio n. 1
0
        public override async void OnNavigatedTo(INavigationParameters parameters)
        {
            base.OnNavigatedFrom(parameters);

            if (!VerifyConnection.GetConnectionStatus())
            {
                Xamarin.Forms.DependencyService.Get <IToastService>().DisplayMessage("Sem conexão.");
            }

            this.IsBusy = true;

            await Policy
            .Handle <HttpRequestException>()
            .WaitAndRetryForeverAsync
            (
                sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
            )
            .ExecuteAsync(async() => await _service.GetFilmes())
            .ContinueWith(t =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Filmes.Clear();
                    Filmes.AddRange(t.Result);

                    SetMessage(Filmes.Count);
                    this.IsBusy = false;
                });
            });
        }
Esempio n. 2
0
        private async void LoginCommandExecuted()
        {
            try
            {
                if (!string.IsNullOrEmpty(Rut))
                {
                    if (!string.IsNullOrEmpty(Usuario))
                    {
                        if (!string.IsNullOrEmpty(Clave))
                        {
                            var verify = await VerifyConnection.IsConnected();

                            if (verify.IsSuccess)
                            {
                                DependencyService.Get <IProgressDialog>().ProgressDialogShow();
                                ServiceClient client   = new ServiceClient();
                                string        query    = string.Format("ValidarAccesoGet?strRutEmpresa={0}&strUsuario={1}&strPass={2}", Rut, Usuario, Clave);
                                var           response = await client.GetListAllWithParam <UserModel>(query);

                                DependencyService.Get <IProgressDialog>().ProgressDialogHide();
                                if (response.Error != null)
                                {
                                    App.MessageError(response.Error.Mensaje);
                                }
                                else
                                {
                                    response.Password = Clave;
                                    InsertUsuario(response);
                                    sync.AsyncData();
                                    App.Current.MainPage = new MasterPage();
                                }
                            }
                            else
                            {
                                App.MessageError(verify.Message);
                            }
                        }
                        else
                        {
                            App.MessageError("Ingrese su Clave");
                        }
                    }
                    else
                    {
                        App.MessageError("Ingrese su usuario");
                    }
                }
                else
                {
                    App.MessageError("Ingrese el Rut");
                }
            }
            catch (Exception e)
            {
                DependencyService.Get <IProgressDialog>().ProgressDialogHide();
                Console.WriteLine(e);
                throw;
            }
        }
Esempio n. 3
0
        public void AsyncData()
        {
            try
            {
                Task.Run(() =>
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        string[] tables = new string[10];
                        var user        = db.GetUser();
                        var verify      = await VerifyConnection.IsConnected();
                        if (verify.IsSuccess)
                        {
                            string validateUserresponse = string.Format("ValidarAccesoGet?strRutEmpresa={0}&strUsuario={1}&strPass={2}", user.RutEmpresa, user.Usuario, user.Password);
                            var validateUser            = await client.GetListAllWithParam <UserModel>(validateUserresponse);
                            if (validateUser.Error == null)
                            {
                                DeleteAllTables();
                                //comienza Service Cliente
                                var responseCliente = await client.GetListAllWithParam <ListClientes>(urlCliente + user.RutEmpresa);
                                if (responseCliente.Error == null)
                                {
                                    if (responseCliente.ListaClientes.Count > 0)
                                    {
                                        foreach (var item in responseCliente.ListaClientes)
                                        {
                                            db.InsertClientes(item);
                                        }
                                    }
                                }
                                else
                                {
                                    tables[0] = "Clientes";
                                    asyncCount++;
                                }
                                //Termina Service Cliente

                                //comienza Service DireccionesCliente
                                var responseDireccionesCliente = await client.GetListAllWithParam <ListDireccionesClientes>(urlDireccionesCliente + user.RutEmpresa);
                                if (responseDireccionesCliente.Error == null)
                                {
                                    if (responseDireccionesCliente.ListaDirecciones.Count > 0)
                                    {
                                        foreach (var item in responseDireccionesCliente.ListaDirecciones)
                                        {
                                            db.InsertDireccionesClientes(item);
                                        }
                                    }
                                }
                                else
                                {
                                    tables[1] = "DirecionesClientes";
                                    asyncCount++;
                                }
                                //Termina Service DireccionesCliente

                                //comienza Service Producto
                                var responseProducto = await client.GetListAllWithParam <ListProducto>(urlProducto + user.RutEmpresa);
                                if (responseProducto.Error == null)
                                {
                                    if (responseProducto.ListaProductos.Count > 0)
                                    {
                                        foreach (var item in responseProducto.ListaProductos)
                                        {
                                            db.InsertProducto(item);
                                        }
                                    }
                                }
                                else
                                {
                                    tables[2] = "Producto";
                                    asyncCount++;
                                }
                                //Termina Service Producto



                                //comienza Service Comuna
                                var responseComuna = await client.GetListAllWithParam <ListComuna>(urlComuna + user.RutEmpresa);
                                if (responseComuna.Error == null)
                                {
                                    if (responseComuna.ListaComunas.Count > 0)
                                    {
                                        foreach (var item in responseComuna.ListaComunas)
                                        {
                                            db.InsertComuna(item);
                                        }
                                    }
                                }
                                else
                                {
                                    tables[3] = "Comuna";
                                    asyncCount++;
                                }
                                //Termina Service Comuna


                                //comienza Service Emisores
                                var responseEmisores = await client.GetListAllWithParam <ListEmisores>(urlEmisores + user.RutEmpresa);
                                if (responseEmisores.Error == null)
                                {
                                    if (responseEmisores.ListaEmisores.Count > 0)
                                    {
                                        foreach (var item in responseEmisores.ListaEmisores)
                                        {
                                            db.InsertEmisores(item);
                                        }
                                    }
                                }
                                else
                                {
                                    tables[4] = "Emisores";
                                    asyncCount++;
                                }
                                //Termina Service Emisores

                                //comienza Service Regiones
                                var responseRegiones = await client.GetListAllWithParam <ListRegiones>(urlRegiones + user.RutEmpresa);
                                if (responseRegiones.Error == null)
                                {
                                    if (responseRegiones.ListaRegiones.Count > 0)
                                    {
                                        foreach (var item in responseRegiones.ListaRegiones)
                                        {
                                            db.InsertRegiones(item);
                                        }
                                    }
                                }
                                else
                                {
                                    tables[5] = "Regiones";
                                    asyncCount++;
                                }
                                if (asyncCount > 0)
                                {
                                    var stringmessage = "Errores al sincronizar: " + tables[0] + "," + tables[1] + "," + tables[2] + "," + tables[3] + "," + tables[4] + "," + tables[5];
                                    var notification  = Plugin.LocalNotifications.CrossLocalNotifications.Current;
                                    notification.Show("IMOS", stringmessage);
                                    asyncCount    = 0;
                                    stringmessage = string.Empty;
                                }
                                else
                                {
                                    Plugin.Toast.CrossToastPopUp.Current.ShowToastMessage("Sincronizacion terminada");
                                    //mostrar un toas qiue indique que se termino de sincronizar
                                }
                                //Termina Service Regiones
                            }
                            else
                            {
                                App.MessageError("hubo un error al sincronizar");
                            }
                        }
                        else
                        {
                            App.MessageError("Verifique su coneccion syncronizacion incompleta");
                        }
                    });
                });
            }
            catch (Exception ex)
            {
            }
        }