public static async Task <GetEligibilityCheckerResponse> RunAsync(GetEligibilityCheckerRequest request) { return(await Task.Run(() => { 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); } return new GetEligibilityCheckerResponse(scraper.MarketPlaceID, scraper.JavaScriptEligibilityChecker); } )); }
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)); }