Exemplo n.º 1
0
        public async Task <bool> ExecuteLoadTripCommandAsync(string id)
        {
            if (IsBusy)
            {
                return(false);
            }

            ProgressDialogManager.LoadProgressDialog("Loading trip details...");

            bool   error        = false;
            string errorMessage = "Please check internet connection and try again.";

            try
            {
                IsBusy = true;
                if (Trip == null)
                {
                    Trip = await StoreManager.TripStore.GetItemAsync(id);
                }

                Trip.Points = new List <TripPoint>(await StoreManager.TripPointStore.GetPointsForTripAsync(id));


                if (Trip.Points != null && Trip.Points.Count > 0)
                {
                    Title = Trip.Name;
                    for (int i = 0; i < Trip.Points.Count; i++)
                    {
                        var point = Trip.Points[i];
                        if (point.MassFlowRate == -255)
                        {
                            point.MassFlowRate = i == 0 ? 0 : Trip.Points[i - 1].MassFlowRate;
                        }
                        if (point.Speed == -255)
                        {
                            point.Speed = i == 0 ? 0 : Trip.Points[i - 1].Speed;
                        }
                    }
                    POIs.AddRange(await StoreManager.POIStore.GetItemsAsync(Trip.Id));

                    Title = Trip.Name;
                    Logger.Instance.Track("LoadPastTrip");
                }
                else
                {
                    Logger.Instance.Track("LoadPastTrip: no trip points! Trip id:" + id);
                    errorMessage = "The trip does not have any points recorded";
                    error        = true;
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Track("Error loading past trip!");
                Logger.Instance.Report(ex);
                error = true;
            }
            finally
            {
                ProgressDialogManager.DisposeProgressDialog();
                IsBusy = false;
            }

            if (error)
            {
                Acr.UserDialogs.UserDialogs.Instance.Alert(
                    errorMessage,
                    "Error loading trip", "OK");
            }

            return(!error);
        }
Exemplo n.º 2
0
        public async Task <bool> ExecuteLoadTripCommandAsync(string id)
        {
            if (IsBusy)
            {
                return(false);
            }

            Logger.Instance.Track("LoadPastTrip");

            var progress = Acr.UserDialogs.UserDialogs.Instance.Loading("Loading trip details...",
                                                                        maskType: Acr.UserDialogs.MaskType.Clear);

            bool error = false;

            try
            {
                IsBusy = true;
                if (Trip == null)
                {
                    Trip = await StoreManager.TripStore.GetItemAsync(id);
                }

                Trip.Points = new List <TripPoint>(await StoreManager.TripPointStore.GetPointsForTripAsync(id));


                if (Trip.Points != null && Trip.Points.Count > 0)
                {
                    Title = Trip.Name;
                    for (int i = 0; i < Trip.Points.Count; i++)
                    {
                        var point = Trip.Points[i];
                        if (point.MassFlowRate == -255)
                        {
                            point.MassFlowRate = i == 0 ? 0 : Trip.Points[i - 1].MassFlowRate;
                        }
                        if (point.Speed == -255)
                        {
                            point.Speed = i == 0 ? 0 : Trip.Points[i - 1].Speed;
                        }
                    }
                    POIs.AddRange(await StoreManager.POIStore.GetItemsAsync(Trip.Id));

                    Title = Trip.Name;
                }
                else
                {
                    error = true;
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Report(ex);
                error = true;
            }
            finally
            {
                progress?.Dispose();
                IsBusy = false;
            }

            if (error)
            {
                Acr.UserDialogs.UserDialogs.Instance.Alert(
                    "Please check internet connection and try again.",
                    "Unable to load Trip", "OK");
            }

            return(!error);
        }