Example #1
0
 public IList <TEntity> Get()
 {
     using (ISession session = _sessionProvider.OpenSession())
     {
         return(session.Query <TEntity>().ToList());
     }
 }
        public static TSession Current <TSession>(this ISessionProvider <TSession> sessionProvider)
            where TSession : ISession
        {
            Func <object> factoryMethod          = () => sessionProvider.OpenSession();
            var           sessionCreateArguments = new { UsingFactoryMethod = factoryMethod, SessionAlias = sessionProvider.SessionAlias };
            TSession      result = ServiceRegistry.Get <TSession>(sessionCreateArguments);

            return(result);
        }
Example #3
0
 private User GetUser(string login, ISessionProvider provider)
 {
     using (ISession session = provider.OpenSession())
     {
         return((from u in session.QueryOver <User>()
                 where u.Login == login
                 select u).SingleOrDefault <User>());
     }
 }
        public UnitOfWork(ISessionProvider sessionProvider)
        {
            if (sessionProvider == null)
            {
                throw new ArgumentNullException("sessionProvider");
            }

            this.internalSession           = sessionProvider.OpenSession();
            this.internalSession.FlushMode = FlushMode.Commit;
        }
        private void CheckEmails(object state)
        {
            _logger.Info("Checking for notifications");
            try
            {
                lock (this)
                {
                    if (_processing)
                    {
                        _logger.Info("Throtling");

                        return;
                    }

                    _processing = true;
                }

                _logger.Trace("Opening session");
                //Open session
                _sessionProvider.OpenSession();
                _logger.Trace("Opened session");

                //Get errors
                var pendingNotifications = _emailNotificationRepository.GetPending();

                //Process emails
                SendNotifications(pendingNotifications);

                _logger.Trace("Commiting");

                //Close session
                _sessionProvider.CloseSession();

                _logger.Trace("Commited");
            }
            catch (Exception e)
            {
                _logger.Fatal(e);
                throw;
            }
            finally
            {
                lock (this)
                {
                    _processing = false;
                }
            }
        }