/** * Samples for Marketplace Web Service functionality */ public static void GetReport(string reportType, string fileName) { /************************************************************************ * Instantiate Implementation of Marketplace Web Service ***********************************************************************/ MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig(); /************************************************************************ * The application name and version are included in each MWS call's * HTTP User-Agent field. These are required fields. ***********************************************************************/ /************************************************************************ * All MWS requests must contain the seller's merchant ID and * marketplace ID. ***********************************************************************/ config.ServiceURL = GlobalConfig.Instance.ServiceURL; config.SetUserAgentHeader(GlobalConfig.Instance.AppName, GlobalConfig.Instance.AppVersion, "C#"); MarketplaceWebService service = new MarketplaceWebServiceClient(GlobalConfig.Instance.AccessKey, GlobalConfig.Instance.SecretKey, config); //*** 1. Submit a report request using the RequestReport operation. This is a request to Amazon MWS to generate a specific report. RequestReportRequest reportRequest = new RequestReportRequest(); reportRequest.Merchant = GlobalConfig.Instance.SellerId; // request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional reportRequest.MarketplaceIdList = new IdList(); reportRequest.MarketplaceIdList.Id = new List<string>( new string [] { GlobalConfig.Instance.MarketplaceId } ); reportRequest.ReportType = reportType; reportRequest.StartDate = new DateTime(2015, 8, 1); reportRequest.EndDate = new DateTime(2015, 9, 21); // @TODO: set additional request parameters here // request.ReportOptions = "ShowSalesChannel=true"; string reportRequestId = RequestReportSample.InvokeRequestReport(service, reportRequest); Dictionary<string, string> requestInfo = new Dictionary<string, string>(); requestInfo["ReportProcessingStatus"] = ""; requestInfo["GeneratedReportId"] = ""; /************************************************************************ * Uncomment to invoke Get Report Request List Action ***********************************************************************/ { GetReportRequestListRequest request = new GetReportRequestListRequest(); request.Merchant = GlobalConfig.Instance.SellerId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here request.ReportRequestIdList = new IdList(); request.ReportRequestIdList.Id = new List<string>(new string[] { reportRequestId }); while(requestInfo["ReportProcessingStatus"] != "_DONE_" && requestInfo["GeneratedReportId"] == "") { if(!GetReportRequestListSample.InvokeGetReportRequestList(service, request, requestInfo)) { // todo �쳣���� } //*** Request every 60s System.Threading.Thread.Sleep(1 * 60 * 1000); } } //*** 2. Using the GetReportList operation and include the ReportRequestId for the report requested. //*** The operation returns a ReportId that you can then pass to the GetReport operation 50193016685 { if (requestInfo["ReportProcessingStatus"] == "_DONE_" && requestInfo["GeneratedReportId"] == "") { GetReportListRequest getReportListRequest = new GetReportListRequest(); getReportListRequest.Merchant = GlobalConfig.Instance.SellerId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional getReportListRequest.ReportRequestIdList = new IdList(); getReportListRequest.ReportRequestIdList.Id = new List<string>(new string[] { reportRequestId }); string reportId = ""; while (reportId == "") { //*** Request every 60s System.Threading.Thread.Sleep(1 * 60 * 1000); reportId = GetReportListSample.InvokeGetReportList(service, getReportListRequest); } requestInfo["reportId"] = reportId; } } //*** 3. Submit a request using the GetReport operation to receive a specific report. //*** You include in the request the GeneratedReportId or the ReportId for the report you want to receive. //*** You then process the Content-MD5 header to confirm that the report was not corrupted during transmission. GetReportRequest getReportRequest = new GetReportRequest(); getReportRequest.Merchant = GlobalConfig.Instance.SellerId; // request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // Note that depending on the type of report being downloaded, a report can reach // sizes greater than 1GB. For this reason we recommend that you _always_ program to // MWS in a streaming fashion. Otherwise, as your business grows you may silently reach // the in-memory size limit and have to re-work your solution. // NOTE: Due to Content-MD5 validation, the stream must be read/write. if (requestInfo["GeneratedReportId"] != "" || requestInfo["reportId"] != "") { getReportRequest.ReportId = requestInfo["GeneratedReportId"] != "" ? requestInfo["GeneratedReportId"] : requestInfo["reportId"]; getReportRequest.Report = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); GetReportSample.InvokeGetReport(service, getReportRequest); getReportRequest.Report.Close(); } }
private void CheckAndWaitForDoneStatusOfRequestedReport() { ProcessingLog.LogAndPrintScreenMessage(string.Format("Get report request list based on Request Id: {0}", _requestedReportRequestId), true); bool reportWasDone = false; int timeOut = 60000 * UpdateOrdersAndInventoryConfigSection.ReportGenerationTimeOutMin.Value; int totalWaitTime = 0; while (!reportWasDone) { GetReportRequestListRequest reportRequestListRequest = new GetReportRequestListRequest(); reportRequestListRequest.Merchant = _merchant; reportRequestListRequest.ReportRequestIdList = new IdList(); reportRequestListRequest.ReportRequestIdList.Id = new List<string>(new string[] { _requestedReportRequestId }); GetReportRequestListResponse getReportRequestListResponse = _marketplaceWebService.GetReportRequestList(reportRequestListRequest); GetReportRequestListResult getReportRequestListResult = getReportRequestListResponse.GetReportRequestListResult; List<ReportRequestInfo> reportRequestInfoList = getReportRequestListResult.ReportRequestInfo; foreach (ReportRequestInfo reportRequestInfo in reportRequestInfoList) { if (reportRequestInfo.IsSetReportProcessingStatus()) { ProcessingLog.LogAndPrintScreenMessage(string.Format("Report processing status: {0}", reportRequestInfo.ReportProcessingStatus),true); if (reportRequestInfo.ReportProcessingStatus.Equals("_DONE_", StringComparison.InvariantCultureIgnoreCase) && reportRequestInfo.IsSetGeneratedReportId()) { reportWasDone = true; _amzDownloadedReportId = reportRequestInfo.GeneratedReportId; ProcessingLog.LogAndPrintScreenMessage(string.Format("Report was done and has a Report Id = {0}", _amzDownloadedReportId), true); } } } if (reportWasDone) continue; ProcessingLog.LogAndPrintScreenMessage("Report not _DONE_ wait 60 seconds and try until _DONE_ or timeout.", true); Thread.Sleep(60000); totalWaitTime += 60000; if (totalWaitTime >= timeOut) { throw new TimeoutException(string.Format("Exceeded time out of {0} minutes for report.", UpdateOrdersAndInventoryConfigSection.ReportGenerationTimeOutMin.Value)); } } }