public async Task <PublishDeltaResult> PublishProductDeltas(IEnumerable <Product> products, IEnumerable <DeletedProductSku> deletedProducts, IEnumerable <AccountPrice> accountPrices, IEnumerable <DeletedAccountPrice> deletedAccountPrices, string accessKey)
        {
            var deltas             = new List <ProcessedProductDelta>();
            var publishDeltaResult = new PublishDeltaResult();
            var endpoint           = RegionEndpoints.GetRegionEndpoints(region);
            var fullEndpoint       = $"{endpoint.APIEndpoint}{deltaEndpointSuffix}";

            try
            {
                deltas = ConversionManager.ProcessProductDeltas(products, deletedProducts, accountPrices, deletedAccountPrices, accessKey);
            }
            catch (Exception e)
            {
                return(new PublishDeltaResult
                {
                    Success = false,
                    Errors = new List <PublishDeltaError> {
                        new PublishDeltaError {
                            Error = e.Message,
                            Skus = products.Count() > 0 ? products.Select(prod => prod.Sku) : null,
                            DeletedSkus = deletedProducts.Count() > 0 ? deletedProducts.Select(deletedProd => deletedProd.Sku) : null,
                            AccountPrices = accountPrices,
                            DeletedAccountPrices = deletedAccountPrices
                        }
                    }
                });
            }

            foreach (var delta in deltas)
            {
                try
                {
                    var json        = JSONSerialization.SerializeToJSON(delta);
                    var deltaResult = await HttpCalls.Post <DeltaResult>(json, fullEndpoint);

                    publishDeltaResult.Tokens.Add(deltaResult.Token);
                }
                catch (Exception e)
                {
                    publishDeltaResult.Errors.Add(new PublishDeltaError {
                        Error                = e.Message,
                        Skus                 = products.Count() > 0 ? products.Select(prod => prod.Sku) : null,
                        DeletedSkus          = deletedProducts.Count() > 0 ? deletedProducts.Select(deletedProd => deletedProd.Sku) : null,
                        AccountPrices        = accountPrices,
                        DeletedAccountPrices = deletedAccountPrices
                    });
                }
            }

            publishDeltaResult.Success = publishDeltaResult.Errors.Count == 0;
            return(publishDeltaResult);
        }
        public async Task <PublishFeedResult> PublishUserFeed(IEnumerable <User> users)
        {
            try
            {
                var userFeed = ConversionManager.ProcessUsers(users);
                var feedJSON = JSONSerialization.SerializeToJSON(userFeed);
                var endpoint = RegionEndpoints.GetRegionEndpoints(region);
                await UploadToSTFPAsync(feedJSON, endpoint.SFTPEndpoint);

                return(new PublishFeedResult {
                    Success = true, Token = ""
                });
            }
            catch (Exception e)
            {
                return(new PublishFeedResult {
                    Success = false, Error = e.Message
                });
            }
        }
        public async Task <PublishFeedResult> PublishProductFeed(IEnumerable <Product> products, IEnumerable <AccountPrice> accountPrices)
        {
            try
            {
                var productFeed = ConversionManager.ProcessProductFeed(products, accountPrices);
                var feedJSON    = JSONSerialization.SerializeToJSON(productFeed);
                var endpoint    = RegionEndpoints.GetRegionEndpoints(region);
                await UploadToSTFPAsync(feedJSON, endpoint.SFTPEndpoint);

                return(new PublishFeedResult {
                    Success = true, Token = ""
                });
            }
            catch (Exception e)
            {
                return(new PublishFeedResult {
                    Success = false, Error = e.Message, StackTrace = e.StackTrace
                });
            }
        }
示例#4
0
        private async Task <QueryTokensResult> CallTokenStatus(IEnumerable <string> tokens)
        {
            var queryResult = new QueryTokensResult();
            var tokenFeed   = new TokenFeed {
                AppKey = _accessKey, Tokens = tokens.ToArray()
            };
            var json    = JSONSerialization.SerializeToJSON(tokenFeed);
            var resonse = await HttpCalls.Post <JArray>(json, _fullEndpoint);

            if (resonse != null)
            {
                foreach (var jsonObject in resonse)
                {
                    var token = JsonConvert.DeserializeObject <TokenStatus>(jsonObject.ToString());
                    queryResult.TokenStatuses.Add(token);
                }
            }

            return(queryResult);
        }