private static void OnModelChangeAtfer(Assembly assembly)
 {
     if (assembly == null)
     {
         return;
     }
     try
     {
         TypeAccessor.Init();
         RedisConnectionPool.Initialize(_setting.Serializer);
         DbConnectionProvider.Initialize();
         ProtoBufUtils.Initialize();
         ProtoBufUtils.LoadProtobufType(assembly);
         EntitySchemaSet.Init();
         EntitySchemaSet.LoadAssembly(assembly);
         EntitySchemaSet.InitSchema(typeof(SensitiveWord));
         Language.Reset();
         CacheFactory.ResetCache();
         TraceLog.ReleaseWrite("Update Model script success.");
         IsRunning = true;
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("OnModelChangeAtfer error:{0}", ex);
     }
 }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="assembly"></param>
        public static void Init(Assembly assembly)
        {
            var htype = Type.GetType("ZyGames.Framework.Game.Sns.Service.IHandler`1", false, true);
            var types = assembly.GetTypes();

            foreach (var type in types)
            {
                if (type.GetInterfaces().Select(t => t.Name).Contains(htype.Name))
                {
                    handlerTypes[type.Name] = type;
                }
            }
            if (!string.IsNullOrEmpty(RedisHost))
            {
                try
                {
                    //use redis cache.
                    RedisConnectionPool.Initialize(new RedisPoolSetting()
                    {
                        Host = RedisHost, DbIndex = RedisDb
                    }, new JsonCacheSerializer(Encoding.UTF8));
                    RedisConnected = true;
                }
                catch (Exception ex)
                {
                    TraceLog.WriteError("Redis Initialize error:{0}", ex);
                }
            }
        }
