Beispiel #1
0
        /// <summary>
        /// Call the OBA webservice to load stops and routes for the current location.
        /// </summary>
        /// <param name="radiusInMeters"></param>
        /// <param name="invalidateCache">If true, will discard any cached result and requery the server</param>
        public void LoadInfoForLocation(bool invalidateCache)
        {
            StopsForLocation.Clear();

            DisplayRouteForLocation.Working.Clear();

            operationTracker.WaitForOperation("CombinedInfoForLocation", "Searching for buses...");
            locationTracker.RunWhenLocationKnown(delegate(GeoCoordinate location)
            {
                busServiceModel.CombinedInfoForLocation(location, defaultSearchRadius, -1, invalidateCache);
            });
        }
Beispiel #2
0
        void busServiceModel_CombinedInfoForLocation_Completed(object sender, EventArgs.CombinedInfoForLocationEventArgs e)
        {
            Debug.Assert(e.error == null);

            if (e.error == null)
            {
                e.stops.Sort(new StopDistanceComparer(e.location));
                e.routes.Sort(new RouteDistanceComparer(e.location));

                int stopCount = 0;
                foreach (Stop stop in e.stops)
                {
                    if (stopCount > maxStops)
                    {
                        break;
                    }

                    Stop currentStop = stop;
                    UIAction(() => StopsForLocation.Add(currentStop));
                    stopCount++;
                }

                int routeCount = 0;
                foreach (Route route in e.routes)
                {
                    if (routeCount > maxRoutes)
                    {
                        break;
                    }

                    DisplayRoute currentDisplayRoute = new DisplayRoute()
                    {
                        Route = route
                    };
                    DisplayRouteForLocation.Working.Add(currentDisplayRoute);
                    routeCount++;
                }

                // Done with work in the background.  Flush the results out to the UI.  This is quick.
                object testref = null;
                UIAction(() =>
                {
                    DisplayRouteForLocation.Toggle();
                    testref = new object();
                }
                         );

                // hack to wait for the UI action to complete
                // note this executes in the background, so it's fine to be slow.
                int execcount = 0;
                while (testref == null)
                {
                    execcount++;
                    Thread.Sleep(100);
                }

                // finally, queue up more work
                lock (DisplayRouteForLocation.CurrentSyncRoot)
                {
                    foreach (DisplayRoute r in DisplayRouteForLocation.Current)
                    {
                        directionHelper[r.Route.id] = r.RouteStops;

                        operationTracker.WaitForOperation(string.Format("StopsForRoute_{0}", r.Route.id), "Loading route details...");
                        busServiceModel.StopsForRoute(LocationTracker.CurrentLocation, r.Route);
                    }
                }
            }
            else
            {
                ErrorOccured(this, e.error);
            }

            operationTracker.DoneWithOperation("CombinedInfoForLocation");
        }