public IEnumerable <object> GetReportList(DateTime startDate, DateTime endDate) { var request = new GetReportListRequest { Merchant = "A12HYFEDED6DEW", AvailableFromDate = startDate, AvailableToDate = endDate, ReportTypeList = new TypeList { Type = new List <string> { "_GET_V2_SETTLEMENT_REPORT_DATA_XML_" } } }; var response = _amazonClient.GetReportList(request); var reportInfoList = response.GetReportListResult.ReportInfo; var nextToken = response.GetReportListResult.NextToken; var hasNext = response.GetReportListResult.HasNext; GetReportListByNextTokenResponse nextResponse = null; var reportCounter = 0; // pause for 2 seconds to give the Amazon MWS a little bit time to process the others Thread.Sleep(2000); // let's find the report we are interested in var reports = findReportTypes(reportInfoList); while (hasNext) { var nextRequest = new GetReportListByNextTokenRequest { Merchant = "A12HYFEDED6DEW", NextToken = nextToken }; nextResponse = _amazonClient.GetReportListByNextToken(nextRequest); reportInfoList = nextResponse.GetReportListByNextTokenResult.ReportInfo; nextToken = nextResponse.GetReportListByNextTokenResult.NextToken; hasNext = nextResponse.GetReportListByNextTokenResult.HasNext; // pause for 2 seconds, this is the restore rate for GetReportListByNextToken Thread.Sleep(2000); // find and add it to the list reports.AddRange(findReportTypes(reportInfoList)); foreach (var reportInfo in reports) { // check if the report request quota reach to 15 if (reportCounter % 15 == 0) { // if so, pause for 1 minute, this is the restore rate for GetReport Thread.Sleep(60000); } var stream = downloadReportStream(reportInfo.ReportId); // save the stream into a file saveStreamToFile(stream, string.Format("{0}_{1}", reportInfo.ReportType, reportInfo.ReportId)); reportCounter++; } // clear the reports lisst reports.Clear(); } return(null); }
public List <string> SubmitSettlementReportRequest(DateTime createdAfter, bool includeAcknowledged) { var request = new GetReportListRequest { Merchant = _merchantId, AvailableFromDate = createdAfter, AvailableToDate = DateTime.Now, ReportTypeList = new TypeList { Type = new List <string> { _SETTLEMENT_REPORT_TYPE } } }; var response = _amazonClient.GetReportList(request); var reportInfoList = response.GetReportListResult.ReportInfo; var nextToken = response.GetReportListResult.NextToken; var hasNext = response.GetReportListResult.HasNext; var reportCounter = 1; bool hasNextReport; var reportFilePaths = new List <string>(); var reportIds = new List <string>(); // pause for 2 seconds to give the Amazon MWS a little bit time to process the others Thread.Sleep(2000); do { hasNextReport = false; // download and parse the report info foreach (var reportInfo in reportInfoList) { if (!includeAcknowledged && reportInfo.Acknowledged) { continue; } // check if the report request quota reach to 15 if (reportCounter % 15 == 0) { // if so, pause for 1 minute, this is the restore rate for GetReport Thread.Sleep(60000); } var stream = downloadReportStream(reportInfo.ReportId); // save the stream into a file var filePath = saveStreamToFile(stream, string.Format("{0}{1}", reportInfo.ReportId, reportInfo.ReportType)); // add the filepath and report id to the lists reportFilePaths.Add(filePath); reportIds.Add(reportInfo.ReportId); reportCounter++; } // send another request for the next report list if (hasNext) { var nextRequest = new GetReportListByNextTokenRequest { Merchant = _merchantId, NextToken = nextToken }; var nextResponse = _amazonClient.GetReportListByNextToken(nextRequest); reportInfoList = nextResponse.GetReportListByNextTokenResult.ReportInfo; nextToken = nextResponse.GetReportListByNextTokenResult.NextToken; hasNext = nextResponse.GetReportListByNextTokenResult.HasNext; hasNextReport = reportInfoList.Any(); } } while (hasNextReport); // then let's send the acknowledgment to the Reports Ids submitReportsAcknowledgement(reportIds); return(reportFilePaths); }