コード例 #1
0
        public async Task SendAsync(Message message)
        {
            ILogger logger = _loggerFactory.Create(nameof(Messenger));

            logger.Info("Sending message", message);

            MessageTemplate messageTemplate = _repository
                                              .GetAll(mt => mt.Kind == message.MessageTemplateKind && mt.Culture == message.Culture)
                                              .SingleOrDefault()
                                              ?? throw new AdminException(
                                                        message: $"No available message template with id {message.MessageTemplateKind} in culture {message.Culture}",
                                                        reason: AdminExceptionReason.Messaging
                                                        )
            ;

            string instantiatedBody      = _substitutor.Substitute(messageTemplate, message.Parameters);
            InstantiatedMessage instance = new InstantiatedMessage(
                messageTemplate.Subject,
                instantiatedBody
                );

            await _strategy.TransmitAsync(message.Recipient, instance);

            logger.Info("Message instance successfully sent", instance);
        }
コード例 #2
0
        public Task TransmitAsync(User recipient, InstantiatedMessage instance)
        {
            User redirectedRecipient = new User(
                name: recipient.Name,
                email: _configuration.Email ?? recipient.Email,
                phone: _configuration.Phone ?? recipient.Phone,
                preferredCulture: recipient.PreferredCulture
                );

            return(_proxee.TransmitAsync(redirectedRecipient, instance));
        }
コード例 #3
0
ファイル: TransmissionTest.cs プロジェクト: wincubate/police
 public void TestInitialize()
 {
     _user = new User(
         name: "Jesper Gulmann Henriksen",
         email: "*****@*****.**",
         phone: "+4522123631",
         preferredCulture: "da"
         );
     _instance = new InstantiatedMessage(
         "This is the subject",
         "This is the body"
         );
 }
コード例 #4
0
        async public Task TransmitAsync(User recipient, InstantiatedMessage instance)
        {
            TwilioClient.Init(TwilioConstants.AccountSid, TwilioConstants.AuthToken);

            string contents = string.Format(TwilioConstants.ContentsFormat,
                                            instance.Subject.ToUpper(),
                                            instance.Body
                                            );
            MessageResource mr = await MessageResource.CreateAsync(
                to : new PhoneNumber(recipient.Phone),
                from : new PhoneNumber(TwilioConstants.FromPhone),
                body : contents
                );
        }
コード例 #5
0
        public async Task TransmitAsync(User recipient, InstantiatedMessage instance)
        {
            ISendGridClient client = new SendGridClient(SendGridConstants.ApiKey);

            EmailAddress from = new EmailAddress(
                SendGridConstants.FromEmail,
                SendGridConstants.FromName
                );
            EmailAddress to = new EmailAddress(
                recipient.Email,
                recipient.Name
                );

            SendGridMessage emailMessage = MailHelper.CreateSingleEmail(
                from,
                to,
                instance.Subject,
                instance.Body,
                null
                );

            await client.SendEmailAsync(emailMessage);
        }
コード例 #6
0
 // Deliberately do nothing! :-)
 public Task TransmitAsync(User recipient, InstantiatedMessage instance) => Task.CompletedTask;
コード例 #7
0
 async public Task TransmitAsync(User recipient, InstantiatedMessage instance)
 {
     await Task.WhenAll(_strategies.
                        Select(s => s.TransmitAsync(recipient, instance))
                        );
 }