示例#1
0
 public void Flush()
 {
     if (_session != null)
     {
         _session.Flush();
         _session.Clear();
         _session.Close();
         _session.Dispose();
         _session = null;
     }
 }
示例#2
0
        public void AfterInvoke(object correlationState)
        {
            foreach (ISessionFactory sessionFactory in sfp)
            {
                ISession session = CurrentSessionContext.Unbind(sessionFactory);
                if (!session.IsOpen)
                {
                    continue;
                }

                try
                {
                    session.Flush();
                    if (session.Transaction.IsActive)
                    {
                        session.Transaction.Commit();
                    }
                }
                catch (Exception)
                {
                    if (session.Transaction.IsActive)
                    {
                        session.Transaction.Rollback();
                    }
                    throw;
                }
                finally
                {
                    session.Close();
                    session.Dispose();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Closes the current session object from http context. This should be called on end request.
        /// </summary>
        public void CloseSession()
        {
            if (HttpContext.Current != null)
            {
                _logger.Debug("Closing NHibernate session from the HttpContext.");

                var session = HttpContext.Current.Items[SessionKey] as ISession;

                if (session != null)
                {
                    if (session.IsOpen)
                    {
                        session.Close();
                        session.Dispose();
                    }
                    HttpContext.Current.Items.Remove(SessionKey);
                }
            }

            if (_currentSession == null)
            {
                return;
            }
            if (_currentSession.IsOpen)
            {
                _logger.Debug("Closing NHibernate session from the current thread.");

                _currentSession.Close();
                _currentSession.Dispose();
            }
            _currentSession = null;
        }
示例#4
0
 public void CloseSession()
 {
     if (CurrentSessionContext.HasBind(_sessionFactory))
     {
         NHibernate.ISession session = CurrentSessionContext.Unbind(_sessionFactory);
         session.Close();
         session.Dispose();
     }
 }
示例#5
0
 public void ClearSession()
 {
     ClearData(true);
     if (session != null && session.IsOpen)
     {
         session.Close();
         session.Dispose();
         session = null;
     }
 }
示例#6
0
 public ISession GetSession()
 {
     if (_session != null && (_session != null || _session.IsConnected))
     {
         return(_session);
     }
     _session?.Dispose();
     _session = _sessionFactory.CreateLazySessionFactory().Value.OpenSession();
     return(_session);
 }
示例#7
0
        public static void flushAndDisposeSession()
        {
            NHibernate.ISession currentSession = getCurrentSession();
            currentSession.Flush();

            //currentSession.Close();
            currentSession.Dispose();
            var context = httpContextAccessor.HttpContext;

            context.Items.Remove(CurrentSessionKey);
        }
        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            NHibernate.ISession Database = NhibernateBootStrapper.GetSession();
            try
            {
                string header = OperationContext.Current.IncomingMessageHeaders.GetHeader <string>("application-name", "http://aspensys.com/");

                // auth hack - daquinohd
                // ServiceSecurityContext.PrimaryIdentity.Name is not returning a value, so I'm
                // using System.Security.Principal.WindowsIdentity.GetCurrent().Name to get the AppPool Identity for now.
                string name = OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name;
                name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

                UnauthorizedAccessException uae = new UnauthorizedAccessException(string.Format("{0} cannot access the application {1}", name, header));
                if (!OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.IsAuthenticated)
                {
                    FaultException faultException = new FaultException(string.Format("{0} cannot access the application {1}, it is unauthenticated", name, header));
                }
                Account account = Database.Query <Account>().FirstOrDefault <Account>((Account acc) => acc.Username.ToLower() == name.ToLower());
                if (account == null)
                {
                    throw new FaultException(string.Format("{0} cannot access the application {1}, it does not have acces to GUAM", name, header));
                }
                IQueryable <Application> app_auth =
                    from app in Database.Query <Application>()
                    join acc in Database.Query <ApplicationAccount>() on app.ApplicationID equals acc.Application.ApplicationID
                    where acc.Account.AccountID == account.AccountID
                    select app;
                if ((account.Admin ? false : !app_auth.Any <Application>()))
                {
                    throw uae;
                }
                GlobalUsersService instance = instanceContext.GetServiceInstance() as GlobalUsersService;
                if (instance != null)
                {
                    instance.CurrentApplication = (
                        from a in Database.Query <Application>()
                        where a.ApplicationName.ToLower() == header.ToLower()
                        select a).FirstOrDefault <Application>();
                    if (instance.CurrentApplication == null)
                    {
                        throw new Exception(string.Concat("Application '", header, "' not found in database."));
                    }
                }
            }
            finally
            {
                if (Database != null)
                {
                    Database.Dispose();
                }
            }
            return(null);
        }
 private void MvcApplication_EndRequest(object sender, System.EventArgs e)
 {
     if (Context.Items.Contains(NHibernateModule.SESSION_KEY))
     {
         Debug.WriteLine("Disposing the NHibernate session");
         NHibernate.ISession Session = (NHibernate.ISession)Context.Items[NHibernateModule.SESSION_KEY];
         Session.Flush();
         Session.Dispose();
         Context.Items[NHibernateModule.SESSION_KEY] = null;
     }
 }
 private async Task CommitTransactionAsync(ISession session, CancellationToken cancellationToken)
 {
     if (session != null)
     {
         var tx = session.GetCurrentTransaction();
         if (tx != null && tx.IsActive)
         {
             await tx.CommitAsync(cancellationToken);
         }
         session.Dispose();
     }
 }
 public void Dispose()
 {
     if (_session != null)
     {
         _session.Dispose();
         _session = null;
     }
     if (_sessionManager != null)
     {
         _sessionManager.Dispose();
         _sessionManager = null;
     }
 }
示例#12
0
        public void Commit()
        {
            if (!_isAlive)
            {
                return;
            }

            try
            {
                _transaction.Commit();
            }
            finally
            {
                _isAlive = false;
                _transaction.Dispose();
                _session.Dispose();
            }
        }
示例#13
0
 private void CloseSession()
 {
     session.Close();
     session.Dispose();
     session = null;
 }
示例#14
0
 public void Dispose()
 {
     _nhSession.Dispose();
     _transactionScope.Complete();
     _transactionScope.Dispose();
 }
示例#15
0
 public void Dispose()
 {
     session.Dispose();
     sessionFactory.Dispose();
 }
示例#16
0
 public static void disposeSession()
 {
     NHibernate.ISession currentSession = getCurrentSession();
     currentSession.Dispose();
 }
 public void BeforeSendReply(ref Message reply, Object correlationState)
 {
     NHibernate.ISession session = CurrentSessionContext.Unbind(SessionFactoryHolder.DefaultSessionFactory);
     session.Dispose();
 }