Ejemplo n.º 1
0
        private async void UpdateShuttles(ThreadPoolTimer timer)
        {
            List <Tuple <string, Point> > shuttleLocs = await MainDataStore.GetShuttles(commonRouteIDsColors.Keys.ToList <string>());

            var oldShuttles = shuttleMap.Children.ToList <UIElement>();

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => {
                foreach (var oldShuttle in oldShuttles)
                {
                    if (oldShuttle.GetType() == typeof(ShuttlePin))
                    {
                        shuttleMap.Children.Remove(oldShuttle);
                    }
                }
                AddShuttles(shuttleLocs);
            });

            // clean up
            oldShuttles = null;
            shuttleLocs = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            Tuple <string, string> items = (Tuple <string, string>)navigationParameter;

            currOrigin = items.Item1;
            currDest   = items.Item2;
            UpdateFavoritesCache(currOrigin, currDest);

            // Register the background task
            if (GroupedItemsPage.asyncStatus != BackgroundAccessStatus.Denied &&
                GroupedItemsPage.asyncStatus != BackgroundAccessStatus.Unspecified)
            {
                RegisterBackgroundTask();
            }

            this.pageTitle.Text = "Trip Results";
            UpdateOriginDest(currOrigin, currDest);

            // grab the route map (route id -> (name, color, segment list)
            commonRouteIDsColors = new Dictionary <string, string>();
            Dictionary <string, Tuple <string, string, List <LocationCollection> > > routeMap;

            routeMap = await PopulateUI();

            uiUpdaterTimer = ThreadPoolTimer.CreatePeriodicTimer(UpdateUI, TimeSpan.FromSeconds(30));
            if (routeMap == null)
            {
                return;
            }

            // cache route IDs and their colors
            commonRouteIDsColors = new Dictionary <string, string>();
            foreach (var key in routeMap.Keys)
            {
                commonRouteIDsColors[key] = routeMap[key].Item2;
            }

            MakePolylines(routeMap);

            // update color codes on UI
            foreach (var key in commonRouteIDsColors.Keys)
            {
                string name = routeMap[key].Item1;
                this.ColorCodePanel.Children.Add(new ColorCodeBox(commonRouteIDsColors[key], name));
            }

            // plot shuttles
            List <Tuple <string, Point> > shuttleLocs = await MainDataStore.GetShuttles(commonRouteIDsColors.Keys.ToList <string>());

            if (shuttleLocs != null) // there is internet
            {
                AddShuttles(shuttleLocs);
            }
            PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(UpdateShuttles, TimeSpan.FromMilliseconds(2500));

            FadeInMap();

            // clean up
            shuttleLocs = null;
            routeMap    = null;
        }