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); }
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); }