Пример #1
0
        public async Task Arrive(RouteStop stop)
        {
            int index = Stops.IndexOf(stop);

            if (index < 0)
            {
                Debug.Print($"### Route.Arrive(): unknown stop #{stop.Ordinal}");
                return;
            }
            if (stop.Status != RoutеStopStatus.Enroute)
            {
                Debug.Print($"### Route.Arrive(): stop #{stop.Ordinal} not in Enroute state ({stop.Status})");
                return;
            }

            stop.ArrivalTime = DateTime.Now;
            await ChangeStopStatus(stop, RoutеStopStatus.Arrived);

            if (index < Stops.Count - 1)
            {
                // Trigger next RouteStopCardModel.UpdateFromSource();
                var next = Stops[index + 1];
                next.SetStatus(RoutеStopStatus.Pending, forceNotification: true);
            }

            if (stop.Kind == RouteStopKind.EndPoint && DeleteStopOnCompleted)
            {
                await DeleteStop(stop);
            }

            await UpdateDurations();
        }
Пример #2
0
        bool CanShowDirections(RouteStop stop, out RouteStop prev, bool currentOnly)
        {
            int index = Stops.IndexOf(stop);

            if (index > 0)
            {
                prev = Stops[index - 1];
            }
            else
            {
                prev = null;
            }

            if (string.IsNullOrWhiteSpace(stop.Address) || stop.Status >= RoutеStopStatus.Arrived)
            {
                return(false);
            }

            if (stop.Status == RoutеStopStatus.Enroute)
            {
                return(true);
            }
            if (prev == null || (currentOnly && prev.Status < RoutеStopStatus.Arrived))
            {
                return(false);
            }

            return(!string.IsNullOrWhiteSpace(prev.Address));
        }
Пример #3
0
        static bool SameLeg(RouteLeg leg, RouteStop start, RouteStop end, RouteLegStatus?status)
        {
            if (leg == null)
            {
                return(false);
            }

            return(leg.StartPoint == start && leg.EndPoint == end && (status == null || leg.Status == status));
        }
Пример #4
0
        public async Task AddNew(RouteStop stop, bool calculateDuration)
        {
            await Add(stop, true);

            if (calculateDuration)
            {
                await CalculateDurations();
            }
        }
Пример #5
0
        public async Task ChangeStopStatus(RouteStop stop, RoutеStopStatus status)
        {
            stop.Status = status;

            if (stop.Leg != null)
            {
                stop.Leg.Status = StopToLegStatus(stop);
            }

            await AppStorage.Instance.ChangeRouteStopStatus(stop);
        }
Пример #6
0
        public Invoice(RouteStop routeStop) :
            this(true)
        {
            Guard.ArgumentNotNull(routeStop, nameof(routeStop));

            var customer = routeStop.Place as Customer;
            Guard.ArgumentNotNull(customer, nameof(customer));

            RouteStop = routeStop;
            Customer  = customer;
        }
Пример #7
0
        static RouteLegStatus StopToLegStatus(RouteStop stop)
        {
            switch (stop.Status)
            {
            case RoutеStopStatus.Pending:
                return(RouteLegStatus.Pending);

            case RoutеStopStatus.Enroute:
                return(RouteLegStatus.Enroute);

            default:
                return(RouteLegStatus.Complete);
            }
        }
Пример #8
0
        RouteLeg GetKnownLeg(RouteStop start, RouteStop end, RouteLegStatus status)
        {
            if (PreviousLegs != null)
            {
                foreach (var leg in PreviousLegs)
                {
                    if (SameLeg(leg, start, end, status))
                    {
                        return(leg);
                    }
                }
            }

            return(null);
        }
Пример #9
0
        public async Task Depart(RouteStop stop)
        {
            Debug.Assert(stop.Status == RoutеStopStatus.Enroute);

            int index = Stops.IndexOf(stop);

            if (index < 0)
            {
                Debug.Print($"### Route.Depart(): unknown stop #{stop.Ordinal}");
                return;
            }
            if (stop.Status != RoutеStopStatus.Arrived)
            {
                Debug.Print($"### Route.Depart(): stop #{stop.Ordinal} not in Arrived state ({stop.Status})");
                return;
            }
            if (stop.Kind == RouteStopKind.EndPoint)
            {
                Debug.Print($"### Route.Depart(): stop #{stop.Ordinal} is end point");
                return;
            }

            if (stop.Kind == RouteStopKind.StartPoint)
            {
                await Start();
            }

            stop.DepartureTime = DateTime.Now;

            await ChangeStopStatus(stop, RoutеStopStatus.Departed);

            if (index < Stops.Count - 1)
            {
                var next = Stops[index + 1];
                await ChangeStopStatus(next, RoutеStopStatus.Enroute);
            }

            if (DeleteStopOnCompleted)
            {
                await DeleteStop(stop);
            }

            await UpdateDurations();
        }
