Exemplo n.º 1
0
        public override void DoJob()
        {
            using (var session = SharpArch.NHibernate.NHibernateSession.GetDefaultSessionFactory().OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    NotificationsRepository notificationsRepository = new NotificationsRepository(session);
                    IList <Notification>    notSent = notificationsRepository.GetAllNotSent();
                    foreach (var notification in notSent)
                    {
                        try
                        {
                            new EmailSender().SendEmail(notification.Site.User.Email, notification.Subject, notification.Contents);
                            notification.SendDate = DateTime.Now;
                            notification.IsSent   = true;
                            notificationsRepository.SaveOrUpdate(notification);
                        }
                        catch (Exception ex)
                        {
                            notification.SendError = ex.Message;
                            notificationsRepository.SaveOrUpdate(notification);
                            Logger.LogError(ex);
                        }
                    }

                    transaction.Commit();
                }
            }
        }