Exemple #1
0
        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;
                    }
                }
            });
        }
Exemple #2
0
        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);
        }
        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);
        }
Exemple #4
0
        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 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;
            }
        }
Exemple #6
0
        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
            });
        }
Exemple #7
0
        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);
        }