Exemple #1
0
        //public bool IsCacheAvailable()
        //{
        //    return WCache.isAvailable(ref _lastError);
        //}

        //private void LinkToCacheServer()
        //{
        //    //检测cacheserver的配置
        //    if (IsCacheAvailable())
        //    {
        //        SyncHSLoginInfoWithCacheServer(0);
        //    }
        //    else
        //    {
        //        _lastError = "Cache server throw an exception!";
        //    }
        //}

        //private void SyncHSLoginInfoWithCacheServer()
        //{
        //    SyncHSLoginInfoWithCacheServer(10);
        //}

        ///// <summary>
        ///// 获取seconds内最新的缓存,seconds主要是为了减少通信次数
        ///// </summary>
        ///// <param name="seconds"></param>
        //private void SyncHSLoginInfoWithCacheServer(int seconds)
        //{
        //    if (IsCacheAvailable())
        //    {
        //        if (DateTime.Now > lastVisitWCacheTime.AddSeconds(seconds))
        //        {
        //            lastVisitWCacheTime = DateTime.Now;
        //            Hashtable tmp = WCache.Get(INFO_KEY) as Hashtable;
        //            if (tmp == null)
        //            {
        //                WCache.Set(INFO_KEY, HSLoginInfo);
        //            }
        //            else
        //            {
        //                HSLoginInfo = tmp;
        //            }
        //        }
        //    }
        //}

        //private void HSLoginInfoUpdate(string key, object value)
        //{
        //    if (IsCacheAvailable())
        //    {
        //        WCache.Set(INFO_KEY, key, value);
        //    }
        //}

        //private void HSLoginInfoRemove(string key)
        //{
        //    if (IsCacheAvailable())
        //    {
        //        WCache.Remove(INFO_KEY, key);
        //    }
        //}

        //private OnlineInfo HSLoginInfoGet(string key)
        //{
        //    if (IsCacheAvailable())
        //    {
        //        HSLoginInfo[key] = WCache.Get(INFO_KEY, key);
        //    }

        //    return HSLoginInfo[key] as OnlineInfo;
        //}

        private void BackupOnlineInfoToSession(OnlineInfo info)
        {
            if (HttpContext.Current.Session != null)
            {
                HttpContext.Current.Session[ONLINEINFO_KEY_INSESSION] = info;
            }
        }
Exemple #2
0
        /// <summary>
        /// 设置oa用户
        /// </summary>
        public void SetOaUser()
        {
            OnlineInfo info = CurrentOnlineInfo();

            info.IsOaUser = "******";
            this.SaveOnlineUserToCache(CurrentSessionInfo.UniqueClientID, info);
        }
Exemple #3
0
 public bool IsKickOff(string userid)
 {
     if (IsOnline())
     {
         OnlineInfo info = GetOnlineUserInfo(CurrentSessionInfo.SessionID + userid);
         if (info != null)
         {
             return(info.IsKilled);
         }
     }
     return(false);
 }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        /// <summary>
        /// Session 失效时,自动清除当前操作员的登录信息
        /// </summary>
        /// <param name="sSessionID"></param>
        /// <returns></returns>
        public bool RemoveLoginUserEndSessioin(string sSessionID)
        {
            OnlineInfo lInfo = HSLoginInfo[sSessionID] as OnlineInfo;

            if (lInfo != null)
            {
                //if (lInfo.Product.ToLower() == "i6")
                //{
                //    SetUICExpert(UicUrl);
                //}

                this.RemoveLoginUser(sSessionID);
            }
            return(true);
        }
Exemple #6
0
        /// <summary>
        /// 刷新在线用户列表,如果session还存在,会自动修复在线列表
        /// </summary>
        /// <param name="refStep">刷新间隔(ms)</param>
        public string Refresh(string refStep)
        {
            //先从当前在线用户中取, 如果取不到 就从Session 自动修复
            OnlineInfo lInfo = CurrentOnlineInfo();//?? RestoreOnlineInfoFromSession();

            lock (objLock)
            {
                if (lInfo != null)
                {
                    if (lInfo.IsKilled)
                    {
                        string msg = lInfo.LogoutMessage;
                        this.RemoveLoginUser(lInfo.SessionID);
                        if (HttpContext.Current.Session != null)
                        {
                            HttpContext.Current.Session.Abandon();
                        }
                        //throw new Exception(msg);
                        return(msg);
                    }

                    long refSteptime = 0;
                    if (!long.TryParse(refStep, out refSteptime))
                    {
                        refSteptime = 180000;                                                                   //没有设置为3分钟
                    }
                    else if (refSteptime < 180000)
                    {
                        refSteptime = 180000;                                                                   //最小为3分钟
                    }

                    //更新信息
                    lInfo.LastRefTime = DateTime.Now;
                    lInfo.RefStep     = refSteptime;

                    //将当前用户的登陆信息更新到哈希表
                    //HSLoginInfo[CurrentSessionInfo.SessionID] = lInfo;
                    //HSLoginInfoUpdate(CurrentSessionInfo.SessionID, lInfo);

                    this.SaveOnlineUserToCache(CurrentSessionInfo.UniqueClientID, lInfo);
                }
            }

            return(string.Empty);
        }
