/// <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); } }
public static void AddProcessingReport(MarketplaceProcessingReport report) { using (var conn = new MySqlConnection(_inventoryConnectionString)) { var parameters = new Dictionary <string, object> { { "@TransactionId", report.TransactionId }, { "@MessageType", report.MessageType }, { "@StatusCode", report.StatusCode }, { "@MessagesProcessed", report.MessagesProcessed }, { "@MessagesSuccessful", report.MessagesSuccessful }, { "@MessagesWithError", report.MessagesWithError }, { "@MessagesWithWarning", report.MessagesWithWarning }, { "@MerchantId", report.MerchantId }, { "@SubmittedBy", report.SubmittedBy }, { "@Created", DateTime.UtcNow } }; // insert first the report MySqlHelper.ExecuteNonQuery(conn, @"INSERT INTO processingreports(TransactionId,MessageType,StatusCode, MessagesProcessed,MessagesSuccessful,MessagesWithError,MessagesWithWarning, MerchantId,SubmittedBy,Created) VALUES(@TransactionId,@MessageType,@StatusCode,@MessagesProcessed,@MessagesSuccessful, @MessagesWithError,@MessagesWithWarning,@MerchantId,@SubmittedBy,@Created)", parameters); // then its details foreach (var item in report.ReportResults) { var param = new Dictionary <string, object> { { "@TransactionId", item.TransactionId }, { "@MessageId", item.MessageId }, { "@Code", item.Code }, { "@MessageCode", item.MessageCode }, { "@AdditionalInfo", item.AdditionalInfo }, { "@Description", item.Description }, }; // then its report details MySqlHelper.ExecuteNonQuery(conn, @"INSERT INTO processingreportresults(TransactionId,MessageId,Code, MessageCode,AdditionalInfo,Description) VALUES(@TransactionId,@MessageId,@Code,@MessageCode,@AdditionalInfo,@Description)", param); } } }
private void loadXmlStream(Stream stream, string messageType) { 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, 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 }); } // add it to the report summary processingReport.ReportResults = reportResults; // save it to the database Logger.AddProcessingReport(processingReport); }
public void AddProcessingReport(MarketplaceProcessingReport processingReportModel) { var report = Mapper.Map <MarketplaceProcessingReport, processingreport>(processingReportModel); report.Created = DateTime.UtcNow; using (var context = new EisInventoryContext()) { context.processingreports.Add(report); foreach (var resultModel in processingReportModel.ReportResults) { var result = Mapper.Map <MarketplaceProcessingReportResult, processingreportresult>(resultModel); context.processingreportresults.Add(result); } context.SaveChanges(); } }
public void AddProcessingReport(MarketplaceProcessingReport model) { using (var context = new EisInventoryContext()) { var report = new processingreport(); CopyObject.CopyFields(model, report); context.processingreports.Add(report); foreach (var resultModel in model.ReportResults) { var reportResult = new processingreportresult(); CopyObject.CopyFields(resultModel, reportResult); context.processingreportresults.Add(reportResult); } context.SaveChanges(); } }