Ejemplo n.º 1
0
        public static async Task <DownloadManager> Create(RouteListing listing, CancellationToken cancellationToken)
        {
            listing.Progress     = 0;
            listing.ShowProgress = true;
            DownloadManager result = new DownloadManager();

            result.Listing = listing;
            result._Route  = result.Listing.Route;
            var stopsAndShapes = await ApiLayer.GetStopsAndShapesForRoute(result.Listing.Route.ID, cancellationToken);

            result._Shapes       = stopsAndShapes.Item2;
            result._StopsPending = new ObservableCollection <BusStop>(stopsAndShapes.Item1);
            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }
            result.Initialize();
            result._TotalStops = result.StopsPending.Count;
            DownloadsInProgress.Add(result);
            if (!FileManager.PendingDownloads.Any(item => item.First() == result.Route.ID))
            {
                List <string> pend = new List <string>()
                {
                    result.Route.ID
                };
                pend.AddRange(result.StopsPending.Select(stop => stop.ID));
                FileManager.PendingDownloads.Add(pend);
                await listing.RefreshIsDownloaded();

                await FileManager.SavePendingDownloads();
            }
            return(result);
        }
Ejemplo n.º 2
0
 public static async Task <Tuple <Tuple <BusStop[], string[]>, DataRetrievalMessage> > GetStopsAndShapesForRoute(string routeId, DataRetrievalOptions options, CancellationToken cancellationToken)
 {
     return(await CloudOrLocal(() => ApiLayer.GetStopsAndShapesForRoute(routeId, cancellationToken), () => FileManager.GetStopsAndShapesForRouteFromCache(routeId), options, typeof(OperationCanceledException)));
 }