/// <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); }); }
/// <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(); }); }
/// <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? } }