public FeedSubmissionInfo SubmitFeed(AmazonFeedType feedType, FileStream feedContent) { try { _amazonLogService.Add(AmazonLogType.Api, AmazonLogStatus.Stage,null,null,AmazonApiSection.Feeds, "SubmitFeed",null,null,null,"Submitting "+feedType.GetDescription()+" to Amazon"); _amazonAnalyticsService.TrackNewApiCall(AmazonApiSection.Feeds, "SubmitFeed"); var service = _amazonApiService.GetFeedsApiService(); var request = _amazonApiService.GetSubmitFeedRequest(feedType, feedContent); var result = service.SubmitFeed(request); feedContent.Close(); if (result != null && result.SubmitFeedResult != null && result.IsSetSubmitFeedResult() && result.SubmitFeedResult.FeedSubmissionInfo != null) return result.SubmitFeedResult.FeedSubmissionInfo; } catch (MarketplaceWebServiceException ex) { _amazonLogService.Add(AmazonLogType.Api, AmazonLogStatus.Error, ex, null, AmazonApiSection.Feeds, "SubmitFeed",null,null,null); } catch (Exception ex) { CurrentRequestData.ErrorSignal.Raise(ex); } return null; }
public FeedSubmissionInfo SubmitFeed(AmazonFeedType feedType, FileStream feedContent) { try { _amazonLogService.Add(AmazonLogType.Api, AmazonLogStatus.Stage, null, null, AmazonApiSection.Feeds, "SubmitFeed", null, null, null, "Submitting " + feedType.GetDescription() + " to Amazon"); _amazonAnalyticsService.TrackNewApiCall(AmazonApiSection.Feeds, "SubmitFeed"); var service = _amazonApiService.GetFeedsApiService(); var request = _amazonApiService.GetSubmitFeedRequest(feedType, feedContent); var result = service.SubmitFeed(request); feedContent.Close(); if (result != null && result.SubmitFeedResult != null && result.IsSetSubmitFeedResult() && result.SubmitFeedResult.FeedSubmissionInfo != null) { return(result.SubmitFeedResult.FeedSubmissionInfo); } } catch (MarketplaceWebServiceException ex) { _amazonLogService.Add(AmazonLogType.Api, AmazonLogStatus.Error, ex, null, AmazonApiSection.Feeds, "SubmitFeed", null, null, null); } catch (Exception ex) { CurrentRequestData.ErrorSignal.Raise(ex); } return(null); }
/// <summary> /// Submit the feed and get the stream response with the specified XML file path and feed type /// </summary> /// <param name="xmlFileName">The full file path of the XML</param> /// <param name="feedType">The type of the feed</param> /// <returns>Returns the stream for XML</returns> public Stream SubmitFeedAndGetResponse(string xmlFileName, AmazonFeedType feedType) { var submitFeedRequest = createSubmitFeedRequest(xmlFileName, feedType); // send the feed request to the mws var submitFeedResponse = _amazonCient.SubmitFeed(submitFeedRequest); WaitForGetFeedSubmissionListToCompleted(submitFeedResponse.SubmitFeedResult.FeedSubmissionInfo.FeedSubmissionId); return(GetFeedSubmissionResult(submitFeedResponse.SubmitFeedResult.FeedSubmissionInfo.FeedSubmissionId)); }
public static string ToString(AmazonFeedType type) { switch (type) { case AmazonFeedType.Product: return("Product"); case AmazonFeedType.Inventory: return("Inventory"); case AmazonFeedType.Price: return("Price"); } return("-"); }
public SubmitFeedRequest GetSubmitFeedRequest(AmazonFeedType feedType, FileStream feedContent) { var request = new SubmitFeedRequest() { Merchant = _amazonSellerSettings.SellerId, ContentType = new ContentType(MediaType.XML), FeedContent = feedContent, FeedType = feedType.ToString(), MarketplaceIdList = new IdList { Id = new List <string>(new[] { _amazonSellerSettings.MarketplaceId }) } }; request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent); return(request); }
/// <summary> /// Create SubmitFeedRequest object with the specified XML file path and the type of the feed /// </summary> /// <param name="filePath">The full file path of the XML</param> /// <param name="feedType">The type of Amazon feed</param> /// <returns></returns> public static SubmitFeedRequest CreateSubmitFeedRequest(string filePath, AmazonFeedType feedType) { // create submit feed request var feedRequest = new SubmitFeedRequest { Merchant = MerchantId, MarketplaceIdList = new IdList { Id = MarketplaceIdList }, FeedType = feedType.ToString(), ContentType = new ContentType(MediaType.OctetStream), FeedContent = File.Open(filePath, FileMode.Open, FileAccess.Read) }; feedRequest.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(feedRequest.FeedContent); return(feedRequest); }
/// <summary> /// Create SubmitFeedRequest given an XML file path and feed type /// </summary> /// <param name="xmlFilePath">The xml full file path</param> /// <param name="feedType">The type of feed to be submitted</param> /// <returns></returns> private SubmitFeedRequest createSubmitFeedRequest(string xmlFilePath, AmazonFeedType feedType) { // create submit feed request var feedRequest = new SubmitFeedRequest { Merchant = _merchantId, MarketplaceIdList = new IdList { Id = new List <string> { _marketplaceId } }, FeedType = feedType.ToString(), ContentType = new ContentType(MediaType.OctetStream), FeedContent = File.Open(xmlFilePath, FileMode.Open, FileAccess.ReadWrite) }; feedRequest.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(feedRequest.FeedContent); return(feedRequest); }
public SubmitFeedRequest GetSubmitFeedRequest(AmazonFeedType feedType, FileStream feedContent) { var request = new SubmitFeedRequest() { Merchant = _amazonSellerSettings.SellerId, ContentType = new ContentType(MediaType.XML), FeedContent = feedContent, FeedType = feedType.ToString(), MarketplaceIdList = new IdList { Id = new List<string>(new[] { _amazonSellerSettings.MarketplaceId }) } }; request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent); return request; }
public static SubmitFeedResponse SendAmazonFeeds(IMarketplaceWebServiceClient feedService, IEnumerable<Product> amazonUpdateList, AmazonEnvelopeMessageType messageType, AmazonFeedType feedType, string AmazonMerchantId, string AmazonMarketplaceId, string AmazonServiceUrl, string AmazonAccessKeyId, string AmazonSecretAccessKey) { //var requestResponse = new List<string>(); SubmitFeedResponse feedResponse = null; var amazonEnvelope = new AmazonEnvelope { Header = new Header { DocumentVersion = "1.01", MerchantIdentifier = AmazonMerchantId, }, MessageType = messageType }; var updates = new List<AmazonEnvelopeMessage>(); var counter = 1; foreach (var amazonUpdate in amazonUpdateList) { var curUpdate = new AmazonEnvelopeMessage { MessageID = counter.ToString(), Item = amazonUpdate }; updates.Add(curUpdate); counter++; } //add all update products to envelope's message amazonEnvelope.Message = updates.ToArray(); var serializer = new XmlSerializer(amazonEnvelope.GetType()); var stringReader = new StringWriter(); serializer.Serialize(stringReader, amazonEnvelope); var xmlResult = stringReader.ToString(); using (MemoryStream feedStream = new MemoryStream()) { serializer.Serialize(feedStream, amazonEnvelope); var feedRequest = new SubmitFeedRequest { Merchant = AmazonMerchantId, MarketplaceIdList = new IdList { Id = new List<string>(new[] { AmazonMarketplaceId }) }, FeedType = feedType.ToString(), ContentType = new ContentType(MediaType.OctetStream), FeedContent = feedStream }; // Calculating the MD5 hash value exhausts the stream, and therefore we must either reset the // position, or create another stream for the calculation. feedRequest.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(feedRequest.FeedContent); //var feedService = new MockMarketplaceWebServiceClient(); var uploadSuccess = false; var retryCount = 0; while (!uploadSuccess) { try { feedResponse = feedService.SubmitFeed(feedRequest); //var submissionId = feedResponse.SubmitFeedResult.FeedSubmissionInfo.FeedSubmissionId; //requestResponse.Add(submissionId); uploadSuccess = true; } catch (Exception ex) { //if sending not succeed after 3 attempts stop retrying retryCount++; if (retryCount == 3) break; //pause sending for 3 minutes Thread.Sleep(18000); if (ex.ToString().ToLowerInvariant().Contains("request is throttled")) continue; //requestResponse.Add(string.Format("ERROR: {0}", ex)); } } } return feedResponse; }
private List <string> SendAmazonFeeds(List <List <object> > amazonUpdateList, AmazonEnvelopeMessageType messageType, AmazonFeedType feedType) { { var masterCounter = 1; var returnResult = new List <string>(); foreach (var amazonUpdateGroup in amazonUpdateList) { var amazonEnvelope = new AmazonEnvelope { Header = new Header { DocumentVersion = "1.01", MerchantIdentifier = _merchantId, }, MessageType = messageType, PurgeAndReplace = false, PurgeAndReplaceSpecified = true }; var updates = new List <AmazonEnvelopeMessage>(); var counter = 1; foreach (var amazonUpdate in amazonUpdateGroup) { var curUpdate = new AmazonEnvelopeMessage { MessageID = counter.ToString(), OperationType = AmazonEnvelopeMessageOperationType.Update, //OperationTypeSpecified = true, Item = amazonUpdate }; updates.Add(curUpdate); counter++; } amazonEnvelope.Message = updates.ToArray(); var xmlString = MarketplaceHelper.ParseObjectToXML(amazonEnvelope); var path = "D:\\logs\\"; var fileName = string.Format("Amazon{0}Feed_{1}{3}.{2}", messageType, masterCounter, "xml", DateTime.Now.Second); var documentFileName = Path.Combine(path, fileName); File.WriteAllText(documentFileName, xmlString); if (!File.Exists(documentFileName)) { throw new ArgumentException("SendFeed document not generated properly"); } var feedRequest = new SubmitFeedRequest { Merchant = _merchantId, MarketplaceIdList = new IdList { Id = new List <string>(new[] { _marketplaceId }) }, FeedType = feedType.ToString(), ContentType = new ContentType(MediaType.OctetStream), FeedContent = File.Open(documentFileName, FileMode.Open, FileAccess.Read) }; feedRequest.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(feedRequest.FeedContent); var feedConfig = new MarketplaceWebServiceConfig { ServiceURL = "https://mws.amazonservices.com" }; var feedService = new MarketplaceWebServiceClient(_awsAccessKey, _secretKey, "Demac", "1.01", feedConfig); var uploadSuccess = false; var retryCount = 0; while (!uploadSuccess) { try { var feedResponse = feedService.SubmitFeed(feedRequest); var submissionId = feedResponse.SubmitFeedResult.FeedSubmissionInfo.FeedSubmissionId; returnResult.Add(submissionId); uploadSuccess = true; masterCounter++; //Thread.Sleep(120000); } catch (Exception ex) { retryCount++; if (retryCount == 3) { break; } //Thread.Sleep(18000); if (ex.ToString().ToLowerInvariant().Contains("request is throttled")) { continue; } returnResult.Add(string.Format("ERROR: {0}", ex)); } } } return(returnResult); } }
public SubmitFeedResult SubmitFeed(MarketplaceWebService service, FileInfo fileInfo, AmazonFeedType feedType) { var response = new SubmitFeedResponse(); var sfRequest = new SubmitFeedRequest(); sfRequest.Merchant = _merchantId; sfRequest.MarketplaceIdList = new IdList { Id = new List <string>(new[] { _marketplaceId }) }; using (var stream = new FileStream(fileInfo.Name, FileMode.Open, FileAccess.ReadWrite)) { sfRequest.FeedContent = stream; sfRequest.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(sfRequest.FeedContent); sfRequest.FeedContent.Position = 0; sfRequest.FeedType = feedType.ToString(); response = service.SubmitFeed(sfRequest); } return(response.SubmitFeedResult); }
public static SubmitFeedResponse SendAmazonFeeds(IMarketplaceWebServiceClient feedService, IEnumerable <Product> amazonUpdateList, AmazonEnvelopeMessageType messageType, AmazonFeedType feedType, string AmazonMerchantId, string AmazonMarketplaceId, string AmazonServiceUrl, string AmazonAccessKeyId, string AmazonSecretAccessKey) { //var requestResponse = new List<string>(); SubmitFeedResponse feedResponse = null; var amazonEnvelope = new AmazonEnvelope { Header = new Header { DocumentVersion = "1.01", MerchantIdentifier = AmazonMerchantId, }, MessageType = messageType }; var updates = new List <AmazonEnvelopeMessage>(); var counter = 1; foreach (var amazonUpdate in amazonUpdateList) { var curUpdate = new AmazonEnvelopeMessage { MessageID = counter.ToString(), Item = amazonUpdate }; updates.Add(curUpdate); counter++; } //add all update products to envelope's message amazonEnvelope.Message = updates.ToArray(); var serializer = new XmlSerializer(amazonEnvelope.GetType()); var stringReader = new StringWriter(); serializer.Serialize(stringReader, amazonEnvelope); var xmlResult = stringReader.ToString(); using (MemoryStream feedStream = new MemoryStream()) { serializer.Serialize(feedStream, amazonEnvelope); var feedRequest = new SubmitFeedRequest { Merchant = AmazonMerchantId, MarketplaceIdList = new IdList { Id = new List <string>(new[] { AmazonMarketplaceId }) }, FeedType = feedType.ToString(), ContentType = new ContentType(MediaType.OctetStream), FeedContent = feedStream }; // Calculating the MD5 hash value exhausts the stream, and therefore we must either reset the // position, or create another stream for the calculation. feedRequest.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(feedRequest.FeedContent); //var feedService = new MockMarketplaceWebServiceClient(); var uploadSuccess = false; var retryCount = 0; while (!uploadSuccess) { try { feedResponse = feedService.SubmitFeed(feedRequest); //var submissionId = feedResponse.SubmitFeedResult.FeedSubmissionInfo.FeedSubmissionId; //requestResponse.Add(submissionId); uploadSuccess = true; } catch (Exception ex) { //if sending not succeed after 3 attempts stop retrying retryCount++; if (retryCount == 3) { break; } //pause sending for 3 minutes Thread.Sleep(18000); if (ex.ToString().ToLowerInvariant().Contains("request is throttled")) { continue; } //requestResponse.Add(string.Format("ERROR: {0}", ex)); } } } return(feedResponse); }