Ejemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            SecurityConfig.ConfigureGlobal(GlobalConfiguration.Configuration);

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            // Register exisitng LMs
            RegisterExisting();

            // Load logging info
            log4net.Config.XmlConfigurator.Configure();

            ISessionManager sessionManager = new NHibernateSessionManager();
            sessionManager.Configuration.CurrentSessionContext<WebSessionContext>();

            SessionFactory = sessionManager.BuildSessionFactory();
        }
Ejemplo n.º 2
0
 public DatabaseManager()
 {
     SessionManager = new NHibernateSessionManager();
 }
Ejemplo n.º 3
0
 public DatabaseManager(string cfg)
 {
     SessionManager = new NHibernateSessionManager(cfg);
 }
Ejemplo n.º 4
0
        private void SaveData(string cfg, IEnumerable<User> users)
        {
            var targetSessionManager = new NHibernateSessionManager(cfg);

            targetSessionManager.CreateDatabase();

            using (var targetSession = targetSessionManager.BuildSessionFactory().OpenSession())
            {
                using (var tx = targetSession.BeginTransaction())
                {
                    try
                    {
                        IRepository repository = new NHibernateRepository(targetSession);

                        foreach (var user in users)
                        {
                            targetSession.Replicate(user, ReplicationMode.Exception);

                            repository.Save(user);
                        }

                        tx.Commit();
                    }
                    catch (Exception)
                    {
                        tx.Rollback();

                        throw;
                    }
                }

                targetSession.Close();
            }
        }