Exemplo n.º 1
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");
        }
        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");
        }