Пример #1
0
 public async Task <Notification> persistNotification(ApplicationCore.DTO.Notification newNotification)
 {
     try
     {
         newNotification = await _retryPolicy.ExecuteAsync(async() => await _notIficationService.CreateNotificationAsync(newNotification));
     }
     catch (Exception ex) {
         Console.WriteLine(ex.Message);
     }
     return(newNotification);
 }
Пример #2
0
        public async Task <NotificationResponse> SendEmail(EmailMessage message)
        {
            var notificationRespose = new NotificationResponse
            {
                statusCode = "1",
                message    = "Email sent Error"
            };

            try
            {
                Console.WriteLine($"Estado del circuito: {_circuitBreakerPolicy.CircuitState}");
                await _circuitBreakerPolicy.ExecuteAsync(async() =>
                {
                    try
                    {
                        var mimeMessage = await CreateMimeMessageFromEmailMessage(message);

                        await _smtpClient.ConnectAsync(_notificationMetadata.SmtpServer,
                                                       _notificationMetadata.Port, false);
                        await _smtpClient.AuthenticateAsync(_notificationMetadata.UserName,
                                                            _notificationMetadata.Password);

                        await _smtpClient.SendAsync(mimeMessage);

                        notificationRespose.statusCode = "0";
                        notificationRespose.message    = "Email sent successfully";
                    }
                    finally
                    {
                        await _smtpClient.DisconnectAsync(true);
                    }
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Erro al enviar correo: {ex.Message}");
            }
            finally
            {
                var newNotification = new ApplicationCore.DTO.Notification
                {
                    Message          = message.Content,
                    status           = notificationRespose.statusCode,
                    Type             = "E",
                    Reciever         = message.Reciever,
                    DateNotification = DateTime.UtcNow.ToLocalTime()
                };

                await persistNotification(newNotification);
            }

            return(notificationRespose);
        }