/**
        * 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 MakeRequestForReport()
        {
            ProcessingLog.LogAndPrintScreenMessage("Make request for inventory report for JK529", true);

            RequestReportRequest requestReportRequest = new RequestReportRequest
            {
                Merchant = AccountSettingsConfigSection.Jk529_sellerId.Value,
                ReportType = ReportTypeToGet,
                MarketplaceIdList = new IdList
                {
                    Id = new List<string>(new[] { AccountSettingsConfigSection.Jk529_marketplaceId.Value })
                }
            };

            RequestReportResponse requestReportResponse = _marketplaceWebService.RequestReport(requestReportRequest);
            _requestedReportRequestId = requestReportResponse.RequestReportResult.ReportRequestInfo.ReportRequestId;

            ProcessingLog.LogAndPrintScreenMessage(string.Format("Inventory report for JK529 RequestId: {0}", _requestedReportRequestId), true);
            ProcessingLog.LogAndPrintScreenMessage("Wait for 60 seconds for Amazon to generate inventory report for JK529", true);

            for (int i = 0; i < 12; i++)
            {
                Console.Write("{0} ", 60 - i * 5);
                Thread.Sleep(5000);
            }
        }
        protected override void SetupAccountSettings()
        {
            base.SetupAccountSettings();

            string accessKey;
            string secretKey;
            string marketPlaceId;

            switch (Account)
            {
                case AccountEnum.AmzJk529:
                    accessKey = AccountSettingsConfigSection.Jk529_accessKey.Value;
                    secretKey = AccountSettingsConfigSection.Jk529_secretKey.Value;
                    _merchant = AccountSettingsConfigSection.Jk529_sellerId.Value;
                    marketPlaceId = AccountSettingsConfigSection.Jk529_marketplaceId.Value;
                    break;
                case AccountEnum.AmzRst:
                    accessKey = AccountSettingsConfigSection.Rst_accessKey.Value;
                    secretKey = AccountSettingsConfigSection.Rst_secretKey.Value;
                    _merchant = AccountSettingsConfigSection.Rst_sellerId.Value;
                    marketPlaceId = AccountSettingsConfigSection.Rst_marketplaceId.Value;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(Account.ToString());
            }

            _marketplaceWebService = new MarketplaceWebServiceClient(
                    accessKey,
                    secretKey,
                    AppName,
                    AppVersion,
                    new MarketplaceWebServiceConfig { ServiceURL = AmzServiceUrl });

            _requestReportRequest = new RequestReportRequest
            {
                Merchant = _merchant,
                ReportType = _reportTypeToGet,
                MarketplaceIdList = new IdList
                {
                    Id = new List<string>(new[] { marketPlaceId })
                }
            };
        }
Пример #4
0
        /// <summary>
        /// returns the number of feeds matching all of the specified criteria
        /// 
        /// </summary>
        /// <param name="service">Instance of MarketplaceWebService service</param>
        /// <param name="request">GetFeedSubmissionCountRequest request</param>
        public static void InvokeRequestReport(MarketplaceWebService service, RequestReportRequest request)
        {
            try
            {
                RequestReportResponse response = service.RequestReport(request);

                Console.WriteLine ("Service Response");
                Console.WriteLine ("=============================================================================");
                Console.WriteLine ();

                Console.WriteLine("        RequestReportResponse");

                if (response.IsSetRequestReportResult())
                {
                    Console.WriteLine("            RequestReportResult");
                    RequestReportResult requestReportResult = response.RequestReportResult;
                    ReportRequestInfo reportRequestInfo = requestReportResult.ReportRequestInfo;
                    Console.WriteLine("                  ReportRequestInfo");

                    if(reportRequestInfo.IsSetReportProcessingStatus() )
                    {
                        Console.WriteLine("               ReportProcessingStatus");
                        Console.WriteLine("                                  {0}", reportRequestInfo.ReportProcessingStatus);
                    }
                    if( reportRequestInfo.IsSetReportRequestId())
                    {
                        Console.WriteLine("                      ReportRequestId");
                        Console.WriteLine("                                  {0}", reportRequestInfo.ReportRequestId);
                    }
                    if (reportRequestInfo.IsSetReportType())
                    {
                        Console.WriteLine("                           ReportType");
                        Console.WriteLine("                                  {0}", reportRequestInfo.ReportType);
                    }
                    if (reportRequestInfo.IsSetStartDate())
                    {
                        Console.WriteLine("                            StartDate");
                        Console.WriteLine("                                  {0}", reportRequestInfo.StartDate);
                    }
                    if(reportRequestInfo.IsSetEndDate())
                    {
                        Console.WriteLine("                              EndDate");
                        Console.WriteLine("                                  {0}", reportRequestInfo.EndDate);
                    }
                    if (reportRequestInfo.IsSetSubmittedDate())
                    {
                        Console.WriteLine("                        SubmittedDate");
                        Console.WriteLine("                                  {0}", reportRequestInfo.SubmittedDate);
                    }
                }
                if (response.IsSetResponseMetadata())
                {
                    Console.WriteLine("            ResponseMetadata");
                    ResponseMetadata  responseMetadata = response.ResponseMetadata;
                    if (responseMetadata.IsSetRequestId())
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", responseMetadata.RequestId);
                    }
                }

                Console.WriteLine("            ResponseHeaderMetadata");
                Console.WriteLine("                RequestId");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.RequestId);
                Console.WriteLine("                ResponseContext");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.ResponseContext);
                Console.WriteLine("                Timestamp");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.Timestamp);

            }
            catch (MarketplaceWebServiceException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
                Console.WriteLine("ResponseHeaderMetadata: " + ex.ResponseHeaderMetadata);
            }
        }