public void onZhanMengJieSan(int bhId)
 {
     if (this.dataCache.Remove(bhId))
     {
         ZhanMengShiJianDBController.getInstance().delete(bhId);
     }
 }
        public bool initialize()
        {
            TCPCmdDispatcher.getInstance().registerProcessor(10138, ZhanMengShiJianCmdProcessor.getInstance());
            TCPCmdDispatcher.getInstance().registerProcessor(10139, ZhanMengShiJianDetailCmdProcessor.getInstance());
            List <ZhanMengShiJianData> dataList = ZhanMengShiJianDBController.getInstance().getZhanMengShiJianDataList();
            bool result;

            if (null == dataList)
            {
                result = true;
            }
            else
            {
                foreach (ZhanMengShiJianData data in dataList)
                {
                    List <ZhanMengShiJianData> _dataList = null;
                    if (!this.dataCache.TryGetValue(data.BHID, out _dataList))
                    {
                        _dataList = new List <ZhanMengShiJianData>();
                        this.dataCache.Add(data.BHID, _dataList);
                    }
                    if (_dataList.Count < ZhanMengShiJianConstants.MaxCacheNum)
                    {
                        _dataList.Add(data);
                    }
                }
                result = true;
            }
            return(result);
        }
        public bool initialize()
        {
            //战盟事件指令处理器
            TCPCmdDispatcher.getInstance().registerProcessor((int)TCPGameServerCmds.CMD_DB_ADD_ZHANMENGSHIJIAN, ZhanMengShiJianCmdProcessor.getInstance());
            //战盟事件详情指令处理器
            TCPCmdDispatcher.getInstance().registerProcessor((int)TCPGameServerCmds.CMD_DB_ZHANMENGSHIJIAN_DETAIL, ZhanMengShiJianDetailCmdProcessor.getInstance());

            List <ZhanMengShiJianData> dataList = ZhanMengShiJianDBController.getInstance().getZhanMengShiJianDataList();

            if (null == dataList)
            {
                return(true);
            }

            foreach (ZhanMengShiJianData data in dataList)
            {
                List <ZhanMengShiJianData> _dataList = null;
                if (!dataCache.TryGetValue(data.BHID, out _dataList))
                {
                    _dataList = new List <ZhanMengShiJianData>();
                    dataCache.Add(data.BHID, _dataList);
                }

                if (_dataList.Count >= MaxCacheNum)
                {
                    continue;
                }

                _dataList.Add(data);
            }

            return(true);
        }
        /// <summary>
        /// 战盟事件触发处理
        /// </summary>
        /// <param name="bhId"></param>
        /// <param name="roleName"></param>
        /// <param name="shijianType"></param>
        /// <param name="param1"></param>
        /// <param name="param2"></param>
        /// <param name="param3"></param>
        public void onAddZhanMengShiJian(ZhanMengShiJianData data)
        {
            List <ZhanMengShiJianData> _dataList = null;

            lock (dataCache)
            {
                if (!dataCache.TryGetValue(data.BHID, out _dataList))
                {
                    _dataList = new List <ZhanMengShiJianData>();
                    dataCache.Add(data.BHID, _dataList);
                }
            }

            lock (_dataList)
            {
                //将最新的数据插入到最前面
                _dataList.Insert(0, data);

                //超过规定容量,删除最后一个
                if (_dataList.Count > MaxCacheNum)
                {
                    _dataList.RemoveAt(_dataList.Count - 1);
                }
            }

            ZhanMengShiJianDBController.getInstance().insert(data);
        }
 private void deleteData()
 {
     foreach (int bhId in this.dataCache.Keys)
     {
         List <ZhanMengShiJianData> list = null;
         this.dataCache.TryGetValue(bhId, out list);
         if (list != null && list.Count != 0)
         {
             string minTime     = list[list.Count - 1].CreateTime;
             int    deleteCount = ZhanMengShiJianDBController.getInstance().delete(bhId, minTime);
         }
     }
 }
        /// <summary>
        /// 定期删除多余的数据
        /// </summary>
        private void deleteData()
        {
            foreach (int bhId in dataCache.Keys)
            {
                List <ZhanMengShiJianData> list = null;
                dataCache.TryGetValue(bhId, out list);

                if (null == list || list.Count == 0)
                {
                    continue;
                }

                string minTime = list[list.Count - 1].CreateTime;

                int deleteCount = ZhanMengShiJianDBController.getInstance().delete(bhId, minTime);
            }
        }
        public void onAddZhanMengShiJian(ZhanMengShiJianData data)
        {
            List <ZhanMengShiJianData> _dataList = null;

            lock (this.dataCache)
            {
                if (!this.dataCache.TryGetValue(data.BHID, out _dataList))
                {
                    _dataList = new List <ZhanMengShiJianData>();
                    this.dataCache.Add(data.BHID, _dataList);
                }
            }
            lock (_dataList)
            {
                _dataList.Insert(0, data);
                if (_dataList.Count > ZhanMengShiJianConstants.MaxCacheNum)
                {
                    _dataList.RemoveAt(_dataList.Count - 1);
                }
            }
            ZhanMengShiJianDBController.getInstance().insert(data);
        }