/// <summary> /// Will continue to call GetFeedSubmissionList unitl it's completed or cancelled /// </summary> /// <param name="feedSubmissionId">The feed submission id</param> private void WaitForGetFeedSubmissionListToCompleted(string feedSubmissionId) { // create submission feed list request GetFeedSubmissionListResponse submissionListResponse = null; var isUpdate = false; var submissionListRequest = new GetFeedSubmissionListRequest { Merchant = _merchantId, FeedSubmissionIdList = new IdList { Id = { feedSubmissionId } } }; do { Console.WriteLine("Checking the submitted feed status..."); // check to see if it's the first time it's been called if (submissionListResponse != null) { // if not yet finished yet, sleep for 45 seconds. This is the restore rate for GetFeedSubmissionList Thread.Sleep(45000); } submissionListResponse = _amazonCient.GetFeedSubmissionList(submissionListRequest); parsedAndPersistSubmissionListResponse(submissionListResponse, ref isUpdate); } while (!submissionListResponse.GetFeedSubmissionListResult.FeedSubmissionInfo.First().FeedProcessingStatus.Equals("_CANCELED_") && !submissionListResponse.GetFeedSubmissionListResult.FeedSubmissionInfo.First().FeedProcessingStatus.Equals("_DONE_")); Console.WriteLine("Submitted feed status is DONE!"); }
/// <summary> /// Will continue to call GetFeedSubmissionList until it's completed or canceled /// </summary> /// <param name="feedSubmissionId">The feed submission id.</param> private void WaitForGetFeedSubmissionListToComplete(string feedSubmissionId) { GetFeedSubmissionListRequest submissionListRequest = new GetFeedSubmissionListRequest(); submissionListRequest.Merchant = _MerchantId; submissionListRequest.FeedSubmissionIdList = new IdList() { Id = { feedSubmissionId } }; GetFeedSubmissionListResponse submissionListResponse = null; // Pause for 5 seconds to give Amazon a little bit to try and process. Otherwise we have to wait 45 seconds. System.Threading.Thread.Sleep(5000); do { // Check to see if it's the first time it's been called. if (submissionListResponse != null) { // If it's not finished yet, sleep for 45 seconds. This is the restore rate for GetFeedSubmissionList System.Threading.Thread.Sleep(45000); } submissionListResponse = _AmazonClient.GetFeedSubmissionList(submissionListRequest); }while (!submissionListResponse.GetFeedSubmissionListResult.FeedSubmissionInfo.First().FeedProcessingStatus.Equals("_CANCELED_") && !submissionListResponse.GetFeedSubmissionListResult.FeedSubmissionInfo.First().FeedProcessingStatus.Equals("_DONE_")); }
public void GetFeedsTest() { MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig(); config.ServiceURL = serviceURL; MarketplaceWebService.MarketplaceWebService service = new MarketplaceWebServiceClient( creds.AccessKey, creds.SecretKey, appName, appVersion, config); GetFeedSubmissionListRequest req = new GetFeedSubmissionListRequest(); req.MWSAuthToken = mWSAuthToken; req.Merchant = sellerId; var response = service.GetFeedSubmissionList(req); foreach (var item in response.GetFeedSubmissionListResult.FeedSubmissionInfo) { Console.WriteLine(item.FeedSubmissionId); } }
public List <(string FeedSubmissionId, string FeedProcessingStatus)> RequestFeedSubmissionStatusesFromAmazon(IFeedSubmissionEntryService feedSubmissionService, IEnumerable <string> feedSubmissionIdList, string merchant) { List <(string FeedSubmissionId, string IsProcessingComplete)> GetProcessingStatusesPerSubmissionIdFromResponse(GetFeedSubmissionListResponse response) { var responseInfo = new List <(string FeedSubmissionId, string IsProcessingComplete)>(); foreach (var feedSubmissionInfo in response.GetFeedSubmissionListResult.FeedSubmissionInfo) { responseInfo.Add((feedSubmissionInfo.FeedSubmissionId, feedSubmissionInfo.FeedProcessingStatus)); } return(responseInfo); } _logger.Debug($"Attempting to request feed submission statuses for all feeds in queue."); var request = new GetFeedSubmissionListRequest() { FeedSubmissionIdList = new IdList(), Merchant = merchant }; request.FeedSubmissionIdList.Id.AddRange(feedSubmissionIdList); if (!string.IsNullOrEmpty(_mWSAuthToken)) { request.MWSAuthToken = _mWSAuthToken; } try { var response = _marketplaceWebServiceClient.GetFeedSubmissionList(request); var requestId = response?.ResponseHeaderMetadata?.RequestId ?? "unknown"; var timestamp = response?.ResponseHeaderMetadata?.Timestamp ?? "unknown"; _logger.Debug($"AmazonMWS request for feed submission statuses succeeded.", new RequestInfo(timestamp, requestId)); if (response?.GetFeedSubmissionListResult?.FeedSubmissionInfo != null) { return(GetProcessingStatusesPerSubmissionIdFromResponse(response)); } else { _logger.Warn("AmazonMWS GetFeedSubmissionList response does not contain any results. The operation will be executed again at the next poll request."); return(null); } } catch (MarketplaceWebServiceException e) { _logger.Warn($"AmazonMWS GetFeedSubmissionList failed! The operation will be executed again at the next poll request.", e); return(null); } catch (Exception e) { _logger.Warn($"AmazonMWS GetFeedSubmissionList failed! The operation will be executed again at the next poll request.", e); return(null); } }
/// <summary> /// Create GetFeedSubmissionListRequest with the specified submission IDs /// </summary> /// <param name="submissionIds"></param> /// <returns></returns> public static GetFeedSubmissionListRequest CreateFeedSubmissionListRequest(List <string> submissionIds) { var request = new GetFeedSubmissionListRequest { Merchant = MerchantId, FeedSubmissionIdList = new IdList { Id = submissionIds }, }; return(request); }
public void CheckFeedSubmissionResultId(string feedId) { //50050016655 var list = new List <String>(); list.Add("50048016655"); var request = new GetFeedSubmissionListRequest { Merchant = _merchantId, Marketplace = _marketplaceId, FeedSubmissionIdList = new IdList { Id = list }, }; var result = _getWebServiceClient().GetFeedSubmissionList(request); }
/// <summary> /// Get Feed Submission List /// </summary> /// <param name="request">Get Feed Submission List request</param> /// <returns>Get Feed Submission List Response from the service</returns> /// <remarks> /// returns a list of feed submission identifiers and their associated metadata /// /// </remarks> public GetFeedSubmissionListResponse GetFeedSubmissionList(GetFeedSubmissionListRequest request) { return(Invoke <GetFeedSubmissionListResponse>("GetFeedSubmissionListResponse.xml")); }
public List <XElement> SubmitFeed(string accountName, XElement feed) { List <XElement> errors = new List <XElement>(); SubmitFeedRequest request = new SubmitFeedRequest(); request.FeedType = "_POST_INVENTORY_AVAILABILITY_DATA_"; request.MWSAuthToken = mwsAuthTokenDictionary[accountName]; request.Merchant = sellerIdDictionary[accountName]; request.MarketplaceIdList = new IdList(); request.MarketplaceIdList.Id = new List <string>(); request.MarketplaceIdList.Id.Add(marketplaceId); MemoryStream memoryStream = new MemoryStream(); feed.Save(memoryStream); request.FeedContent = memoryStream; request.FeedContent.Position = 0; request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent); request.FeedContent.Position = 0; int retryCount = 0; SubmitFeedResponse response = null; while (retryCount <= 4 && response == null) { Thread.Sleep(TimeSpan.FromMinutes(retryCount * 2)); try { response = mwsClient.SubmitFeed(request); } catch (Exception e) { if (retryCount >= 4) { throw e; } retryCount++; } } memoryStream.Close(); string feedSubmissionId = response.SubmitFeedResult.FeedSubmissionInfo.FeedSubmissionId; int count = 0; bool done = false; while (count < 100 && !done) { Thread.Sleep(60000); GetFeedSubmissionListRequest feedSubmissionListRequest = new GetFeedSubmissionListRequest(); feedSubmissionListRequest.MWSAuthToken = mwsAuthTokenDictionary[accountName]; feedSubmissionListRequest.Merchant = sellerIdDictionary[accountName]; feedSubmissionListRequest.FeedSubmissionIdList = new IdList(); feedSubmissionListRequest.FeedSubmissionIdList.Id.Add(feedSubmissionId); GetFeedSubmissionListResponse feedSubmissionResponse = mwsClient.GetFeedSubmissionList(feedSubmissionListRequest); foreach (FeedSubmissionInfo info in feedSubmissionResponse.GetFeedSubmissionListResult.FeedSubmissionInfo) { if (info.FeedSubmissionId == feedSubmissionId) { if (info.FeedProcessingStatus == "_DONE_") { done = true; GetFeedSubmissionResultRequest feedSubmissionResultRequest = new GetFeedSubmissionResultRequest(); feedSubmissionResultRequest.MWSAuthToken = mwsAuthTokenDictionary[accountName]; feedSubmissionResultRequest.Merchant = sellerIdDictionary[accountName]; feedSubmissionResultRequest.FeedSubmissionId = feedSubmissionId; MemoryStream stream = new MemoryStream(); feedSubmissionResultRequest.FeedSubmissionResult = stream; retryCount = 0; GetFeedSubmissionResultResponse feedSubmissionResultResponse = null; while (retryCount <= m_maxRetry && feedSubmissionResultResponse == null) { Thread.Sleep(TimeSpan.FromMinutes(retryCount * 2)); try { feedSubmissionResultResponse = mwsClient.GetFeedSubmissionResult(feedSubmissionResultRequest); } catch (MarketplaceWebServiceException e) { if (e.ErrorCode == "RequestThrottled") { retryCount++; } } } XElement responseElement = XElement.Load(stream); IEnumerable <XElement> messages = responseElement.Descendants("Message"); foreach (XElement message in messages) { XElement processingReportElement = message.Element("ProcessingReport"); int nError = (int)processingReportElement.Element("ProcessingSummary").Element("MessagesWithError"); if (nError > 0) { int messageId = (int)message.Element("MessageID"); } } } } } count++; } return(errors); }
/// <summary> /// returns a list of feed submission identifiers and their associated metadata /// /// </summary> /// <param name="service">Instance of MarketplaceWebService service</param> /// <param name="request">GetFeedSubmissionListRequest request</param> public static async Task InvokeGetFeedSubmissionList(MarketplaceWebService service, GetFeedSubmissionListRequest request) { try { GetFeedSubmissionListResponse response = await service.GetFeedSubmissionList(request); Console.WriteLine("Service Response"); Console.WriteLine("============================================================================="); Console.WriteLine(); Console.WriteLine(" GetFeedSubmissionListResponse"); if (response.IsSetGetFeedSubmissionListResult()) { Console.WriteLine(" GetFeedSubmissionListResult"); GetFeedSubmissionListResult getFeedSubmissionListResult = response.GetFeedSubmissionListResult; if (getFeedSubmissionListResult.IsSetNextToken()) { Console.WriteLine(" NextToken"); Console.WriteLine(" {0}", getFeedSubmissionListResult.NextToken); } if (getFeedSubmissionListResult.IsSetHasNext()) { Console.WriteLine(" HasNext"); Console.WriteLine(" {0}", getFeedSubmissionListResult.HasNext); } List <FeedSubmissionInfo> feedSubmissionInfoList = getFeedSubmissionListResult.FeedSubmissionInfo; foreach (FeedSubmissionInfo feedSubmissionInfo in feedSubmissionInfoList) { Console.WriteLine(" FeedSubmissionInfo"); if (feedSubmissionInfo.IsSetFeedSubmissionId()) { Console.WriteLine(" FeedSubmissionId"); Console.WriteLine(" {0}", feedSubmissionInfo.FeedSubmissionId); } if (feedSubmissionInfo.IsSetFeedType()) { Console.WriteLine(" FeedType"); Console.WriteLine(" {0}", feedSubmissionInfo.FeedType); } if (feedSubmissionInfo.IsSetSubmittedDate()) { Console.WriteLine(" SubmittedDate"); Console.WriteLine(" {0}", feedSubmissionInfo.SubmittedDate); } if (feedSubmissionInfo.IsSetFeedProcessingStatus()) { Console.WriteLine(" FeedProcessingStatus"); Console.WriteLine(" {0}", feedSubmissionInfo.FeedProcessingStatus); } if (feedSubmissionInfo.IsSetStartedProcessingDate()) { Console.WriteLine(" StartedProcessingDate"); Console.WriteLine(" {0}", feedSubmissionInfo.StartedProcessingDate); } if (feedSubmissionInfo.IsSetCompletedProcessingDate()) { Console.WriteLine(" CompletedProcessingDate"); Console.WriteLine(" {0}", feedSubmissionInfo.CompletedProcessingDate); } } } if (response.IsSetResponseMetadata()) { Console.WriteLine(" ResponseMetadata"); ResponseMetadata responseMetadata = response.ResponseMetadata; if (responseMetadata.IsSetRequestId()) { Console.WriteLine(" RequestId"); Console.WriteLine(" {0}", responseMetadata.RequestId); } } Console.WriteLine(" ResponseHeaderMetadata"); Console.WriteLine(" RequestId"); Console.WriteLine(" " + response.ResponseHeaderMetadata.RequestId); Console.WriteLine(" ResponseContext"); Console.WriteLine(" " + response.ResponseHeaderMetadata.ResponseContext); Console.WriteLine(" Timestamp"); Console.WriteLine(" " + response.ResponseHeaderMetadata.Timestamp); } catch (MarketplaceWebServiceException ex) { Console.WriteLine("Caught Exception: " + ex.Message); Console.WriteLine("Response Status Code: " + ex.StatusCode); Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine("Error Type: " + ex.ErrorType); Console.WriteLine("Request ID: " + ex.RequestId); Console.WriteLine("XML: " + ex.XML); Console.WriteLine("ResponseHeaderMetadata: " + ex.ResponseHeaderMetadata); } }
/// <summary> /// Get Feed Submission List /// </summary> /// <param name="request">Get Feed Submission List request</param> /// <returns>Get Feed Submission List Response from the service</returns> /// <remarks> /// returns a list of feed submission identifiers and their associated metadata /// /// </remarks> public async Task <GetFeedSubmissionListResponse> GetFeedSubmissionList(GetFeedSubmissionListRequest request) { return(await Invoke <GetFeedSubmissionListResponse>("GetFeedSubmissionListResponse.xml")); }
private FeedSubmissionInfo[] _GetFeedSubmissionList(string[] FeedSubmissionIdList, EFeedType[] FeedTypeList, EFeedProcessingStatus[] FeedProcessingStatusList, DateTime SubmittedFromDate, DateTime SubmittedToDate) { string NextToken = string.Empty; AmazonCredential Credentials = this.GetCredential(); MarketplaceWebServiceClient Client = this.GetClient(Credentials); GetFeedSubmissionListRequest Request = new GetFeedSubmissionListRequest() { Merchant = Credentials.MerchantID, MaxCount = 100 }; if (FeedSubmissionIdList != null) { Request.FeedSubmissionIdList = new IdList() { Id = FeedSubmissionIdList.ToList() } } ; else if (FeedTypeList != null) { Request.FeedTypeList = new TypeList() { Type = FeedTypeList.Select(Item => EnumStringHandler.GetEnumString <EFeedType>(Item)).ToList() } } ; else if (FeedProcessingStatusList != null) { Request.FeedProcessingStatusList = new StatusList() { Status = FeedProcessingStatusList.Select(Item => EnumStringHandler.GetEnumString <EFeedProcessingStatus>(Item)).ToList() } } ; else if (SubmittedFromDate != default(DateTime) && SubmittedToDate != default(DateTime)) { Request.SubmittedFromDate = SubmittedFromDate; Request.SubmittedToDate = SubmittedToDate; } List <FeedSubmissionInfo> Info = new List <FeedSubmissionInfo>(); Task GetFeedSubmissionListTask = new Task(() => { while (true) { switch (NextToken == string.Empty) { case true: this.Throttle(ERequestType.GetFeedSubmissionList); GetFeedSubmissionListResponse Response = Client.GetFeedSubmissionList(Request); if (Response.IsSetGetFeedSubmissionListResult()) { GetFeedSubmissionListResult Result = Response.GetFeedSubmissionListResult; if (Result.IsSetFeedSubmissionInfo()) { foreach (var FeedInfo in Result.FeedSubmissionInfo) { Info.Add(FeedInfo); } } if (Result.HasNext) { NextToken = Result.NextToken; } else { goto EndOfLoop; } } break; case false: this.Throttle(ERequestType.GetFeedSubmissionListByNextToken); GetFeedSubmissionListByNextTokenRequest RequestNextToken = new GetFeedSubmissionListByNextTokenRequest() { Merchant = Credentials.MerchantID, NextToken = NextToken, }; GetFeedSubmissionListByNextTokenResponse ResponseNextToken = Client.GetFeedSubmissionListByNextToken(RequestNextToken); if (ResponseNextToken.IsSetGetFeedSubmissionListByNextTokenResult()) { GetFeedSubmissionListByNextTokenResult ResultNextToken = ResponseNextToken.GetFeedSubmissionListByNextTokenResult; if (ResultNextToken.IsSetFeedSubmissionInfo()) { foreach (var FeedInfo in ResultNextToken.FeedSubmissionInfo) { Info.Add(FeedInfo); } } if (ResultNextToken.HasNext) { NextToken = ResultNextToken.NextToken; } else { goto EndOfLoop; } } break; } } EndOfLoop: Console.Write(""); }); GetFeedSubmissionListTask.Start(); GetFeedSubmissionListTask.Wait((int)Math.Ceiling(TimeSpan.FromMinutes(Definitions.Timeout_Minutes).Add(TimeSpan.FromHours(Definitions.Timeout_Hours)).TotalMilliseconds)); return(Info.ToArray()); }