コード例 #1
0
        public static bool Initialize()
        {
            if (!RealmDBMgr.Initialized)
            {
                RealmDBMgr.Initialized        = true;
                DatabaseUtil.DBErrorHook      = (Predicate <Exception>)(exception => CharacterRecord.GetCount() < 100);
                DatabaseUtil.DBType           = RealmServerConfiguration.DatabaseType;
                DatabaseUtil.ConnectionString = RealmServerConfiguration.DBConnectionString;
                DatabaseUtil.DefaultCharset   = RealmDBMgr.DefaultCharset;
                Assembly assembly = typeof(RealmDBMgr).Assembly;
                try
                {
                    if (!DatabaseUtil.InitAR(assembly))
                    {
                        return(false);
                    }
                }
                catch (Exception ex1)
                {
                    RealmDBMgr.OnDBError(ex1);
                    try
                    {
                        if (!DatabaseUtil.InitAR(assembly))
                        {
                            return(false);
                        }
                    }
                    catch (Exception ex2)
                    {
                        LogUtil.ErrorException(ex2, true, "Failed to initialize the Database.", new object[0]);
                    }
                }
            }

            int num = 0;

            try
            {
                num = CharacterRecord.GetCount();
            }
            catch
            {
            }

            if (num == 0)
            {
                DatabaseUtil.CreateSchema();
            }
            NHIdGenerator.InitializeCreators(new Action <Exception>(RealmDBMgr.OnDBError));
            ServerApp <WCell.RealmServer.RealmServer> .InitMgr.SignalGlobalMgrReady(typeof(RealmDBMgr));

            return(true);
        }
コード例 #2
0
ファイル: NHIdGenerator.cs プロジェクト: uvbs/Asda2-Server
        private void Init()
        {
            ScalarQuery <object> scalarQuery = new ScalarQuery <object>(this.m_type,
                                                                        string.Format("SELECT max(r.{0}) FROM {1} r", (object)this.m_idMember, (object)this.m_table));
            object obj;

            try
            {
                obj = scalarQuery.Execute();
            }
            catch (Exception ex)
            {
                NHIdGenerator.OnError(ex);
                obj = scalarQuery.Execute();
            }

            this.m_highestId = obj != null ? (long)Convert.ChangeType(obj, typeof(long)) : 0L;
            if (this.m_highestId >= this.m_minId)
            {
                return;
            }
            this.m_highestId = this.m_minId;
        }
コード例 #3
0
        public static bool Initialize()
        {
            if (!Initialized)
            {
                Initialized = true;
                DatabaseUtil.DBErrorHook = exception => CharacterRecord.GetCount() < 100;

                DatabaseUtil.DBType           = RealmServerConfiguration.DatabaseType;
                DatabaseUtil.ConnectionString = RealmServerConfiguration.DBConnectionString;
                DatabaseUtil.DefaultCharset   = DefaultCharset;

                var asm = typeof(RealmDBMgr).Assembly;

                try
                {
                    if (!DatabaseUtil.InitAR(asm))
                    {
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    // repeat init
                    OnDBError(e);
                    try
                    {
                        if (!DatabaseUtil.InitAR(asm))
                        {
                            return(false);
                        }
                    }
                    catch (Exception e2)
                    {
                        LogUtil.ErrorException(e2, true, "Failed to initialize the Database.");
                    }
                }
            }

            // Create tables if not already existing:
            // NHibernate wraps up all added Persistors once the first connection to the DB is established
            // which again happens during the first query to the DB - The line to check for any existing Characters.

            // After the first query, you cannot register any further types.
            var count = 0;

            try
            {
                count = CharacterRecord.GetCount();
            }
            catch
            {
            }

            if (count == 0)
            {
                // in case that the CharacterRecord table does not exist -> Recreate schema
                DatabaseUtil.CreateSchema();
            }

            NHIdGenerator.InitializeCreators(OnDBError);

            RealmServer.InitMgr.SignalGlobalMgrReady(typeof(RealmDBMgr));
            return(true);
        }