public async Task UpdateData()
        {
            IsLoading = true;
            var data = await DevicesService.GetDevicesList(new GetDeviceListQuery { PageNumber = 1, PageSize = 100 });

            var deviceDetailTasks = data.Result.Select(x =>
                                                       DevicesService.GetDeviceStatus(new GetDeviceStatusQuery {
                DeviceId = x.DeviceId
            }));
            var deviceDetails = await Task.WhenAll(deviceDetailTasks);

            Data = data.Result.Zip(deviceDetails, (deviceData, deviceStatusDetails) => new DeviceListRowVm
            {
                DeviceId            = deviceData.DeviceId,
                DeviceName          = deviceData.DeviceName,
                IsOnline            = deviceData.IsOnline,
                LastStatusUpdate    = deviceData.LastStatusUpdate,
                DeviceStatusDetails = deviceStatusDetails
            });
            IsLoading = false;
        }
예제 #2
0
        private async void GetDeviceStatus()
        {
            IsChecking = true;

            await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(1));


            tblUsersDTO User = App.CurrentUser;

            Response response = await DeviceService.GetDeviceStatus(User.DeviceID);

            if (response.Result != Result.NETWORK_UNAVAILABLE)
            {
                if (response.Result == Result.ERROR_GETTING_DATA)
                {
                    await Alerts.HideLoadingPageAsync();

                    Alerts.ShowAlert(string.Empty, "Error al obtener datos del servidor");
                }
                else if (response.Result == Result.SERVICE_EXCEPTION)
                {
                    await Alerts.HideLoadingPageAsync();

                    Alerts.ShowAlert(string.Empty, "Error al obtener datos del servidor (SX)");
                }
                else if (response.Result == Result.OK)
                {
                    if (!string.IsNullOrEmpty(response.Data))
                    {
                        string responseNormalized = response.Data.NormalizeResponse();

                        string[] UserData = response.Data.ReplaceAndSplit();
                        if (responseNormalized == Constants.Error_Code)
                        {
                            await Alerts.HideLoadingPageAsync();

                            Alerts.ShowAlert(string.Empty, "Error al registrar el dispositivo en el servidor,intente mas tarde.");
                            return;
                        }

                        User.DeviceStatus = responseNormalized;
                        App.UsersB.Update(User);

                        if (User.DeviceStatus == DeviceStatus.Approved)
                        {
                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                StopTimer();
                                CheckingMsg = "Dispositivo aprobado";

                                await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(2));

                                App.Current.MainPage = new NavigationPage(new Reports());
                            });
                        }
                        else if (User.DeviceStatus == DeviceStatus.Rejected)
                        {
                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                StopTimer();

                                CheckingMsg = "Dispositivo rechazado";

                                await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(2));

                                App.Current.MainPage = new Login();
                            });
                        }
                    }
                    else
                    {
                        await Alerts.HideLoadingPageAsync();

                        Alerts.ShowAlert(string.Empty, "Los datos obtenidos son invalidos.");
                    }
                }
            }
            else
            {
                await Alerts.HideLoadingPageAsync();

                Alerts.ShowNetworkError();
            }


            IsChecking = false;
        }