public List <BigCommerceProduct> GetProducts(bool includeExtendInfo) { var products = new List <BigCommerceProduct>(); var marker = this.GetMarker(); for (var i = 1; i < int.MaxValue; i++) { var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)); endpoint += includeExtendInfo ? ParamsBuilder.GetFieldsForProductSync() : ParamsBuilder.GetFieldsForInventorySync(); var productsWithinPage = ActionPolicies.Get(marker, endpoint).Get(() => this._webRequestServices.GetResponseByRelativeUrl <List <BigCommerceProduct> >(BigCommerceCommand.GetProductsV2_OAuth, endpoint, marker)); this.CreateApiDelay(productsWithinPage.Limits).Wait(); //API requirement if (productsWithinPage.Response == null) { break; } this.FillProductsSkus(productsWithinPage.Response, marker); products.AddRange(productsWithinPage.Response); if (productsWithinPage.Response.Count < RequestMaxLimit) { break; } } if (includeExtendInfo) { base.FillWeightUnit(products, marker); base.FillBrands(products, marker); } return(products); }
protected override async Task FillBrandsAsync(IEnumerable <BigCommerceProduct> products, CancellationToken token, string marker) { var brands = new List <BigCommerceBrand>(); for (var i = 1; i < int.MaxValue; i++) { var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)); var brandsWithinPage = await ActionPolicies.GetAsync(marker, endpoint).Get(async() => await this._webRequestServices.GetResponseByRelativeUrlAsync <List <BigCommerceBrand> >(BigCommerceCommand.GetBrandsV2, endpoint, marker)); await this.CreateApiDelay(brandsWithinPage.Limits, token); //API requirement if (brandsWithinPage.Response == null) { break; } brands.AddRange(brandsWithinPage.Response); if (brandsWithinPage.Response.Count < RequestMaxLimit) { break; } } this.FillBrandsForProducts(products, brands); }
private async Task <List <BigCommerceOrder> > GetOrdersForV3Async(DateTime dateFrom, DateTime dateTo, CancellationToken token) { var mainEndpoint = ParamsBuilder.CreateOrdersParams(dateFrom, dateTo); var orders = new List <BigCommerceOrder>(); var marker = this.GetMarker(); for (var i = 1; i < int.MaxValue; i++) { var compositeEndpoint = mainEndpoint.ConcatParams(ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit))); var ordersWithinPage = await ActionPolicies.GetAsync(marker, compositeEndpoint).Get(async() => await this._webRequestServices.GetResponseByRelativeUrlAsync <List <BigCommerceOrder> >(BigCommerceCommand.GetOrdersV2_OAuth, compositeEndpoint, marker)); await this.CreateApiDelay(ordersWithinPage.Limits, token); //API requirement if (ordersWithinPage.Response == null) { break; } await this.GetOrdersProductsAsync(ordersWithinPage.Response, ordersWithinPage.Limits.IsUnlimitedCallsCount, token, marker); await this.GetOrdersCouponsAsync(ordersWithinPage.Response, ordersWithinPage.Limits.IsUnlimitedCallsCount, token, marker); await this.GetOrdersShippingAddressesAsync(ordersWithinPage.Response, ordersWithinPage.Limits.IsUnlimitedCallsCount, token, marker); orders.AddRange(ordersWithinPage.Response); if (ordersWithinPage.Response.Count < RequestMaxLimit) { break; } } return(orders); }
public virtual async Task <GetMagentoInfoResponse> GetMagentoInfoAsync(bool suppressException, Mark mark = null) { try { const int maxCheckCount = 2; const int delayBeforeCheck = 1800000; var res = new magentoInfoResponse(); var privateClient = this._clientFactory.GetClient(); await ActionPolicies.GetWithMarkAsync(mark).Do(async() => { var statusChecker = new StatusChecker(maxCheckCount); TimerCallback tcb = statusChecker.CheckStatus; privateClient = this._clientFactory.RefreshClient(privateClient); var sessionId = await this.GetSessionId().ConfigureAwait(false); using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck)) res = await privateClient.magentoInfoAsync(sessionId.SessionId).ConfigureAwait(false); }).ConfigureAwait(false); return(new GetMagentoInfoResponse(res, this.GetServiceVersion())); } catch (Exception exc) { if (suppressException) { return(null); } throw new MagentoSoapException(string.Format("An error occured during GetMagentoInfoAsync()"), exc); } }
public List <BigCommerceOrder> GetOrdersForV3(DateTime dateFrom, DateTime dateTo) { var mainEndpoint = ParamsBuilder.CreateOrdersParams(dateFrom, dateTo); var orders = new List <BigCommerceOrder>(); var marker = this.GetMarker(); for (var i = 1; i < int.MaxValue; i++) { var compositeEndpoint = mainEndpoint.ConcatParams(ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit))); var ordersWithinPage = ActionPolicies.Get(marker, compositeEndpoint).Get(() => this._webRequestServices.GetResponseByRelativeUrl <List <BigCommerceOrder> >(BigCommerceCommand.GetOrdersV2_OAuth, compositeEndpoint, marker)); this.CreateApiDelay(ordersWithinPage.Limits).Wait(); //API requirement if (ordersWithinPage.Response == null) { break; } this.GetOrdersProducts(ordersWithinPage.Response, marker); this.GetOrdersCoupons(ordersWithinPage.Response, marker); this.GetOrdersShippingAddresses(ordersWithinPage.Response, marker); orders.AddRange(ordersWithinPage.Response); if (ordersWithinPage.Response.Count < RequestMaxLimit) { break; } } return(orders); }
protected async Task FillProductsSkusAsync(IEnumerable <BigCommerceProduct> products, bool isUnlimit, CancellationToken token, string marker) { var threadCount = isUnlimit ? MaxThreadsCount : 1; var skuProducts = products.Where(product => product.InventoryTracking.Equals(InventoryTrackingEnum.sku)); await skuProducts.DoInBatchAsync(threadCount, async product => { for (var i = 1; i < int.MaxValue; i++) { var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)); var options = await ActionPolicies.GetAsync(marker, endpoint).Get(async() => await this._webRequestServices.GetResponseByRelativeUrlAsync <List <BigCommerceProductOption> >(product.ProductOptionsReference.Url, endpoint, marker)); await this.CreateApiDelay(options.Limits, token); //API requirement if (options.Response == null) { break; } product.ProductOptions.AddRange(options.Response); if (options.Response.Count < RequestMaxLimit) { break; } } }); }
protected virtual void FillBrands(IEnumerable <BigCommerceProduct> products, string marker) { var brands = new List <BigCommerceBrand>(); for (var i = 1; i < int.MaxValue; i++) { var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)); var brandsWithinPage = ActionPolicies.Get(marker, endpoint).Get(() => this._webRequestServices.GetResponseByRelativeUrl <List <BigCommerceBrand> >(BigCommerceCommand.GetBrandsV2_OAuth, endpoint, marker)); this.CreateApiDelay(brandsWithinPage.Limits).Wait(); //API requirement if (brandsWithinPage.Response == null) { break; } brands.AddRange(brandsWithinPage.Response); if (brandsWithinPage.Response.Count < RequestMaxLimit) { break; } } this.FillBrandsForProducts(products, brands); }
private async Task <TResult> GetWithAsync <TResult, TServerResponse, TClient>(Func <TServerResponse, TResult> converter, Func <TClient, string, Task <TServerResponse> > action, int abortAfter, Func <TClient> clientFactory, Func <TClient, TClient> clientRecreateFactory, bool suppressException = false, Mark mark = null, [CallerMemberName] string callerName = null) where TServerResponse : new() where TClient : class { try { var res = new TServerResponse(); var privateClient = clientFactory(); await ActionPolicies.GetWithMarkAsync(mark).Do(async() => { privateClient = clientRecreateFactory(privateClient); var sessionId = await this.GetSessionId().ConfigureAwait(false); var temp = await ClientBaseActionRunner.RunWithAbortAsync( abortAfter, async() => res = await action(privateClient, sessionId.SessionId).ConfigureAwait(false), privateClient).ConfigureAwait(false); if (temp.Item2) { throw new TaskCanceledException(); } }).ConfigureAwait(false); return(converter(res)); } catch (Exception exc) { if (suppressException) { return(default(TResult)); } throw new MagentoSoapException($"An error occured during{callerName}->{nameof( this.GetWithAsync )}", exc); } }
private async Task GetOrdersCouponsAsync(IEnumerable <BigCommerceOrder> orders, bool isUnlimit, CancellationToken token, string marker) { var threadCount = isUnlimit ? MaxThreadsCount : 1; await orders.DoInBatchAsync(threadCount, async order => { if (string.IsNullOrWhiteSpace(order.CouponsReference?.Url)) { return; } for (var i = 1; i < int.MaxValue; i++) { var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)); var coupons = await ActionPolicies.GetAsync(marker, endpoint).Get(async() => await this._webRequestServices.GetResponseByRelativeUrlAsync <List <BigCommerceOrderCoupon> >(order.CouponsReference.Url, endpoint, marker)); await this.CreateApiDelay(coupons.Limits, token); //API requirement if (coupons.Response == null) { break; } order.Coupons.AddRange(coupons.Response); if (coupons.Response.Count < RequestMaxLimit) { break; } } }); }
private void GetOrdersCoupons(IEnumerable <BigCommerceOrder> orders, string marker) { foreach (var order in orders) { if (string.IsNullOrWhiteSpace(order.CouponsReference?.Url)) { continue; } for (var i = 1; i < int.MaxValue; i++) { var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)); var coupons = ActionPolicies.Get(marker, endpoint).Get(() => this._webRequestServices.GetResponseByRelativeUrl <List <BigCommerceOrderCoupon> >(order.CouponsReference.Url, endpoint, marker)); this.CreateApiDelay(coupons.Limits).Wait(); //API requirement if (coupons.Response == null) { break; } order.Coupons.AddRange(coupons.Response); if (coupons.Response.Count < RequestMaxLimit) { break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="GasStationController" /> class. /// </summary> /// <param name="unitOfWork">The unit of work.</param> public GasStationController(IUnitOfWorkAsync unitOfWork) : base(unitOfWork) { ActionPolicies.Add(ModelAction.Create, UserRoleEnum.Admin); ActionPolicies.Add(ModelAction.Update, UserRoleEnum.Admin); ActionPolicies.Add(ModelAction.Delete, UserRoleEnum.Admin); ActionPolicies.Add(ModelAction.Export, UserRoleEnum.Admin); ActionPolicies.Add(ModelAction.Publish, UserRoleEnum.Admin); }
protected virtual string GetSecureURL(string marker) { var command = BigCommerceCommand.GetStoreV2_OAuth; var store = ActionPolicies.Get(marker, command.Command).Get(() => this._webRequestServices.GetResponseByRelativeUrl <BigCommerceStore>(command, string.Empty, marker)); this.CreateApiDelay(store.Limits).Wait(); //API requirement return(store.Response.SecureURL); }
/// <summary> /// Initializes a new instance of the <see cref="NotebookController" /> class. /// </summary> /// <param name="unitOfWork">The unit of work.</param> /// <param name="userInfo">The user information.</param> public NotebookController(IUnitOfWorkAsync unitOfWork, IUserInfo userInfo) : base(unitOfWork, userInfo) { var AccessLevels = new[] { UserAccessLevel.User, UserAccessLevel.Admin }; ActionPolicies.Add(ModelAction.Read, AccessLevels); ActionPolicies.Add(ModelAction.Create, AccessLevels); ActionPolicies.Add(ModelAction.Update, AccessLevels); ActionPolicies.Add(ModelAction.Delete, AccessLevels); }
public virtual async Task <OrderInfoResponse> GetOrderAsync(string incrementId, Mark mark = null) { try { //var frameworkSearchFilterGroups = new List< FrameworkSearchFilterGroup > //{ // new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { field = "increment_id", conditionType = "eq", value = incrementId } } }, //}; //if( string.IsNullOrWhiteSpace( this.Store ) ) // frameworkSearchFilterGroups.Add( new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { field = "store_Id", conditionType = "eq", value = this.Store } } } ); var filters = new SalesOrderRepositoryV1GetRequest { id = int.Parse(incrementId) }; const int maxCheckCount = 2; const int delayBeforeCheck = 1800000; var res = new salesOrderRepositoryV1GetResponse1(); var privateClient = this._clientFactory.CreateMagentoSalesOrderRepositoryServiceClient(); await ActionPolicies.GetWithMarkAsync(mark).Do(async() => { var statusChecker = new StatusChecker(maxCheckCount); TimerCallback tcb = statusChecker.CheckStatus; privateClient = this._clientFactory.RefreshMagentoSalesOrderRepositoryServiceClient(privateClient); using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck)) try { res = await privateClient.salesOrderRepositoryV1GetAsync(filters).ConfigureAwait(false); } catch (Exception ex) { if (ex.Message.ToLower() == "requested entity doesn't exist") { res = null; return; } throw; } }).ConfigureAwait(false); return(res == null ? null : new OrderInfoResponse(res)); } catch (Exception exc) { throw new MagentoSoapException($"An error occured during GetOrderAsync(incrementId:{incrementId}) ", exc, mark); } }
public List <BigCommerceCategory> GetCategories() { 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 = ActionPolicy.Handle <Exception>().Retry(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; } ActionPolicies.LogRetryAndWait(ex, marker, endpoint, retryAttempt); }).Get(() => { return(this._webRequestServices.GetResponseByRelativeUrl <BigCommerceCategoryInfoData>(BigCommerceCommand.GetCategoriesV3, endpoint, marker)); }); this.CreateApiDelay(categoriesWithinPage.Limits).Wait(); //API requirement if (categoriesWithinPage.Response == null) { break; } foreach (var category in categoriesWithinPage.Response.Data) { var CatURL = category.Category_URL; categories.Add(new BigCommerceCategory { Id = category.Id, Category_URL = new BigCommerceCategoryURL() { Url = CatURL.Url }, Category_Name = category.Name, IsVisible = category.IsVisible }); } if (categoriesWithinPage.Response.Data.Length < RequestMaxLimit) { break; } } return(categories); }
protected override void FillWeightUnit(IEnumerable <BigCommerceProduct> products, string marker) { var command = BigCommerceCommand.GetStoreV2; var store = ActionPolicies.Get(marker, command.Command).Get(() => this._webRequestServices.GetResponseByRelativeUrl <BigCommerceStore>(command, string.Empty, marker)); this.CreateApiDelay(store.Limits).Wait(); //API requirement foreach (var product in products) { product.WeightUnit = store.Response.WeightUnits; } }
protected override async Task FillWeightUnitAsync(IEnumerable <BigCommerceProduct> products, CancellationToken token, string marker) { var command = BigCommerceCommand.GetStoreV2; var store = await ActionPolicies.GetAsync(marker, command.Command).Get(async() => await this._webRequestServices.GetResponseByRelativeUrlAsync <BigCommerceStore>(command, string.Empty, marker)); await this.CreateApiDelay(store.Limits, token); //API requirement foreach (var product in products) { product.WeightUnit = store.Response.WeightUnits; } }
public void UpdateProductOptions(List <BigCommerceProductOption> productOptions) { var marker = this.GetMarker(); foreach (var option in productOptions) { var endpoint = ParamsBuilder.CreateProductOptionUpdateEndpoint(option.ProductId, option.Id); var jsonContent = new { inventory_level = option.Quantity }.ToJson(); var limit = ActionPolicies.Submit(marker, endpoint).Get(() => this._webRequestServices.PutData(BigCommerceCommand.UpdateProductV2_OAuth, endpoint, jsonContent, marker)); this.CreateApiDelay(limit).Wait(); //API requirement } }
public void UpdateProducts(List <BigCommerceProduct> products) { var marker = this.GetMarker(); foreach (var product in products) { var endpoint = string.Format("/{0}", product.Id); var jsonContent = new { inventory_level = product.Quantity }.ToJson(); var limit = ActionPolicies.Submit(marker, endpoint).Get(() => this._webRequestServices.PutData(BigCommerceCommand.UpdateProductsV3, endpoint, jsonContent, marker)); this.CreateApiDelay(limit).Wait(); //API requirement } }
public async Task UpdateProductOptionsAsync(List <BigCommerceProductOption> productOptions, CancellationToken token) { var marker = this.GetMarker(); await productOptions.DoInBatchAsync(MaxThreadsCount, async productOption => { var endpoint = string.Format("/{0}/variants/{1}", productOption.ProductId, productOption.Id); var jsonContent = new { inventory_level = productOption.Quantity }.ToJson(); var limit = await ActionPolicies.SubmitAsync(marker, endpoint).Get(async() => await this._webRequestServices.PutDataAsync(BigCommerceCommand.UpdateProductsV3, endpoint, jsonContent, marker)); await this.CreateApiDelay(limit, token); //API requirement }); }
public async Task UpdateProductsAsync(List <BigCommerceProduct> products, CancellationToken token) { var marker = this.GetMarker(); await products.DoInBatchAsync(MaxThreadsCount, async product => { var endpoint = ParamsBuilder.CreateProductUpdateEndpoint(product.Id); var jsonContent = new { inventory_level = product.Quantity }.ToJson(); var limit = await ActionPolicies.SubmitAsync(marker, endpoint).Get(async() => await this._webRequestServices.PutDataAsync(BigCommerceCommand.UpdateProductV2_OAuth, endpoint, jsonContent, marker)); await this.CreateApiDelay(limit, token); //API requirement }); }
private void GetOrdersShippingAddresses(IEnumerable <BigCommerceOrder> orders, string marker) { foreach (var order in orders) { if (string.IsNullOrWhiteSpace(order.ShippingAddressesReference?.Url)) { continue; } var addresses = ActionPolicies.Get(marker, order.ShippingAddressesReference.Url).Get(() => this._webRequestServices.GetResponse <List <BigCommerceShippingAddress> >(order.ShippingAddressesReference.Url, marker)); order.ShippingAddresses = addresses.Response; this.CreateApiDelay(addresses.Limits).Wait(); //API requirement } }
private async Task GetOrdersShippingAddressesAsync(IEnumerable <BigCommerceOrder> orders, bool isUnlimit, CancellationToken token, string marker) { var threadCount = isUnlimit ? MaxThreadsCount : 1; await orders.DoInBatchAsync(threadCount, async order => { if (string.IsNullOrWhiteSpace(order.ShippingAddressesReference?.Url)) { return; } var addresses = await ActionPolicies.GetAsync(marker, order.ShippingAddressesReference.Url).Get(async() => await this._webRequestServices.GetResponseAsync <List <BigCommerceShippingAddress> >(order.ShippingAddressesReference.Url, marker)); order.ShippingAddresses = addresses.Response; await this.CreateApiDelay(addresses.Limits, token); //API requirement }); }
public virtual async Task <OrderInfoResponse> GetOrderAsync(string incrementId, Mark mark = null) { try { var filters = new SalesOrderRepositoryV1GetRequest { id = int.Parse(incrementId) }; const int maxCheckCount = 2; const int delayBeforeCheck = 1800000; var res = new salesOrderRepositoryV1GetResponse1(); var privateClient = this._clientFactory.CreateMagentoSalesOrderRepositoryServiceClient(); await ActionPolicies.GetWithMarkAsync(mark).Do(async() => { var statusChecker = new StatusChecker(maxCheckCount); TimerCallback tcb = statusChecker.CheckStatus; privateClient = this._clientFactory.RefreshMagentoSalesOrderRepositoryServiceClient(privateClient); using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck)) try { res = await privateClient.salesOrderRepositoryV1GetAsync(filters).ConfigureAwait(false); } catch (Exception ex) { if (ex.Message.ToLower() == "requested entity doesn't exist") { res = null; return; } throw; } }).ConfigureAwait(false); return(res == null ? null : new OrderInfoResponse(res)); } catch (Exception exc) { throw new MagentoSoapException($"An error occured during GetOrderAsync(incrementId:{incrementId}) ", exc, mark); } }
private async Task <salesOrderRepositoryV1GetListResponse1> GetOrdersPageByFilter(SalesOrderRepositoryV1GetListRequest filters, Mark mark) { const int maxCheckCount = 2; const int delayBeforeCheck = 1800000; var res = new salesOrderRepositoryV1GetListResponse1(); var privateClient = this._clientFactory.CreateMagentoSalesOrderRepositoryServiceClient(); await ActionPolicies.GetWithMarkAsync(mark).Do(async() => { var statusChecker = new StatusChecker(maxCheckCount); TimerCallback tcb = statusChecker.CheckStatus; privateClient = this._clientFactory.RefreshMagentoSalesOrderRepositoryServiceClient(privateClient); using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck)) res = await privateClient.salesOrderRepositoryV1GetListAsync(filters).ConfigureAwait(false); }).ConfigureAwait(false); return(res); }
protected void FillProductsSkus(IEnumerable <BigCommerceProduct> products, string marker) { foreach (var product in products.Where(product => product.InventoryTracking.Equals(InventoryTrackingEnum.sku))) { for (var i = 1; i < int.MaxValue; i++) { var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)); var options = ActionPolicies.Get(marker, endpoint).Get(() => this._webRequestServices.GetResponseByRelativeUrl <List <BigCommerceProductOption> >(product.ProductOptionsReference.Url, endpoint, marker)); this.CreateApiDelay(options.Limits).Wait(); //API requirement if (options.Response == null) { break; } product.ProductOptions.AddRange(options.Response); if (options.Response.Count < RequestMaxLimit) { break; } } } }
public async Task <List <BigCommerceProduct> > GetProductsAsync(CancellationToken token, bool includeExtendedInfo) { var products = new List <BigCommerceProduct>(); var marker = this.GetMarker(); for (var i = 1; i < int.MaxValue; i++) { var endpoint = ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)); endpoint += includeExtendedInfo ? ParamsBuilder.GetFieldsForProductSync() : ParamsBuilder.GetFieldsForInventorySync(); var productsWithinPage = await ActionPolicies.GetAsync(marker, endpoint).Get(async() => await base._webRequestServices.GetResponseByRelativeUrlAsync <List <BigCommerceProduct> >(BigCommerceCommand.GetProductsV2_OAuth, endpoint, marker)); await this.CreateApiDelay(productsWithinPage.Limits, token); //API requirement if (productsWithinPage.Response == null) { break; } await this.FillProductsSkusAsync(productsWithinPage.Response, productsWithinPage.Limits.IsUnlimitedCallsCount, token, marker); products.AddRange(productsWithinPage.Response); if (productsWithinPage.Response.Count < RequestMaxLimit) { break; } } if (includeExtendedInfo) { await base.FillWeightUnitAsync(products, token, marker); await base.FillBrandsAsync(products, token, marker); } return(products); }
public List <BigCommerceProduct> GetProducts(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 = ActionPolicy.Handle <Exception>().Retry(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; } ActionPolicies.LogRetryAndWait(ex, marker, endpoint, retryAttempt); }).Get(() => { return(this._webRequestServices.GetResponseByRelativeUrl <BigCommerceProductInfoData>(BigCommerceCommand.GetProductsV3, endpoint, marker)); }); this.CreateApiDelay(productsWithinPage.Limits).Wait(); //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; var custom_url = product.Product_URL; products.Add(new BigCommerceProduct { Id = product.Id, InventoryTracking = this.ToCompatibleWithV2InventoryTrackingEnum(product.InventoryTracking), Upc = product.Upc, Sku = product.Sku, Name = product.Name, Description = product.Description, Price = product.Price, IsProductVisible = product.IsVisible, Condition = product.Condition, Availability = product.Availability, ProductType = product.Type, SalePrice = product.SalePrice, RetailPrice = product.RetailPrice, CostPrice = product.CostPrice, Weight = product.Weight, BrandId = product.BrandId, Quantity = product.Quantity, Product_URL = custom_url.ProductURL, Categories = product.Categories, 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) { base.FillWeightUnit(products, marker); base.FillBrands(products, marker); } return(products); }
public virtual async Task <GetOrdersResponse> GetOrdersAsync(DateTime modifiedFrom, DateTime modifiedTo, Mark mark = null) { try { var frameworkSearchFilterGroups = new List <FrameworkSearchFilterGroup> { new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { field = "updated_At", conditionType = "gt", value = modifiedFrom.ToSoapParameterString() } } }, new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { field = "updated_At", conditionType = "lt", value = modifiedTo.ToSoapParameterString() } } }, }; if (!string.IsNullOrWhiteSpace(this.Store)) { frameworkSearchFilterGroups.Add(new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { field = "store_Id", conditionType = "eq", value = this.Store } } }); } var filters = new SalesOrderRepositoryV1GetListRequest { searchCriteria = new FrameworkSearchCriteria() { currentPage = 1, currentPageSpecified = true, filterGroups = frameworkSearchFilterGroups.ToArray(), sortOrders = new FrameworkSortOrder[] { new FrameworkSortOrder() { direction = "ASC", field = "Id" } }, pageSize = 100, pageSizeSpecified = true, } }; const int maxCheckCount = 2; const int delayBeforeCheck = 1800000; var res = new salesOrderRepositoryV1GetListResponse1(); var privateClient = this._clientFactory.CreateMagentoSalesOrderRepositoryServiceClient(); await ActionPolicies.GetWithMarkAsync(mark).Do(async() => { var statusChecker = new StatusChecker(maxCheckCount); TimerCallback tcb = statusChecker.CheckStatus; privateClient = this._clientFactory.RefreshMagentoSalesOrderRepositoryServiceClient(privateClient); using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck)) res = await privateClient.salesOrderRepositoryV1GetListAsync(filters).ConfigureAwait(false); }).ConfigureAwait(false); return(new GetOrdersResponse(res)); } catch (Exception exc) { throw new MagentoSoapException($"An error occured during GetOrdersAsync(modifiedFrom:{modifiedFrom},modifiedTo{modifiedTo})", exc); } }