internal FeedSubmissionProcessor(AmazonRegion region, string merchantId, string mWSAuthToken, IMarketplaceWebServiceClient marketplaceWebServiceClient, IEasyMwsLogger logger, EasyMwsOptions options) { _region = region; _merchantId = merchantId; _options = options; _logger = logger; _marketplaceWebServiceClient = marketplaceWebServiceClient; _mWSAuthToken = mWSAuthToken; }
/// <summary> /// Constructor to be used for UnitTesting/Mocking (in the absence of a dedicated DependencyInjection framework) /// </summary> internal ReportProcessor(AmazonRegion region, string merchantId, string mWSAuthToken, EasyMwsOptions options, IMarketplaceWebServiceClient mwsClient, IRequestReportProcessor requestReportProcessor, ICallbackActivator callbackActivator, IEasyMwsLogger logger) : this(region, merchantId, mWSAuthToken, options, mwsClient, logger) { _requestReportProcessor = requestReportProcessor; _callbackActivator = callbackActivator; RegisterEvents(); }
public AmazonMerchantController( IAmazonSettings settingsManager, IAmazonProductProvider productProvider, IPushNotificationManager pushNotificationManager, IDateTimeProvider dateTimeProvider, IMarketplaceWebServiceClient amazonMwsService) { _settingsManager = settingsManager; _productProvider = productProvider; _pushNotificationManager = pushNotificationManager; _dateTimeProvider = dateTimeProvider; _amazonMwsService = amazonMwsService; }
internal ReportProcessor(AmazonRegion region, string merchantId, string mWSAuthToken, EasyMwsOptions options, IMarketplaceWebServiceClient mwsClient, IEasyMwsLogger logger) { _region = region; _merchantId = merchantId; _options = options; _logger = logger; _callbackActivator = _callbackActivator ?? new CallbackActivator(); _requestReportProcessor = _requestReportProcessor ?? new RequestReportProcessor(_region, _merchantId, mWSAuthToken, mwsClient, _logger, _options); RegisterEvents(); }
/// <summary> /// Constructor to be used for UnitTesting/Mocking (in the absence of a dedicated DependencyInjection framework) /// </summary> internal FeedProcessor(AmazonRegion region, string merchantId, string mWSAuthToken, EasyMwsOptions options, IMarketplaceWebServiceClient mwsClient, IFeedSubmissionProcessor feedSubmissionProcessor, ICallbackActivator callbackActivator, IEasyMwsLogger logger) : this(region, merchantId, mWSAuthToken, options, mwsClient, logger) { _feedSubmissionProcessor = feedSubmissionProcessor; _callbackActivator = callbackActivator; RegisterEvents(); }
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; }
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); }