示例#1
0
        /// <summary>
        /// Convert the SubmitFeedResponse stream for the post feed folow into a AmazonExeption if needed
        /// </summary>
        /// <param name="responseStream">The response stream object</param>
        /// <param name="messageType">The type of the message</param>
        /// <returns></returns>
        private void parsedResultStreamAndLogReport(Stream responseStream, AmazonEnvelopeMessageType messageType, string submittedBy)
        {
            try
            {
                using (var stream = responseStream)
                {
                    // the result may not be an XML document. This will be reveled with testing.
                    var doc = new XmlDocument();
                    doc.Load(stream);

                    var report            = doc.SelectSingleNode("/AmazonEnvelope/Message/ProcessingReport");
                    var processingSummary = report.SelectSingleNode("ProcessingSummary");
                    var processingReport  = new MarketplaceProcessingReport
                    {
                        MerchantId          = _credential.MerchantId,
                        MessageType         = messageType.ToString(),
                        TransactionId       = report.SelectSingleNode("DocumentTransactionID").InnerText,
                        MessagesProcessed   = int.Parse(processingSummary.SelectSingleNode("MessagesProcessed").InnerText),
                        MessagesSuccessful  = int.Parse(processingSummary.SelectSingleNode("MessagesSuccessful").InnerText),
                        MessagesWithError   = int.Parse(processingSummary.SelectSingleNode("MessagesWithError").InnerText),
                        MessagesWithWarning = int.Parse(processingSummary.SelectSingleNode("MessagesWithWarning").InnerText),
                        StatusCode          = report.SelectSingleNode("StatusCode").InnerText,
                        SubmittedBy         = submittedBy
                    };

                    // parsed the any processing report results
                    var results       = report.SelectNodes("Result");
                    var reportResults = new List <MarketplaceProcessingReportResult>();
                    foreach (XmlNode result in results)
                    {
                        reportResults.Add(new MarketplaceProcessingReportResult
                        {
                            TransactionId  = processingReport.TransactionId,
                            MessageId      = int.Parse(result.SelectSingleNode("MessageID").InnerText),
                            Code           = result.SelectSingleNode("ResultCode").InnerText,
                            MessageCode    = result.SelectSingleNode("ResultMessageCode").InnerText,
                            Description    = result.SelectSingleNode("ResultDescription").InnerText,
                            AdditionalInfo = result.SelectSingleNode("AdditionalInfo/AmazonOrderID") == null ? "" : result.SelectSingleNode("AdditionalInfo/AmazonOrderID").InnerText
                        });
                    }

                    // add it to the report summary
                    processingReport.ReportResults = reportResults;

                    // save it to the database
                    _logger.AddProcessingReport(processingReport);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEntryType.AmazonOrdersProvider,
                                 string.Format("Error in parsing {0} result response stream. <br/> Error Message: {1}", messageType.ToString(),
                                               ex.InnerException != null ? string.Format("{0} <br/>Inner Message: {1}", ex.Message, ex.InnerException.Message) : ex.Message),
                                 ex.StackTrace);
            }
        }