public void Flush() { if (_session != null) { _session.Flush(); _session.Clear(); _session.Close(); _session.Dispose(); _session = null; } }
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(); } } }
/// <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; }
public void CloseSession() { if (CurrentSessionContext.HasBind(_sessionFactory)) { NHibernate.ISession session = CurrentSessionContext.Unbind(_sessionFactory); session.Close(); session.Dispose(); } }
public void ClearSession() { ClearData(true); if (session != null && session.IsOpen) { session.Close(); session.Dispose(); session = null; } }
public ISession GetSession() { if (_session != null && (_session != null || _session.IsConnected)) { return(_session); } _session?.Dispose(); _session = _sessionFactory.CreateLazySessionFactory().Value.OpenSession(); return(_session); }
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; } }
public void Commit() { if (!_isAlive) { return; } try { _transaction.Commit(); } finally { _isAlive = false; _transaction.Dispose(); _session.Dispose(); } }
private void CloseSession() { session.Close(); session.Dispose(); session = null; }
public void Dispose() { _nhSession.Dispose(); _transactionScope.Complete(); _transactionScope.Dispose(); }
public void Dispose() { session.Dispose(); sessionFactory.Dispose(); }
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(); }