示例#1
0
        public void ReleaseIdleDBUserInfos(int ticksSlot)
        {
            long          nowTicks       = DateTime.Now.Ticks / 10000L;
            List <string> idleUserIDList = new List <string>();

            lock (this.DictUserInfos)
            {
                foreach (MyWeakReference weakRef in this.DictUserInfos.Values)
                {
                    if (weakRef.IsAlive)
                    {
                        DBUserInfo dbUserInfo = weakRef.Target as DBUserInfo;
                        if (null != dbUserInfo)
                        {
                            if (nowTicks - dbUserInfo.LastReferenceTicks >= (long)ticksSlot)
                            {
                                idleUserIDList.Add(dbUserInfo.UserID);
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < idleUserIDList.Count; i++)
            {
                this.RemoveDBUserInfo(idleUserIDList[i]);
                LogManager.WriteLog(LogTypes.Info, string.Format("释放空闲的用户数据: {0}", idleUserIDList[i]), null, true);
            }
        }
示例#2
0
        public DBUserInfo FindDBUserInfo(string userID)
        {
            DBUserInfo      dbUserInfo = null;
            MyWeakReference weakRef    = null;

            lock (this.DictUserInfos)
            {
                if (this.DictUserInfos.Count > 0)
                {
                    if (this.DictUserInfos.TryGetValue(userID, out weakRef))
                    {
                        if (weakRef.IsAlive)
                        {
                            dbUserInfo = (weakRef.Target as DBUserInfo);
                        }
                    }
                }
            }
            if (null != dbUserInfo)
            {
                lock (dbUserInfo)
                {
                    dbUserInfo.LastReferenceTicks = DateTime.Now.Ticks / 10000L;
                }
            }
            return(dbUserInfo);
        }
示例#3
0
        public DBUserInfo GetDBUserInfo(string userID)
        {
            DBUserInfo dbUserInfo = this._DBUserMgr.FindDBUserInfo(userID);

            if (null == dbUserInfo)
            {
                dbUserInfo = new DBUserInfo();
                MySQLConnection conn = this._DBConns.PopDBConnection();
                try
                {
                    if (!dbUserInfo.Query(conn, userID))
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    LogManager.WriteException(ex.ToString());
                }
                finally
                {
                    this._DBConns.PushDBConnection(conn);
                }
                dbUserInfo = this._DBUserMgr.AddDBUserInfo(dbUserInfo);
            }
            return(dbUserInfo);
        }
示例#4
0
        /// <summary>
        /// 获取指定的用户信息
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public DBUserInfo GetDBUserInfo(string userID)
        {
            DBUserInfo dbUserInfo = _DBUserMgr.FindDBUserInfo(userID);

            if (null == dbUserInfo)
            {
                dbUserInfo = new DBUserInfo();
                MySQLConnection conn = _DBConns.PopDBConnection();

                try
                {
                    if (!dbUserInfo.Query(conn, userID))
                    {
                        return(null);
                    }
                }
                finally
                {
                    _DBConns.PushDBConnection(conn);
                }

                //放入缓存
                _DBUserMgr.AddDBUserInfo(dbUserInfo);
            }

            return(dbUserInfo);
        }
示例#5
0
        /// <summary>
        /// 添加用户信息到字典中
        /// </summary>
        /// <param name="dbUserInfo"></param>
        public void AddDBUserInfo(DBUserInfo dbUserInfo)
        {
            MyWeakReference weakRef = null;

            lock (DictUserInfos)
            {
                if (DictUserInfos.TryGetValue(dbUserInfo.UserID, out weakRef))
                {
                    weakRef.Target = dbUserInfo;
                }
                else
                {
                    DictUserInfos.Add(dbUserInfo.UserID, new MyWeakReference(dbUserInfo));
                }
            }
        }
示例#6
0
        public DBUserInfo AddDBUserInfo(DBUserInfo dbUserInfo)
        {
            MyWeakReference weakRef = null;

            lock (this.DictUserInfos)
            {
                if (this.DictUserInfos.TryGetValue(dbUserInfo.UserID, out weakRef))
                {
                    DBUserInfo old = weakRef.Target as DBUserInfo;
                    if (null != old)
                    {
                        return(old);
                    }
                    weakRef.Target = dbUserInfo;
                }
                else
                {
                    this.DictUserInfos.Add(dbUserInfo.UserID, new MyWeakReference(dbUserInfo));
                }
            }
            return(dbUserInfo);
        }