Пример #1
0
        public static ISessionFactory CreateSessionFactory()
        {
            Configuration   config;
            ISessionFactory factory;
            HttpContext     currentContext = HttpContext.Current;
            cAppConfig      oApp;
            Utility         oUtil = new Utility();

            config = new NHibernate.Cfg.Configuration();

            if (HttpContext.Current == null)
            {
                oApp = new cAppConfig(ConfigFileType.AppConfig);
                config.SetProperty("hibernate.connection.connection_string", oApp.GetValue("hibernate.connection.connection_string"));
            }
            else
            {
                oApp = new cAppConfig(ConfigFileType.WebConfig);
                //	string strDesEnc  = oUtil.Decrypt(oApp.GetValue("hibernate.connection.connection_string"));
                config.SetProperty("hibernate.connection.connection_string", oApp.GetValue("hibernate.connection.connection_string"));
            }


            if (config == null)
            {
                throw new InvalidOperationException("NHibernate configuration is null.");
            }

            if (HttpContext.Current == null)
            {
                config.SetProperty("hibernate.connection.connection_string", oApp.GetValue("hibernate.connection.connection_string"));
            }

            config.AddAssembly("Business");
            factory = config.BuildSessionFactory();

            if (currentContext != null)
            {
                currentContext.Items[KEY_NHIBERNATE_FACTORY] = factory;
            }

            if (factory == null)
            {
                throw new InvalidOperationException("Call to Configuration.BuildSessionFactory() returned null.");
            }
            else
            {
                return(factory);
            }
        }
Пример #2
0
        public static void ResetSessionFactory()
        {
            Configuration config;
            HttpContext   currentContext = HttpContext.Current;
            cAppConfig    oApp           = new cAppConfig(ConfigFileType.AppConfig);

            config = new NHibernate.Cfg.Configuration();

            config.SetProperty("hibernate.connection.connection_string", oApp.GetValue("hibernate.connection.connection_string"));
            config.AddAssembly("Business");

            NHibernateHttpModule.m_factory = config.BuildSessionFactory();
            NHibernateHttpModule.m_session = NHibernateHttpModule.m_factory.OpenSession();

            if (NHibernateHttpModule.m_factory == null)
            {
                throw new InvalidOperationException("Call to Configuration.BuildSessionFactory() returned null.");
            }
        }