public void NoPersistorsActiveNoProcessingOccursUserIsWarned() { A.CallTo(() => _multiAttachmentPersistor.Active).Returns(false); A.CallTo(() => _multiDenormalisedRecordPersistor.Active).Returns(false); A.CallTo(() => _mulitAggregateReportPersistor.Active).Returns(false); A.CallTo(() => _mimeMessageFactory.Create(A <Stream> ._)).Returns(CreateEmailMessage()); _aggregateReportParser.Parse(new EmailMessageInfo(new EmailMetadata("", "", "", 100), Stream.Null)); A.CallTo(() => _attachmentStreamNormaliser.Normalise(A <MimePart> ._)).MustNotHaveHappened(); A.CallTo(() => _aggregateReportDeserialiser.Deserialise(A <AttachmentInfo> ._, A <EmailMetadata> ._)).MustNotHaveHappened(); A.CallTo(() => _log.Warn(A <string> ._)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _denormalisedRecordConverter.ToDenormalisedRecord(A <Domain.Dmarc.AggregateReport> ._, A <string> ._)).MustNotHaveHappened(); A.CallTo(() => _multiAttachmentPersistor.Persist(A <List <AttachmentInfo> > ._)).MustNotHaveHappened(); A.CallTo(() => _multiDenormalisedRecordPersistor.Persist(A <IEnumerable <DenormalisedRecord> > ._)).MustNotHaveHappened(); A.CallTo(() => _mulitAggregateReportPersistor.Persist(A <IEnumerable <AggregateReportInfo> > ._)).MustNotHaveHappened(); }
public void Persist(AggregateReportInfo report) { List <DenormalisedRecord> denormalisedRecords = _denormalisedRecordConverter.ToDenormalisedRecord(report.AggregateReport, report.EmailMetadata.OriginalUri); _persistors.ForEach(_ => _.Persist(denormalisedRecords)); }
public void Parse(EmailMessageInfo messageInfo) { try { Stopwatch stopwatch = new Stopwatch(); List <AttachmentInfo> attachments = null; if (_multiAttachmentPersistor.Active || _multiDenormalisedRecordPersistor.Active || _multiAggregateReportPersistor.Active) { _log.Debug($"Processing {messageInfo.EmailMetadata.OriginalUri}."); stopwatch.Start(); attachments = _mimeMessageFactory .Create(messageInfo.EmailStream) .BodyParts.OfType <MimePart>() .Select(_attachmentStreamNormaliser.Normalise) .Where(_ => !_.Equals(AttachmentInfo.EmptyAttachmentInfo)) .ToList(); if (attachments.Count == 0) { _log.Warn($"Didnt find any aggregate report attachments for {messageInfo.EmailMetadata.OriginalUri}."); } else { _log.Debug($"Found {attachments.Count} aggregate report attachment(s) for {messageInfo.EmailMetadata.OriginalUri}."); } _log.Debug($"Aggregate report attachment processing took {stopwatch.Elapsed}"); stopwatch.Reset(); } else { _log.Warn($"Not Processing {messageInfo.EmailMetadata.OriginalUri} as no persistors found."); } List <AggregateReportInfo> aggregateReports = null; if (_multiDenormalisedRecordPersistor.Active || _multiAggregateReportPersistor.Active) { stopwatch.Start(); aggregateReports = attachments .Select(_ => _aggregateReportDeserialiser.Deserialise(_, messageInfo.EmailMetadata)) .ToList(); _log.Debug($"Deserialising aggregate reports took {stopwatch.Elapsed}"); stopwatch.Reset(); aggregateReports.ForEach(_ => _log.Debug($"Found {_.AggregateReport.Records.Length} records in {_.AttachmentMetadata.Filename}")); } List <DenormalisedRecord> denormalisedRecords = null; if (_multiDenormalisedRecordPersistor.Active) { stopwatch.Start(); denormalisedRecords = aggregateReports .Select(_ => _denormalisedRecordConverter.ToDenormalisedRecord(_.AggregateReport, messageInfo.EmailMetadata.OriginalUri)) .SelectMany(_ => _) .ToList(); _log.Debug($"Denormalised record processing took {stopwatch.Elapsed}"); stopwatch.Reset(); } if (_multiAttachmentPersistor.Active) { stopwatch.Start(); _multiAttachmentPersistor.Persist(attachments); _log.Debug($"Persisting attachments took {stopwatch.Elapsed}"); stopwatch.Reset(); } if (_multiDenormalisedRecordPersistor.Active) { stopwatch.Start(); _multiDenormalisedRecordPersistor.Persist(denormalisedRecords); _log.Debug($"Persisting denormalised records took {stopwatch.Elapsed}"); stopwatch.Reset(); } if (_multiAggregateReportPersistor.Active) { stopwatch.Start(); _multiAggregateReportPersistor.Persist(aggregateReports); _log.Debug($"Persisting denormalised records took {stopwatch.Elapsed}"); stopwatch.Reset(); } attachments?.ForEach(_ => _.Dispose()); } catch (Exception e) { _log.Error($"An error occurred processing {messageInfo.EmailMetadata.OriginalUri}{Environment.NewLine}{e.Message}{Environment.NewLine}{Environment.NewLine}{e.StackTrace}"); } }