Exemple #3
0
        public void ReLoadRedis()
        {
            try
            {
                RedisConfig = RedisSettingFactory.Load();

                ICacheSerializer serializer = RedisConfig.Serializer == StorageMode.Protobuf
                    ? (ICacheSerializer) new ProtobufCacheSerializer()
                    : new JsonCacheSerializer(Encoding.UTF8);

                RedisConnectionPool.Initialize(new RedisPoolSetting()
                {
                    Host             = RedisConfig.Host,
                    ReadOnlyHost     = RedisConfig.Host,
                    MaxWritePoolSize = 2,
                    MaxReadPoolSize  = 2,
                    DbIndex          = RedisConfig.Db
                }, serializer);

                var _redisSection = ConfigManager.Configger.GetFirstOrAddConfig <RedisSection>();
                if (_redisSection == null)
                {
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("ReLoadRedis error:{0}", ex);
            }
        }
        /// <summary>
        /// The game service start.
        /// </summary>
        /// <param name="setting">Environment setting.</param>
        /// <param name="cacheSetting">Cache setting.</param>
        public static void Start(EnvironmentSetting setting, CacheSetting cacheSetting)
        {
            if (IsRunning)
            {
                return;
            }

            TraceLog.WriteLine("{0} Server is starting...", DateTime.Now.ToString("HH:mm:ss"));
            _setting = setting;
            if (!RedisConnectionPool.Ping("127.0.0.1"))
            {
                string error = string.Format("Error: NIC is not connected or no network.");
                TraceLog.WriteLine(error);
                TraceLog.WriteError(error);
                return;
            }
            RedisConnectionPool.Initialize(_setting.Serializer);
            if (!RedisConnectionPool.CheckConnect())
            {
                string error = string.Format("Error: the redis server is not started.");
                TraceLog.WriteLine(error);
                TraceLog.WriteError(error);
                return;
            }
            TraceLog.WriteLine("{0} Redis server connect successfully.", DateTime.Now.ToString("HH:mm:ss"));

            DbConnectionProvider.Initialize();
            TraceLog.WriteLine("{0} DB server connect successfully.", DateTime.Now.ToString("HH:mm:ss"));

            EntitySchemaSet.CacheGlobalPeriod = _setting.CacheGlobalPeriod;
            EntitySchemaSet.CacheUserPeriod   = _setting.CacheUserPeriod;
            if (_setting.EntityAssembly != null)
            {
                ProtoBufUtils.LoadProtobufType(_setting.EntityAssembly);
                EntitySchemaSet.LoadAssembly(_setting.EntityAssembly);
            }

            ZyGameBaseConfigManager.Intialize();
            //init script.
            if (_setting.ScriptSysAsmReferences.Length > 0)
            {
                ScriptEngines.AddSysReferencedAssembly(_setting.ScriptSysAsmReferences);
            }
            ScriptEngines.AddReferencedAssembly("ZyGames.Framework.Game.dll");
            if (_setting.ScriptAsmReferences.Length > 0)
            {
                ScriptEngines.AddReferencedAssembly(_setting.ScriptAsmReferences);
            }
            ScriptEngines.RegisterModelChangedBefore(OnModelChangeBefore);
            ScriptEngines.RegisterModelChangedAfter(OnModelChangeAtfer);
            ScriptEngines.OnLoaded += OnScriptLoaded;
            ScriptEngines.Initialize();
            Language.SetLang();
            CacheFactory.Initialize(cacheSetting, _setting.Serializer);
            EntitySchemaSet.StartCheckTableTimer();
            Global = new ContextCacheSet <CacheItem>("__gameenvironment_global");
        }
Exemple #5
0
        public void Init()
        {
            var ser = new JsonCacheSerializer(Encoding.UTF8);

            ConfigManager.GetConfigger <MyDataConfigger>();
            RedisConnectionPool.Initialize(ser);
            DbConnectionProvider.Initialize();
            EntitySchemaSet.LoadAssembly(typeof(SingleData).Assembly);
            var setting = new CacheSetting();

            CacheFactory.Initialize(setting, ser);
        }
Exemple #6
0
        /// <summary>
        /// Initialize cache.
        /// </summary>
        /// <param name="dbTransponder">db trans object</param>
        /// <param name="redisTransponder">redis trans object</param>
        /// <param name="setting">setting.</param>
        public static void Initialize(ITransponder dbTransponder, ITransponder redisTransponder, CacheSetting setting)
        {
            _readonlyPools = new CachePool(dbTransponder, redisTransponder, true);
            _writePools    = new CachePool(dbTransponder, redisTransponder, false)
            {
                Setting = setting
            };

            RedisConnectionPool.Initialize();
            EntitySchemaSet.InitSchema(typeof(EntityHistory));

            _entitySync.Start();
            InitListener("__CachePoolListener", setting.ExpiredInterval, "__CachePoolUpdateListener", setting.UpdateInterval);
            if (setting.AutoRunEvent)
            {
                StartListener();
            }
        }
Exemple #7
0
        /// <summary>
        /// The game service start.
        /// </summary>
        /// <param name="setting">Environment setting.</param>
        /// <param name="cacheSetting">Cache setting.</param>
        public static void Start(EnvironmentSetting setting, CacheSetting cacheSetting)
        {
            if (_isRunning == 1)
            {
                return;
            }

            _setting = setting;
            RedisConnectionPool.Initialize();
            if (!RedisConnectionPool.CheckConnect())
            {
                string error = string.Format("Error: the redis server is not started.");
                Console.WriteLine(error);
                TraceLog.WriteError(error);
                return;
            }
            DbConnectionProvider.Initialize();
            EntitySchemaSet.CacheGlobalPeriod = _setting.CacheGlobalPeriod;
            EntitySchemaSet.CacheUserPeriod   = _setting.CacheUserPeriod;
            if (_setting.EntityAssembly != null)
            {
                ProtoBufUtils.LoadProtobufType(_setting.EntityAssembly);
                EntitySchemaSet.LoadAssembly(_setting.EntityAssembly);
            }
            EntitySchemaSet.StartCheckTableTimer();
            ZyGameBaseConfigManager.Intialize();
            //init script.
            if (_setting.ScriptSysAsmReferences.Length > 0)
            {
                ScriptEngines.AddSysReferencedAssembly(_setting.ScriptSysAsmReferences);
            }
            ScriptEngines.AddReferencedAssembly("ZyGames.Framework.Game.dll");
            if (_setting.ScriptAsmReferences.Length > 0)
            {
                ScriptEngines.AddReferencedAssembly(_setting.ScriptAsmReferences);
            }
            ScriptEngines.RegisterModelChangedBefore(OnModelChangeBefore);
            ScriptEngines.RegisterModelChangedAfter(OnModelChangeAtfer);
            ScriptEngines.Initialize();
            Language.SetLang();
            CacheFactory.Initialize(cacheSetting);
            Global = new ContextCacheSet <CacheItem>("__gameenvironment_global");
            Interlocked.Exchange(ref _isRunning, 1);
        }