public void ClearSession()
 {
     ClearData();
     if (session != null && session.IsOpen)
     {
         session.Dispose();
         session = null;
     }
 }
예제 #2
0
 private void MvcApplication_EndRequest(object sender, System.EventArgs e)
 {
     if (Context.Items.Contains(Budget.Services.Registrations.NHibernateModule.SESSION_KEY))
     {
         NHibernate.ISession Session = (NHibernate.ISession)Context.Items[Services.Registrations.NHibernateModule.SESSION_KEY];
         Session.Dispose();
         Context.Items[Services.Registrations.NHibernateModule.SESSION_KEY] = null;
     }
 }
예제 #3
0
        public void ClearSession()
        {
            ClearData();
            if (session != null && session.IsOpen)
            {
                dataGridView.Rows.Clear();

                session.Close();
                session.Dispose();
                session = null;
            }
        }
예제 #4
0
        protected override void OnClosing(CancelEventArgs e)
        {
            if (Application.UseWaitCursor)
            {
                e.Cancel = true;
            }
            else
            {
                session.Dispose();
            }

            base.OnClosing(e);
        }
        private static async Task CloseSession(ISession session)
        {
            try
            {
                if (session.Transaction?.IsActive ?? false)
                {
                    await session.Transaction.CommitAsync();
                }
            }
            catch
            {
                if (session.Transaction?.IsActive ?? false)
                {
                    await session.Transaction.RollbackAsync();
                }

                throw;
            }
            finally
            {
                session.Dispose();
            }
        }
예제 #6
0
        IMethodReturn IInterceptionBehavior.Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            IMethodReturn retour = null;

            TransactionalAttribute transactional = null;

            object[] atts = input.MethodBase.GetCustomAttributes(typeof(TransactionalAttribute), false);
            if (atts.Count() > 0)
            {
                transactional = (TransactionalAttribute)atts[0];
            }

            if (Utility.MyNHibernateHelper.SessionManager.Configuration == null)
            {
                SessionManager.Configuration = TransactionInterceptorConfiguration.Configuration;
                TransactionInterceptorConfiguration.SessionManager = new SessionManager();
            }

            if (NHibernate.Context.CurrentSessionContext.HasBind(SessionManager.SessionFactory) == false)
            {
                NHibernate.Context.CurrentSessionContext.Bind(SessionManager.SessionFactory.OpenSession());
            }

            NHibernate.ISession     session     = null;
            NHibernate.ITransaction transaction = null;
            if (transactional != null)
            {
                session = TransactionInterceptorConfiguration.SessionManager.CurrentSession;
                if (transactional.OpenTransaction)
                {
                    transaction = session.BeginTransaction();
                }
            }

            try
            {
                retour = getNext()(input, getNext);
                if (transaction != null && transactional.RollBack == true)
                {
                    transaction.Rollback();
                    //if (typeof(retour.Exception) == typeof(NHibernate.Exceptions.GenericADOException)) retour.Exception = null;
                }
                else if (retour.Exception == null && transaction != null)
                {
                    transaction.Commit();
                }
                else if (retour.Exception != null)
                {
                    throw retour.Exception;
                }
            }
            catch (Exception ex)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                else
                {
                    throw ex;
                }
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Dispose();
                }
                if (session != null)
                {
                    session.Close();
                    session.Dispose();
                    NHibernate.Context.CurrentSessionContext.Unbind(SessionManager.SessionFactory);
                }
            }

            return(retour);
        }
 void IDisposable.Dispose() => nhSession.Dispose();