/// <summary>
        /// Default public contructor. All properties are set via the config file
        /// </summary>
        public AmazonIntegration()
        {
            // Verify that the settings in the config file are setup correctly.
            if (string.IsNullOrWhiteSpace(_AccessKeyId))
                throw new InvalidOperationException("AWSAccessKeyId setting in the config file can't be whitespace, blank or null");
            if (string.IsNullOrWhiteSpace(_SecretAccessKey))
                throw new InvalidOperationException("AWSSecretAccessKey setting in the config file can't be whitespace, blank or null");
            if (string.IsNullOrWhiteSpace(_ApplicationName))
                throw new InvalidOperationException("AWSApplicationName setting in the config file can't be whitespace, blank or null");
            if (string.IsNullOrWhiteSpace(_ApplicationVersion))
                throw new InvalidOperationException("AWSApplicationVersion setting in the config file can't be whitespace, blank or null");
            if (string.IsNullOrWhiteSpace(_MerchantId))
                throw new InvalidOperationException("AWSMerchantId setting in the config file can't be whitespace, blank or null");
            if (string.IsNullOrWhiteSpace(_MarketplaceId))
                throw new InvalidOperationException("AWSMarketplaceId setting in the config file can't be whitespace, blank or null");
            if (string.IsNullOrWhiteSpace(_TemporaryFileDirectory))
                throw new InvalidOperationException("TempFileDirectory setting in the config file can't be whitespace, blank or null");

            var config = new MarketplaceWebServiceConfig();
            // Set configuration to use US marketplace
            config.ServiceURL = "https://mws.amazonservices.com";
            // Set the HTTP Header for user agent for the application.
            config.SetUserAgentHeader(
                _ApplicationName,
                _ApplicationVersion,
                "C#");
            _AmazonClient = new MarketplaceWebServiceClient(_AccessKeyId, _SecretAccessKey, config);

            // Setup the orders service client
            var ordersConfig = new MarketplaceWebServiceOrdersConfig();
            ordersConfig.ServiceURL = "https://mws.amazonservices.com/Orders/2011-01-01";
            ordersConfig.SetUserAgent(_ApplicationName, _ApplicationVersion);
            _AmazonOrdersClient = new MarketplaceWebServiceOrdersClient(
                _ApplicationName, _ApplicationVersion, _AccessKeyId, _SecretAccessKey, ordersConfig);
        }
Пример #2
0
 public MarketplaceWebServiceClient GetFeedsApiService()
 {
     var config = new MarketplaceWebServiceConfig() { ServiceURL = _amazonAppSettings.ApiEndpoint };
     return new MarketplaceWebServiceClient(MrCMSApplication.Get<AmazonAppSettings>().AWSAccessKeyId,
                                             MrCMSApplication.Get<AmazonAppSettings>().SecretKey, "MrCMS", MrCMSApplication.AssemblyVersion,
                                             config);
 }
Пример #3
0
 private MarketplaceWebService.MarketplaceWebService Configurations(string intergrationType, string accessKey, string secretKey)
 {
     MarketplaceWebService.MarketplaceWebServiceConfig config = new MarketplaceWebService.MarketplaceWebServiceConfig();
     config.ServiceURL = SOHelper.GetIntegrationType(intergrationType.Trim(), SOConstants.serviceUrl);
     MarketplaceWebService.MarketplaceWebService serviceConfig = new MarketplaceWebService.MarketplaceWebServiceClient(accessKey, secretKey, SOConstants.appName, SOConstants.version, config);
     return(serviceConfig);
 }
Пример #4
0
        public override void Initialize()
        {
            var settingsManager = _container.Resolve<ISettingsManager>();
            

            var amazonManager = new AmazonManagerSettings(
                settingsManager,
                _merchantIdPropertyName,
                _serviceUrlPropertyName,
                _marketplaceIdPropertyName,
                _awsAccessKeyIdPropertyName,
                _awsSecretAccessKeyPropertyName);

            var feedConfig = new MarketplaceWebServiceConfig { ServiceURL = amazonManager.ServiceURL };

            //test mock registration
            _container.RegisterInstance<IMarketplaceWebServiceClient>(new MockMarketplaceWebServiceClient());

            //production registration
            //_container.RegisterInstance<IMarketplaceWebServiceClient>(new MarketplaceWebServiceClient(amazonManager.AwsAccessKeyId, amazonManager.AwsSecretAccessKey, "VirtoCommerce", "1.01", feedConfig));

            _container.RegisterInstance<IDateTimeProvider>(new DefaultDateTimeProvider());
            _container.RegisterInstance<IAmazonSettings>(amazonManager);

            _container.RegisterType<AmazonMerchantController>();
        }
