Exemplo n.º 1
0
        private void Push(IEnumerable <ServiceMailEM> mails, SenderConfig config)
        {
            var factory = new ConnectionFactory {
                HostName = config.QueueHost
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    mails.ToList().ForEach(m =>
                    {
                        try
                        {
                            var messageText = JsonConvert.SerializeObject(m);

                            channel.QueueDeclare(Constants.EMAIL_QUEUE_NAME, false, false, false, null);
                            channel.BasicPublish(exchange: string.Empty, routingKey: Constants.EMAIL_QUEUE_NAME, basicProperties: null, body: Encoding.UTF8.GetBytes(messageText));

                            LogMessage(m);
                        }
                        catch
                        {
                            LogError(m);
                        }
                    });

                    UpdateStatuses();
                }
        }
Exemplo n.º 2
0
        public async Task SendEmailAsync(SendEmailRequest request, SenderConfig senderConfig)
        {
            MimeMessage emailMessage = new MimeMessage();

            emailMessage.From.Add(new MailboxAddress(senderConfig.Name, senderConfig.Email));
            emailMessage.To.Add(new MailboxAddress(request.ReceiverName, request.ReceiverEmail));
            emailMessage.Subject = request.Subject;

            emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html)
            {
                Text = request.Text
            };

            using (SmtpClient client = new SmtpClient())
            {
                try
                {
                    await client.ConnectAsync("smtp.gmail.com", 587, false);

                    await client.AuthenticateAsync(senderConfig.Email, senderConfig.Password);

                    await client.SendAsync(emailMessage);

                    await client.DisconnectAsync(true);
                }
                catch                 //нужно придумать что обработать. может отдельные ошибки на каждый вызов
                {
                    throw;
                }
            }
        }
 public EmailNotificationService(NotificationContext context, IEmailSenderService emailSenderService, IMapper mapper, IOptionsMonitor <SenderConfig> senderConfig)
 {
     m_context            = context;
     m_emailSenderService = emailSenderService;
     m_mapper             = mapper;
     m_senderConfig       = senderConfig.CurrentValue;
 }
Exemplo n.º 4
0
 public SubscriptionService(NotificationContext context, INotificationService notificationService, IEmailNotificationService emailNotificationService, IOptionsMonitor <SenderConfig> senderConfig, IMapper mapper)
 {
     m_context                  = context;
     m_notificationService      = notificationService;
     m_emailNotificationService = emailNotificationService;
     m_senderConfig             = senderConfig.CurrentValue;
     m_mapper = mapper;
 }
Exemplo n.º 5
0
 public void Send(SenderConfig config)
 {
     using (var repo = Factory.GetService <IMailSenderRepository>())
     {
         var data = repo.GetSendData();
         Push(data, config);
     }
 }
Exemplo n.º 6
0
        public void Equality()
        {
            var sc1 = new SenderConfig();
            var sc2 = new SenderConfig();

            Assert.IsTrue(sc1.Equals(sc2));
            Assert.IsFalse(sc1.Equals(null));
            Assert.IsFalse(sc1.Equals(new object()));
        }
Exemplo n.º 7
0
        public void NotEqual()
        {
            var sc1 = new SenderConfig();
            var sc2 = new SenderConfig {
                MaxNumOfSmtpClients = 99999
            };

            Assert.IsFalse(sc1.Equals(sc2));
            Assert.IsFalse(sc1.Equals(null));
            Assert.IsFalse(sc1.Equals(new object()));
        }
        public async Task ConsumeAsync(RegistrationMessage message)
        {
            SenderConfig     senderConfig = m_config.GetSection("SenderConfig").Get <SenderConfig>();
            SendEmailRequest request      = new SendEmailRequest
            {
                ReceiverEmail = message.Name,
                ReceiverName  = message.Email,
                Subject       = "Подтверждение регистрации",
                Text          = $"Для подтверждения регистрации прейдите по ссылке {m_config[$"RegistrationUrl"]}/{message.Name}"
            };

            await m_service.SendRegistrationNotification(request);
        }
        public void Test_SenderConfig_ToStringFunctionality()
        {
            // Arrange
            var config = new SenderConfig
            {
                EntityName = "entityName",
                CreateEntityIfNotExists = true,
                ProjectId = "12345"
            };

            // Act
            var str = config.ToString();

            // Assert
            str.Should().Be("EntityName: entityName, EntityDeadLetterName: entityName_deadletter, CreateEntityIfNotExists: True");
        }
        public void Test_SenderConfig_Setup()
        {
            // Arrange
            var sender = new SenderConfig
            {
                EntityName = "entityName",
                CreateEntityIfNotExists = false,
                ProjectId = "projId"
            };

            // Assert
            sender.TopicRelativeName.Should().Be($"projects/projId/topics/entityName");
            sender.EntityDeadLetterName.Should().Be($"entityName_deadletter");
            sender.TopicDeadletterRelativeName.Should().Be($"projects/projId/topics/entityName_deadletter");
            sender.ToString().Length.Should().BeGreaterThan(0);
            sender.ProjectId.Should().Be("projId");
        }
        public void Test_SenderSetup_Validate()
        {
            // Arrange
            var senderSetup = new SenderConfig()
            {
                CreateEntityIfNotExists = false,
                EntityName = ""
            };

            // Act/Assert
            Assert.Throws <ValidateException>(() => senderSetup.ThrowIfInvalid());
            Assert.False(senderSetup.CreateEntityIfNotExists);
            Assert.True(senderSetup.EntityName == "");
            Assert.True(senderSetup.MaxMessageSizeBytes > 0);
            Assert.True(senderSetup.MaxMessageSizeKb > 0);
            senderSetup.ToString().Should().NotBeNullOrEmpty();
        }
