コード例 #1
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));
        }
コード例 #2
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();
        }
コード例 #3
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();
        }
コード例 #4
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();
        }