예제 #1
0
        public AggregateReportInfo Parse(EmailMessageInfo messageInfo)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            _log.Debug($"Processing {messageInfo.EmailMetadata.OriginalUri}.");

            List <AttachmentInfo> attachments = _mimeMessageFactory
                                                .Create(messageInfo.EmailStream)
                                                .BodyParts.OfType <MimePart>()
                                                .Select(_attachmentStreamNormaliser.Normalise)
                                                .Where(_ => !_.Equals(AttachmentInfo.EmptyAttachmentInfo))
                                                .ToList();

            _log.Debug($"Aggregate report attachment processing took {stopwatch.Elapsed}");
            stopwatch.Reset();

            AttachmentInfo attachment = attachments.Single();

            stopwatch.Start();
            AggregateReportInfo aggregateReport = _aggregateReportDeserialiser.Deserialise(attachment, messageInfo.EmailMetadata);

            _log.Debug($"Deserialising aggregate report took {stopwatch.Elapsed}");
            stopwatch.Reset();

            _log.Debug($"Found {aggregateReport.AggregateReport.Records.Length} records in {aggregateReport.AttachmentMetadata.Filename}");

            if (_multiAttachmentPersistor.Active)
            {
                stopwatch.Start();
                _multiAttachmentPersistor.Persist(attachment);
                _log.Debug($"Persisting attachments took {stopwatch.Elapsed}");
                stopwatch.Reset();
            }

            attachment?.Dispose();

            return(aggregateReport);
        }