Example #1
0
        public void Ping(Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString));

                AP.CreateQuery(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(() =>
                {
                    var result = this._client.Ping(this._credentials);
                    this.CheckCaSuccess(result);
                });

                ChannelAdvisorLogger.LogTraceEnd(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString));
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
        public void UpdateQuantityAndPrices(IEnumerable <InventoryItemQuantityAndPrice> itemQuantityAndPrices, Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: itemQuantityAndPrices.ToJson()));

                var itemQuantityAndPricesByPages = ToChunks(itemQuantityAndPrices, 500);
                foreach (var itemsPage in itemQuantityAndPricesByPages)
                {
                    AP.CreateSubmit(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(() =>
                    {
                        ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : itemsPage.ToJson()));
                        var resultOfBoolean = this._client.UpdateInventoryItemQuantityAndPriceList(this._credentials, this.AccountId, itemsPage.ToArray());
                        CheckCaSuccess(resultOfBoolean);
                        ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : resultOfBoolean.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : itemsPage.ToJson()));
                    });
                }

                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: "void", additionalInfo: this.AdditionalLogInfo(), methodParameters: itemQuantityAndPrices.ToJson()));
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
Example #3
0
        public async Task DeleteItemAsync(string sku, Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: sku));

                await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() =>
                {
                    ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : sku));
                    var resultOfBoolean = await this._client.DeleteInventoryItemAsync(this._credentials, this.AccountId, sku).ConfigureAwait(false);
                    CheckCaSuccess(resultOfBoolean.DeleteInventoryItemResult);
                    ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : resultOfBoolean.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : sku));
                }).ConfigureAwait(false);

                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: sku));
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
Example #4
0
        public async Task <ClassificationConfigurationInformation[]> GetClassificationConfigInfoAsync(Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()));

                var classificationConfigurationInformations = await AP.CreateQueryAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(async() =>
                {
                    ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()));
                    var result = await this._client.GetClassificationConfigurationInformationAsync(this._credentials, this.AccountId).ConfigureAwait(false);
                    CheckCaSuccess(result.GetClassificationConfigurationInformationResult);
                    ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : result.ToJson(), additionalInfo: this.AdditionalLogInfo()));
                    return(result.GetClassificationConfigurationInformationResult.ResultData);
                }).ConfigureAwait(false);

                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: classificationConfigurationInformations.ToJson(), additionalInfo: this.AdditionalLogInfo()));
                return(classificationConfigurationInformations);
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
        public async Task AssignLabelListToItemListAsync(string[] labels, bool createLabelIfNotExist, IEnumerable <string> skus, string reason, Mark mark = null)
        {
            Condition.Requires(labels, "labels").IsShorterOrEqual(3, "Only up to 3 labels allowed.").IsNotNull();

            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            var parameters = new { labels, createLabelIfNotExist, skus, reason };

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson()));

                await skus.DoWithPagesAsync(500, async s => await AP.CreateSubmitAsync( ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do( async() =>
                {
                    ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : s.ToJson()));
                    var resultOfBoolean = await this._client.AssignLabelListToInventoryItemListAsync(this._credentials, this.AccountId, labels, createLabelIfNotExist, s.ToArray(), reason).ConfigureAwait(false);
                    CheckCaSuccess(resultOfBoolean.AssignLabelListToInventoryItemListResult);
                    ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : resultOfBoolean.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : s.ToJson()));
                } ).ConfigureAwait(false)).ConfigureAwait(false);

                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson()));
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
Example #6
0
        public async Task PingAsync(Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }
            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString));

                await AP.CreateQueryAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() =>
                {
                    var result = await this._client.PingAsync(this._credentials).ConfigureAwait(false);
                    this.CheckCaSuccess(result.PingResult);
                }).ConfigureAwait(false);

                ChannelAdvisorLogger.LogTraceEnd(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString));
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
Example #7
0
        public AuthorizationResponse[] GetAuthorizationList(string localId, Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }
            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString, methodParameters: localId));

                var authorizationResponses = AP.CreateSubmit(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(() =>
                {
                    var result = this._client.GetAuthorizationList(this._credentials, localId);
                    this.CheckCaSuccess(result);
                    return(result.ResultData);
                });

                ChannelAdvisorLogger.LogTraceEnd(this.CreateMethodCallInfo(mark: mark, methodResult: authorizationResponses.ToJson(), additionalInfo: this.AdditionalLogInfoString, methodParameters: localId));

                return(authorizationResponses);
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
        public async Task UpdateQuantityAndPricesAsync(IEnumerable <InventoryItemQuantityAndPrice> itemQuantityAndPrices, Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: itemQuantityAndPrices.ToJson()));

                var itemQuantityAndPricesByPages = ToChunks(itemQuantityAndPrices, 800);
                await itemQuantityAndPricesByPages.DoInBatchAsync(3, async itemsPage =>
                {
                    await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() =>
                    {
                        ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : itemsPage.ToJson()));
                        var result = await this._client.UpdateInventoryItemQuantityAndPriceListAsync(this._credentials, this.AccountId, itemsPage.ToArray()).ConfigureAwait(false);
                        CheckCaSuccess(result.UpdateInventoryItemQuantityAndPriceListResult);
                        ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : result.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : itemsPage.ToJson()));
                    }).ConfigureAwait(false);
                }).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
