Exemple #1
0
        /// <summary>
        /// Converts a SubmitFeedResponse for the UpdateInventory flow into an InventoryException if needed.
        /// </summary>
        /// <param name="submitFeedResponse">The response object.</param>
        /// <returns>An exception if an error exists in the response object, else null.</returns>
        private AmazonUpdateInventoryException ConvertResultToUpdateInventoryException(Stream submitFeedResponse)
        {
            using (Stream responseStream = submitFeedResponse)
            {
                // The result may not be an xml document. This will be revealed with testing.
                var doc = new XmlDocument();
                doc.Load(responseStream);

                // Check to see if any of the updates had an error else just return fine.
                var report       = doc.SelectSingleNode("/AmazonEnvelope/Message/ProcessingReport");
                var errorResults = report.SelectNodes("Result[ResultCode='Error']");
                if (errorResults.Count > 0)
                {
                    var processingSummary = report.SelectSingleNode("ProcessingSummary");
                    var successCount      = int.Parse(processingSummary.SelectSingleNode("MessagesSuccessful").InnerText);
                    var errorCount        = int.Parse(processingSummary.SelectSingleNode("MessagesWithError").InnerText);
                    var warningCount      = int.Parse(processingSummary.SelectSingleNode("MessagesWithWarning").InnerText);
                    var exception         = new AmazonUpdateInventoryException(string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                                                             "{0} Products did not update successfully. {1} Products updated sucessfully. {2} Products updated with warnings.",
                                                                                             errorCount,
                                                                                             successCount,
                                                                                             warningCount));

                    foreach (XmlNode result in errorResults)
                    {
                        exception.ErrorResults.Add(new AmazonUpdateInventoryException.Result()
                        {
                            Code        = result.SelectSingleNode("ResultMessageCode").InnerText,
                            Description = result.SelectSingleNode("ResultDescription").InnerText,
                            SKU         = result.SelectSingleNode("AdditionalInfo/SKU").InnerText
                        });
                    }
                    return(exception);
                }
                else
                {
                    return(null);
                }
            }
        }
        /// <summary>
        /// Converts a SubmitFeedResponse for the UpdateInventory flow into an InventoryException if needed.
        /// </summary>
        /// <param name="submitFeedResponse">The response object.</param>
        /// <returns>An exception if an error exists in the response object, else null.</returns>
        private AmazonUpdateInventoryException ConvertResultToUpdateInventoryException(Stream submitFeedResponse)
        {
            using (Stream responseStream = submitFeedResponse)
            {
                // The result may not be an xml document. This will be revealed with testing.
                var doc = new XmlDocument();
                doc.Load(responseStream);

                // Check to see if any of the updates had an error else just return fine.
                var report = doc.SelectSingleNode("/AmazonEnvelope/Message/ProcessingReport");
                var errorResults = report.SelectNodes("Result[ResultCode='Error']");
                if (errorResults.Count > 0)
                {
                    var processingSummary = report.SelectSingleNode("ProcessingSummary");
                    var successCount = int.Parse(processingSummary.SelectSingleNode("MessagesSuccessful").InnerText);
                    var errorCount = int.Parse(processingSummary.SelectSingleNode("MessagesWithError").InnerText);
                    var warningCount = int.Parse(processingSummary.SelectSingleNode("MessagesWithWarning").InnerText);
                    var exception = new AmazonUpdateInventoryException(string.Format(System.Globalization.CultureInfo.CurrentCulture,
                        "{0} Products did not update successfully. {1} Products updated sucessfully. {2} Products updated with warnings.",
                        errorCount,
                        successCount,
                        warningCount));

                    foreach (XmlNode result in errorResults)
                    {
                        exception.ErrorResults.Add(new AmazonUpdateInventoryException.Result()
                        {
                            Code = result.SelectSingleNode("ResultMessageCode").InnerText,
                            Description = result.SelectSingleNode("ResultDescription").InnerText,
                            SKU = result.SelectSingleNode("AdditionalInfo/SKU").InnerText
                        });
                    }
                    return exception;
                }
                else return null;
            }
        }