Example #1
0
        private ListOrdersResponse InvokeListOrders(PXGraph graph, ServiceCallParameters objParams)
        {
            ListOrdersResponse response = new ListOrdersResponse();

            try
            {
                ListOrdersRequest request = new ListOrdersRequest();
                request.SellerId     = objParams.objSOAmazonSetup.SellerId;
                request.MWSAuthToken = objParams.objSOAmazonSetup.AuthToken;
                List <string> marketplaceId = new List <string>();
                marketplaceId.Add(objParams.objSOAmazonSetup.MarketplaceId);
                request.MarketplaceId = marketplaceId;
                request.CreatedAfter  = Convert.ToDateTime(objParams.fromDate);
                if (objParams.toDate.Value.Date < DateTime.Now.Date)
                {
                    request.CreatedBefore = objParams.toDate.Value.AddDays(1).AddTicks(-1);
                }
                PXTrace.WriteInformation("objParams.fromDate.Value.Date:" + objParams.fromDate.Value.Date.ToString());
                PXTrace.WriteInformation("objParams.toDate.Value.Date:" + objParams.toDate.Value.Date.ToString());
                PXTrace.WriteInformation("request.CreatedAfter:" + request.CreatedAfter.ToString());
                PXTrace.WriteInformation("request.CreatedBefore:" + request.CreatedBefore.ToString());
                List <string> liFulfillmentChannel = null;
                List <string> liOrderStatus        = null;
                SOHelper.GetFilterValues(objParams.objSOAmazonSetup.IntegrationType.Trim(), out liFulfillmentChannel, out liOrderStatus);
                request.FulfillmentChannel = liFulfillmentChannel;
                request.OrderStatus        = liOrderStatus;
                response = this.clientOrder.ListOrders(request);
            }
            catch (Exception ex)
            {
                if (ex is MarketplaceWebServiceOrdersException)
                {
                    MarketplaceWebServiceOrdersException exception = ex as MarketplaceWebServiceOrdersException;
                    if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOMessages.requestThrottled)
                    {
                        Thread.Sleep(SOHelper.DelayProcess(graph, SOConstants.apiListOrders));
                        response = InvokeListOrders(graph, objParams);
                    }
                    else
                    {
                        throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                              ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                           : SOConstants.exceptionIsEmpty);
                    }
                }
                else
                {
                    throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                          ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                            : SOConstants.exceptionIsEmpty);
                }
            }
            return(response);
        }