Пример #1
0
        public async Task UpdateScreenshotsAsync(Product product, IStatus status)
        {
            var requestProductPageTask = await statusController.CreateAsync(status, "Request product page containing screenshots information");

            var productPageUri     = string.Format(getUpdateUriDelegate.GetUpdateUri(Entity.Screenshots), product.Url);
            var productPageContent = await networkController.GetResourceAsync(requestProductPageTask, productPageUri);

            await statusController.CompleteAsync(requestProductPageTask);

            var extractScreenshotsTask = await statusController.CreateAsync(status, "Exract screenshots from the page");

            var extractedProductScreenshots = itemizeScreenshotsDelegates.Itemize(productPageContent);

            if (extractedProductScreenshots == null)
            {
                return;
            }

            var productScreenshots = new ProductScreenshots
            {
                Id    = product.Id,
                Title = product.Title,
                Uris  = new List <string>(extractedProductScreenshots)
            };
            await statusController.CompleteAsync(extractScreenshotsTask);

            var updateProductScreenshotsTask = await statusController.CreateAsync(status, "Add product screenshots");

            await screenshotsDataController.UpdateAsync(productScreenshots, updateProductScreenshotsTask);

            await statusController.CompleteAsync(updateProductScreenshotsTask);
        }
        public override async Task ProcessActivityAsync(IStatus status)
        {
            var updateProductsTask = await statusController.CreateAsync(status, $"Update {updateTypeDescription}");

            // We'll limit detail updates to user specified ids.
            // if user didn't provide a list of ids - we'll use the details gaps
            // (ids that exist in master list, but not detail) and updated
            var productsUpdateList = await itemizeUserRequestedOrDefaultAsyncDelegate.ItemizeAllAsync(updateProductsTask);

            var currentProduct = 0;

            foreach (var id in productsUpdateList)
            {
                var product = await masterDataController.GetByIdAsync(id, updateProductsTask);

                if (product == null)
                {
                    continue;
                }

                await statusController.UpdateProgressAsync(
                    updateProductsTask,
                    ++currentProduct,
                    productsUpdateList.Count(),
                    product.Title);

                var updateIdentity = getUpdateIdentityDelegate.GetUpdateIdentity(product);
                if (string.IsNullOrEmpty(updateIdentity))
                {
                    continue;
                }

                var uri = string.Format(
                    getUpdateUriDelegate.GetUpdateUri(context),
                    updateIdentity);

                var data = await getDeserializedDelegate.GetDeserializedAsync(updateProductsTask, uri);

                if (data != null)
                {
                    fillGapsDelegate?.FillGaps(data, product);
                    await detailDataController.UpdateAsync(data, updateProductsTask);
                }
            }

            await detailDataController.CommitAsync(updateProductsTask);

            await statusController.CompleteAsync(updateProductsTask);
        }
        public GetPageResultsAsyncDelegate(
            Entity context,
            IGetUpdateUriDelegate <Entity> getUpdateUriDelegate,
            IGetQueryParametersDelegate <Entity> getQueryParametersDelegate,
            IRequestPageAsyncDelegate requestPageAsyncDelegate,
            IGetHashAsyncDelegate <string> getStringHashDelegate,
            IStoredHashController storedHashController,
            ISerializationController <string> serializationController,
            IStatusController statusController)
        {
            this.context = context;
            this.getUpdateUriDelegate       = getUpdateUriDelegate;
            this.getQueryParametersDelegate = getQueryParametersDelegate;

            this.requestPageAsyncDelegate = requestPageAsyncDelegate;
            this.getStringHashDelegate    = getStringHashDelegate;
            this.storedHashController     = storedHashController;
            this.serializationController  = serializationController;

            this.statusController = statusController;

            requestUri        = getUpdateUriDelegate.GetUpdateUri(context);
            requestParameters = getQueryParametersDelegate.GetQueryParameters(context);
        }