Exemple #1
0
        public async Task FetchFullDownloadableDataIntoDatabase(
            string exhibitId, int idForRestApi, CancellationToken token, IProgressListener listener)
        {
            double totalSteps = await FetchNeededMediaForFullExhibit(idForRestApi);

            if (token.IsCancellationRequested)
            {
                return;
            }

            listener.SetMaxProgress(totalSteps);

            // We need to attach all images since the quiz download may download existing images
            var itemsToTrack = DbManager
                               .DataAccess
                               .GetItems <Image>()
                               .Where(image => image.Id != BackupData.BackupImage.Id && image.Id != BackupData.BackupImageTag.Id);
            await mediaDataFetcher.FetchMedias(requiredMedia, token, listener);

            var quizzes = await DownloadQuizes(idForRestApi, token);

            var mediaToFilePath = await mediaDataFetcher.WriteMediaToDiskAsync();

            DbManager.InTransaction(itemsToTrack, transaction =>
            {
                ProcessPages(exhibitId, token, transaction.DataAccess, mediaToFilePath);
                transaction.DataAccess.Quizzes().Add(quizzes);

                if (token.IsCancellationRequested)
                {
                    transaction.Rollback();
                }
            });
        }
Exemple #2
0
        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 Task <Dictionary <MediaDto, string> > WriteMediaToDiskAsync()
 {
     return(mediaDataFetcher.WriteMediaToDiskAsync());
 }