コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Active,CronExpression")] MailSendingJob mailSendingJob)
        {
            if (id != mailSendingJob.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(mailSendingJob);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MailSendingJobExists(mailSendingJob.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(mailSendingJob));
        }
コード例 #2
0
        public void CanSendEmail()
        {
            var queueStreamName  = "Test" + EventStoreQueueConstants.QueueStreamName;
            var outboxStreamName = "Test" + EventStoreQueueConstants.OutboxStreamName;

            var mainLog = LogManager.GetLoggerFor("TEST");

            // EventStoreSettings
            var eventStoreIp      = "127.0.0.1";
            var eventStoreTcpPort = 1113;
            var eventStoreUser    = "******";
            var eventStorePass    = "******";

            // Conectando el EventStore
            var eventStoreSettings = ConnectionSettings
                                     .Create()
                                     .KeepReconnecting()
                                     .SetHeartbeatTimeout(TimeSpan.FromSeconds(30))
                                     .SetDefaultUserCredentials(new UserCredentials(eventStoreUser, eventStorePass))
                                     .Build();

            var tcp              = new IPEndPoint(IPAddress.Parse(eventStoreIp), eventStoreTcpPort);
            var connection       = EventStoreConnection.Create(eventStoreSettings, tcp);
            var connectionSource = "local";

            connection.Closed += (s, e) =>
                                 mainLog.Error($"The {connectionSource} ES connection was closed");
            connection.Connected += (s, e) =>
                                    mainLog.Log($"The connection with {connectionSource} ES was establised");
            connection.Disconnected += (s, e) =>
                                       mainLog.Log($"The connection with {connectionSource} ES was lost");
            connection.Reconnecting += (s, e) =>
                                       mainLog.Log($"Reconnecting with {connectionSource} ES");
            connection.ConnectAsync().Wait();

            var serializer = new JsonSerializer();

            var repo = new EventSourcedRepository(connection, serializer, enablePersistentSnapshotting: true, snapshotInterval: 1);

            var client = new SimpleEmailSenderEsClient(connection, serializer, queueStreamName);

            var mail = EmailFactory.NewFrom("Alexis", "*****@*****.**")
                       .To("Alexis", "*****@*****.**")
                       .Subject("Test")
                       .BodyUsingTemplateFromFile(@"~/testmail.html", new { Name = "Chary" })
                       .Build();

            client.Send(mail);

            // Consuming
            //var sender = new FakeEmailSender("mail.fecoprod.com.py", 25);
            var sender = new WaitEmailSender("mail.fecoprod.com.py", 25);

            using (var job = new MailSendingJob(connection, repo, serializer, sender, queueStreamName, outboxStreamName))
            {
                job.Start();

                sender.WaitForSending();
            }
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Active,CronExpression")] MailSendingJob mailSendingJob)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mailSendingJob);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mailSendingJob));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Active,CronExpression")]
                                                 MailSendingJob mailSendingJob)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mailSendingJob);
                await _context.SaveChangesAsync();

                if (mailSendingJob.Active)
                {
                    RecurringJob.AddOrUpdate(mailSendingJob.Name, () => _mailSendingJobService.SendTodayMergeRequestMail(), mailSendingJob.CronExpression);
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(mailSendingJob));
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Console.Title = "Simple Email Sender";

            _log = LogManager.GetLoggerFor("MAIN");

            // EventStoreSettings
            var eventStoreIp      = ConfigurationManager.AppSettings["EventStoreIp"];
            var eventStoreTcpPort = int.Parse(ConfigurationManager.AppSettings["EventStoreTcpPort"]);
            var eventStoreUser    = ConfigurationManager.AppSettings["EventStoreUser"];
            var eventStorePass    = ConfigurationManager.AppSettings["EventStorePass"];

            // Conectando el EventStore
            var eventStoreSettings = ConnectionSettings
                                     .Create()
                                     .KeepReconnecting()
                                     .SetDefaultUserCredentials(new UserCredentials(eventStoreUser, eventStorePass))
                                     .Build();

            var ip = new IPEndPoint(IPAddress.Parse(eventStoreIp), eventStoreTcpPort);

            _connection         = EventStoreConnection.Create(eventStoreSettings, ip);
            _connection.Closed += (s, e) =>
            {
                var ex = new InvalidOperationException($"The connection was {_connection.ConnectionName} closed. Reason: {e.Reason}");
                _log.Error(ex, "The connection was closed");
                throw ex;
            };
            _connection.Disconnected  += (s, e) => _log.Log($"The connection {_connection.ConnectionName} was disconnected. Reconnecting....");
            _connection.Reconnecting  += (s, e) => _log.Log($"The connection {_connection.ConnectionName} is now reconnecting");
            _connection.ErrorOccurred += (s, e) =>
            {
                _log.Error(e.Exception, "An error ocurred in connection " + _connection.ConnectionName);
                throw e.Exception;
            };
            _connection.Connected += (s, e) => _log.Log($"The connection {_connection.ConnectionName} is now connected");
            _connection.ConnectAsync();

            var serializer = new JsonSerializer();

            // Main sender settings
            var snapshotInterval             = int.Parse(ConfigurationManager.AppSettings["snapshotInterval"]);
            var enablePersistentSnapshotting = snapshotInterval > 0;
            var host = ConfigurationManager.AppSettings["host"];
            var port = int.Parse(ConfigurationManager.AppSettings["port"]);


            var repo        = new EventSourcedRepository(() => _connection, serializer, "MailQueueRepo", enablePersistentSnapshotting, snapshotInterval);
            var emailSender = new EmailSender(host, port);

            using (var job = new MailSendingJob(_connection, repo, serializer, emailSender, EventStoreQueueConstants.QueueStreamName, EventStoreQueueConstants.OutboxStreamName))
            {
                job.Start();

                string exitCode;
                do
                {
                    Console.WriteLine("Type [exit] to shut down...");
                    exitCode = Console.ReadLine();
                } while (exitCode.ToUpper().Trim() != "EXIT");
            }
        }