/// <summary> /// Copies the elements of the specified <see cref="OnlineUserInfo">OnlineUserInfo</see> array to the end of the collection. /// </summary> /// <param name="value">An array of type <see cref="OnlineUserInfo">OnlineUserInfo</see> containing the Components to add to the collection.</param> public void AddRange(OnlineUserInfo[] value) { for (int i = 0; (i < value.Length); i = (i + 1)) { this.Add(value[i]); } }
/// <summary> /// 执行在线用户向表及缓存中添加的操作。 /// </summary> /// <param name="onlineuserinfo">在组用户信息内容</param> /// <returns>添加成功则返回刚刚添加的olid,失败则返回0</returns> public static int CreateOnlineUserInfo(OnlineUserInfo onlineuserinfo, int timeout) { //如果启用用户缓存则进行更新 if (Users.appDBCache && Users.IUserService != null) { UserInfo userInfo = Users.IUserService.GetUserInfo(onlineuserinfo.Userid); if (userInfo != null) { userInfo.Onlinestate = 1; Users.IUserService.UpdateUser(userInfo); } } //如果启用在线用户表缓存 if (appDBCache) return IOnlineUserService.CreateOnlineUserInfo(onlineuserinfo, timeout); else return DatabaseProvider.GetInstance().AddOnlineUser(onlineuserinfo, timeout, GeneralConfigs.GetConfig().Deletingexpireduserfrequency); }
private static OnlineUserInfo LoadSingleOnlineUser(DataRow dr) { OnlineUserInfo info = new OnlineUserInfo(); info.Olid = TypeConverter.ObjectToInt(dr["olid"]); info.Userid = TypeConverter.ObjectToInt(dr["userid"]); info.Ip = dr["ip"].ToString(); info.Username = dr["username"].ToString(); info.Nickname = dr["nickname"].ToString(); info.Password = dr["password"].ToString(); info.Groupid = Int16.Parse(dr["groupid"].ToString()); info.Olimg = dr["olimg"].ToString(); info.Adminid = Int16.Parse(dr["adminid"].ToString()); info.Invisible = Int16.Parse(dr["invisible"].ToString()); info.Action = Int16.Parse(dr["action"].ToString()); info.Actionname = ""; info.Lastactivity = Int16.Parse(dr["lastactivity"].ToString()); info.Lastposttime = dr["lastposttime"].ToString(); info.Lastpostpmtime = dr["lastpostpmtime"].ToString(); info.Lastsearchtime = dr["lastsearchtime"].ToString(); info.Lastupdatetime = dr["lastupdatetime"].ToString(); info.Forumid = TypeConverter.ObjectToInt(dr["forumid"]); if (dr["forumname"] != DBNull.Value) info.Forumname = dr["forumname"].ToString(); info.Titleid = TypeConverter.ObjectToInt(dr["titleid"]); if (dr["title"] != DBNull.Value) info.Title = dr["title"].ToString(); info.Verifycode = dr["verifycode"].ToString(); if (dr["newpms"] != DBNull.Value) info.Newpms = Int16.Parse(dr["newpms"].ToString()); if (dr["newnotices"] != DBNull.Value) info.Newnotices = Int16.Parse(dr["newnotices"].ToString()); //if (dr["newfriendrequest"] != DBNull.Value) // info.Newfriendrequest = Int16.Parse(dr["newfriendrequest"].ToString()); //if (dr["newapprequest"] != DBNull.Value) // info.Newapprequest = Int16.Parse(dr["newapprequest"].ToString()); return info; }
/// <summary> /// Gets a value indicating whether the collection contains the specified <see cref="OnlineUserInfoCollection">OnlineUserInfoCollection</see>. /// </summary> /// <param name="value">The <see cref="OnlineUserInfoCollection">OnlineUserInfoCollection</see> to search for in the collection.</param> /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns> public bool Contains(OnlineUserInfo value) { return this.List.Contains(value); }
/// <summary> /// Initializes a new instance of the <see cref="OnlineUserInfoCollection">OnlineUserInfoCollection</see> class containing the specified array of <see cref="OnlineUserInfo">OnlineUserInfo</see> Components. /// </summary> /// <param name="value">An array of <see cref="OnlineUserInfo">OnlineUserInfo</see> Components with which to initialize the collection. </param> public OnlineUserInfoCollection(OnlineUserInfo[] value) { this.AddRange(value); }
public int Add(OnlineUserInfo value) { return this.List.Add(value); }
public void Remove(OnlineUserInfo value) { List.Remove(value); }
public void Insert(int index, OnlineUserInfo value) { List.Insert(index, value); }
/// <summary> /// Gets the index in the collection of the specified <see cref="OnlineUserInfoCollection">OnlineUserInfoCollection</see>, if it exists in the collection. /// </summary> /// <param name="value">The <see cref="OnlineUserInfoCollection">OnlineUserInfoCollection</see> to locate in the collection.</param> /// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns> public int IndexOf(OnlineUserInfo value) { return this.List.IndexOf(value); }
/// <summary> /// Copies the collection Components to a one-dimensional <see cref="T:System.Array">Array</see> instance beginning at the specified index. /// </summary> /// <param name="array">The one-dimensional <see cref="T:System.Array">Array</see> that is the destination of the values copied from the collection.</param> /// <param name="index">The index of the array at which to begin inserting.</param> public void CopyTo(OnlineUserInfo[] array, int index) { this.List.CopyTo(array, index); }
/// <summary> /// 执行在线用户向表及缓存中添加的操作。 /// </summary> /// <param name="onlineuserinfo">在组用户信息内容</param> /// <param name="timeout">系统设置用户多少时间即算做离线</param> /// <param name="deletingfrequency">删除过期用户频率(单位:分钟)</param> /// <returns>添加成功则返回刚刚添加的olid,失败则返回0</returns> public int AddOnlineUser(OnlineUserInfo onlineUserInfo, int timeOut, int deletingFrequency) { //标识需要更新用户在线状态,0表示需要更新 int onlinestate = 1; // 如果timeout为负数则代表不需要精确更新用户是否在线的状态 if (timeOut > 0) { if (onlineUserInfo.Userid > 0) onlinestate = 0; } else timeOut = timeOut * -1; if (timeOut > 9999) timeOut = 9999; DbParameter[] parms = { DbHelper.MakeInParam("@onlinestate",(DbType)SqlDbType.Int,4,onlinestate), DbHelper.MakeInParam("@userid",(DbType)SqlDbType.Int,4,onlineUserInfo.Userid), DbHelper.MakeInParam("@ip",(DbType)SqlDbType.VarChar,15,onlineUserInfo.Ip), DbHelper.MakeInParam("@username",(DbType)SqlDbType.NVarChar,40,onlineUserInfo.Username), DbHelper.MakeInParam("@nickname",(DbType)SqlDbType.NVarChar,40,onlineUserInfo.Nickname), DbHelper.MakeInParam("@password",(DbType)SqlDbType.Char,32,onlineUserInfo.Password), DbHelper.MakeInParam("@groupid",(DbType)SqlDbType.SmallInt,2,onlineUserInfo.Groupid), DbHelper.MakeInParam("@olimg",(DbType)SqlDbType.VarChar,80,onlineUserInfo.Olimg), DbHelper.MakeInParam("@adminid",(DbType)SqlDbType.SmallInt,2,onlineUserInfo.Adminid), DbHelper.MakeInParam("@invisible",(DbType)SqlDbType.SmallInt,2,onlineUserInfo.Invisible), DbHelper.MakeInParam("@action",(DbType)SqlDbType.SmallInt,2,onlineUserInfo.Action), DbHelper.MakeInParam("@lastactivity",(DbType)SqlDbType.SmallInt,2,onlineUserInfo.Lastactivity), DbHelper.MakeInParam("@lastposttime",(DbType)SqlDbType.DateTime,8,TypeConverter.StrToDateTime(onlineUserInfo.Lastposttime)), DbHelper.MakeInParam("@lastpostpmtime",(DbType)SqlDbType.DateTime,8,TypeConverter.StrToDateTime(onlineUserInfo.Lastpostpmtime)), DbHelper.MakeInParam("@lastsearchtime",(DbType)SqlDbType.DateTime,8,TypeConverter.StrToDateTime(onlineUserInfo.Lastsearchtime)), DbHelper.MakeInParam("@lastupdatetime",(DbType)SqlDbType.DateTime,8,TypeConverter.StrToDateTime(onlineUserInfo.Lastupdatetime)), DbHelper.MakeInParam("@forumid",(DbType)SqlDbType.Int,4,onlineUserInfo.Forumid), DbHelper.MakeInParam("@forumname",(DbType)SqlDbType.NVarChar,50,""), DbHelper.MakeInParam("@titleid",(DbType)SqlDbType.Int,4,onlineUserInfo.Titleid), DbHelper.MakeInParam("@title",(DbType)SqlDbType.NVarChar,80,""), DbHelper.MakeInParam("@verifycode",(DbType)SqlDbType.VarChar,10,onlineUserInfo.Verifycode), DbHelper.MakeInParam("@newpms",(DbType)SqlDbType.SmallInt,2,onlineUserInfo.Newpms), DbHelper.MakeInParam("@newnotices",(DbType)SqlDbType.SmallInt,2,onlineUserInfo.Newnotices) //DbHelper.MakeInParam("@newfriendrequest",(DbType)SqlDbType.SmallInt,2,onlineUserInfo.Newfriendrequest), //DbHelper.MakeInParam("@newapprequest",(DbType)SqlDbType.SmallInt,2,onlineUserInfo.Newapprequest) }; //当在线表被布署到别的数据库时 if (EntLibConfigs.GetConfig() != null) { OnlineTableConnect onlineTableConnect = EntLibConfigs.GetConfig().Onlinetableconnect; if (onlineTableConnect.Enable && !string.IsNullOrEmpty(onlineTableConnect.SqlServerConn)) { if (onlinestate == 0) DbHelper.ExecuteNonQuery(CommandType.Text, string.Format("UPDATE [{0}users] SET [onlinestate]=1 WHERE [uid]=@userid", BaseConfigs.GetTablePrefix), parms); parms[0].Value = 1;//HACK:这个就不会在存储过程中运行更新users表信息的语句了,因为可能在分离的dnt_online表所在数据库中没有USER表。 } } int olid = TypeConverter.ObjectToInt(DbHelper.ExecuteScalar(CommandType.StoredProcedure, string.Format("{0}createonlineuser", BaseConfigs.GetTablePrefix), parms)); //按照系统设置频率(默认5分钟)清除过期用户 if (_lastRemoveTimeout == 0 || (System.Environment.TickCount - _lastRemoveTimeout) > 60000 * deletingFrequency) { DeleteExpiredOnlineUsers(timeOut); _lastRemoveTimeout = System.Environment.TickCount; } // 如果id值太大则重建在线表 if (olid > 2147483000) { CreateOnlineTable(); olid = TypeConverter.ObjectToInt(DbHelper.ExecuteScalar(CommandType.StoredProcedure, string.Format("{0}createonlineuser", BaseConfigs.GetTablePrefix), parms)); //DbHelper.ExecuteNonQuery(CommandType.StoredProcedure, string.Format("{0}createonlineuser", BaseConfigs.GetTablePrefix), parms); // return olid; } return olid; }