Пример #5
0
        private void InitMwsFeedClient()
        {
            var mwsConfig = new MarketplaceWebServiceConfig();
            mwsConfig.SetUserAgentHeader( "Speadbot", "1.0", "C#" );
            mwsConfig.ServiceURL = AmazonSettings.ServiceUrl;

            _mwsFeedClient = new MarketplaceWebServiceClient(
                AmazonSettings.AwsAccessKeyId,
                AmazonSettings.AwsSecretAccessKey,
                mwsConfig );
        }
Пример #6
0
        protected override void RegisterServices(IKernel kernel)
        {
            kernel.Bind<MarketplaceWebServiceOrders.MarketplaceWebServiceOrders>().ToMethod(context =>
            {
                var amazonAppSettings = context.Kernel.Get<AmazonAppSettings>();
                var config = new MarketplaceWebServiceOrdersConfig { ServiceURL = amazonAppSettings.OrdersApiEndpoint };
                return new MarketplaceWebServiceOrdersClient
                        ("MrCMS", MrCMSApplication.AssemblyVersion, amazonAppSettings.AWSAccessKeyId, amazonAppSettings.SecretKey, config);
            }).InRequestScope();

            kernel.Bind<MarketplaceWebServiceProducts.MarketplaceWebServiceProducts>().ToMethod(context =>
            {
                var amazonAppSettings = context.Kernel.Get<AmazonAppSettings>();
                var config = new MarketplaceWebServiceProductsConfig { ServiceURL = amazonAppSettings.ProductsApiEndpoint };
                return new MarketplaceWebServiceProductsClient
                        ("MrCMS", MrCMSApplication.AssemblyVersion, amazonAppSettings.AWSAccessKeyId, amazonAppSettings.SecretKey, config);
            }).InRequestScope();
            kernel.Bind<MarketplaceWebService.MarketplaceWebService>().ToMethod(context =>
            {
                var amazonAppSettings = context.Kernel.Get<AmazonAppSettings>();
                var config = new MarketplaceWebServiceConfig { ServiceURL = amazonAppSettings.ProductsApiEndpoint };
                return new MarketplaceWebServiceClient(amazonAppSettings.AWSAccessKeyId, amazonAppSettings.SecretKey, "MrCMS", MrCMSApplication.AssemblyVersion, config);
            }).InRequestScope();
        }