Example #9
0
        public async Task <bool> RequestAccessAsync(int localId, Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }
            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString, methodParameters: localId.ToString()));

                var requestAsyncResult = await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(async() =>
                {
                    var result = await this._client.RequestAccessAsync(this._credentials, localId).ConfigureAwait(false);
                    this.CheckCaSuccess(result.RequestAccessResult);
                    return(result.RequestAccessResult.ResultData);
                }).ConfigureAwait(false);

                ;
                ChannelAdvisorLogger.LogTraceEnd(this.CreateMethodCallInfo(mark: mark, methodResult: requestAsyncResult.ToJson(), additionalInfo: this.AdditionalLogInfoString, methodParameters: localId.ToString()));

                return(requestAsyncResult);
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
        public async Task PingAsync(Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()));
                await AP.CreateQueryAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() =>
                {
                    ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()));
                    var result = await this._client.PingAsync(this._credentials).ConfigureAwait(false);
                    ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : result.ToJson(), additionalInfo: this.AdditionalLogInfo()));
                    this.CheckCaSuccess(result.PingResult);
                }).ConfigureAwait(false);

                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()));
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
        public async Task SynchItemAsync(InventoryItemSubmit item, bool isCreateNew = false, Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            var parameters = new { item, isCreateNew };

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson()));

                await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() =>
                {
                    ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : parameters.ToJson()));
                    if (!isCreateNew && !(await this.DoesSkuExistAsync(item.Sku, mark).ConfigureAwait(false)))
                    {
                        return;
                    }

                    var resultOfBoolean = await this._client.SynchInventoryItemAsync(this._credentials, this.AccountId, item).ConfigureAwait(false);
                    CheckCaSuccess(resultOfBoolean.SynchInventoryItemResult);
                    ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : resultOfBoolean.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : parameters.ToJson()));
                }).ConfigureAwait(false);

                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: "void", additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson()));
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
Example #12
0
        public DistributionCenterResponse[] GetDistributionCenterList(Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()));

                var distributionCenterResponses = AP.CreateQuery(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(() =>
                {
                    ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()));
                    var result = this._client.GetDistributionCenterList(this._credentials, this.AccountId);
                    this.CheckCaSuccess(result);
                    ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : result.ToJson(), additionalInfo: this.AdditionalLogInfo()));
                    return(result.ResultData);
                });
                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: distributionCenterResponses.ToJson(), additionalInfo: this.AdditionalLogInfo()));
                return(distributionCenterResponses);
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
        private void LogUnexpectedError(OrderCriteria orderCriteria, APIResultOfArrayOfOrderResponseItem orderList, int?pageNumberBy1, string callerMemberName, int attempt)
        {
            var additionalLogInfo = ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo, callerMemberName)();
            var criteria          = string.Format("StatusUpdateFilterBeginTimeGMTField: {0}. StatusUpdateFilterEndTimeGMTField: {1}. Number in sequence for pageSize equal 1 : {2}", orderCriteria.StatusUpdateFilterBeginTimeGMT.GetValueOrDefault(), orderCriteria.StatusUpdateFilterEndTimeGMT.GetValueOrDefault(), pageNumberBy1);
            var message           = "Unexpected Error. Attempt: {0}. Additional info: {1} {2}".FormatWith(attempt, additionalLogInfo, criteria);
            var exception         = new ChannelAdvisorException(orderList.MessageCode, message);

            ChannelAdvisorLogger.LogTraceException(exception);
        }
