Beispiel #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);
            }
        }
Beispiel #2
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?
            }
        }