コード例 #1
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        public async Task InitializeAsync(object parameter)
        {
            if (parameter is PageInitializationParameters)
            {
                PageInitializationParameters parameters = (PageInitializationParameters)parameter;
                string stopId = parameters.GetParameter <string>("stopId");
                double lat    = parameters.GetParameter <double>("lat");
                double lon    = parameters.GetParameter <double>("lon");

                if (!string.IsNullOrEmpty(stopId) && lat != 0 && lon != 0)
                {
                    await this.viewModel.NavigateDirectlyToStop(lat, lon, stopId);
                }
            }
            else if (parameter is StopSelectedEventArgs)
            {
                StopSelectedEventArgs stopSelectedEventArgs = (StopSelectedEventArgs)parameter;
                await this.viewModel.NavigateDirectlyToStop(
                    stopSelectedEventArgs.Latitude,
                    stopSelectedEventArgs.Longitude,
                    stopSelectedEventArgs.SelectedStopId,
                    stopSelectedEventArgs.StopName,
                    stopSelectedEventArgs.Direction);
            }
        }
コード例 #2
0
        /// <summary>
        /// Navigates to a page control.
        /// </summary>
        public void NavigateToPageControlByArguments(string arguments)
        {
            IPageControl pageControl = null;
            object       parameter   = arguments;

            if (string.IsNullOrEmpty(arguments))
            {
                pageControl = new FavoritesPageControl();
            }
            else
            {
                PageInitializationParameters parameters;
                if (PageInitializationParameters.TryCreate(arguments, out parameters))
                {
                    string pageControlName = parameters.GetParameter <string>("pageControl");
                    if (!string.IsNullOrEmpty(pageControlName))
                    {
                        // Make sure the type is a valid page control:
                        Type pageControlType = Type.GetType(pageControlName, false);
                        if (pageControlType != null)
                        {
                            pageControl = Activator.CreateInstance(pageControlType) as IPageControl;
                            parameter   = parameters;
                        }
                    }
                }
            }

            // Important: to make sure we don't time out opening OBA on ARM devices, load the page control when we idle.
            var ignored = this.Dispatcher.RunIdleAsync(async() =>
            {
                await NavigationController.Instance.NavigateToPageControlAsync(pageControl, parameter);
            });
        }
コード例 #3
0
        /// <summary>
        /// Pages should be represent themselves as a string of parameters.
        /// </summary>
        public PageInitializationParameters GetParameters()
        {
            PageInitializationParameters parameters = new PageInitializationParameters();

            var selectedStop = this.viewModel.MapControlViewModel.SelectedBusStop;

            parameters.SetParameter("pageControl", this.GetType().FullName);
            parameters.SetParameter("stopId", selectedStop.StopId);
            parameters.SetParameter("lat", selectedStop.Latitude);
            parameters.SetParameter("lon", selectedStop.Longitude);

            return(parameters);
        }
コード例 #4
0
        /// <summary>
        /// Navigates to a page control by parsing an argument string. If the argument string is null or empty,
        /// then we default to the favorites page. If the string begins with "?" then we try and parse it as a
        /// deep link. If the string is anything else then we assume it's a search.
        /// </summary>
        public void NavigateToPageControlByArguments(string arguments)
        {
            IPageControl pageControl = null;
            object       parameter   = arguments;

            if (string.IsNullOrEmpty(arguments))
            {
                pageControl = new FavoritesPageControl();
            }
            else
            {
                PageInitializationParameters parameters;
                if (PageInitializationParameters.TryCreate(arguments, out parameters))
                {
                    string pageControlName = parameters.GetParameter <string>("pageControl");
                    if (!string.IsNullOrEmpty(pageControlName))
                    {
                        // Make sure the type is a valid page control:
                        Type pageControlType = Type.GetType(pageControlName, false);
                        if (pageControlType != null)
                        {
                            pageControl = Activator.CreateInstance(pageControlType) as IPageControl;
                            parameter   = parameters;
                        }
                    }
                }

                // We have a query string, but it's not structured in a way we expect, so let's assume it's a search query:
                if (pageControl == null)
                {
                    pageControl = new SearchResultsPageControl();
                }
            }

            // Important: to make sure we don't time out opening OBA on ARM devices, load the page control when we idle.
            var ignored = this.Dispatcher.RunIdleAsync(async cb =>
            {
                await NavigationController.Instance.NavigateToPageControlAsync(pageControl, parameter);
                await this.TryRegisterBackgroundTask();
            });
        }