Exemplo n.º 12
0
 /// <summary>
 /// Add Storage Queue singleton of type StorageQueueMessenger, using named properties (as opposed to passing MsiConfig/ServicePrincipleConfig etc).
 /// Will automatically use MsiConfiguration.
 /// </summary>
 /// <param name="services">Service collection to extend.</param>
 /// <param name="key">Key to identify the named instance of the Storage Queue singleton.</param>
 /// <param name="instanceName">Instance name of Storage Queue.</param>
 /// <param name="tenantId">Tenant Id where Storage Queue exists.</param>
 /// <param name="subscriptionId">Subscription within the tenancy to use for the Storage Queue instance.</param>
 /// <param name="receiver">Receiver configuration (if any).</param>
 /// <param name="sender">Sender configuration (if any).</param>
 /// <returns>Modified service collection with the StorageQueueMessenger and NamedInstanceFactory{StorageQueueMessenger} configured.</returns>
 public static IServiceCollection AddStorageQueueSingletonNamed(this IServiceCollection services, string key, string instanceName, string tenantId, string subscriptionId, ReceiverConfig receiver = null, SenderConfig sender = null)
 {
     return(AddNamedInstance <StorageQueueMessenger>(services, key, new StorageQueueMessenger(new MsiConfig
     {
         InstanceName = instanceName,
         TenantId = tenantId,
         SubscriptionId = subscriptionId,
         Receiver = receiver,
         Sender = sender
     })));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Add Storage Queue singleton of type StorageQueueMessenger, using named properties (as opposed to passing MsiConfig/ServicePrincipleConfig etc).
 /// Will automatically use MsiConfiguration.
 /// </summary>
 /// <param name="services">Service collection to extend</param>
 /// <param name="instanceName">Instance name of Storage Queue.</param>
 /// <param name="tenantId">Tenant Id where Storage Queue exists.</param>
 /// <param name="subscriptionId">Subscription within the tenancy to use for the Storage Queue instance.</param>
 /// <param name="receiver">Receiver configuration (if any).</param>
 /// <param name="sender">Sender configuration (if any).</param>
 /// <returns>Modified service collection with the StorageQueueMessenger and NamedInstanceFactory{StorageQueueMessenger} configured.</returns>
 public static IServiceCollection AddStorageQueueSingleton(this IServiceCollection services, string instanceName, string tenantId, string subscriptionId, ReceiverConfig receiver = null, SenderConfig sender = null)
 {
     return(services.AddStorageQueueSingletonNamed <StorageQueueMessenger>(null, instanceName, tenantId, subscriptionId, receiver, sender));
 }
 public EmailNotificationController(IEmailNotificationService emailService, IBus bus, IOptionsMonitor <SenderConfig> config)
 {
     m_emailService = emailService;
     m_bus          = bus;
     m_config       = config.CurrentValue;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Adds the Gcp Pub/Sub singleton using the passed in params to build configuration.
 /// </summary>
 /// <param name="services">The service collection to extend.</param>
 /// <param name="projectId">The Gcp Project Id.</param>
 /// <param name="jsonAuthFile">The json authentication file.</param>
 /// <param name="sender">The sender configuration.</param>
 /// <returns>IServiceCollection.</returns>
 public static IServiceCollection AddPubSubSingleton(this IServiceCollection services, string projectId, string jsonAuthFile, SenderConfig sender)
 {
     return(services.AddPubSubSingletonNamed <PubSubMessenger>(null, new PubSubJsonAuthConfig
     {
         ProjectId = projectId,
         JsonAuthFile = jsonAuthFile,
         Sender = sender
     }));
 }
Exemplo n.º 16
0
 /// <summary>
 /// Adds the Gcp Pub/Sub singleton using the passed in params to build configuration.
 /// </summary>
 /// <param name="services">The service collection to extend.</param>
 /// <param name="projectId">The Gcp Project Id.</param>
 /// <param name="receiver">The receiver configuration.</param>
 /// <param name="sender">The sender configuration.</param>
 /// <returns>IServiceCollection.</returns>
 public static IServiceCollection AddPubSubSingleton(this IServiceCollection services, string projectId, ReceiverConfig receiver = null, SenderConfig sender = null)
 {
     return(services.AddPubSubSingletonNamed <PubSubMessenger>(null, new PubSubConfig {
         ProjectId = projectId, ReceiverConfig = receiver, Sender = sender
     }));
 }