Exemple #1
0
        /// <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!");
        }
        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);
            }
        }
        /// <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_"));
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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());
        }