public void RefreshAll() { //SyncHSLoginInfoWithCacheServer(0); this.GetALLOnlineUserFromCache(); OnlineInfo lInfo = null; List <string> delList = new List <string>(); lock (objLock) { IDictionaryEnumerator myEnumerator = HSLoginInfo.GetEnumerator(); int oauser = 0; while (myEnumerator.MoveNext()) { if (myEnumerator.Current == null) { continue; } lInfo = myEnumerator.Value as OnlineInfo; if (lInfo.IsOaUser == "0") { oauser++; } //删除为空的和打上Kill标记并且90分钟以上都没有刷新的 if (lInfo == null || (lInfo != null && lInfo.IsKilled && DateTime.Now > lInfo.LastRefTime.AddMinutes(6))) { delList.Add(myEnumerator.Key.ToString()); continue; } //如果超时,则剔除该用户 [写死]超时时间为70分钟 if (DateTime.Now > lInfo.LastRefTime.AddMinutes(5)) { //delList.Add(lInfo.SessionID); delList.Add(lInfo.UniqueClientID); } } NG3.Cache.Interface.IMemCachedClient memClient = NG3.MemCached.Client.MemCachedClientFactory.GetMemCachedClient(); memClient.SetSmallObject("NSSERVERALLUSERSINFO_CURRENT", oauser.ToString()); } foreach (string s in delList) { this.RemoveLoginUser(s); } }
/// <summary> /// 设置登录套件的信息 /// </summary> /// <param name="product">产品</param> /// <param name="suitInfo">套件,采用i6Hr,i6WM,..格式,用逗号分开</param> /// <returns></returns> //[MethodImpl(MethodImplOptions.Synchronized)] public bool SetLoginUsers(string product, string suitInfo, string mac) { //UserDac userDac = new UserDac(); bool lockedSuccess = false; //在此检测登录数 NG3.Cache.Interface.IMemCachedClient memClient = NG3.MemCached.Client.MemCachedClientFactory.GetMemCachedClient(); Mutex mutex = GetMutex(); try { //lockedSuccess = userDac.LockByDb(ConnectionInfoService.GetSessionConnectString()); //memClient.BeginLock("NNSERVERMAXUSERCONTROLKEY"); mutex.WaitOne(15000); //15秒超时 int currentUsers = GetOnlineUserCount(); string maxUsers = "36984"; #if !DEBUG maxUsers = memClient.GetSmallObject(NSSERVER_MAX_USERS_INFO) as string; if (maxUsers == null) { int oauser = new NGCOM().OAUsers; int alluser = new NGCOM().AllUsers; maxUsers = (oauser + alluser).ToString(); memClient.SetSmallObject(NSSERVER_MAX_USERS_INFO, maxUsers); } #endif #region string[] idArr = GetSessionID(CurrentSessionInfo.LoginID); foreach (string id in idArr) { OnlineInfo infoTmp = HSLoginInfo[id] as OnlineInfo; if (infoTmp != null) { if (infoTmp.IsOaUser == "0") //当前坑是非OA { string currentAllusers = memClient.GetSmallObject("NSSERVERALLUSERSINFO_CURRENT") as string; if ((!String.IsNullOrEmpty(currentAllusers)) && (currentAllusers != "0")) //非OA当前用户数-1 { currentAllusers = (int.Parse(currentAllusers) - 1).ToString(); memClient.SetSmallObject("NSSERVERALLUSERSINFO_CURRENT", currentAllusers); } } } } #endregion if (currentUsers < int.Parse(maxUsers)) { OnlineInfo lInfo = new OnlineInfo(); #region 注册登录信息 lInfo.UniqueClientID = CurrentSessionInfo.UniqueClientID; lInfo.SessionID = CurrentSessionInfo.SessionID; lInfo.IPAddr = CurrentSessionInfo.IPAddr; lInfo.MacAddr = mac; lInfo.Product = product; lInfo.LoginID = CurrentSessionInfo.LoginID; lInfo.LoginName = CurrentSessionInfo.LoginName; lInfo.LoginTime = DateTime.Now; lInfo.LastRefTime = DateTime.Now; lInfo.LoginUCode = CurrentSessionInfo.LoginUCode; lInfo.LoginUName = CurrentSessionInfo.LoginUName; lInfo.LoginOCode = CurrentSessionInfo.LoginOCode; lInfo.LoginOName = CurrentSessionInfo.LoginOName; lInfo.DeptNo = CurrentSessionInfo.DeptNo; lInfo.DeptName = CurrentSessionInfo.DeptName; if (suitInfo != null && suitInfo.Trim().Length > 0) { lInfo.LoginSuitInfo = suitInfo; } else { lInfo.LoginSuitInfo = string.Empty; } #endregion //SyncHSLoginInfoWithCacheServer(0); this.GetALLOnlineUserFromCache(); //踢掉已登录的用户 //string[] idArr = GetSessionID(CurrentSessionInfo.LoginID); foreach (string id in idArr) { OnlineInfo infoTmp = HSLoginInfo[id] as OnlineInfo; if (infoTmp != null) { //if (infoTmp.IPAddr == CurrentSessionInfo.IPAddr) //{//自己登陆 // //HSLoginInfo.Remove(id); // RemoveOnlineUserInfo(id); //} //else //{//强制登陆,踢掉别人 // this.KillLoginUser(id, CurrentSessionInfo.IPAddr); //} //由于远程登录用户无法获取到真实ip,如果根据ip判断会导致不同用户远程同一台机器的时候用相同的用户名登录而不会踢人 this.KillLoginUser(id, CurrentSessionInfo.IPAddr); } } //HSLoginInfo[CurrentSessionInfo.SessionID] = lInfo; //存到缓存服务器中 this.SaveOnlineUserToCache(CurrentSessionInfo.UniqueClientID, lInfo); //HSLoginInfoUpdate(CurrentSessionInfo.SessionID, lInfo); //写一份OnlineInfo到Session BackupOnlineInfoToSession(lInfo); //memClient.EndLock("NNSERVERMAXUSERCONTROLKEY"); return(true); } else //超过最大用户数 { return(false); } } catch (Exception ex) { throw ex; } finally { //if (lockedSuccess)//加锁成功的才进行解锁 //{ // userDac.UnLockByDb(ConnectionInfoService.GetSessionConnectString()); //} //memClient.EndLock("NNSERVERMAXUSERCONTROLKEY"); mutex.ReleaseMutex(); } }