/// <summary>
        /// Constructs MarketplaceWebServiceClient with AWS Access Key ID and AWS Secret Key
        /// an application name, and application version.
        /// </summary>
        /// <param name="awsAccessKeyId">AWS Access Key ID</param>
        /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
        /// <param name="applicationName">Application Name</param>
        /// <param name="applicationVersion">Application Version</param>
        /// /// <param name="applicationVersion">Custom Configuration (User-Agent not set)</param>
        public MarketplaceWebServiceClient(
            String awsAccessKeyId,
            String awsSecretAccessKey,
            String applicationName,
            String applicationVersion,
            MarketplaceWebServiceConfig config)
        {
            this.awsAccessKeyId     = awsAccessKeyId;
            this.awsSecretAccessKey = awsSecretAccessKey;
            this.config             = config;

            buildUserAgentHeader(applicationName, applicationVersion, config);
        }
 private void buildUserAgentHeader(
     string applicationName,
     string applicationVersion,
     MarketplaceWebServiceConfig config)
 {
     config.SetUserAgentHeader(
         applicationName,
         applicationVersion,
         "C#",
         "CLI", Environment.Version.ToString(),
         "Platform", Environment.OSVersion.Platform + "/" + Environment.OSVersion.Version,
         "MWSClientVersion", mwsClientVersion);
 }
        /// <summary>
        /// Constructs MarketplaceWebServiceClient with AWS Access Key ID and AWS Secret Key.
        /// Since the User-Agent is required for all MWS calls, this value must be set
        /// in the config.
        /// </summary>
        /// <param name="awsAccessKeyId">AWS Access Key ID</param>
        /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
        /// <param name="config">Custom Configuration (User-Agent is set)</param>
        public MarketplaceWebServiceClient(
            String awsAccessKeyId,
            String awsSecretAccessKey,
            MarketplaceWebServiceConfig config)
        {
            this.awsAccessKeyId     = awsAccessKeyId;
            this.awsSecretAccessKey = awsSecretAccessKey;

            if (!config.IsSetUserAgent())
            {
                throw new MarketplaceWebServiceException("Missing required value: User-Agent.");
            }

            this.config = config;
        }
Esempio n. 4
0
        private static bool SendAmazonFeed(KeyValuePair <string, string> type, List <FeedModel> liObj)
        {
            var config2 = new MarketplaceWebServiceConfig();

            // Set configuration to use US marketplace
            config2.ServiceURL = ConfigurationHelper.ServiceURL;
            // Set the HTTP Header for user agent for the application.
            config2.SetUserAgentHeader(
                ConfigurationHelper.AppName,
                ConfigurationHelper.Version,
                "C#");

            var amazonClient = new MarketplaceWebServiceClient(ConfigurationHelper.AccessKey,
                                                               ConfigurationHelper.SecretKey,
                                                               config2);

            SubmitFeedRequest request = new SubmitFeedRequest
            {
                Merchant    = ConfigurationHelper.SellerId,
                FeedContent = FeedRequestXML.GenerateInventoryDocument(ConfigurationHelper.AppName, liObj, type.Key)
            };

            // 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 = type.Value;

            var subResp = FeedSample.InvokeSubmitFeed(amazonClient, request);

            request.FeedContent.Close();
            var feedReq = new GetFeedSubmissionResultRequest()
            {
                Merchant             = ConfigurationHelper.SellerId,
                FeedSubmissionId     = subResp.SubmitFeedResult.FeedSubmissionInfo.FeedSubmissionId,//"50148017726",
                FeedSubmissionResult = File.Create("feedSubmissionResult1.xml")
            };

            Thread.Sleep(10000);
            bool bRet = false;

            //need to handle error else the loop will be infinite
            while (true)
            {
                GetFeedSubmissionResultResponse getResultResp = null;

                getResultResp = FeedSample.InvokeGetFeedSubmissionResult(amazonClient, feedReq);

                if (getResultResp != null)
                {
                    //using (var op = File.Open("feedSubmissionResult1.xml", FileMode.Open))
                    //{
                    using (var stream = feedReq.FeedSubmissionResult)
                    {
                        XDocument doc      = XDocument.Parse(stream.ReadToEnd()); //or XDocument.Load(path)
                        string    jsonText = JsonConvert.SerializeXNode(doc);
                        Console.WriteLine("\n*** Got Response: {0} ", jsonText);
                        dynamic dyn = JsonConvert.DeserializeObject <ExpandoObject>(jsonText);
                        dynamic processingSummary = dyn.AmazonEnvelope.Message.ProcessingReport.ProcessingSummary;
                        if (processingSummary.MessagesProcessed == processingSummary.MessagesSuccessful)
                        {
                            ProductDAL.UpdateProductAfterAmazonFeed(ConfigurationHelper.ConnectionString, liObj, type.Key);
                            bRet = true;
                            break;
                        }
                        else
                        {
                            //send email with failed sku info - need to handle this
                            Console.WriteLine("\n*** Feed Submission failed. Error: {0} ", jsonText);
                            bRet = false;
                        }
                    }
                    //}
                }
                feedReq.FeedSubmissionResult.Close();
                File.Delete("feedSubmissionResult1.xml");
                feedReq.FeedSubmissionResult = File.Create("feedSubmissionResult1.xml");
                Console.WriteLine("Going to sleep for 1 min at {0}", DateTime.Now);
                Thread.Sleep(60000);
            }
            File.Delete("feedSubmissionResult1.xml");
            return(bRet);
        }