コード例 #1
0
ファイル: Global.asax.cs プロジェクト: lhrolim/softwrench
        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;
        }
コード例 #2
0
        public static void OpenSession(HttpContext context)
        {
            var session = sessionFactory.OpenSession();

            session.BeginTransaction();
            ManagedWebSessionContext.Bind(context, session);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        /// <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();
                }
            }
        }
コード例 #5
0
        protected virtual void BindSession(HttpContext context)
        {
            ISession session = Database.OpenSession();

            // Tell NH session context to use it
            ManagedWebSessionContext.Bind(context, session);
        }
コード例 #6
0
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            var      sessionFactory = Container.Resolve <ISessionFactory>();
            ISession session        = sessionFactory.OpenSession();

            ManagedWebSessionContext.Bind(HttpContext.Current, session);
        }
コード例 #7
0
ファイル: Global.asax.cs プロジェクト: Lucascarbaj99/cys
        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();
        }
コード例 #8
0
        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();
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        void context_EndRequest(object sender, EventArgs e)
        {
            ISession session = ManagedWebSessionContext.Unbind(
                HttpContext.Current, DependencyResolver.Current.GetService <ISessionFactory>());

            if (session != null)
            {
                session.Close();
                session.Dispose();
            }
        }
コード例 #11
0
        private void OpenSessionInView()
        {
            string path = Context.Request.Url.AbsolutePath;

            if (IgnoreExtension(path))
            {
                return;
            }

            ManagedWebSessionContext.Bind(Context,
                                          SessionManager.SessionFactory.OpenSession());
        }
コード例 #12
0
        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();
            }
        }
コード例 #13
0
        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());
        }
コード例 #14
0
        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();
        }
コード例 #15
0
        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();
            }
        }
コード例 #16
0
        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();
        }
コード例 #17
0
        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();
                    }
                }
            }
        }
コード例 #18
0
        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.
            }
        }
コード例 #19
0
        /// <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();
            }
        }
コード例 #20
0
        /// <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);
            }
        }
コード例 #21
0
        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();
            }
        }
コード例 #22
0
        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();
            }
        }
コード例 #23
0
 private void context_BeginRequest(object sender, EventArgs e)
 {
     ManagedWebSessionContext.Bind(HttpContext.Current, SessionManager.SessionFactory.OpenSession());
 }
コード例 #24
0
 private void Application_BeginRequest(object sender, EventArgs e)
 {
     ManagedWebSessionContext.Bind(HttpContext.Current, ExampleApplication.SessionFactory.OpenSession());
 }
コード例 #25
0
 void context_BeginRequest(object sender, EventArgs e)
 {
     ManagedWebSessionContext.Bind(HttpContext.Current, DependencyResolver.Current.GetService <ISessionFactory>().OpenSession());
 }