Example #14
0
        public async Task <IEnumerable <string> > GetFilteredSkusAsync(ItemsFilter filter, Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson()));
                filter.Criteria.PageSize   = 100;
                filter.Criteria.PageNumber = 0;

                var skus = new List <string>();
                while (true)
                {
                    filter.Criteria.PageNumber += 1;
                    var itemResponse = await AP.CreateQueryAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(async() =>
                    {
                        ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : filter.ToJson()));
                        var getFilteredSkuListResponse = await this._client.GetFilteredSkuListAsync
                                                             (this._credentials, this.AccountId, filter.Criteria,
                                                             filter.SortField, filter.SortDirection).ConfigureAwait(false);
                        ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : getFilteredSkuListResponse.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : filter.ToJson()));
                        return(getFilteredSkuListResponse);
                    }).ConfigureAwait(false);

                    ChannelAdvisorLogger.LogTrace(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndReturnsForTrace) ? null : itemResponse.ToJson(), additionalInfo: this.AdditionalLogInfo()));

                    if (!this.IsRequestSuccessful(itemResponse.GetFilteredSkuListResult))
                    {
                        continue;
                    }

                    var pageSkus = itemResponse.GetFilteredSkuListResult.ResultData;
                    if (pageSkus == null)
                    {
                        ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: skus.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson()));
                        return(skus);
                    }

                    skus.AddRange(pageSkus);

                    if (pageSkus.Length == 0 || pageSkus.Length < filter.Criteria.PageSize)
                    {
                        ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: skus.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson()));
                        return(skus);
                    }
                }
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
        /// <summary>
        /// Gets the orders.
        /// </summary>
        /// <typeparam name="T">Type of order response.</typeparam>
        /// <param name="orderCriteria">The order criteria.</param>
        /// <param name="mark"></param>
        /// <returns>Orders matching supplied criteria.</returns>
        public async Task <IEnumerable <T> > GetOrdersAsync <T>(OrderCriteria orderCriteria, Mark mark = null)
            where T : OrderResponseItem
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: orderCriteria.ToJson()));

                if (string.IsNullOrEmpty(orderCriteria.DetailLevel))
                {
                    orderCriteria.DetailLevel = "High";
                }

                int pageSize;
                orderCriteria.PageSize         = this._pageSizes.TryGetValue(orderCriteria.DetailLevel, out pageSize) ? pageSize : 20;
                orderCriteria.PageNumberFilter = 1;

                var orders = new List <T>();
                while (true)
                {
                    var ordersFromPage = await this.GetOrdersPageAsync(orderCriteria, mark).ConfigureAwait(false);

                    if (ordersFromPage == null || ordersFromPage.Length == 0)
                    {
                        break;
                    }

                    orders.AddRange(ordersFromPage.OfType <T>());
                    orderCriteria.PageNumberFilter += 1;
                }

                await this.CheckFulfillmentStatusAsync(orders, mark);

                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: orders.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: orderCriteria.ToJson()));
                return(orders);
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: orderCriteria.ToJson()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
Example #16
0
        public IEnumerable <string> GetAllSkus(Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()));
                var filteredSkus = this.GetFilteredSkus(new ItemsFilter(), mark);
                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: filteredSkus.ToJson(), additionalInfo: this.AdditionalLogInfo()));
                return(filteredSkus);
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
        public void SynchItems(IEnumerable <InventoryItemSubmit> items, bool isCreateNew = false, Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            var parameters = new { items, isCreateNew };

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson()));

                if (!isCreateNew)
                {
                    var existSkus = this.DoSkusExist(items.Select(x => x.Sku), mark).Select(x => x.Sku);
                    items = items.Where(x => existSkus.Contains(x.Sku));
                }

                var itemsByPages = ToChunks(items, 100);
                foreach (var i in itemsByPages)
                {
                    AP.CreateSubmit(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(() =>
                    {
                        ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : i.ToJson()));
                        var resultOfBoolean = this._client.SynchInventoryItemList(this._credentials, this.AccountId, i.ToArray());
                        CheckCaSuccess(resultOfBoolean);
                        ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : resultOfBoolean.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : i.ToJson()));
                    });
                }
                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: "void", additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson()));
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
Example #18
0
        public async Task <AuthorizationResponse[]> GetAuthorizationListAsync(Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }
            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString));

                var authorizationResponses = await this.GetAuthorizationListAsync(string.Empty, mark).ConfigureAwait(false);

                ChannelAdvisorLogger.LogTraceEnd(this.CreateMethodCallInfo(mark: mark, methodResult: authorizationResponses.ToJson(), additionalInfo: this.AdditionalLogInfoString));

                return(authorizationResponses);
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
        public void RemoveLabelListFromItemList(string[] labels, IEnumerable <string> skus, string reason, Mark mark = null)
        {
            Condition.Requires(labels, "labels").IsShorterOrEqual(3, "Only up to 3 labels allowed.").IsNotNull();

            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            var parameters = new { labels, skus, reason };

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson()));

                var skusByPages = ToChunks(skus, 500);
                foreach (var s in skusByPages)
                {
                    AP.CreateSubmit(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(() =>
                    {
                        ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : s.ToJson()));
                        var resultOfBoolean = this._client.RemoveLabelListFromInventoryItemList(this._credentials, this.AccountId, labels, s.ToArray(), reason);
                        CheckCaSuccess(resultOfBoolean);
                        ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : resultOfBoolean.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : s.ToJson()));
                    });
                }

                ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson()));
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }
Example #20
0
        private void CheckCaSuccess(APIResultOfArrayOfShipmentResponse result)
        {
            if (result.Status != ResultStatus.Success)
            {
                throw new ChannelAdvisorException(result.MessageCode, result.Message);
            }
            ChannelAdvisorException exceptionToThrow = null;

            foreach (var shipmentResponse in result.ResultData)
            {
                if (!shipmentResponse.Success)
                {
                    ChannelAdvisorLogger.LogTrace(string.Format("Error encountered while marking order shipped: {0}", shipmentResponse.Message));
                    if (exceptionToThrow == null)
                    {
                        exceptionToThrow = new ChannelAdvisorException(shipmentResponse.Message);
                    }
                }
            }
            if (exceptionToThrow != null)
            {
                throw exceptionToThrow;
            }
        }