Пример #10
0
        public async Task Add(RouteStop stop, bool addToStorage)
        {
            if (Stops.Count > 0)
            {
                var last = Stops[Stops.Count - 1];
                stop.Ordinal = last.Ordinal + 1;
            }
            else if (addToStorage && stop.Kind != RouteStopKind.StartPoint)
            {
                await AddStop(new RouteStartStop(this), addToStorage);

                stop.Ordinal = 1;
            }
            else
            {
                stop.Ordinal = 0;
            }

            await AddStop(stop, addToStorage);
        }
Пример #11
0
        public async Task ShowRouteMap()
        {
            var locations = new List <ILocation>();

            RouteStop lastStop = null;

            foreach (var stop in Stops)
            {
                if (stop.Status == RoutеStopStatus.Departed)
                {
                    continue;
                }

                if (stop.Status == RoutеStopStatus.Enroute)
                {
                    locations.Add(await Location.GetCurrentLocation());
                }

                locations.Add(new Location {
                    Address = stop.Address
                });
                lastStop = stop;
            }

            if (locations.Count == 0)
            {
                return;
            }

            if (lastStop.Kind != RouteStopKind.EndPoint)
            {
                lastStop = new RouteEndStop(this);
                locations.Add(new Location {
                    Address = lastStop.Address
                });
            }

            await Maps.MapApplication.OpenDirections(locations, Maps.DefaultOptions);
        }
Пример #12
0
        public List <RouteLeg> UpdateLegs(bool requestETAs)
        {
            if (CurrentLegs == null)
            {
                CurrentLegs = new List <RouteLeg>();

                RouteStop prevStop = null;
                for (int i = 0; i < Stops.Count; i++)
                {
                    var stop      = Stops[i];
                    var legStatus = StopToLegStatus(stop);
                    if (!SameLeg(stop.Leg, prevStop, stop, legStatus))
                    {
                        stop.Leg = GetKnownLeg(prevStop, stop, legStatus);
                        if (stop.Leg == null)
                        {
                            stop.Leg = new RouteLeg {
                                StartPoint = prevStop,
                                EndPoint   = stop,
                                Status     = legStatus
                            };

                            if (requestETAs)
                            {
                                RequestLegDuration(stop.Leg);
                            }
                        }
                    }
                    CurrentLegs.Add(stop.Leg);

                    prevStop = stop;
                }

                PreviousLegs = null;
            }

            return(CurrentLegs);
        }
Пример #13
0
        public async Task DeleteStop(RouteStop stop)
        {
            int ord   = stop.Ordinal;
            int index = Stops.IndexOf(stop);

            if (index < 0)
            {
                Debug.Print($"### Route.DeleteStop(): Stop #{ord} not found in the Route");
            }

            await AppStorage.Instance.DeleteRouteStop(stop);

            Stops.RemoveAt(index);

            if (Stops.Count == 0)
            {
                IsStarted = false;
                return;
            }

            if (index < Stops.Count && (stop.Status == RoutеStopStatus.Enroute || stop.Status == RoutеStopStatus.Arrived))
            {
                var next = Stops[index];
                await ChangeStopStatus(next, RoutеStopStatus.Enroute);
            }

            if (ord > 0 && stop.Status == RoutеStopStatus.Pending)
            {
                while (index < Stops.Count)
                {
                    stop         = Stops[index++];
                    stop.Ordinal = ord++;
                    await AppStorage.Instance.ChangeRouteStopOrdinal(stop);
                }
            }

            await UpdateDurations();
        }
Пример #14
0
        public async Task ShowDirections(RouteStop stop)
        {
            RouteStop prev;

            if (!CanShowDirections(stop, out prev, DirectionsForCurrentOnly))
            {
                return;
            }

            if (stop.Status == RoutеStopStatus.Enroute)
            {
                await Maps.MapApplication.OpenDirections(
                    null,
                    new Location { Address = stop.Address },
                    Maps.DefaultOptions);
            }
            else
            {
                await Maps.MapApplication.OpenDirections(
                    new Location { Address = prev.Address },
                    new Location { Address = stop.Address },
                    Maps.DefaultOptions);
            }
        }
Пример #15
0
        async Task AddStop(RouteStop stop, bool addToStorage)
        {
            Debug.Assert(stop.Route == this);

            if (addToStorage)
            {
                await AppStorage.Instance.AddRouteStop(stop);
            }

            if (Stops.Count > 0 && stop.Kind != RouteStopKind.EndPoint && HasEndPoint)
            {
                Stops.Insert(Stops.Count - 1, stop);
            }
            else
            {
                Stops.Add(stop);
            }

            Debug.AssertIsNull(CurrentLegs);
            UpdateLegs(true);

            //Debug.AssertNotNull(stop.Leg);
            //RequestLegDuration(stop.Leg);
        }
Пример #16
0
        public bool CanShowDirections(RouteStop stop)
        {
            RouteStop prev;

            return(CanShowDirections(stop, out prev, DirectionsForCurrentOnly));
        }