Esempio n. 1
0
        /// <summary>
        /// retrieves the feed processing report
        ///
        /// </summary>
        /// <param name="service">Instance of MarketplaceWebService service</param>
        /// <param name="request">GetFeedSubmissionResultRequest request</param>
        public static async Task InvokeGetFeedSubmissionResult(MarketplaceWebService service, GetFeedSubmissionResultRequest request)
        {
            try
            {
                GetFeedSubmissionResultResponse response = await service.GetFeedSubmissionResult(request);


                Console.WriteLine("Service Response");
                Console.WriteLine("=============================================================================");
                Console.WriteLine();

                Console.WriteLine("        GetFeedSubmissionResultResponse");
                if (response.IsSetGetFeedSubmissionResultResult())
                {
                    Console.WriteLine("            GetFeedSubmissionResult");
                    GetFeedSubmissionResultResult getFeedSubmissionResultResult = response.GetFeedSubmissionResultResult;
                    if (getFeedSubmissionResultResult.IsSetContentMD5())
                    {
                        Console.WriteLine("                ContentMD5");
                        Console.WriteLine("                    {0}", getFeedSubmissionResultResult.ContentMD5);
                    }
                }

                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);
            }
        }
Esempio n. 2
0
        private void Setup_GetFeedSubmissionResult_Returns_SubmissionReportContentStream(string expectedFeedSubmissionId, string submissionReportContent)
        {
            var stream       = StreamHelper.CreateMemoryStream(submissionReportContent);
            var validMd5Hash = MD5ChecksumHelper.ComputeHashForAmazon(stream);
            var response     = new GetFeedSubmissionResultResponse
            {
                ResponseHeaderMetadata        = new ResponseHeaderMetadata("requestId", "responseContext", "timestamp"),
                GetFeedSubmissionResultResult = new GetFeedSubmissionResultResult()
                {
                    ContentMD5 = validMd5Hash
                }
            };

            _mwsClientMock
            .Setup(mws => mws.GetFeedSubmissionResult(It.Is <GetFeedSubmissionResultRequest>(grr => grr.FeedSubmissionId == expectedFeedSubmissionId && grr.Merchant == _merchantId)))
            .Callback <GetFeedSubmissionResultRequest>(request => { stream.CopyTo(request.FeedSubmissionResult); })
            .Returns(response);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 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);
        }
Esempio n. 5
0
        /// <summary>
        /// retrieves the feed processing report
        ///
        /// </summary>
        /// <param name="service">Instance of MarketplaceWebService service</param>
        /// <param name="request">GetFeedSubmissionResultRequest request</param>
        public static GetFeedSubmissionResultResponse InvokeGetFeedSubmissionResult(MarketplaceWebService service, GetFeedSubmissionResultRequest request)
        {
            try
            {
                GetFeedSubmissionResultResponse response = service.GetFeedSubmissionResult(request);

                string re = response.ToXML();
                Console.WriteLine("Service Response");
                Console.WriteLine("=============================================================================");
                Console.WriteLine();

                Console.WriteLine("        GetFeedSubmissionResultResponse");
                if (response.IsSetGetFeedSubmissionResultResult())
                {
                    Console.WriteLine("            GetFeedSubmissionResult");
                    GetFeedSubmissionResultResult getFeedSubmissionResultResult = response.GetFeedSubmissionResultResult;
                    //if (getFeedSubmissionResultResult.IsSetContentMD5())
                    //{
                    //    Console.WriteLine("                ContentMD5");
                    //    Console.WriteLine("                    {0}", getFeedSubmissionResultResult.ContentMD5);
                    //}
                }

                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.ResponseHeaderMetadata2.RequestId);
                //Console.WriteLine("                ResponseContext");
                //Console.WriteLine("                    " + response.ResponseHeaderMetadata2.ResponseContext);
                //Console.WriteLine("                Timestamp");
                //Console.WriteLine("                    " + response.ResponseHeaderMetadata2.Timestamp);
                return(response);
            }
            catch (MarketplaceWebServiceException ex)
            {
                if (ex.ErrorCode == "FeedProcessingResultNotReady")
                {
                    Console.WriteLine("{0} {1} ", ex.Message, DateTime.Now);
                }
                else
                {
                    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);
                }
                return(null);
            }
        }
Esempio n. 6
0
        public static void GetAmazonTrackingFeedSubmissionResult(string feedSubmissionId, string merchantId, string marketplaceId, string accessKeyId, string secretAccessKey)
        {
            GetFeedSubmissionResultRequest request = new GetFeedSubmissionResultRequest();

            request.Merchant         = merchantId;
            request.FeedSubmissionId = feedSubmissionId;
            //request.FeedSubmissionResult = File.Open("feedSubmissionResult.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            request.FeedSubmissionResult = new FileStream(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\AmazonTrackingResult.xml", FileMode.Truncate, FileAccess.ReadWrite);

            const string applicationName       = "<Your Application Name>";
            const string applicationVersion    = "<Your Application Version>";
            MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();

            config.ServiceURL = "https://mws.amazonservices.com";
            config.SetUserAgentHeader(
                applicationName,
                applicationVersion,
                "C#",
                "<Parameter 1>", "<Parameter 2>");
            MarketplaceWebService.MarketplaceWebService service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, config);
            string requestId = "";

            try
            {
                GetFeedSubmissionResultResponse response = service.GetFeedSubmissionResult(request);


                Console.WriteLine("Service Response");
                Console.WriteLine("=============================================================================");
                Console.WriteLine();

                Console.WriteLine("        GetFeedSubmissionResultResponse");
                if (response.IsSetGetFeedSubmissionResultResult())
                {
                    Console.WriteLine("            GetFeedSubmissionResult");
                    GetFeedSubmissionResultResult getFeedSubmissionResultResult = response.GetFeedSubmissionResultResult;
                    if (getFeedSubmissionResultResult.IsSetContentMD5())
                    {
                        Console.WriteLine("                ContentMD5");
                        Console.WriteLine("                    {0}", getFeedSubmissionResultResult.ContentMD5);
                    }
                }

                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)
            {
                ExceptionUtility exceptionUtility = new ExceptionUtility();
                exceptionUtility.CatchMethod(ex, "AmazonTrackingResult->GetAmazonTrackingResult: ", feedSubmissionId + ": " + ex.Message.ToString(), senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum);

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

            request.FeedSubmissionResult.Close();
            request.FeedSubmissionResult.Dispose();
        }