Beispiel #1
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;
            }
        }
Beispiel #2
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;
            }
        }
        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;
            }
        }
Beispiel #4
0
 public async Task PingAsync()
 {
     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);
 }
Beispiel #5
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;
            }
        }
        private async Task <OrderResponseItem[]> GetOrdersPageAsync(OrderCriteria orderCriteria, Mark mark = null)
        {
            return(await AP.CreateQueryAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo, mark: mark)).Get(async() =>
            {
                var results = await this._client.GetOrderListAsync(this._credentials, this.AccountId, orderCriteria).ConfigureAwait(false);
                CheckCaSuccess(results.GetOrderListResult);
                var resultData = results.GetOrderListResult.ResultData ?? new OrderResponseItem[0];

                // If you get message code = 1 (Unexpected)
                if (results.GetOrderListResult.MessageCode == 1)
                {
                    resultData = await this.HandleErrorUnexpectedAsync(orderCriteria).ConfigureAwait(false);
                }

                return resultData;
            }).ConfigureAwait(false));
        }
        private async Task CheckFulfillmentStatusAsync <T>(List <T> orders, Mark mark = null) where T : OrderResponseItem
        {
            var refundedOrderIds = GetRefundedOrderIds(orders);

            if (refundedOrderIds.Count == 0)
            {
                return;
            }

            int pageSize;

            if (!this._pageSizes.TryGetValue("High", out pageSize))
            {
                pageSize = 50;
            }

            var ordersParts = ItemsService.ToChunks(refundedOrderIds, pageSize);

            ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: refundedOrderIds.ToJson()));
            var cancelledOrderIds = (await ordersParts.ProcessInBatchAsync(3, async part =>
            {
                var ordersFulfillment = await AP.CreateQueryAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(async() =>
                {
                    var results = await this._fulfillmentServiceClient.GetOrderFulfillmentDetailListAsync(this._fulfillmentServiceCredentials, this.AccountId, part.ToArray(), null).ConfigureAwait(false);
                    CheckCaSuccess(results.GetOrderFulfillmentDetailListResult);
                    var resultData = results.GetOrderFulfillmentDetailListResult.ResultData ?? new FulfillmentService.OrderFulfillmentResponse[0];

                    return(resultData);
                }).ConfigureAwait(false);

                ChannelAdvisorLogger.LogTrace(this.CreateMethodCallInfo(mark: mark, methodResult: ordersFulfillment.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: part.ToJson()));

                return(ordersFulfillment.Where(o => o.FulfillmentList.All(fulfillment => fulfillment.FulfillmentStatus == "Canceled")).Select(o => o.OrderID));
            }).ConfigureAwait(false)).SelectMany(x => x).ToArray();

            ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: cancelledOrderIds.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: refundedOrderIds.ToJson()));

            CancelOrders(orders, cancelledOrderIds);
        }