Example #21
0
        public IEnumerable <string> GetFilteredSkus(ItemsFilter filter, Mark mark = null)
        {
            if (mark.IsBlank())
            {
                mark = Mark.CreateNew();
            }

            try
            {
                ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson()));

                filter.Criteria.PageSize   = 100;
                filter.Criteria.PageNumber = 0;

                filter.DetailLevel.IncludeClassificationInfo = true;
                filter.DetailLevel.IncludePriceInfo          = true;
                filter.DetailLevel.IncludeQuantityInfo       = true;

                var filteredSkus = new List <string>();
                while (true)
                {
                    filter.Criteria.PageNumber += 1;
                    var itemResponse = AP.CreateQuery(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(
                        () =>
                    {
                        ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : filter.ToJson()));
                        var apiResultOfArrayOfString = this._client.GetFilteredSkuList
                                                       (
                            this._credentials, this.AccountId, filter.Criteria,
                            filter.SortField, filter.SortDirection);
                        ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: apiResultOfArrayOfString.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : filter.ToJson()));

                        return(apiResultOfArrayOfString);
                    });
                    ChannelAdvisorLogger.LogTrace(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndReturnsForTrace) ? null : itemResponse.ToJson(), additionalInfo: this.AdditionalLogInfo()));

                    if (!this.IsRequestSuccessful(itemResponse))
                    {
                        filteredSkus.Add(null);
                        continue;
                    }

                    var items = itemResponse.ResultData;

                    if (items == null)
                    {
                        ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: filteredSkus.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson()));
                        return(filteredSkus);
                    }

                    filteredSkus.AddRange(items);

                    if (items.Length == 0 || items.Length < filter.Criteria.PageSize)
                    {
                        ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: filteredSkus.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson()));
                        return(filteredSkus);
                    }
                }
            }
            catch (Exception exception)
            {
                var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception);
                ChannelAdvisorLogger.LogTraceException(channelAdvisorException);
                throw channelAdvisorException;
            }
        }