예제 #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/SKU") == null ? "" : result.SelectSingleNode("AdditionalInfo/SKU").InnerText
                        });
                    }

                    // determine the real total number of warning messages
                    var warningCount = reportResults.Count(x => x.Code == "Warning");
                    processingReport.MessagesWithWarning = warningCount;

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

                    // save it to the database
                    _logger.AddProcessingReport(processingReport);
                }
            }
            catch (Exception ex)
            {
                _logger.Add(LogEntrySeverity.Error,
                            LogEntryType.AmazonListing,
                            string.Format("Error in parsing {0} result response stream. <br/> Error Message: {1}", messageType.ToString(), EisHelper.GetExceptionMessage(ex)),
                            ex.StackTrace);
            }
        }
예제 #2
0
        public async Task <MwsResponse <SubmitFeedResponse> > SubmitFeed <T>(List <T> messageItems, AmazonEnvelopeMessageType messageType, DateTime effectiveDate, string feedType, bool purgeAndReplace = false, AmazonEnvelopeMessageOperationType operationType = AmazonEnvelopeMessageOperationType.Update) where T : AmazonMessageChoice
        {
            if (typeof(T).Name != messageType.ToString())
            {
                return(new MwsResponse <SubmitFeedResponse>
                {
                    Error = new ErrorResponse(),
                    ExceptionMessage = "Feed items do not match given messageChoice"
                });
            }


            var parameters = new SortedDictionary <string, string>(new SortDecendingBytes());

            var envelope = InstantiateEnvelope <T>(this.SellerId, this.MarketPlaceId, purgeAndReplace, messageItems, messageType, effectiveDate, operationType);

            parameters["PurgeAndReplace"] = purgeAndReplace.ToString().ToLower();
            parameters["FeedType"]        = feedType;

            try {
                var result = await SendMws <AmazonEnvelope>(envelope, parameters, "SubmitFeed");

                var resultText = await result.Content.ReadAsStringAsync();

                var submitFeedResult = MwsUtilities.Deserialize <SubmitFeedResponse>(resultText);

                if (submitFeedResult != null)
                {
                    return(new MwsResponse <SubmitFeedResponse>
                    {
                        Result = submitFeedResult
                    });
                }


                var submitFeedError = MwsUtilities.Deserialize <ErrorResponse>(resultText);

                if (submitFeedError != null)
                {
                    return(new MwsResponse <SubmitFeedResponse>
                    {
                        Error = submitFeedError
                    });
                }


                return(new MwsResponse <SubmitFeedResponse>
                {
                    Error = new ErrorResponse(),
                    ExceptionMessage = "Unknown Error"
                });
            }
            catch (Exception ex) {
                return(new MwsResponse <SubmitFeedResponse>
                {
                    Error = new ErrorResponse(),
                    ExceptionMessage = ex.ToString()
                });
            }
        }
        /// <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)
        {
            try
            {
                using (var stream = responseStream)
                {
                    // the result may not be an XML document. This will be reveled with testing.
                    loadXmlStream(stream, messageType.ToString());

                    using (var fileStream = File.Create(string.Format("D:\\logs\\resultfeed{0:yyyyMMdd_HHmmss}.txt", DateTime.Now)))
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        stream.CopyTo(fileStream);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(LogEntryType.AmazonProductInventory,
                                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);
            }
        }