public static async Task <QueryBANResponse> RunAsync( QueryBANRequest request, GetCacheKey getCacheKey, GetCacheAsync getCache, SetCacheAsync setCache ) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!request.IsValid) { throw new ArgumentException(nameof(request)); } string content = await getCache?.Invoke(getCacheKey?.Invoke(request)); if (string.IsNullOrEmpty(content)) { content = request.Coordinates == null ? await LookupAddressAsync(request.Address) : await LookupLocationAsync(request.Coordinates); await setCache?.Invoke(getCacheKey?.Invoke(request), content); } return(GetAddressInfos(content)); }
public static async Task <GuessIPLocationResponse> RunAsync( GuessIPLocationRequest request, GetCacheKey getCacheKey, GetCacheAsync getCache, SetCacheAsync setCache ) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!request.IsValid) { throw new ArgumentException(nameof(request)); } string content = await getCache?.Invoke(getCacheKey?.Invoke(request)); if (string.IsNullOrEmpty(content)) { content = await QueryIPGeolocationAsync(request.IP); await setCache?.Invoke(getCacheKey?.Invoke(request), content); } return(new GuessIPLocationResponse(GetLocation(content), false)); }
public static async Task <QuerySireneResponse> RunAsync( QuerySireneRequest request, GetCacheKey getCacheKey, GetCacheAsync getCache, SetCacheAsync setCache ) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!request.IsValid) { throw new ArgumentException(nameof(request)); } string content = await getCache?.Invoke(getCacheKey?.Invoke(request)); if (string.IsNullOrEmpty(content)) { content = await QueryOrganizationsAsync(request.Token, request.Siren, request.Siret); await setCache?.Invoke(getCacheKey?.Invoke(request), content); } var infos = GetOrganizationsInfos(content); return(new QuerySireneResponse(infos)); }
public static async Task <GetSireneAccessTokenResponse> RunAsync( GetSireneAccessTokenRequest request, GetCacheKey getCacheKey, GetCacheAsync getCache, SetCacheAsync setCache ) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!request.IsValid) { throw new ArgumentException(nameof(request)); } API.GetSireneAccessTokenResponse respAccessToken; if (request.IsCheckCache) { respAccessToken = await getCache?.Invoke(getCacheKey?.Invoke(request)); if (respAccessToken != null) { Configuration.Instance.LogInformation($"Sirene access token loaded from cache: {JsonConvert.SerializeObject(respAccessToken)}"); } if (respAccessToken?.Age < AgeMax && !(respAccessToken?.IsExpired ?? true)) { Configuration.Instance.LogInformation("Sirene access token recycled."); return(respAccessToken); } Configuration.Instance.LogInformation("Sirene access token out of date."); } Configuration.Instance.LogInformation("Request new Sirene access token."); respAccessToken = await GetSireneAccessTokenAsync(); await setCache?.Invoke(getCacheKey?.Invoke(request), respAccessToken); return(respAccessToken); }
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)); }
public static async Task <ScrapSellerResponse> RunAsync( ScrapSellerRequest request, GetCacheKey getCacheKey, GetCacheAsync getCache, SetCacheAsync setCache ) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!request.IsValid) { throw new ArgumentException(nameof(request)); } var scrapper = ScrapSellerFactory.CreateInstance(request.MarketPlaceID); if (scrapper == null) { throw new NotSupportedException(request.MarketPlaceID); } string content = await getCache?.Invoke(getCacheKey?.Invoke(request)); if (string.IsNullOrEmpty(content)) { content = await WebUtils.GetWebPageAsync(scrapper.GetPageUri(request.SellerID)); await setCache?.Invoke(getCacheKey?.Invoke(request), content); } var properties = scrapper.GetProperties(content); return(new ScrapSellerResponse(request.SellerID, properties)); }