public static ActionPolicyAsync CreateSubmitAsync(Func <string> additionalLogInfo = null) { return(ActionPolicyAsync.Handle <Exception>().RetryAsync(RetryCount, async(ex, i) => { var delay = GetDelay(ex, i); var message = CreateRetryMessage(additionalLogInfo, i, delay, ex); ChannelAdvisorLogger.LogTrace(ex, message); await Task.Delay(delay).ConfigureAwait(false); })); }
public async Task <List <BigCommerceCategory> > GetCategoriesAsync(CancellationToken token) { var categories = new List <BigCommerceCategory>(); var marker = this.GetMarker(); for (var i = 1; i < int.MaxValue; i++) { var endpoint = ""; //mainEndpoint.ConcatParams(ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit))); var categoriesWithinPage = await ActionPolicyAsync.Handle <Exception>().RetryAsync(ActionPolicies.RetryCount, (ex, retryAttempt) => { if (PageAdjuster.TryAdjustPageIfResponseTooLarge(new PageInfo(i, this.RequestMaxLimit), this.RequestMinLimit, ex, out var newPageInfo)) { i = newPageInfo.Index; this.RequestMaxLimit = newPageInfo.Size; } return(ActionPolicies.LogRetryAndWaitAsync(ex, marker, endpoint, retryAttempt)); }).Get(() => { return(this._webRequestServices.GetResponseByRelativeUrlAsync <BigCommerceCategoryInfoData>(BigCommerceCommand.GetCategoriesV3, endpoint, marker)); }); await this.CreateApiDelay(categoriesWithinPage.Limits, token); //API requirement if (categoriesWithinPage.Response == null) { break; } foreach (var product in categoriesWithinPage.Response.Data) { var productCatURL = product.Category_URL; categories.Add(new BigCommerceCategory { Id = product.Id, Category_URL = new BigCommerceCategoryURL() { Url = productCatURL.Url }, Category_Name = product.Name }); } if (categoriesWithinPage.Response.Data.Length < RequestMaxLimit) { break; } } return(categories); }
public static ActionPolicyAsync GetAsync(string marker, string url) { return(ActionPolicyAsync.Handle <Exception>().RetryAsync(RetryCount, async(ex, retryAttempt) => { var delay = TimeSpan.FromSeconds(5 + 20 * retryAttempt); BigCommerceLogger.LogTraceException(new RetryInfo() { Mark = marker, Url = url, CurrentRetryAttempt = retryAttempt, TotalRetriesAttempts = RetryCount, DelayInSeconds = delay.TotalSeconds, Category = MessageCategoryEnum.Warning }, ex); await Task.Delay(delay); })); }
public async Task <List <BigCommerceProduct> > GetProductsAsync(CancellationToken token, bool includeExtendedInfo) { var mainEndpoint = "?include=variants,images"; var products = new List <BigCommerceProduct>(); var marker = this.GetMarker(); for (var i = 1; i < int.MaxValue; i++) { var endpoint = mainEndpoint.ConcatParams(ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit))); var productsWithinPage = await ActionPolicyAsync.Handle <Exception>().RetryAsync(ActionPolicies.RetryCount, (ex, retryAttempt) => { if (PageAdjuster.TryAdjustPageIfResponseTooLarge(new PageInfo(i, this.RequestMaxLimit), this.RequestMinLimit, ex, out var newPageInfo)) { i = newPageInfo.Index; this.RequestMaxLimit = newPageInfo.Size; } return(ActionPolicies.LogRetryAndWaitAsync(ex, marker, endpoint, retryAttempt)); }).Get(() => { return(this._webRequestServices.GetResponseByRelativeUrlAsync <BigCommerceProductInfoData>(BigCommerceCommand.GetProductsV3, endpoint, marker)); }); await this.CreateApiDelay(productsWithinPage.Limits, token); //API requirement if (productsWithinPage.Response == null) { break; } foreach (var product in productsWithinPage.Response.Data) { var productImageThumbnail = product.Images.FirstOrDefault(img => img.IsThumbnail); var additional_images = product.Images; products.Add(new BigCommerceProduct { Id = product.Id, Sku = product.Sku, InventoryTracking = this.ToCompatibleWithV2InventoryTrackingEnum(product.InventoryTracking), Upc = product.Upc, Name = product.Name, Description = product.Description, Price = product.Price, SalePrice = product.SalePrice, RetailPrice = product.RetailPrice, CostPrice = product.CostPrice, Weight = product.Weight, BrandId = product.BrandId, Quantity = product.Quantity, ThumbnailImageURL = new BigCommerceProductPrimaryImages() { StandardUrl = productImageThumbnail != null ? productImageThumbnail.UrlStandard : string.Empty }, ProductOptions = product.Variants.Select(x => new BigCommerceProductOption { Id = x.Id, ProductId = x.ProductId, Sku = x.Sku, Quantity = x.Quantity, Upc = x.Upc, Price = x.Price, CostPrice = x.CostPrice, Weight = x.Weight, ImageFile = x.ImageUrl }).ToList(), Main_Images = product.Images.Select(y => new BigCommerceImage { UrlStandard = y.UrlStandard, IsThumbnail = y.IsThumbnail }).ToList() }); } if (productsWithinPage.Response.Data.Count < RequestMaxLimit) { break; } } if (includeExtendedInfo) { await base.FillWeightUnitAsync(products, token, marker); await base.FillBrandsAsync(products, token, marker); } return(products); }