Exemple #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;
            }
        }
        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;
            }
        }
        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;
            }
        }
Exemple #5
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;
            }
        }
Exemple #6
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;
            }
        }
Exemple #7
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;
            }
        }
Exemple #8
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 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;
            }
        }
Exemple #10
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 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;
            }
        }
Exemple #12
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;
            }
        }
Exemple #13
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 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);
        }
Exemple #15
0
        /// <summary>
        /// Determines whether request was successful or not.
        /// </summary>
        /// <param name="status">Result status</param>
        /// <param name="message">Result message</param>
        /// <param name="messageCode">Result message code</param>
        /// <param name="logError">Need to log error message</param>
        /// <returns>
        ///     <c>true</c> if request was successful; otherwise, <c>false</c>.
        /// </returns>
        private bool IsRequestSuccessfulCommon(ResultStatus status, string message, int messageCode, bool logError = true)
        {
            var isRequestSuccessful = status == ResultStatus.Success && messageCode == 0;

            if (!isRequestSuccessful && logError)
            {
                ChannelAdvisorLogger.LogTrace(string.Format("CA Api Request for '{0}' failed with message: {1}", this.AccountId, message));
            }

            return(isRequestSuccessful);
        }
        /// <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;
            }
        }
Exemple #17
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;
            }
        }
        private void CheckFulfillmentStatus <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 cancelledOrderIds = new List <int>();
            var ordersParts       = ItemsService.ToChunks(refundedOrderIds, pageSize);

            ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: refundedOrderIds.ToJson()));
            foreach (var part in ordersParts)
            {
                var ordersFulfillment = AP.CreateQuery(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(() =>
                {
                    var results = this._fulfillmentServiceClient.GetOrderFulfillmentDetailList(this._fulfillmentServiceCredentials, this.AccountId, part.ToArray(), null);
                    CheckCaSuccess(results);
                    var resultData = results.ResultData ?? new FulfillmentService.OrderFulfillmentResponse[0];

                    return(resultData);
                });

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

                var cancelledOrderIdsPart = ordersFulfillment.Where(o => o.FulfillmentList.All(fulfillment => fulfillment.FulfillmentStatus == "Canceled")).Select(o => o.OrderID);
                cancelledOrderIds.AddRange(cancelledOrderIdsPart);
            }
            ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: cancelledOrderIds.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: refundedOrderIds.ToJson()));

            CancelOrders(orders, cancelledOrderIds);
        }
        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);
        }
        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;
            }
        }
Exemple #21
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;
            }
        }
Exemple #22
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;
            }
        }
        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;
            }
        }
 public async Task DoDelayUnexpectedAsync(TimeSpan time, int attempt)
 {
     ChannelAdvisorLogger.LogTrace(string.Format(@"Wait by reason of error 1 (Unexpected) {0} minute(s). Attempt: {1}", time.Minutes, attempt));
     await Task.Delay(time).ConfigureAwait(false);
 }
Exemple #25
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;
            }
        }