Example #1
0
        /// <summary>
        /// returns a list of reports; by default the most recent ten reports,
        /// regardless of their acknowledgement status
        /// 
        /// </summary>
        /// <param name="service">Instance of MarketplaceWebService service</param>
        /// <param name="request">GetReportListRequest request</param>
        public static void InvokeGetReportList(MarketplaceWebService service, GetReportListRequest request)
        {
            try
            {
                GetReportListResponse response = service.GetReportList(request);

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

                Console.WriteLine("        GetReportListResponse");
                if (response.IsSetGetReportListResult())
                {
                    Console.WriteLine("            GetReportListResult");
                    GetReportListResult  getReportListResult = response.GetReportListResult;
                    if (getReportListResult.IsSetNextToken())
                    {
                        Console.WriteLine("                NextToken");
                        Console.WriteLine("                    {0}", getReportListResult.NextToken);
                    }
                    if (getReportListResult.IsSetHasNext())
                    {
                        Console.WriteLine("                HasNext");
                        Console.WriteLine("                    {0}", getReportListResult.HasNext);
                    }
                    List<ReportInfo> reportInfoList = getReportListResult.ReportInfo;
                    foreach (ReportInfo reportInfo in reportInfoList)
                    {
                        Console.WriteLine("                ReportInfo");
                        if (reportInfo.IsSetReportId())
                        {
                            Console.WriteLine("                    ReportId");
                            Console.WriteLine("                        {0}", reportInfo.ReportId);
                        }
                        if (reportInfo.IsSetReportType())
                        {
                            Console.WriteLine("                    ReportType");
                            Console.WriteLine("                        {0}", reportInfo.ReportType);
                        }
                        if (reportInfo.IsSetReportRequestId())
                        {
                            Console.WriteLine("                    ReportRequestId");
                            Console.WriteLine("                        {0}", reportInfo.ReportRequestId);
                        }
                        if (reportInfo.IsSetAvailableDate())
                        {
                            Console.WriteLine("                    AvailableDate");
                            Console.WriteLine("                        {0}", reportInfo.AvailableDate);
                        }
                        if (reportInfo.IsSetAcknowledged())
                        {
                            Console.WriteLine("                    Acknowledged");
                            Console.WriteLine("                        {0}", reportInfo.Acknowledged);
                        }
                        if (reportInfo.IsSetAcknowledgedDate())
                        {
                            Console.WriteLine("                    AcknowledgedDate");
                            Console.WriteLine("                        {0}", reportInfo.AcknowledgedDate);
                        }
                    }
                }
                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);
            }
        }
        /**
        * 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();
            }
        }