示例#1
0
        private AmazonOrdersList GetUserOrders(AmazonOrdersRequestInfo amazonRequestInfo, ActionAccessType access)
        {
            const string getFlatFileOrdersDataRequestStr = "_GET_FLAT_FILE_ORDERS_DATA_";

            var reportRequestList = new RequestsListInfo(amazonRequestInfo, "GetUserOrders", access /*timeout: 3 hours*/, amazonRequestInfo.ErrorRetryingInfo);

            reportRequestList.AddRequest(getFlatFileOrdersDataRequestStr);

            RequestAndWait(reportRequestList);

            return(ParseOrdersResult(getFlatFileOrdersDataRequestStr, reportRequestList));
        }
示例#2
0
        private void RequestReports(RequestsListInfo reportRequestList)
        {
            var marketplaceIdList = new IdList {
                Id = reportRequestList.MarketPlaceId
            };
            var access = reportRequestList.Access;

            foreach (var requestInfo in reportRequestList)
            {
                var reportType = requestInfo.Name;

                var requestReportRequest = new RequestReportRequest {
                    MarketplaceIdList = marketplaceIdList,
                    Merchant          = reportRequestList.UserId,
                    ReportOptions     = "ShowSalesChannel=true",
                    ReportType        = reportType
                };

                if (reportRequestList.StartDate.HasValue)
                {
                    requestReportRequest.StartDate = reportRequestList.StartDate.Value.ToUniversalTime();
                }

                if (reportRequestList.EndDate.HasValue)
                {
                    requestReportRequest.EndDate = reportRequestList.EndDate.Value.ToUniversalTime();
                }

                RequestInfo info = requestInfo;

                var resp = AmazonWaitBeforeRetryHelper.DoServiceAction(
                    reportRequestList.ErrorRetryingInfo,
                    RequestGetReportTrapForThrottling,
                    reportType,
                    access,
                    reportRequestList.RequestsCounter,
                    () => _Service.RequestReport(requestReportRequest),
                    "RequestReport");

                if (resp != null && resp.IsSetRequestReportResult())
                {
                    info.SetId(resp.RequestReportResult.ReportRequestInfo.ReportRequestId);
                }
            }
        }
示例#3
0
        private void WaitRequestsDone(RequestsListInfo requestsListInfo)
        {
            var actionName       = requestsListInfo.ActionName;
            var timeOutInMinutes = requestsListInfo.TimeOutInMinutes;
            var access           = requestsListInfo.Access;

            var amazonIsdList = requestsListInfo.AmazonIds;

            var getReportRequestListRequest = new GetReportRequestListRequest {
                Merchant            = requestsListInfo.UserId,
                ReportRequestIdList = amazonIsdList
            };

            var endDate = DateTime.Now.AddMinutes(timeOutInMinutes);

            while (DateTime.Now <= endDate)
            {
                var reportRequestListResponse = AmazonWaitBeforeRetryHelper.DoServiceAction(
                    requestsListInfo.ErrorRetryingInfo,
                    ReportGetRequestListTrapForThrottling,
                    actionName,
                    access,
                    requestsListInfo.RequestsCounter,
                    () => _Service.GetReportRequestList(getReportRequestListRequest),
                    "GetReportRequestList");

                if (reportRequestListResponse != null && reportRequestListResponse.IsSetGetReportRequestListResult())
                {
                    var getReportRequestListResult = reportRequestListResponse.GetReportRequestListResult;

                    requestsListInfo.UpdateAmazonReportRequestInfo(getReportRequestListResult == null ? null : getReportRequestListResult.ReportRequestInfo);
                }

                if (!requestsListInfo.HasAmazonResult)
                {
                    continue;
                }

                if (requestsListInfo.IsDoneAll)
                {
                    break;
                }
            }
        }
示例#4
0
        private AmazonOrdersList ParseOrdersResult(string getFlatFileOrdersDataRequestStr, RequestsListInfo reportRequestList)
        {
            var requestInfo = reportRequestList.GetRequestByName(getFlatFileOrdersDataRequestStr);

            AmazonOrdersList data = new AmazonOrdersList(reportRequestList.StartDate.Value);

            if (requestInfo != null && requestInfo.IsDone)
            {
                var reportRequestInfo = requestInfo.ReportData;
                if (reportRequestInfo != null)
                {
                    data = new AmazonOrdersList(reportRequestInfo.SubmittedDate);

                    using (var stream = new MemoryStream()) {
                        GetReportData(requestInfo, stream);
                        ParseOrdersStream(data, stream);
                    }
                }
            }
            return(data);
        }
示例#5
0
 private void RequestAndWait(RequestsListInfo reportRequestList)
 {
     RequestReports(reportRequestList);
     WaitRequestsDone(reportRequestList);
 }
示例#6
0
 public RequestInfo(RequestsListInfo owner, string requestName)
 {
     Owner = owner;
     Name  = requestName;
     ResetData();
 }