public static async Task <ScrapProductResponse> RunAsync(ScrapProductRequest request)
 {
     return(await RunAsync(
                request,
                GetLocalCacheKey,
                GetLocalCacheAsync,
                SetLocalCacheAsync
                ));
 }
        public static async Task <ScrapProductResponse> RunAsync(
            ScrapProductRequest request,
            GetCacheKey getCacheKey,
            GetCacheAsync getCache,
            SetCacheAsync setCache
            )
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (!request.IsValid)
            {
                throw new ArgumentException(nameof(request));
            }

            var scraper = ScrapProductFactory.CreateInstance(request.Page);

            if (scraper == null)
            {
                throw new NotSupportedException(request.Page.Host);
            }

            string content = await getCache?.Invoke(getCacheKey?.Invoke(request));

            if (string.IsNullOrEmpty(content))
            {
                content = await WebUtils.GetWebPageAsync(request.Page);

                await setCache?.Invoke(getCacheKey?.Invoke(request), content);
            }

            string productName = scraper.GetProductName(content);
            var    sellerIDs   = scraper.GetSellers(content).Distinct().ToList();

            return(new ScrapProductResponse(scraper.MarketPlaceID, productName, sellerIDs, false));
        }
 private static string GetLocalCacheKey(ScrapProductRequest request) =>
 $"product_{HashUtils.ToMD5(request.Page.AbsoluteUri)}.html";