public async Task <IDictionary <long, IList <string> > > GetDownloadSourcesAsync(IStatus status)
        {
            var processUpdatesTask = await statusController.CreateAsync(status, "Process screenshots updates");

            var screenshotsSources = new Dictionary <long, IList <string> >();
            var current            = 0;
            var total = await screenshotsDataController.CountAsync(processUpdatesTask);

            var processProductsScreenshotsTask = await statusController.CreateAsync(processUpdatesTask, "Process product screenshots");

            foreach (var id in await screenshotsDataController.ItemizeAllAsync(processProductsScreenshotsTask))
            {
                var productScreenshots = await screenshotsDataController.GetByIdAsync(id, processProductsScreenshotsTask);

                if (productScreenshots == null)
                {
                    await statusController.WarnAsync(processProductsScreenshotsTask, $"Product {id} doesn't have screenshots");

                    continue;
                }

                await statusController.UpdateProgressAsync(
                    processUpdatesTask,
                    ++current,
                    total,
                    productScreenshots.Title);

                var currentProductScreenshotSources = new List <string>();

                foreach (var uri in productScreenshots.Uris)
                {
                    var sourceUri      = formatScreenshotsUriDelegate.Format(uri);
                    var destinationUri = Path.Combine(
                        screenshotsDirectoryDelegate.GetDirectory(string.Empty),
                        Path.GetFileName(sourceUri));

                    if (fileController.Exists(destinationUri))
                    {
                        continue;
                    }

                    currentProductScreenshotSources.Add(sourceUri);
                }

                if (currentProductScreenshotSources.Any())
                {
                    screenshotsSources.Add(id, currentProductScreenshotSources);
                }
            }

            await statusController.CompleteAsync(processProductsScreenshotsTask);

            await statusController.CompleteAsync(processUpdatesTask);

            return(screenshotsSources);
        }
Ejemplo n.º 2
0
        public async Task DownloadFromUriAsync(string sourceUri, string destination, IStatus status)
        {
            var downloadEntryTask = await statusController.CreateAsync(status, "Download from source");

            try
            {
                using (var response = await requestResponseAsyncDelegate.RequestResponseAsync(downloadEntryTask, HttpMethod.Get, sourceUri))
                    await downloadFromResponseAsyncDelegate.DownloadFromResponseAsync(response, destination, downloadEntryTask);
            }
            catch (Exception ex)
            {
                await statusController.WarnAsync(downloadEntryTask, $"{sourceUri}: {ex.Message}");
            }
            finally
            {
                await statusController.CompleteAsync(downloadEntryTask);
            }
        }
Ejemplo n.º 3
0
        public async Task SaveAsync(IStatus status)
        {
            if (!DataAvailable)
            {
                await statusController.WarnAsync(status,
                                                 "Attempted to save stashed data that has not been made available");

                return;
            }
            ;

            var saveStatus = await statusController.CreateAsync(status, "Save stored data", false);

            var storedDataUri = getPathDelegate.GetPath(string.Empty, string.Empty);

            await serializedStorageController.SerializePushAsync(storedDataUri, storedData, saveStatus);

            await statusController.CompleteAsync(saveStatus, false);
        }