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();
            }
        }
Example #2
0
        protected void Application_Start()
        {
            ISessionManager sessionManager = new NHibernateSessionManager();
            sessionManager.Configuration.CurrentSessionContext<WebSessionContext>();

            SessionFactory = sessionManager.BuildSessionFactory();

            AreaRegistration.RegisterAllAreas();

            SecurityConfig.ConfigureGlobal(GlobalConfiguration.Configuration);

            WebApi.Config.Register(GlobalConfiguration.Configuration, SessionFactory, Environment);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            // Register exisitng LMs
            RegisterExisting();

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