Exemplo n.º 1
0
        public void LoadArrivalsForStop(Stop stop, Route routeFilter)
        {
            lock (arrivalsLock)
            {
                unfilteredArrivals.Clear();
                ArrivalsForStop.Clear();
            }

            this.routeFilter = routeFilter;
            RefreshArrivalsForStop(stop);

            // We've sent our first call off, set resultsLoaded to true
            resultsLoaded = true;
        }
Exemplo n.º 2
0
        private void FilterArrivals()
        {
            lock (arrivalsLock)
            {
                UIAction(() => ArrivalsForStop.Clear());

                unfilteredArrivals.Sort(new DepartureTimeComparer());
                foreach (ArrivalAndDeparture arrival in unfilteredArrivals)
                {
                    if (routeFilter != null && routeFilter.id != arrival.routeId)
                    {
                        continue;
                    }

                    ArrivalAndDeparture currentArrival = arrival;
                    UIAction(() => ArrivalsForStop.Add(currentArrival));
                }
            }

            // Refresh NoResultsAvailable status
            OnPropertyChanged("NoResultsAvailable");
        }
Exemplo n.º 3
0
        void busServiceModel_ArrivalsForStop_Completed(object sender, EventArgs.ArrivalsForStopEventArgs e)
        {
            Debug.Assert(e.error == null);

            if (e.error == null)
            {
                lock (arrivalsLock)
                {
                    // We are loading arrivals fresh, add all of them
                    if (unfilteredArrivals.Count == 0)
                    {
                        unfilteredArrivals = e.arrivals;
                        FilterArrivals();
                    }
                    else
                    {
                        // We already have arrivals in the list, so just refresh them
                        // Start by updating all the times for all of the arrivals currently in the list,
                        // and find any arrivals that have timed out for this stop
                        List <ArrivalAndDeparture> arrivalsToRemove = new List <ArrivalAndDeparture>();
                        foreach (ArrivalAndDeparture arrival in unfilteredArrivals)
                        {
                            int index = e.arrivals.IndexOf(arrival);
                            if (index >= 0)
                            {
                                ArrivalAndDeparture newArrivalTime = e.arrivals[index];
                                ArrivalAndDeparture currentArrival = arrival;
                                UIAction(() =>
                                {
                                    currentArrival.predictedArrivalTime   = newArrivalTime.predictedArrivalTime;
                                    currentArrival.predictedDepartureTime = newArrivalTime.predictedDepartureTime;

                                    currentArrival.tripDetails.scheduleDeviationInSec = newArrivalTime.tripDetails.scheduleDeviationInSec;
                                    currentArrival.tripDetails.closestStopId          = newArrivalTime.tripDetails.closestStopId;
                                    currentArrival.tripDetails.closestStopTimeOffset  = newArrivalTime.tripDetails.closestStopTimeOffset;
                                    currentArrival.tripDetails.coordinate             = newArrivalTime.tripDetails.coordinate;
                                });
                            }
                            else
                            {
                                // The latest collection no longer has this arrival, delete it from the
                                // list.  Otherwise we will keep it around forever, no longer updating
                                // its time
                                arrivalsToRemove.Add(arrival);
                            }
                        }

                        arrivalsToRemove.ForEach(arrival =>
                        {
                            UIAction(() => ArrivalsForStop.Remove(arrival));
                            unfilteredArrivals.Remove(arrival);
                        }
                                                 );

                        // Now add any new arrivals that just starting showing up for this stop
                        foreach (ArrivalAndDeparture arrival in e.arrivals)
                        {
                            // Ensure that we aren't adding routes that are filtered out
                            if ((routeFilter == null || routeFilter.id == arrival.routeId) &&
                                ArrivalsForStop.Contains(arrival) == false)
                            {
                                ArrivalAndDeparture currentArrival = arrival;
                                UIAction(() => ArrivalsForStop.Add(currentArrival));
                                unfilteredArrivals.Add(currentArrival);
                            }
                        }
                    }
                }
            }
            else
            {
                ErrorOccured(this, e.error);
            }

            operationTracker.DoneWithOperation("ArrivalsForStop");

            // Refresh NoResultsAvailable status
            OnPropertyChanged("NoResultsAvailable");
        }