public async Task FetchFullDownloadableDataIntoDatabase( string routeId, int idForRestApi, CancellationToken token, IProgressListener listener) { routeDto = (await routesApiAccess.GetRoutes(new List <int> { idForRestApi })).Items.First(); if (token.IsCancellationRequested) { return; } route = DbManager.DataAccess.Routes().GetRoute(routeId); pagesAndMediaForMissingExhibits = new List <ExhibitPagesAndMediaContainer>(); var allMissingExhibits = DbManager.DataAccess.Exhibits().GetExhibits().ToList().FindAll(x => !x.DetailsDataLoaded); // Exhibits not fully loaded yet missingExhibitsForRoute = allMissingExhibits.ToList().FindAll(x => routeDto.Exhibits.Contains(x.IdForRestApi)); // Select those part of the route double totalSteps = FetchNeededMediaForFullRoute(); foreach (var exhibit in missingExhibitsForRoute) // Fetch media for missing exhibits and save them for later download { var pagesAndRequiredMediaForExhibit = await fullExhibitDataFetcher.FetchPagesAndMediaForExhibitFromRouteFetcher(exhibit.IdForRestApi); if (token.IsCancellationRequested) { return; } pagesAndMediaForMissingExhibits.Add(pagesAndRequiredMediaForExhibit); totalSteps += pagesAndRequiredMediaForExhibit.RequiredMedia.Count; } listener.SetMaxProgress(totalSteps); await AddFullExhibitsToRoute(route, token, listener); // Download all missing exhibits if (token.IsCancellationRequested) { return; } await FetchMediaData(token, listener); var mediaToFilePath = await mediaDataFetcher.WriteMediaToDiskAsync(); DbManager.InTransaction(transaction => { var dataAccess = transaction.DataAccess; ProcessRoute(token, dataAccess, mediaToFilePath); // Download audio if (token.IsCancellationRequested) { transaction.Rollback(); } }); }
public async Task <bool> AnyRouteChanged(IReadOnlyDataAccess dataAccess) { RoutesDto changedRoutes; var dbRoutes = dataAccess.Routes().GetRoutes().ToList(); if (dbRoutes.Any()) { var latestTimestamp = dbRoutes.Max(x => x.Timestamp); changedRoutes = await routesApiAccess.GetRoutes(latestTimestamp); } else { changedRoutes = await routesApiAccess.GetRoutes(); } fetchedChangedRoutes = changedRoutes.Items; return(fetchedChangedRoutes.Any()); }