Exemple #7
0
        private OnlineInfo RestoreOnlineInfoFromSession()
        {
            OnlineInfo info = null;

            lock (objLock)
            {
                if (HttpContext.Current.Session != null)
                {
                    info = HttpContext.Current.Session[ONLINEINFO_KEY_INSESSION] as OnlineInfo;
                    if (info != null && !info.IsKilled && info.SessionID == CurrentSessionInfo.SessionID)
                    {
                        // HSLoginInfoUpdate(info.SessionID, info.SessionID);
                        HSLoginInfo[info.SessionID] = info;
                    }
                }
            }

            return(info);
        }
Exemple #8
0
        /// <summary>
        /// 移除登录用户信息
        /// </summary>
        public bool RemoveLoginUser()
        {
            lock (objLock)
            {
                OnlineInfo lInfo = CurrentOnlineInfo();
                if (lInfo != null)
                {
                    this.RemoveLoginUser(lInfo.UniqueClientID);
                    string[] sArr = GetSessionID(CurrentSessionInfo.LoginID);
                    foreach (string s in sArr)
                    {
                        if (!string.IsNullOrEmpty(s))
                        {
                            this.RemoveLoginUser(s);
                        }
                    }

                    return(true);
                }
                return(false);
            }
        }
Exemple #9
0
        public void KillLoginUser(string id, string logoutMessage)
        {
            lock (objLock)
            {
                OnlineInfo lInfo = this.GetOnlineUserInfo(id);

                if (lInfo != null)
                {
                    if (string.IsNullOrEmpty(logoutMessage))
                    {
                        //"当前登录被强制注销,点击确定后将取消当前登录!";
                        logoutMessage = Resource.ForceLogOff;
                    }
                    else
                    {
                        //return "客户端[" + ipAddr + "]采用强制登录,点击确定后将取消当前登录!";
                        logoutMessage = string.Format(Resource.ClientForceLogOff, logoutMessage);
                    }
                    lInfo.KillMe(logoutMessage);
                    this.UpdateOnlineUserInfo(id, lInfo);
                }
            }
        }
Exemple #10
0
        /// <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();
            }
        }
Exemple #11
0
        /// <summary>
        /// 重启缓存服务后重新添加登录信息
        /// </summary>
        /// <param name="product"></param>
        /// <param name="suitInfo"></param>
        /// <param name="mac"></param>
        public void AddLogInfoIfLost(string product, string suitInfo, string mac)
        {
            this.GetALLOnlineUserFromCache();
            IDictionaryEnumerator myEnumerator = HSLoginInfo.GetEnumerator();
            OnlineInfo            lInfo;
            bool isexist = false;

            while (myEnumerator.MoveNext())
            {
                if (myEnumerator.Current == null)
                {
                    continue;
                }
                lInfo = myEnumerator.Value as OnlineInfo;
                if (lInfo == null)
                {
                    continue;
                }
                if (lInfo.IsKilled)
                {
                    continue;
                }
                if ((lInfo.Product == product) && (lInfo.MacAddr == mac))
                {
                    isexist = true;
                    break;
                }
            }
            if (isexist)
            {
                return;
            }
            else
            {
                lInfo = new OnlineInfo();
                lInfo.UniqueClientID = CurrentSessionInfo.UniqueClientID;
                lInfo.SessionID      = CurrentSessionInfo.SessionID;
                lInfo.IPAddr         = CurrentSessionInfo.IPAddr;
                lInfo.MacAddr        = mac;
                lInfo.Product        = product;
                if (AppInfoBase.LoginID == null)//被T的时候有可能客户端还没关闭定时检测
                {
                    return;
                }
                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;
                }
                this.SaveOnlineUserToCache(CurrentSessionInfo.UniqueClientID, lInfo);
            }
        }