コード例 #5
0
        /// <summary>
        /// Pages should be represent themselves as a string of parameters.
        /// </summary>
        public PageInitializationParameters GetParameters()
        {
            PageInitializationParameters parameters = new PageInitializationParameters();

            var selectedStop = this.viewModel.MapControlViewModel.SelectedBusStop;
            parameters.SetParameter("pageControl", this.GetType().FullName);
            parameters.SetParameter("stopId", selectedStop.StopId);
            parameters.SetParameter("lat", selectedStop.Latitude);
            parameters.SetParameter("lon", selectedStop.Longitude);

            return parameters;
        }
コード例 #6
0
        /// <summary>
        /// Runs the tile updating service.
        /// </summary>
        public static async Task UpdateTilesAsync(CancellationToken token)
        {
            // Inject the platform services into the PCL:
            ServiceRepository.FileService        = new FileService();
            ServiceRepository.GeoLocationService = new GeoLocationService();
            ServiceRepository.SettingsService    = new SettingsService();

            try
            {
                // First update the favorites:
                var favorites = await Model.Favorites.GetAsync();

                // Get the tracking data for favorites & filter it out by the routes:
                List <TrackingData> favoritesRealTimeData = new List <TrackingData>();
                foreach (StopAndRoutePair favorite in favorites)
                {
                    token.ThrowIfCancellationRequested();

                    // Get tracking data for this stop:
                    var            obaDataAccess = ObaDataAccess.Create();
                    TrackingData[] trackingData  = await obaDataAccess.GetTrackingDataForStopAsync(favorite.Stop, token);

                    // Adds the tracking data to the list:
                    favoritesRealTimeData.AddRange(from data in trackingData
                                                   where string.Equals(favorite.Route, data.RouteId, StringComparison.OrdinalIgnoreCase)
                                                   select data);
                }

                // Now it's time to update the main tile with data:
                TileXMLBuilder mainTileBuilder = new TileXMLBuilder();
                AppendTrackingDataToTile(mainTileBuilder, favoritesRealTimeData);

                // And now we can update the secondary tiles!
                var pinnedStopTiles = await SecondaryTile.FindAllAsync();

                foreach (var pinnedStopTile in pinnedStopTiles)
                {
                    token.ThrowIfCancellationRequested();
                    PageInitializationParameters parameters = null;

                    // Be safe and try this first...should never happen.
                    if (PageInitializationParameters.TryCreate(pinnedStopTile.Arguments, out parameters))
                    {
                        double lat    = parameters.GetParameter <double>("lat");
                        double lon    = parameters.GetParameter <double>("lon");
                        string stopId = parameters.GetParameter <string>("stopId");

                        if (!string.IsNullOrEmpty(stopId) && lat != 0 && lon != 0)
                        {
                            // Get the tracking data:
                            var            obaDataAccess = ObaDataAccess.Create(lat, lon);
                            TrackingData[] trackingData  = await obaDataAccess.GetTrackingDataForStopAsync(stopId, token);

                            TileXMLBuilder secondaryTileBuilder = new TileXMLBuilder(pinnedStopTile.TileId);

                            await secondaryTileBuilder.AppendTileWithLargePictureAndTextAsync(
                                pinnedStopTile.TileId,
                                lat,
                                lon,
                                pinnedStopTile.DisplayName);

                            AppendTrackingDataToTile(secondaryTileBuilder, trackingData);
                        }
                    }
                }
            }
            catch
            {
                // Sometimes OBA will fail. What can you do?
            }
        }