Ejemplo n.º 1
0
        private bool SendToDb <T>(T data, EntityPropertyGetFunc <T> getFunc, EnttiyPostColumnFunc <T> postColumnFunc, bool synchronous) where T : ISqlEntity
        {
            if (Equals(data, null))
            {
                return(false);
            }
            SchemaTable    schemaTable = EntitySchemaSet.Get(data.GetType());
            DbBaseProvider dbProvider  = DbConnectionProvider.CreateDbProvider(_connectKey ?? schemaTable.ConnectKey);

            if (dbProvider == null)
            {
                return(false);
            }
            CommandStruct command = GenerateCommand(dbProvider, data, schemaTable, getFunc, postColumnFunc);

            if (command != null)
            {
                bool result = (synchronous
                    ? dbProvider.ExecuteQuery(CommandType.Text, command.Sql, command.Parameters)
                    : dbProvider.ExecuteNonQuery(data.GetMessageQueueId(), CommandType.Text, command.Sql, command.Parameters)) > 0;
                data.ResetState();
                return(result);
            }
            return(false);
        }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="fromScore"></param>
        /// <param name="toScore">-1: all</param>
        /// <returns></returns>
        public bool RemoveRankByScore <V>(string key, double fromScore, double?toScore) where V : RankEntity, new()
        {
            LoadingStatus loadStatus;
            CacheList <V> cacheItems;

            if (!TryGetCacheItem(key, true, out cacheItems, out loadStatus))
            {
                return(false);
            }
            List <V> removeList;

            if (!cacheItems.RemoveAll(t => t.Score >= fromScore && (!toScore.HasValue || t.Score <= toScore.Value), out removeList))
            {
                return(true);
            }
            foreach (var entity in removeList)
            {
                entity.IsInCache = false;
                entity.IsExpired = true;
                entity.OnDelete();
            }
            var            schema    = EntitySchemaSet.Get <V>();
            TransSendParam sendParam = new TransSendParam(key)
            {
                Schema = schema
            };

            return(_cachePool.TrySetRankData(sendParam, removeList.ToArray()));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="personalId"></param>
        /// <param name="dataList"></param>
        /// <returns></returns>
        protected bool TryLoadFromRedis(out List <T> dataList, string personalId = null)
        {
            string      redisKey = string.IsNullOrEmpty(personalId) ? containerKey : string.Format("{0}_{1}", containerKey, personalId);
            SchemaTable schema   = EntitySchemaSet.Get <T>();

            return(RedisConnectionPool.TryGetEntity(redisKey, schema, out dataList));
        }
Ejemplo n.º 5
0
 private static void OnModelChangeAtfer(Assembly assembly)
 {
     if (assembly == null)
     {
         return;
     }
     try
     {
         TypeAccessor.Init();
         ProtoBufUtils.Initialize();
         ProtoBufUtils.LoadProtobufType(assembly);
         EntitySchemaSet.Init();
         EntitySchemaSet.LoadAssembly(assembly);
         Language.Reset();
         CacheFactory.ResetCache();
         //Declan 2017-4-19 model下脚本动态编译报错,所有注释该行
         //SensitiveWordService.Init();
         TraceLog.ReleaseWrite("Update Model script success.");
         IsRunning = true;
     }
     catch (Exception ex)
     {
         TraceLog.WriteError("OnModelChangeAtfer error:{0}", ex);
     }
 }
Ejemplo n.º 6
0
        private bool SendToDb <T>(T data, EntityPropertyGetFunc <T> getFunc, EnttiyPostColumnFunc <T> postColumnFunc, bool synchronous) where T : ISqlEntity
        {
            if (Equals(data, null))
            {
                return(false);
            }
            SchemaTable    schemaTable = EntitySchemaSet.Get(data.GetType());
            DbBaseProvider dbProvider  = DbConnectionProvider.CreateDbProvider(_connectKey ?? schemaTable.ConnectKey);

            if (dbProvider == null)
            {
                return(false);
            }
            CommandStruct command = GenerateCommand(dbProvider, data, schemaTable, getFunc, postColumnFunc);

            if (command != null)
            {
                int result;
                if (synchronous)
                {
                    //同时采集
                    ProfileManager.PostSqlOfMessageQueueTimes(command.TableName, 1);
                    ProfileManager.ProcessSqlOfMessageQueueTimes(command.TableName);
                    result = dbProvider.ExecuteQuery(CommandType.Text, command.Sql, command.Parameters);
                }
                else
                {
                    //put into pool
                    result = dbProvider.ExecuteNonQuery(data.GetMessageQueueId(), CommandType.Text, command.TableName, command.Sql, command.Parameters);
                }
                data.ResetState();
                return(result > 0);
            }
            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="redisKey"></param>
        /// <param name="dataList"></param>
        /// <returns>返回是否加载成功</returns>
        public static bool TryGet <T>(string redisKey, out List <T> dataList) where T : AbstractEntity
        {
            bool     result = false;
            List <T> list   = null;

            Process(client =>
            {
                try
                {
                    //modify: check gload key
                    var schema = EntitySchemaSet.Get <T>();
                    if (schema != null && schema.CacheType == CacheType.Entity)
                    {
                        var keyList = client.SearchKeys(string.Format("{0}_*", redisKey));
                        if (keyList.Count > 0)
                        {
                            var buffers = client.MGet(keyList.ToArray());
                            list        = new List <T>();
                            foreach (var buffer in buffers)
                            {
                                var temp = ProtoBufUtils.Deserialize <T>(buffer);
                                list.Add(temp);
                            }
                            result = true;
                            return;
                        }
                        //convert store type
                        byte[] data = client.Get <byte[]>(redisKey) ?? new byte[0];
                        var dataSet = ProtoBufUtils.Deserialize <Dictionary <string, T> >(data);
                        if (dataSet != null)
                        {
                            list = dataSet.Values.ToList();
                            SaveEntity(client, redisKey, list.ToArray());
                            client.Remove(redisKey);
                        }
                    }
                    else
                    {
                        byte[] buffer = client.Get <byte[]>(redisKey) ?? new byte[0];
                        var dataSet   = ProtoBufUtils.Deserialize <Dictionary <string, T> >(buffer);
                        if (dataSet != null)
                        {
                            list = dataSet.Values.ToList();
                        }
                    }
                    if (list == null)
                    {
                        list = new List <T>();
                    }
                    result = true;
                }
                catch (Exception ex)
                {
                    TraceLog.WriteError("Get redis \"{0}\" key:\"{1}\" cache error:{2}", typeof(T).FullName, redisKey, ex);
                }
            });
            dataList = list;
            return(result);
        }
Ejemplo n.º 8
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)
            {
                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");
        }
        private static ScriptRuntimeScope InitScriptRuntimeScope()
        {
            //star compile
            Interlocked.Exchange(ref _isCompiling, 1);
            try
            {
                string runtimePath = MathUtils.RuntimePath ?? MathUtils.RuntimeBinPath;
                AppDomain.CurrentDomain.AppendPrivatePath(ScriptCompiler.ScriptPath);
                bool isFirstRun = _runtimeDomain == null;
                if (!isFirstRun && _settupInfo.ModelChangedBefore != null)
                {
                    _settupInfo.ModelChangedBefore(_runtimeDomain.Scope.ModelAssembly);
                }

                // Declan 2017-4-19 防止重复new,加入判断
                if (_runtimeDomain == null)
                {
                    _runtimeDomain = new ScriptRuntimeDomain(typeof(ScriptRuntimeDomain).Name, new[] { _settupInfo.RuntimePrivateBinPath, ScriptCompiler.ScriptPath });
                }

                ScriptDomainContext domainContext = _runtimeDomain.InitDomainContext();

                foreach (var assemblyName in _settupInfo.ReferencedAssemblyNames)
                {
                    //排除System的dll
                    if (string.IsNullOrEmpty(assemblyName) ||
                        !Path.IsPathRooted(assemblyName))
                    {
                        continue;
                    }
                    string key = Path.GetFileNameWithoutExtension(assemblyName);
                    domainContext.LoadAssembly(key, assemblyName);
                }

                var scope = _runtimeDomain.CreateScope(_settupInfo);
                if (scope == null)
                {
                    return(scope);
                }
                PrintCompiledMessage();
                if (!isFirstRun && _settupInfo.ModelChangedAfter != null)
                {
                    _settupInfo.ModelChangedAfter(scope.ModelAssembly);
                }
                else if (scope.ModelAssembly != null)
                {
                    ProtoBufUtils.LoadProtobufType(scope.ModelAssembly);
                    EntitySchemaSet.LoadAssembly(scope.ModelAssembly);
                }
                return(scope);
            }
            finally
            {
                Interlocked.Exchange(ref _isCompiling, 0);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 获取Container中存在的Cache,不重新创建
        /// </summary>
        /// <param name="redisKey"></param>
        /// <param name="itemPair"></param>
        /// <param name="periodTime"></param>
        /// <returns></returns>
        public static bool TryGetContainerCacheItem(string redisKey, out KeyValuePair <string, CacheItemSet> itemPair, int periodTime = 0)
        {
            itemPair = default(KeyValuePair <string, CacheItemSet>);
            CacheItemSet cacheItem;

            string[] keys = (redisKey ?? "").Split('_');
            if (keys.Length == 2 && !string.IsNullOrEmpty(keys[0]))
            {
                CacheContainer container = null;
                string         typeName  = RedisConnectionPool.DecodeTypeName(keys[0]);
                var            schema    = EntitySchemaSet.Get(typeName);
                periodTime = periodTime > 0 ? periodTime : schema.PeriodTime;
                if (_writePools != null && !_writePools.TryGetValue(typeName, out container))
                {
                    _writePools.InitContainer(typeName);
                    _writePools.TryGetValue(typeName, out container);
                }
                if (container == null)
                {
                    return(false);
                }

                string[] childKeys   = keys[1].Split('|');
                string   personalKey = childKeys[0];
                string   entityKey   = childKeys.Length > 1 ? childKeys[1] : "";
                if (schema.CacheType == CacheType.Dictionary)//|| schema.CacheType == CacheType.Entity)
                {
                    var result = container.Collection.TryGetValue(personalKey, out cacheItem);
                    itemPair = new KeyValuePair <string, CacheItemSet>(entityKey, cacheItem);
                    return(result);
                }
                if (schema.CacheType == CacheType.Entity)
                {
                    var result = container.Collection.TryGetValue(entityKey, out cacheItem);
                    itemPair = new KeyValuePair <string, CacheItemSet>(entityKey, cacheItem);
                    return(result);
                }
                if (schema.CacheType == CacheType.Queue)
                {
                    TraceLog.WriteError("Not support CacheType.Queue get cache, key:{0}.", redisKey);
                }

                ////存在分类id与实体主键相同情况, 要优先判断实体主键
                //if (!string.IsNullOrEmpty(personalKey) && container.Collection.TryGetValue(entityKey, out cacheItem))
                //{
                //    itemPair = new KeyValuePair<string, CacheItemSet>(entityKey, cacheItem);
                //    return true;
                //}
                //if (!string.IsNullOrEmpty(personalKey) && container.Collection.TryGetValue(personalKey, out cacheItem))
                //{
                //    itemPair = new KeyValuePair<string, CacheItemSet>(entityKey, cacheItem);
                //    return true;
                //}
            }
            return(false);
        }
Ejemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="match"></param>
 /// <param name="hasChanged"></param>
 public static void Update(Predicate <SchemaTable> match, bool hasChanged = false)
 {
     foreach (var schemaTable in EntitySchemaSet.GetEnumerable())
     {
         if (match(schemaTable))
         {
             Update(schemaTable, hasChanged);
         }
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取实体数据架构信息
        /// </summary>
        /// <returns>返回有Null值</returns>
        protected SchemaTable SchemaTable()
        {
            SchemaTable schemaTable;

            if (EntitySchemaSet.TryGet <T>(out schemaTable))
            {
                return(schemaTable);
            }
            return(null);
        }
Ejemplo n.º 13
0
        private static void LoadGameEntitySchema()
        {
            SchemaTable schema;

            if (EntitySchemaSet.TryGet <SensitiveWord>(out schema))
            {
                schema.ConnectionProviderType = ConfigManger.Provider.ConnectionSetting.ProviderTypeName;
                schema.ConnectionString       = ConfigManger.Provider.ConnectionString;
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="isReadOnly"></param>
 protected AbstractEntity(bool isReadOnly)
     : base(isReadOnly)
 {
     _isNew    = true;
     IsInCache = false;
     if (EntitySchemaSet.TryGet(GetType(), out _schema))
     {
         _isReadOnly = _schema.AccessLevel == AccessLevel.ReadOnly;
     }
 }
Ejemplo n.º 15
0
        private void DoUpdateChangeKey(RedisClient client, string setId, object keyByte, byte[] values, bool isHash, byte[] buffer)
        {
            string key = isHash
                ? Encoding.UTF8.GetString((byte[])keyByte)
                : keyByte.ToString();
            dynamic entity = null;

            try
            {
                entity = CovertEntityObject(key, values);
                CacheType cacheType = CacheType.None;
                if (entity != null)
                {
                    SchemaTable schema;
                    Type        entityType = entity.GetType();
                    if (!EntitySchemaSet.TryGet(entityType, out schema))
                    {
                        EntitySchemaSet.InitSchema(entityType);
                    }
                    if (schema != null || EntitySchemaSet.TryGet(entityType, out schema))
                    {
                        cacheType = schema.CacheType;
                    }
                    if (cacheType != CacheType.None)
                    {
                        string redisKey = cacheType == CacheType.Dictionary
                            ? key.Split('|')[0]
                            : key.Split('_')[0];

                        using (IDataSender sender = DataSyncManager.GetRedisSender(redisKey))
                        {
                            sender.Send(entity);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("ChangeKey:{0} error:{1}", key, ex);
            }
            if (isHash)
            {
                client.HDel(setId, (byte[])keyByte);
            }
            else
            {
                client.ZRem(setId, buffer);
            }
            if (entity != null)
            {
                Type   type      = entity.GetType();
                string entityKey = string.Format("{0},{1}", key, type.Assembly.GetName().Name);
                client.HSet("__GLOBAL_SQL_CHANGE_KEYS_NEW", Encoding.UTF8.GetBytes(entityKey), new byte[] { 1 });
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 ///
 /// </summary>
 public static void ReLoad(string personalId, Predicate <SchemaTable> match)
 {
     personalId = AbstractEntity.EncodeKeyCode(personalId);
     foreach (var schemaTable in EntitySchemaSet.GetEnumerable())
     {
         if (match(schemaTable))
         {
             ReLoad(personalId, schemaTable);
         }
     }
 }
Ejemplo n.º 17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="personalId"></param>
 /// <param name="match"></param>
 /// <param name="hasChanged"></param>
 public static void Update(string personalId, Predicate <SchemaTable> match, bool hasChanged = false)
 {
     personalId = AbstractEntity.EncodeKeyCode(personalId);
     foreach (var schemaTable in EntitySchemaSet.GetEnumerable())
     {
         if (match(schemaTable))
         {
             Update(personalId, schemaTable, hasChanged);
         }
     }
 }
Ejemplo n.º 18
0
        static SensitiveWordService()
        {
            _cacheSet = new ShareCacheStruct <SensitiveWord>();
            SchemaTable schema;

            if (EntitySchemaSet.TryGet <SensitiveWord>(out schema))
            {
                schema.ConnectionType   = "";
                schema.ConnectionString = ConfigManger.connectionString;
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        ///
        /// </summary>
        protected BaseCacheStruct()
        {
            IsReadonly = false;
            SchemaTable schema;

            if (EntitySchemaSet.TryGet <T>(out schema))
            {
                IsReadonly = schema.AccessLevel == AccessLevel.ReadOnly;
            }
            DataContainer = CacheFactory.GetOrCreate <T>(IsReadonly, LoadFactory, LoadItemFactory);
        }
Ejemplo n.º 20
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        protected override bool LoadFactory()
        {
            int         capacity = 0;
            SchemaTable schemaTable;

            if (EntitySchemaSet.TryGet <T>(out schemaTable))
            {
                capacity = schemaTable.Capacity;
            }
            return(OnLoad(new DbDataFilter(capacity)));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="groupKey"></param>
        /// <param name="dataFilter"></param>
        /// <param name="periodTime"></param>
        /// <returns></returns>
        protected bool TryLoadCache(string groupKey, DbDataFilter dataFilter, int periodTime)
        {
            string      redisKey = CreateRedisKey(groupKey);
            SchemaTable schema;

            if (EntitySchemaSet.TryGet <T>(out schema))
            {
                TransReceiveParam receiveParam = new TransReceiveParam(redisKey, schema, dataFilter.Capacity, dataFilter);
                return(TryLoadCache(groupKey, receiveParam, periodTime));
            }
            return(false);
        }
        /// <summary>
        /// 是否有多个键且未加载成功状态
        /// </summary>
        /// <param name="personalId"></param>
        private void CheckMutilKeyAndLoad(string personalId)
        {
            CacheItemSet itemSet;
            var          schema = EntitySchemaSet.Get <T>();

            if (schema.Keys.Length > 1 &&
                DataContainer.TryGetCacheItem(personalId, out itemSet) &&
                !itemSet.HasLoadSuccess)
            {
                TryLoadItem(personalId, true);
            }
        }
Ejemplo n.º 23
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);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 删除自定的索引
        /// </summary>
        /// <param name="keyCode"></param>
        /// <param name="value"></param>
        internal void Remove(string keyCode, T value)
        {
            SchemaTable schemaTable;

            if (EntitySchemaSet.TryGet <T>(out schemaTable))
            {
                foreach (var pair in schemaTable.IndexList)
                {
                    _indexDictionary.RemoveIndex(pair.Key, GetIndexValues(pair.Value, value), keyCode);
                }
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 从数据库恢复
        /// </summary>
        /// <param name="chart">条件</param>
        /// <param name="value">值</param>
        public static void RecoverFromDb(string chart, int value = -2)
        {
            var cacheSet = new GameDataCacheSet <tb_User>();

            if (cacheSet.Count == 0)
            {
                SchemaTable    schema   = EntitySchemaSet.Get <tb_User>();
                DbBaseProvider provider = DbConnectionProvider.CreateDbProvider(schema);
                DbDataFilter   filter   = new DbDataFilter(0);
                filter.Condition = provider.FormatFilterParam("isRobot", chart);
                filter.Parameters.Add("isRobot", value);
                cacheSet.TryRecoverFromDb(filter);//从数据库中恢复数据
            }
        }
Ejemplo n.º 26
0
 static BaseCacheStruct()
 {
     try
     {
         var schema = EntitySchemaSet.InitSchema(typeof(T));
         if (schema.IncreaseStartNo > 0)
         {
             string key = string.Format(PrimaryKeyFormat, schema.EntityName);
             RedisConnectionPool.SetNo(key, schema.IncreaseStartNo);
         }
         CacheFactory.RegistUpdateNotify(new DefaultCacheStruct <T>());
     }
     catch (Exception)
     { }
 }
Ejemplo n.º 27
0
        /// <summary>
        /// 初始化容器
        /// </summary>
        /// <param name="groupKey"></param>
        /// <param name="periodTime"></param>
        /// <returns></returns>
        public CacheItemSet InitGroupContainer(string groupKey, int periodTime)
        {
            bool isMutilKey = EntitySchemaSet.Get <T>().IsMutilKey;
            var  lazy       = new Lazy <CacheItemSet>(() =>
            {
                BaseCollection itemCollection = IsReadonly
                    ? (BaseCollection) new ReadonlyCacheCollection()
                    : new CacheCollection(isMutilKey ? 0 : 1);
                var itemSet           = CreateItemSet(CacheType.Dictionary, periodTime);
                itemSet.HasCollection = true;
                itemSet.SetItem(itemCollection);
                return(itemSet);
            });

            return(Container.GetOrAdd(groupKey, name => lazy.Value));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Initialize cache.
        /// </summary>
        /// <param name="dbTransponder">db trans object</param>
        /// <param name="redisTransponder">redis trans object</param>
        /// <param name="setting">setting.</param>
        /// <param name="serializer"></param>
        public static void Initialize(ITransponder dbTransponder, ITransponder redisTransponder, CacheSetting setting, ICacheSerializer serializer)
        {
            _readonlyPools = new CachePool(dbTransponder, redisTransponder, true, serializer);
            _writePools    = new CachePool(dbTransponder, redisTransponder, false, serializer)
            {
                Setting = setting
            };

            EntitySchemaSet.InitSchema(typeof(EntityHistory));
            DataSyncQueueManager.Start(setting, serializer);
            InitListener("__CachePoolListener", setting.ExpiredInterval, "__CachePoolUpdateListener", setting.UpdateInterval);
            if (setting.AutoRunEvent)
            {
                StartListener();
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 初始化机哭人队列,MySQLDAL.Model.tb_User 数据
        /// </summary>
        public static void InitiRobotList()
        {
            _robotUserList = new List <tb_User>();

            var cacheSet = new GameDataCacheSet <tb_User>();

            cacheSet.ReLoad();
            if (cacheSet.Count == 0)
            {
                SchemaTable    schema   = EntitySchemaSet.Get <tb_User>();
                DbBaseProvider provider = DbConnectionProvider.CreateDbProvider(schema);
                DbDataFilter   filter   = new DbDataFilter(0);
                filter.Condition = provider.FormatFilterParam("isRobot", "=");
                filter.Parameters.Add("isRobot", 1);

                cacheSet.TryRecoverFromDb(filter);//从数据库中恢复数据
            }
            var            robotIdList = tb_UserEx.GetUserIdListByRobot(1);
            List <tb_User> _userList   = new List <tb_User>(); // List<tb_User> _userList = cacheSet.FindAll();

            if (robotIdList.Any())
            {
                robotIdList.ForEach(t =>
                {
                    tb_User user;
                    cacheSet.TryFindKey(t.ToString(), out user);
                    if (user != null)
                    {
                        _userList.Add(user);
                    }
                });
            }

            //// List<tb_User> _userList = cacheSet.FindAll();
            if (_userList == null || _userList.Count == 0)
            {
                ErrorRecord.Record(" tb_user 中没有机器人,201610231608");
                return;
            }
            //SetWebChartName();
            // var setName = SetWebChartName(_userList);
            // var temp = SetRobotWebChartImg(_userList);
            // ModifyFileName();
            // cacheSet.AddOrUpdate(setName);
            //cacheSet.Update();
            _robotUserList.AddRange(_userList);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Generate sql statement
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <param name="getFunc"></param>
        /// <param name="postColumnFunc"></param>
        /// <returns></returns>
        internal SqlStatement GenerateSqlQueue <T>(T data, EntityPropertyGetFunc <T> getFunc = null, EnttiyPostColumnFunc <T> postColumnFunc = null) where T : ISqlEntity
        {
            SchemaTable    schemaTable = EntitySchemaSet.Get(data.GetType());
            DbBaseProvider dbProvider  = DbConnectionProvider.CreateDbProvider(schemaTable.ConnectKey);

            if (dbProvider != null)
            {
                //process all columns.
                CommandStruct command = GenerateCommand(dbProvider, data, schemaTable, getFunc, postColumnFunc);
                if (command != null)
                {
                    var identityId = data.GetMessageQueueId();
                    return(dbProvider.GenerateSql(identityId, command));
                }
            }
            return(null);
        }