protected void Application_Start(object sender, EventArgs args) { Console.SetOut(new System.IO.StreamWriter(System.IO.Stream.Null)); Console.SetError(new System.IO.StreamWriter(System.IO.Stream.Null)); var before = Stopwatch.StartNew(); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new ClientAwareRazorViewEngine()); ViewEngines.Engines.Add(new FixedWebFormViewEngine()); // to render the reports user controls (.ascx) AreaRegistration.RegisterAllAreas(); MetadataProvider.DoInit(); ConfigureLogging(); EnableJsonCamelCasing(); RegisterDataMapFormatter(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); new MigratorExecutor("SWDB").Migrate(runner => runner.MigrateUp()); ManagedWebSessionContext.Bind( System.Web.HttpContext.Current, SWDBHibernateDAO.SessionManager.SessionFactory.OpenSession()); SecurityFacade.InitSecurity(); var container = SimpleInjectorScanner.InitDIController(); var dispatcher = (IEventDispatcher)container.GetInstance(typeof(IEventDispatcher)); dispatcher.Dispatch(new ApplicationStartedEvent()); Log.Info(LoggingUtil.BaseDurationMessage("**************App started in {0}*************", before)); ApplicationConfiguration.StartDate = DateTime.Now; }
public static void OpenSession(HttpContext context) { var session = sessionFactory.OpenSession(); session.BeginTransaction(); ManagedWebSessionContext.Bind(context, session); }
private ICurrentSessionContext BuildCurrentSessionContext() { var impl = System.Configuration.ConfigurationManager.AppSettings["sessionContextType"]; ICurrentSessionContext result = null; switch (impl) { case "CallSessionContext": result = new CallSessionContext(this); break; case "ThreadStaticSessionContext": result = new ThreadStaticSessionContext(this); break; case "WebSessionContext": result = new WebSessionContext(this); break; case "ManagedWebSessionContext": result = new ManagedWebSessionContext(this); break; } return(result); }
/// <summary> /// Unbinds the <see cref="ISession"/> associated with the current request. /// </summary> /// <param name="context"></param> protected virtual void UnbindSession(HttpContext context) { var providerList = GetSessionProviders(); if (providerList == null || providerList.Count == 0) { return; } foreach (var provider in providerList) { // Get the default NH session factory var factory = provider.GetSessionFactory(); var session = ManagedWebSessionContext.Unbind(context, factory); // Give it to NH so it can pull the right session if (session == null) { return; } using (session) { session.Flush(); } } }
protected virtual void BindSession(HttpContext context) { ISession session = Database.OpenSession(); // Tell NH session context to use it ManagedWebSessionContext.Bind(context, session); }
protected void Application_BeginRequest(object sender, EventArgs e) { var sessionFactory = Container.Resolve <ISessionFactory>(); ISession session = sessionFactory.OpenSession(); ManagedWebSessionContext.Bind(HttpContext.Current, session); }
protected void Application_BeginRequest(object sender, EventArgs e) { ISession session = FactoryDAO.Instance.GetSessionFactory().OpenSession(); ManagedWebSessionContext.Bind(HttpContext.Current, session); session.BeginTransaction(); //FactoryDAO.Instance.GetSessionFactory().GetCurrentSession().Transaction.Begin(); }
protected void Application_EndRequest(object sender, EventArgs e) { var sessionFactory = Container.Resolve <ISessionFactory>(); ISession session = ManagedWebSessionContext.Unbind(HttpContext.Current, sessionFactory); if (session != null && session.IsOpen) { session.Close(); } }
private static void BindSession(HttpContext context) { var sessionBuilder = SessionBuilderFactory.CurrentBuilder; // Create a new session (it's the beginning of the request) var session = sessionBuilder.OpenSession(); // Tell NH session context to use it ManagedWebSessionContext.Bind(context, session); }
void context_EndRequest(object sender, EventArgs e) { ISession session = ManagedWebSessionContext.Unbind( HttpContext.Current, DependencyResolver.Current.GetService <ISessionFactory>()); if (session != null) { session.Close(); session.Dispose(); } }
private void OpenSessionInView() { string path = Context.Request.Url.AbsolutePath; if (IgnoreExtension(path)) { return; } ManagedWebSessionContext.Bind(Context, SessionManager.SessionFactory.OpenSession()); }
private void Application_EndRequest(object sender, EventArgs e) { ISession session = ManagedWebSessionContext.Unbind(HttpContext.Current, ExampleApplication.SessionFactory); if (session.Transaction.IsActive) { session.Transaction.Rollback(); } if (session != null) { session.Close(); } }
private void Application_BeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; if (app.Request.CurrentExecutionFilePathExtension == ".js" || app.Request.CurrentExecutionFilePathExtension == ".png" || app.Request.CurrentExecutionFilePathExtension == ".jpg" || app.Request.CurrentExecutionFilePathExtension == ".gif" || app.Request.CurrentExecutionFilePathExtension == ".css") { return; } ManagedWebSessionContext.Bind(HttpContext.Current, NhbHelper.SessionFactory.OpenSession()); }
private static void UnbindSession(HttpContext context) { var sessionBuilder = SessionBuilderFactory.CurrentBuilder; // Get the default NH session factory var factory = sessionBuilder.GetSessionFactory(); // Give it to NH so it can pull the right session var session = ManagedWebSessionContext.Unbind(context, factory); if (session == null) { return; } session.Flush(); session.Close(); }
public static void CleanUp(HttpContext context, ISessionFactory sessionFactory) { ISession session = ManagedWebSessionContext.Unbind(context, sessionFactory); if (session != null) { if (session.Transaction != null && session.Transaction.IsActive) { session.Transaction.Rollback(); } else if (context.Error == null && session.IsDirty()) { session.Flush(); } session.Close(); } }
private void context_EndRequest(object sender, EventArgs e) { ISession session = ManagedWebSessionContext.Unbind(HttpContext.Current, SessionManager.SessionFactory); if (session == null || !session.IsOpen) { return; } if (session.Transaction != null && session.Transaction.IsActive) { session.Transaction.Rollback(); } else { session.Flush(); } session.Close(); }
public static void CloseSession(HttpContext context) { var session = ManagedWebSessionContext.Unbind(context, sessionFactory); if (session != null) { try { session.Transaction.Commit(); } catch { session.Transaction.Rollback(); } finally { if (session.IsOpen) { session.Flush(); session.Dispose(); } } } }
protected virtual void UnbindSession(HttpContext context) { // Get the default NH session factory ISessionFactory factory = Database.GetSessionFactory(); ISession session = ManagedWebSessionContext.Unbind(context, factory); try { // Give it to NH so it can pull the right session if (session == null) { return; } session.Flush(); session.Close(); } catch { // No need to handle this for this piece. } }
/// <summary> /// Cleans the session up. /// </summary> public void CleanUp() { this.logger.Debug("Cleaning up the session"); ISession session = ManagedWebSessionContext.Unbind(HttpContext.Current, this.SessionFactory); if (session != null) { if (session.Transaction != null && session.Transaction.IsActive) { this.logger.Debug("Session has active transaction which will be rolled back"); session.Transaction.Rollback(); } else if (HttpContext.Current.Error == null && session.IsDirty()) { this.logger.Debug("Session is dirty and error free, it will be flushed"); session.Flush(); } this.logger.Debug("Closing session"); session.Close(); } }
/// <summary> /// Binds the list of <see cref="ISessionProvider"/> to session context for NHibernate. /// </summary> /// <param name="context"></param> protected virtual void BindSession(HttpContext context) { var providerList = GetSessionProviders(); if (providerList == null || providerList.Count == 0) { return; } foreach (var provider in providerList) { // Create a new session (it's the beginning of the request) var session = provider.OpenSession(); // HACK: To handle the ISessionBuilder resolution pieces. if (session == null) { continue; } ManagedWebSessionContext.Bind(context, session); } }
private void CloseSessionInView() { string path = Context.Request.Url.AbsolutePath; if (IgnoreExtension(path)) { return; } ISession session = ManagedWebSessionContext.Unbind(Context, SessionManager.SessionFactory); if (session != null) { if (session.Transaction != null && session.Transaction.IsActive) { session.Transaction.Rollback(); } session.Close(); } }
private void Application_EndRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; if (app.Request.CurrentExecutionFilePathExtension == ".js" || app.Request.CurrentExecutionFilePathExtension == ".png" || app.Request.CurrentExecutionFilePathExtension == ".jpg" || app.Request.CurrentExecutionFilePathExtension == ".gif" || app.Request.CurrentExecutionFilePathExtension == ".css") { return; } ISession session = ManagedWebSessionContext.Unbind(HttpContext.Current, NhbHelper.SessionFactory); if (session.Transaction.IsActive) { session.Transaction.Rollback(); } if (session != null) { session.Close(); } }
private void context_BeginRequest(object sender, EventArgs e) { ManagedWebSessionContext.Bind(HttpContext.Current, SessionManager.SessionFactory.OpenSession()); }
private void Application_BeginRequest(object sender, EventArgs e) { ManagedWebSessionContext.Bind(HttpContext.Current, ExampleApplication.SessionFactory.OpenSession()); }
void context_BeginRequest(object sender, EventArgs e) { ManagedWebSessionContext.Bind(HttpContext.Current, DependencyResolver.Current.GetService <ISessionFactory>().OpenSession()); }