Пример #7
0
    private void DownloadSalesData()
    {
      this.StatusDescription = string.Format("Creating MWS client");
      // Set up MWS client
      string accessKey = System.Configuration.ConfigurationManager.AppSettings["MwsAccK"];
      string secretKey = System.Configuration.ConfigurationManager.AppSettings["MwsSecK"];
      string sellerId = System.Configuration.ConfigurationManager.AppSettings["MwsSeller"];
      string marketplaceId = System.Configuration.ConfigurationManager.AppSettings["MwsMktpl"];
      MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
      config.ServiceURL = "https://mws.amazonservices.com ";
      config.SetUserAgentHeader("CMA", "1.0", "C#", new string[] { });
      MarketplaceWebServiceClient client = new MarketplaceWebServiceClient(accessKey, secretKey, config);


      // Submit the report request
      MarketplaceWebService.Model.RequestReportRequest request = new MarketplaceWebService.Model.RequestReportRequest();
      request.ReportType = "_GET_FLAT_FILE_ALL_ORDERS_DATA_BY_LAST_UPDATE_";
      request.Merchant = sellerId;
      request.StartDate = DateTime.Now.AddDays(-30).AddHours(-6);
      request.EndDate = DateTime.Now.AddHours(-6);

      this.StatusDescription = string.Format("Requesting Report Type {0} for {1} through {2}", request.ReportType, request.StartDate.ToShortDateString(), request.EndDate.ToShortDateString());
      var responseToRequestReport = client.RequestReport(request);

      Thread.Sleep(1000);

      string reportRequestId = "";
      
      if (responseToRequestReport.IsSetRequestReportResult())
      {
        if (responseToRequestReport.RequestReportResult.IsSetReportRequestInfo())
        {
          if (responseToRequestReport.RequestReportResult.ReportRequestInfo.IsSetReportRequestId())
          {
            reportRequestId = responseToRequestReport.RequestReportResult.ReportRequestInfo.ReportRequestId;
          }
          else
          {
            // Would be good to implement wait-and-retry here
            throw new Exception("ReportRequestId was not returned from RequestReport()");
          }
        }
      }

      this.StatusDescription = string.Format("Report Request ID: {0}", reportRequestId);
      Thread.Sleep(1000);

      // Check for the report to have a _DONE_ status
      string reportId = "";

      bool reportDone = false;

      do
      {
        this.StatusDescription = string.Format("Checking report status");
        MarketplaceWebService.Model.GetReportRequestListRequest requestGetReportRequestList = new MarketplaceWebService.Model.GetReportRequestListRequest();
        requestGetReportRequestList.ReportRequestIdList = new MarketplaceWebService.Model.IdList();
        requestGetReportRequestList.ReportRequestIdList.Id = new List<string>();
        requestGetReportRequestList.ReportRequestIdList.Id.Add(reportRequestId);
        requestGetReportRequestList.Merchant = sellerId;

        var responseToGetReportRequestList = client.GetReportRequestList(requestGetReportRequestList);

        if (responseToGetReportRequestList.IsSetGetReportRequestListResult() && responseToGetReportRequestList.GetReportRequestListResult.IsSetReportRequestInfo() && responseToGetReportRequestList.GetReportRequestListResult.ReportRequestInfo.Count != 0)
        {
          this.StatusDescription = string.Format("Report status: {0}", responseToGetReportRequestList.GetReportRequestListResult.ReportRequestInfo[0].ReportProcessingStatus);
          Thread.Sleep(500);
          if (responseToGetReportRequestList.GetReportRequestListResult.ReportRequestInfo[0].ReportProcessingStatus.Equals("_DONE_"))
          {
            reportDone = true;
            if (responseToGetReportRequestList.GetReportRequestListResult.ReportRequestInfo[0].IsSetGeneratedReportId())
            {
              reportId = responseToGetReportRequestList.GetReportRequestListResult.ReportRequestInfo[0].GeneratedReportId;
              this.StatusDescription = string.Format("Report ID: {0}", reportId);
            }
            else
            {
              // ReportId was not returned, call GetReportList()
              this.StatusDescription = string.Format("Report ID was not returned. Trying GetReportList()");
              var requestGetReportList = new MarketplaceWebService.Model.GetReportListRequest();
              requestGetReportList.ReportRequestIdList = new MarketplaceWebService.Model.IdList();
              requestGetReportList.ReportRequestIdList.Id = new List<string>();
              requestGetReportList.ReportRequestIdList.Id.Add(reportRequestId);
              requestGetReportList.Merchant = sellerId;

              var responseToGetReportList = client.GetReportList(requestGetReportList);

              if (responseToGetReportList.IsSetGetReportListResult() && responseToGetReportList.GetReportListResult.IsSetReportInfo() && responseToGetReportList.GetReportListResult.ReportInfo.Count != 0)
              {
                reportId = responseToGetReportList.GetReportListResult.ReportInfo[0].ReportId;
                this.StatusDescription = string.Format("Report ID: {0}", reportId);
              }
              else
              {
                throw new Exception("ReportId could not be retrieved.");
              }
            }
          }
          else if (responseToGetReportRequestList.GetReportRequestListResult.ReportRequestInfo[0].ReportProcessingStatus.Equals("_DONE_NO_DATA_"))
          {
            throw new Exception("Report returned with status _DONE_NO_DATA_");
          }
          else
          {
            for (int secondsTilRetry = 60; secondsTilRetry > 0; secondsTilRetry--)
            {
              this.StatusDescription = string.Format("Report status: {0} (Will check again in {1}s)", responseToGetReportRequestList.GetReportRequestListResult.ReportRequestInfo[0].ReportProcessingStatus, secondsTilRetry);
              Thread.Sleep(1000);
            }
          }
        }

      } while (!reportDone);

      Thread.Sleep(1000);

      // Retrieve the report
      string saveFileName = reportId + ".txt";
      this.StatusDescription = string.Format("Downloading report to {0}", saveFileName);
      MarketplaceWebService.Model.GetReportRequest requestGetReport = new MarketplaceWebService.Model.GetReportRequest();
      requestGetReport.ReportId = reportId;
      requestGetReport.Merchant = sellerId;

      using (Stream file = File.Open(saveFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) {
        requestGetReport.Report = file;
        var responseToGetReport = client.GetReport(requestGetReport);
      }
    }
        public static void SubmitFeed(string fileName, string feedType)
        {
            //IniReader iniReader = new IniReader(System.Environment.CurrentDirectory + "\\config.ini");
            //string awsSection = "AWS_US";

            //String accessKeyId = iniReader.ReadValue(awsSection, "accessKey");
            //String secretAccessKey = iniReader.ReadValue(awsSection, "secretKey");

            /************************************************************************
            * 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.
             ***********************************************************************/

            //string applicationName = iniReader.ReadValue(awsSection, "appName"); ;
            //string applicationVersion = iniReader.ReadValue(awsSection, "appVersion");

            /************************************************************************
             * All MWS requests must contain the seller's merchant ID and
             * marketplace ID.
             ***********************************************************************/
            //string merchantId = iniReader.ReadValue(awsSection, "sellerId");
            //string marketplaceId = iniReader.ReadValue(awsSection, "marketplaceId");

            // United States:
            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);

            SubmitFeedRequest request = new SubmitFeedRequest();
            request.Merchant = GlobalConfig.Instance.SellerId;
            // request.MWSAuthToken = iniReader.ReadValue(awsSection, "MWSAuthToken"); // Optional
            request.MarketplaceIdList = new IdList();
            request.MarketplaceIdList.Id = new List<string>(new string[] { GlobalConfig.Instance.MarketplaceId });

            // MWS exclusively offers a streaming interface for uploading your feeds. This is because
            // feed sizes can grow to the 1GB+ range - and as your business grows you could otherwise
            // silently reach the feed size where your in-memory solution will no longer work, leaving you
            // puzzled as to why a solution that worked for a long time suddenly stopped working though
            // you made no changes. For the same reason, we strongly encourage you to generate your feeds to
            // local disk then upload them directly from disk to MWS.

            request.FeedContent = File.Open(fileName, FileMode.Open, FileAccess.Read);

            // Calculating the MD5 hash value exhausts the stream, and therefore we must either reset the
            // position, or create another stream for the calculation.
            request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);
            request.FeedContent.Position = 0;

            request.FeedType = feedType;

            SubmitFeedSample.InvokeSubmitFeed(service, request);
            request.FeedContent.Close();
        }
        /**
        * 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();
            }
        }
        public static void RunSample()
        {
            Console.WriteLine("===========================================");
            Console.WriteLine("Welcome to Marketplace Web Service Samples!");
            Console.WriteLine("===========================================");

            Console.WriteLine("To get started:");
            Console.WriteLine("===========================================");
            Console.WriteLine("  - Fill in your AWS credentials");
            Console.WriteLine("  - Uncomment sample you're interested in trying");
            Console.WriteLine("  - Set request with desired parameters");
            Console.WriteLine("  - Hit F5 to run!");
            Console.WriteLine();

            Console.WriteLine("===========================================");
            Console.WriteLine("Samples Output");
            Console.WriteLine("===========================================");
            Console.WriteLine();

            /************************************************************************
             * Access Key ID and Secret Acess Key ID, obtained from:
             * http://aws.amazon.com
             *
             * IMPORTANT: Your Secret Access Key is a secret, and should be known
             * only by you and AWS. You should never include your Secret Access Key
             * in your requests to AWS. You should never e-mail your Secret Access Key
             * to anyone. It is important to keep your Secret Access Key confidential
             * to protect your account.
             ***********************************************************************/

            IniReader iniReader = new IniReader(System.Environment.CurrentDirectory + "\\config.ini");
            string awsSection = "AWS_US";

            String accessKeyId = iniReader.ReadValue(awsSection, "accessKey");
            String secretAccessKey = iniReader.ReadValue(awsSection, "secretKey");

            /************************************************************************
            * 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.
             ***********************************************************************/

            string applicationName = iniReader.ReadValue(awsSection, "appName"); ;
            string applicationVersion = iniReader.ReadValue(awsSection, "appVersion"); ;

            //MarketplaceWebService service =
            //    new MarketplaceWebServiceClient(
            //        accessKeyId,
            //        secretAccessKey,
            //        applicationName,
            //        applicationVersion,
            //        config);

            /************************************************************************
             * All MWS requests must contain the seller's merchant ID and
             * marketplace ID.
             ***********************************************************************/
            string merchantId = iniReader.ReadValue(awsSection, "sellerId");
            string marketplaceId = iniReader.ReadValue(awsSection, "marketplaceId");

            /************************************************************************
             * Uncomment to configure the client instance. Configuration settings
             * include:
             *
             *  - MWS Service endpoint URL
             *  - Proxy Host and Proxy Port
             *  - User Agent String to be sent to Marketplace Web Service  service
             *
             ***********************************************************************/
            //MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
            //config.ProxyHost = "https://PROXY_URL";
            //config.ProxyPort = 9090;
            //
            // IMPORTANT: Uncomment out the appropiate line for the country you wish
            // to sell in:
            //
            // United States:
            config.ServiceURL = "https://mws.amazonservices.com";
            //
            // United Kingdom:
            // config.ServiceURL = "https://mws.amazonservices.co.uk";
            //
            // Germany:
            // config.ServiceURL = "https://mws.amazonservices.de";
            //
            // France:
            // config.ServiceURL = "https://mws.amazonservices.fr";
            //
            // Japan:
            // config.ServiceURL = "https://mws.amazonservices.jp";
            //
            // China:
            // config.ServiceURL = "https://mws.amazonservices.com.cn";
            //
            // Canada:
            // config.ServiceURL = "https://mws.amazonservices.ca";
            //
            // Italy:
            // config.ServiceURL = "https://mws.amazonservices.it";
            //
            config.SetUserAgentHeader(
                applicationName,
                applicationVersion,
                "C#"
                );
            MarketplaceWebService service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, config);

            /************************************************************************
             * Uncomment to try out Mock Service that simulates Marketplace Web Service
             * responses without calling Marketplace Web Service  service.
             *
             * Responses are loaded from local XML files. You can tweak XML files to
             * experiment with various outputs during development
             *
             * XML files available under MarketplaceWebService\Mock tree
             *
             ***********************************************************************/
            // MarketplaceWebService service = new MarketplaceWebServiceMock();

            /************************************************************************
             * Uncomment to invoke Get Report Action
             ***********************************************************************/
            {
                // GetReportRequest request = new GetReportRequest();
                // request.Merchant = merchantId;
                // 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.
                // request.ReportId = "REPORT_ID";
                // request.Report = File.Open("report.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite );
                // GetReportSample.InvokeGetReport(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Report Schedule Count Action
             ***********************************************************************/
            {
                //GetReportScheduleCountRequest request = new GetReportScheduleCountRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                // @TODO: set additional request parameters here
                //GetReportScheduleCountSample.InvokeGetReportScheduleCount(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Report Request List By Next Token Action
             ***********************************************************************/
            {
                //GetReportRequestListByNextTokenRequest request = new GetReportRequestListByNextTokenRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                //request.NextToken = "NextToken from GetReportRequestList";
                // @TODO: set additional request parameters here
                //GetReportRequestListByNextTokenSample.InvokeGetReportRequestListByNextToken(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Update Report Acknowledgements Action
             ***********************************************************************/
            {
                //UpdateReportAcknowledgementsRequest request = new UpdateReportAcknowledgementsRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                //request.WithReportIdList(new IdList().WithId("REPORT_ID"));
                // @TODO: set additional request parameters here
                //UpdateReportAcknowledgementsSample.InvokeUpdateReportAcknowledgements(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Submit Feed Action
             ***********************************************************************/
            {
                //SubmitFeedRequest request = new SubmitFeedRequest();
                //request.Merchant = merchantId;
                // request.MWSAuthToken = iniReader.ReadValue(awsSection, "MWSAuthToken"); // Optional
                //request.MarketplaceIdList = new IdList();
                //request.MarketplaceIdList.Id = new List<string>(new string[] { marketplaceId });

                // MWS exclusively offers a streaming interface for uploading your feeds. This is because
                // feed sizes can grow to the 1GB+ range - and as your business grows you could otherwise
                // silently reach the feed size where your in-memory solution will no longer work, leaving you
                // puzzled as to why a solution that worked for a long time suddenly stopped working though
                // you made no changes. For the same reason, we strongly encourage you to generate your feeds to
                // local disk then upload them directly from disk to MWS.

                //request.FeedContent = File.Open("feed.xml", FileMode.Open, FileAccess.Read);

                // Calculating the MD5 hash value exhausts the stream, and therefore we must either reset the
                // position, or create another stream for the calculation.
                //request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);
                //request.FeedContent.Position = 0;

                //request.FeedType = "_POST_PRODUCT_PRICING_DATA_";

                //SubmitFeedSample.InvokeSubmitFeed(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Report Count Action
             ***********************************************************************/
            {
                // GetReportCountRequest request = new GetReportCountRequest();
                // request.Merchant = merchantId;
                // request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                // @TODO: set additional request parameters here
                // GetReportCountSample.InvokeGetReportCount(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Feed Submission List By Next Token Action
             ***********************************************************************/
            //{
            //    GetFeedSubmissionListByNextTokenRequest request = new GetFeedSubmissionListByNextTokenRequest();
            //    request.Merchant = merchantId;
            //    // request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
            //    request.NextToken = "NextToken from GetFeedSubmissionList";
            //    // @TODO: set additional request parameters here
            //    GetFeedSubmissionListByNextTokenSample.InvokeGetFeedSubmissionListByNextToken(service, request);
            //}

            /************************************************************************
             * Uncomment to invoke Cancel Feed Submissions Action
             ***********************************************************************/
            {
                //CancelFeedSubmissionsRequest request = new CancelFeedSubmissionsRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                // @TODO: set additional request parameters here
                //CancelFeedSubmissionsSample.InvokeCancelFeedSubmissions(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Request Report Action
             ***********************************************************************/
            {
                //RequestReportRequest request = new RequestReportRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                //request.MarketplaceIdList = new IdList();
                //request.MarketplaceIdList.Id = new List<string>( new string [] { marketplaceId } );

                //request.ReportType = "Desired Report Type";
                // @TODO: set additional request parameters here
                //request.ReportOptions = "ShowSalesChannel=true";
                //RequestReportSample.InvokeRequestReport(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Feed Submission Count Action
             ***********************************************************************/
            {
                //GetFeedSubmissionCountRequest request = new GetFeedSubmissionCountRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                // @TODO: set additional request parameters here
                //GetFeedSubmissionCountSample.InvokeGetFeedSubmissionCount(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Cancel Report Requests Action
             ***********************************************************************/
            {
                //CancelReportRequestsRequest request = new CancelReportRequestsRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                // @TODO: set additional request parameters here
                //CancelReportRequestsSample.InvokeCancelReportRequests(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Report List Action
             ***********************************************************************/
            {
                //GetReportListRequest request = new GetReportListRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                // @TODO: set additional request parameters here
                //GetReportListSample.InvokeGetReportList(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Feed Submission Result Action
             ***********************************************************************/
            {
                GetFeedSubmissionResultRequest request = new GetFeedSubmissionResultRequest();
                request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional

                // Note that depending on the size of the feed sent in, and the number of errors and warnings,
                // the result 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.
                request.FeedSubmissionId = "51635016699";
                request.FeedSubmissionResult = File.Open("feedSubmissionResult1.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite);

                GetFeedSubmissionResultSample.InvokeGetFeedSubmissionResult(service, request);
                request.FeedSubmissionResult.Close();
            }

            /************************************************************************
             * Uncomment to invoke Get Feed Submission List Action
             ***********************************************************************/
            {
                //GetFeedSubmissionListRequest request = new GetFeedSubmissionListRequest();
                //request.Merchant = merchantId;
                ////request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                //// @TODO: set additional request parameters here
                //GetFeedSubmissionListSample.InvokeGetFeedSubmissionList(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Report Request List Action
             ***********************************************************************/
            {
                //GetReportRequestListRequest request = new GetReportRequestListRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                // @TODO: set additional request parameters here
                //GetReportRequestListSample.InvokeGetReportRequestList(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Report Schedule List By Next Token Action
             ***********************************************************************/
            {
                //GetReportScheduleListByNextTokenRequest request = new GetReportScheduleListByNextTokenRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                //request.NextToken = "NextToken from GetReportScheduleList";
                // @TODO: set additional request parameters here
                //GetReportScheduleListByNextTokenSample.InvokeGetReportScheduleListByNextToken(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Report List By Next Token Action
             ***********************************************************************/
            {
                // GetReportListByNextTokenRequest request = new GetReportListByNextTokenRequest();
                // request.Merchant = merchantId;
                // request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                //request.NextToken = "NextToken from GetReportList";
                // @TODO: set additional request parameters here
                // GetReportListByNextTokenSample.InvokeGetReportListByNextToken(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Manage Report Schedule Action
             ***********************************************************************/
            {
                //ManageReportScheduleRequest request = new ManageReportScheduleRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                //request.ReportType = "Report Type";
                //request.Schedule = "Schedule";
                // @TODO: set additional request parameters here
                //ManageReportScheduleSample.InvokeManageReportSchedule(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Report Request Count Action
             ***********************************************************************/
            {
                //GetReportRequestCountRequest request = new GetReportRequestCountRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                // @TODO: set additional request parameters here
                //GetReportRequestCountSample.InvokeGetReportRequestCount(service, request);
            }

            /************************************************************************
             * Uncomment to invoke Get Report Schedule List Action
             ***********************************************************************/
            {
                //GetReportScheduleListRequest request = new GetReportScheduleListRequest();
                //request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional
                // @TODO: set additional request parameters here
                //GetReportScheduleListSample.InvokeGetReportScheduleList(service, request);
            }

            Console.WriteLine();
            Console.WriteLine("===========================================");
            Console.WriteLine("End of output. You can close this window");
            Console.WriteLine("===========================================");

            System.Threading.Thread.Sleep(50000);
        }
        public static void GetFeedSubmissionResult(string market_id, string feedSubmissionId, string fileName)
        {
            //IniReader iniReader = new IniReader(System.Environment.CurrentDirectory + "\\config.ini");
            //string awsSection = "AWS_US";

            String accessKeyId = GlobalConfig.Instance.GetConfigValue(market_id, "accessKey");
            String secretAccessKey = GlobalConfig.Instance.GetConfigValue(market_id, "secretKey");

            /************************************************************************
            * 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.
             ***********************************************************************/

            string applicationName = GlobalConfig.Instance.GetCommonConfigValue("appName");
            string applicationVersion = GlobalConfig.Instance.GetCommonConfigValue("appVersion");

            /************************************************************************
             * All MWS requests must contain the seller's merchant ID and
             * marketplace ID.
             ***********************************************************************/
            string merchantId = GlobalConfig.Instance.GetConfigValue(market_id, "sellerId");
            string marketplaceId = GlobalConfig.Instance.GetConfigValue(market_id, "marketplaceId");

            // United States:
            config.ServiceURL = GlobalConfig.Instance.GetConfigValue(market_id, "serviceURL");
            //
            // United Kingdom:
            // config.ServiceURL = "https://mws.amazonservices.co.uk";
            //
            // Germany:
            // config.ServiceURL = "https://mws.amazonservices.de";
            //
            // France:
            // config.ServiceURL = "https://mws.amazonservices.fr";
            //
            // Japan:
            // config.ServiceURL = "https://mws.amazonservices.jp";
            //
            // China:
            // config.ServiceURL = "https://mws.amazonservices.com.cn";
            //
            // Canada:
            // config.ServiceURL = "https://mws.amazonservices.ca";
            //
            // Italy:
            // config.ServiceURL = "https://mws.amazonservices.it";
            //
            config.SetUserAgentHeader(
                applicationName,
                applicationVersion,
                "C#"
                );
            MarketplaceWebService service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, config);

            /************************************************************************
             * Uncomment to invoke Get Feed Submission Result Action
             ***********************************************************************/
            {
                GetFeedSubmissionResultRequest request = new GetFeedSubmissionResultRequest();
                request.Merchant = merchantId;
                //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional

                // Note that depending on the size of the feed sent in, and the number of errors and warnings,
                // the result 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.
                request.FeedSubmissionId = feedSubmissionId;
                request.FeedSubmissionResult = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);

                GetFeedSubmissionResultSample.InvokeGetFeedSubmissionResult(service, request);
                request.FeedSubmissionResult.Close();
            }
        }