Beispiel #1
0
        public async Task <Result <TDomain> > ProcessEmailMessage(EmailMessageInfo messageInfo)
        {
            Result <TDomain> result = await _processor.ProcessEmailMessage(messageInfo);

            try
            {
                if (result.Success)
                {
                    TEntity entity = _converter.Convert(result.Report);

                    _log.Info($"Persisting email message for message Id: {messageInfo.EmailMetadata.MessageId}, request Id: {messageInfo.EmailMetadata.RequestId}");

                    bool added = await _dao.Add(entity);

                    if (added)
                    {
                        _log.Info($"Successfully persisted email message for message Id: {messageInfo.EmailMetadata.MessageId}, request Id: {messageInfo.EmailMetadata.RequestId}");
                    }
                    else
                    {
                        _log.Info($"Did not persist email message for message Id: {messageInfo.EmailMetadata.MessageId}, request Id: {messageInfo.EmailMetadata.RequestId} as it was a duplicate.");
                    }

                    return(new Result <TDomain>(result.Report, result.Success, !added));
                }

                return(result);
            }
            catch (Exception e)
            {
                _log.Error($"Failed to persist email message, message Id: {messageInfo.EmailMetadata.MessageId}, request Id: {messageInfo.EmailMetadata.RequestId} with error {e.Message}{System.Environment.NewLine}{e.StackTrace}");
                return(Result <TDomain> .FailedResult);
            }
        }
        public async Task <Result <TDomain> > ProcessEmailMessage(EmailMessageInfo messageInfo)
        {
            Result <TDomain> result = await _processor.ProcessEmailMessage(messageInfo);

            try
            {
                if (result.Success)
                {
                    if (!result.Duplicate)
                    {
                        foreach (var publisher in _publishers)
                        {
                            await publisher.Publish(result.Report);
                        }
                    }
                    else
                    {
                        _log.Info($"Didnt publish aggregate aggregateReportInfo events for duplicate message, message Id: {messageInfo.EmailMetadata.MessageId}, request Id: {messageInfo.EmailMetadata.RequestId}");
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error($"Failed to publish aggregate aggregateReportInfo events, message Id: {messageInfo.EmailMetadata.MessageId}, request Id: {messageInfo.EmailMetadata.RequestId} with error {e.Message}{Environment.NewLine}{e.StackTrace}");
                return(Result <TDomain> .FailedResult);
            }

            return(result);
        }
Beispiel #3
0
        public async Task ProcessMailMessageMessageIsProcessed()
        {
            A.CallTo(() => _lambdaReportParseConfig.MaxS3ObjectSizeKilobytes).Returns(2);

            A.CallTo(() => _emailMessageClient.GetEmailMessages(A <string> ._, A <string> ._, A <S3Event> ._)).Returns(Task.FromResult(new[]
            {
                new EmailMessageInfo(new EmailMetadata("uri", "filename", 1), Stream.Null)
            }));

            A.CallTo(() => _emailMessageInfoProcessor.ProcessEmailMessage(A <EmailMessageInfo> ._))
            .Returns(new Result <Domain>(new Domain(), true, false));

            ILambdaContext lambdaContext = A.Fake <ILambdaContext>();
            S3Event        s3Event       = new S3Event();
            bool           result        = await _s3EmailMessageProcessor.ProcessEmailMessage(string.Empty, lambdaContext, s3Event);

            Assert.That(result, Is.True);
            A.CallTo(() => _log.Warn(A <string> ._)).MustNotHaveHappened();
            A.CallTo(() => _emailMessageInfoProcessor.ProcessEmailMessage(A <EmailMessageInfo> ._)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public async Task <bool> ProcessEmailMessage(string messageId, ILambdaContext context, S3Event s3Event)
        {
            EmailMessageInfo[] emailMessageInfos = await _s3EmailMessageClient.GetEmailMessages(context.AwsRequestId, messageId, s3Event);

            if (emailMessageInfos.Any(_ => _.EmailMetadata.FileSizeKb > _config.MaxS3ObjectSizeKilobytes))
            {
                _log.Warn($"Didn't process messages as MaxS3ObjectSizeKilobytes of {_config.MaxS3ObjectSizeKilobytes} Kb was exceeded");
                return(false);
            }

            List <Result <TDomain> > results = new List <Result <TDomain> >();

            foreach (EmailMessageInfo emailMessageInfo in emailMessageInfos)
            {
                results.Add(await _emailMessageInfoProcessor.ProcessEmailMessage(emailMessageInfo));
            }

            return(results.Any() && results.All(_ => _.Success));
        }