示例#1
0
        public void TestCanAddSingleItem()
        {
            ISessionFactory fac     = RomViewContainer.Container.GetInstance <ISessionFactory>();
            ISession        session = fac.OpenSession();
            ITransaction    tx      = session.BeginTransaction();

            LazySessionContext.Bind(new Lazy <ISession>(() => session), fac);

            try
            {
                IRepository <NonPlayerEntity> rep        = RomViewContainer.Container.GetInstance <IRepository <NonPlayerEntity> >();
                INonPlayerEntityRepository    repository = new NonPlayerEntityRespository(rep);

                NonPlayerEntity def = new NonPlayerEntity
                {
                    RomId = 225932,
                    Name  = "MyNPC",
                };

                string expected = def.ToDelimitedString(1);

                repository.Add(def);

                //NonPlayerEntity result = repository.GetByRomId(def.RomId);
                //Assert.AreEqual(expected, result.ToDelimitedString(1));
            }
            finally
            {
                tx.Rollback();
                session.Close();
            }
        }
示例#2
0
        /// <summary>
        /// Unbind all lazy NHibernate sessions
        /// </summary>
        private void UnbindLazySessions()
        {
            try
            {
                _logger.Debug("Unbind all NH lazy sessions");
                foreach (var sessionFactory in GetSessionFactories())
                {
                    var session = LazySessionContext.UnBind(sessionFactory);
                    if (session == null)
                    {
                        _logger.Debug($"lazy NH session is null");
                        continue;
                    }
                    _logger.Debug($"lazy NH session has been unbound: {session.GetId()}");

                    session.EndSession();
                }
                _logger.Debug("All lazy NH sessions have been unbound");
            }
            catch (Exception ex)
            {
                _logger.Error("Failed to unbind lazy NH sessions", ex);
                throw;
            }
        }
示例#3
0
 /// <summary>
 ///     Opens session
 /// </summary>
 public void Open()
 {
     foreach (ISessionFactory sessionFactory in GetSessionFactories())
     {
         ISessionFactory localFactory = sessionFactory;
         LazySessionContext.Bind(new Lazy <ISession>(() => BeginSession(localFactory)), localFactory);
     }
 }
        private void ContextBeginRequest(object sender, EventArgs e)
        {
            foreach (var sessionFactory in GetSessionFactories())
            {
                var localFactory = sessionFactory;

                LazySessionContext.Bind(new Lazy <ISession>(() => BeginSession(localFactory)), sessionFactory);
            }
        }
        private void ContextError(object sender, EventArgs e)
        {
            ISession s = LazySessionContext.UnBind(_factory);

            if (s == null)
            {
                return;
            }
            NHibernateHelper.SessionManager.CommitSession(s);
            s.Dispose();
        }
 private void ContextError(object sender, EventArgs e)
 {
     foreach (var sessionfactory in GetSessionFactories())
     {
         var session = LazySessionContext.UnBind(sessionfactory);
         if (session == null)
         {
             continue;
         }
         EndSession(session, false);
     }
 }
示例#7
0
 private void ContextEndRequest(object sender, EventArgs e)
 {
     foreach (ISessionFactory sessionfactory in GetSessionFactories())
     {
         ISession session = LazySessionContext.UnBind(sessionfactory);
         if (session == null)
         {
             continue;
         }
         EndSession(session);
     }
 }
 private void ContextEndRequest(object sender, EventArgs e)
 {
     foreach (var sf in sfp.GetSessionFactories())
     {
         var session = LazySessionContext.UnBind(sf);
         if (session == null)
         {
             continue;
         }
         EndSession(session);
     }
 }
示例#9
0
 /// <summary>
 ///     Closes session
 /// </summary>
 public void Close()
 {
     foreach (ISessionFactory sessionfactory in GetSessionFactories())
     {
         ISession session = LazySessionContext.UnBind(sessionfactory);
         if (session == null)
         {
             continue;
         }
         EndSession(session);
     }
 }
示例#10
0
        public void BindLazySession()
        {
            try
            {
                _logger.Debug("bind lazy NH session");

                foreach (var sessionFactory in GetSessionFactories())
                {
                    var localFactory = sessionFactory;

                    LazySessionContext.Bind(new Lazy <ISession>(() => BeginSession(localFactory, _logger)), sessionFactory);
                }
            }
            catch (Exception ex)
            {
                _logger.Fatal($"bind lazy session failed", ex);
                throw;
            }
        }
示例#11
0
        public void TestCanAddAndCanDeleteItem()
        {
            ISessionFactory fac     = RomViewContainer.Container.GetInstance <ISessionFactory>();
            ISession        session = fac.OpenSession();
            ITransaction    tx      = session.BeginTransaction();

            LazySessionContext.Bind(new Lazy <ISession>(() => session), fac);

            IRomMessageProcessor p          = RomViewContainer.Container.GetInstance <IRomMessageProcessor>();
            IItemRepository      repository = RomViewContainer.Container.GetInstance <IItemRepository>();

            ItemDefinition expected = new ItemDefinition()
            {
                RomId          = 999999,
                Name           = "TestItem",
                ItemType       = "ItemType",
                ItemSubType    = "ItemSubType",
                ItemSubSubType = "ItemSubSubType",
                Value          = 999
            };



            //romItem id = 228216
            string source   = string.Format("ITEM{0}SAVE{0}{1}", (char)1, expected.ToDelimitedString(2));
            string response = p.HandleMessage(source);

            Assert.IsNull(response);

            ItemDefinition result = repository.GetByRomId(expected.RomId);

            Assert.IsNotNull(result);

            Assert.AreEqual(expected.ToDelimitedString(1), result.ToDelimitedString(1));
            tx.Rollback();
        }
 private void ContextBeginRequest(object sender, EventArgs e)
 {
     _factory = NHibernateHelper.SessionManager.CurrentSessionFactory;
     LazySessionContext.Bind(new Lazy <ISession>(() => BeginSession(_factory)), _factory);
 }
示例#13
0
        private static void BindSessionFactoryToContext()
        {
            var sessionFactory = _container.Resolve <ISessionFactory>();

            LazySessionContext.Bind(new Lazy <ISession>(() => BeginSession(sessionFactory)), sessionFactory);
        }