ASP.NET通用权限管理系统(FrameWork) 之用户在线列表 泛型缓存 [原创]

本文主要介绍 基础平台管理系统(FrameWork) 中的用户在线缓存类,本文提到源码可以去http://framework.supesoft.com下载.

在我们一般开发一个web系统时,都会有一个用户在线列表,记录当前在线用户.以及在线时长/当前访问址/用户IP/等一些用户信息.并保证当前系统只能有一个用户登陆在线.如果当前用户已经在线,可让用户选择是否退出已经登陆用户.
现在大多数系统都使用数据库来记录在线用户列表.使用数据库记录在线用户列表不好之处,用户每次刷新页面都需要更新数据库.增加数据库压力.
在线用户列表 在 基础平台管理系统(FrameWork) 中是通过一个泛型缓存类来实现. 当然了,用数据库有用数据库的好处,用缓存也有用缓存的好处.看各人所需了.

在 基础平台管理系统(FrameWork) 设计用户在线列表主要实现思路:
1.使用缓存记录用户在线列表,在线列表中保存每个在线用户:用户名,进入时间,最后访问时间,登入IP,最后访问地址等.
2.定义一个用户在线时长.如:5分钟,也就是说如果此用户在5分钟没有访问网站页面则将其算为离开.
3.用户登陆流程:
login.jpg
4.用户登入成功后,每访问一个页面.即按用户名,更新一下在线表中的最后访问时间,和最后访问网页地址.
5.使用定时器清除超过5分钟没有更新过的在线列表缓存中的用户.

基础平台管理系统(FrameWork) 在线用户列表泛型缓存类图:
CacheOnlineClass.jpg
附源码:
ContractedBlock.gif ExpandedBlockStart.gif 缓存源码
ExpandedBlockStart.gifContractedBlock.gif/**//************************************************************************************
InBlock.gif *      Copyright (C) 2007 supesoft.com,All Rights Reserved                            *
InBlock.gif *      File:                                                                        *
InBlock.gif *                CacheOnline.cs                                                        *
InBlock.gif *      Description:                                                                *
InBlock.gif *                 用户在线类                                                           *
InBlock.gif *      Author:                                                                        *
InBlock.gif *                Lzppcc                                                                *
InBlock.gif *                Lzppcc@hotmail.com                                                    *
InBlock.gif *                
http://www.supesoft.com                                                *
InBlock.gif *      Finish DateTime:                                                            *
InBlock.gif *                2007年8月6日                                                        *
InBlock.gif *      History:                                                                    *
ExpandedBlockEnd.gif **********************************************************************************
*/

None.gif
using System;
None.gif
using System.Collections.Generic;
None.gif
using System.Text;
None.gif
using System.Threading;
None.gif
None.gif
namespace FrameWork
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 用户在线类
InBlock.gif    
/// </summary>
InBlock.gif    
/// <typeparam name="TKey">Key</typeparam>
ExpandedSubBlockEnd.gif    
/// <typeparam name="TValue"></typeparam>

InBlock.gif    public class CacheOnline<TKey, TValue>
InBlock.gif        where TKey : IComparable
<TKey>
InBlock.gif        where TValue : OnlineUser
<TKey>new()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
InBlock.gif        
//会员列表
InBlock.gif
        Dictionary<string, LinkedListNode<TValue>> _MemberUserList;
InBlock.gif        
//所人数列表
InBlock.gif
        Dictionary<TKey, LinkedListNode<TValue>> _AllUserList;
InBlock.gif        
//所有会员列表排序
InBlock.gif
        LinkedList<TValue> _TValueLink;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Cache锁
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        protected ReaderWriterLock _CacheDataRwl = new ReaderWriterLock();
InBlock.gif        
//定时器
InBlock.gif
        System.Timers.Timer _UpdateTimer;
InBlock.gif        
//用户登陆超时设置(毫秒)
InBlock.gif
        double _TimeOutMilliseconds;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 构造函数
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="LoginTimeOutMinute">用户登陆超时设置(分钟)</param>

InBlock.gif        public CacheOnline(int LoginTimeOutMinute)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _MemberUserList 
= new Dictionary<string, LinkedListNode<TValue>>();
InBlock.gif            _AllUserList 
= new Dictionary<TKey, LinkedListNode<TValue>>();
InBlock.gif            _TValueLink 
= new LinkedList<TValue>();
InBlock.gif            _TimeOutMilliseconds 
= 1000 * 60 * LoginTimeOutMinute;
InBlock.gif            _UpdateTimer 
= new System.Timers.Timer();
InBlock.gif            _UpdateTimer.AutoReset 
= true;
InBlock.gif            _UpdateTimer.Elapsed 
+= new System.Timers.ElapsedEventHandler(ClearTimeOutUser);
InBlock.gif            _UpdateTimer.Interval 
= _TimeOutMilliseconds;
InBlock.gif            _UpdateTimer.Start();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 构造函数
ExpandedSubBlockEnd.gif        
/// </summary>

ExpandedSubBlockStart.gifContractedSubBlock.gif        public CacheOnline() : this(30dot.gif{ }
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 清除到期在线用户
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="sender"></param>
ExpandedSubBlockEnd.gif        
/// <param name="e"></param>

InBlock.gif        private void ClearTimeOutUser(object sender, System.Timers.ElapsedEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
double NextRunTime = _TimeOutMilliseconds;
InBlock.gif            DateTime _CheckTime 
= e.SignalTime.AddMilliseconds(_TimeOutMilliseconds * -1);
InBlock.gif            _UpdateTimer.Stop();
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireWriterLock(Timeout.Infinite);
InBlock.gif                
if (_TValueLink.Count > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    LinkedListNode
<TValue> UserNode = _TValueLink.Last;
InBlock.gif                    TimeSpan ts 
= UserNode.Value.U_LastTime - _CheckTime;
InBlock.gif                    
if (ts.TotalMilliseconds <= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
if (UserNode.Previous != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            ts 
= UserNode.Previous.Value.U_LastTime - _CheckTime;
InBlock.gif                            
if (ts.TotalMilliseconds <= 0)
InBlock.gif                                NextRunTime 
= 1;
InBlock.gif                            
else
InBlock.gif                                NextRunTime 
= ts.TotalMilliseconds;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        Remove(UserNode);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        NextRunTime 
= ts.TotalMilliseconds;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                _UpdateTimer.Interval 
= NextRunTime;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.ReleaseWriterLock();
ExpandedSubBlockEnd.gif            }

InBlock.gif            _UpdateTimer.Start();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 获取所有用户列表(IEnumerable)
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IEnumerable<TValue> GetListIEnumerable
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireReaderLock(Timeout.Infinite);
InBlock.gif                
foreach (TValue var in _TValueLink)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    yield 
return var;
ExpandedSubBlockEnd.gif                }

InBlock.gif                _CacheDataRwl.ReleaseReaderLock();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 获取在线用户列表(List)
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public List<TValue> GetList
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireReaderLock(Timeout.Infinite);
InBlock.gif                List
<TValue> lst = new List<TValue>();
InBlock.gif                
foreach (TValue var in _TValueLink)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    lst.Add(var);
ExpandedSubBlockEnd.gif                }

InBlock.gif                _CacheDataRwl.ReleaseReaderLock();
InBlock.gif                
return lst;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 获取用户信息
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="U_Name"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public TValue GetValue(string U_Name)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            TValue value 
= default(TValue);
InBlock.gif            LinkedListNode
<TValue> NodeUser;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireReaderLock(Timeout.Infinite);
InBlock.gif                
if (_MemberUserList.TryGetValue(U_Name, out NodeUser))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    value 
= NodeUser.Value;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.ReleaseReaderLock();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return value;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
"插入用户"#region "插入用户"
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 插入游客
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="key"></param>

InBlock.gif        public void InsertUser(TKey key)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            InsertUser(key, 
new TValue());
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 插入用户
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="key"></param>
ExpandedSubBlockEnd.gif        
/// <param name="value"></param>

InBlock.gif        public void InsertUser(TKey key, TValue value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            LinkedListNode
<TValue> OldUserNode_A;
InBlock.gif            value.U_Guid 
= key;
InBlock.gif            LinkedListNode
<TValue> UserNode = new LinkedListNode<TValue>(value);
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireWriterLock(Timeout.Infinite);
InBlock.gif
InBlock.gif
InBlock.gif                
if (_AllUserList.TryGetValue(key, out OldUserNode_A))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    OldUserNode_A.Value 
= UserNode.Value;
InBlock.gif                    ReNewUser(OldUserNode_A);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (value.U_Type)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
if (!_MemberUserList.TryGetValue(value.U_Name, out OldUserNode_A))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            _MemberUserList.Add(value.U_Name, UserNode);
InBlock.gif                            _AllUserList.Add(key, UserNode);
InBlock.gif                            ReNewUser(UserNode);
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            OldUserNode_A.Value 
= UserNode.Value;
InBlock.gif                            ReNewUser(OldUserNode_A);
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        _AllUserList.Add(key, UserNode);
InBlock.gif                        ReNewUser(UserNode);
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.ReleaseWriterLock();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 更新用户请求信息
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="key"></param>

InBlock.gif        public void Access(TKey key)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            LinkedListNode
<TValue> OutNodeUser;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireWriterLock(Timeout.Infinite);
InBlock.gif
InBlock.gif                
if (_AllUserList.TryGetValue(key, out OutNodeUser))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    ReNewUser(OutNodeUser);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.ReleaseWriterLock();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 访问请求 更新key
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="key"></param>
ExpandedSubBlockEnd.gif        
/// <param name="U_LastUrl"></param>

InBlock.gif        public void Access(TKey key, string U_LastUrl)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            LinkedListNode
<TValue> OutNodeUser;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireWriterLock(Timeout.Infinite);
InBlock.gif
InBlock.gif                
if (_AllUserList.TryGetValue(key, out OutNodeUser))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    ReNewUser(OutNodeUser, U_LastUrl);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.ReleaseWriterLock();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 重建用户列表排序
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="UserNode"></param>

InBlock.gif        private void ReNewUser(LinkedListNode<TValue> UserNode)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (UserNode.List != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                UserNode.List.Remove(UserNode);
ExpandedSubBlockEnd.gif            }

InBlock.gif            _TValueLink.AddFirst(UserNode);
InBlock.gif            TimeSpan ts 
= DateTime.Now - UserNode.Value.U_StartTime;
InBlock.gif            UserNode.Value.U_OnlineSeconds 
= ts.TotalSeconds;
InBlock.gif            UserNode.Value.U_LastTime 
= DateTime.Now;
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 重建
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="UserNode"></param>
ExpandedSubBlockEnd.gif        
/// <param name="U_LastUrl"></param>

InBlock.gif        private void ReNewUser(LinkedListNode<TValue> UserNode, string U_LastUrl)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (UserNode.List != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                UserNode.List.Remove(UserNode);
ExpandedSubBlockEnd.gif            }

InBlock.gif            _TValueLink.AddFirst(UserNode);
InBlock.gif            TimeSpan ts 
= DateTime.Now - UserNode.Value.U_StartTime;
InBlock.gif            UserNode.Value.U_OnlineSeconds 
= ts.TotalSeconds;
InBlock.gif            UserNode.Value.U_LastTime 
= DateTime.Now;
InBlock.gif            UserNode.Value.U_LastUrl 
= U_LastUrl;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 根据Key移除用户
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="key"></param>

InBlock.gif        public void Remove(TKey key)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            LinkedListNode
<TValue> UserNode;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireWriterLock(Timeout.Infinite);
InBlock.gif                
if (_AllUserList.TryGetValue(key, out UserNode))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Remove(UserNode);
ExpandedSubBlockEnd.gif                }

InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.ReleaseWriterLock();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 根据用户名移除用户
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="U_Name"></param>

InBlock.gif        public void RemoveUserName(string U_Name)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            LinkedListNode
<TValue> UserNode;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireWriterLock(Timeout.Infinite);
InBlock.gif                
if (_MemberUserList.TryGetValue(U_Name, out UserNode))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Remove(UserNode);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.ReleaseWriterLock();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 移除用户资料
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="UserNode"></param>

InBlock.gif        private void Remove(LinkedListNode<TValue> UserNode)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (UserNode.List != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _AllUserList.Remove(UserNode.Value.U_Guid);
InBlock.gif                
if (UserNode.Value.U_Type)
InBlock.gif                    _MemberUserList.Remove(UserNode.Value.U_Name);
InBlock.gif                UserNode.List.Remove(UserNode);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 检测用户是否在线
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="U_Name">用户名</param>
InBlock.gif        
/// <param name="key">用户标识</param>
ExpandedSubBlockEnd.gif        
/// <returns>True在线 False不在线</returns>

InBlock.gif        public bool CheckMemberOnline(string U_Name, TKey key)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
bool rBool = false;
InBlock.gif            LinkedListNode
<TValue> UserNode;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireReaderLock(Timeout.Infinite);
InBlock.gif                
if (_MemberUserList.TryGetValue(U_Name, out UserNode))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (UserNode.Value.U_Guid.CompareTo(key) == 0)
InBlock.gif                        rBool 
= true;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.ReleaseReaderLock();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return rBool;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 根据用户名检测是否在线
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="U_Name"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public bool CheckMemberOnline(string U_Name)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
bool rBool = false;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.AcquireReaderLock(Timeout.Infinite);
InBlock.gif                
if (_MemberUserList.ContainsKey(U_Name))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    rBool 
= true;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _CacheDataRwl.ReleaseReaderLock();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return rBool;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 所有用户总数
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public int AllCount
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _AllUserList.Count;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 会员总数
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public int MemberCount
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _MemberUserList.Count;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 清除所有在线人数
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public void Clear()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _CacheDataRwl.AcquireWriterLock(Timeout.Infinite);
InBlock.gif            _MemberUserList.Clear();
InBlock.gif            _AllUserList.Clear();
InBlock.gif            _TValueLink.Clear();
InBlock.gif            _CacheDataRwl.ReleaseWriterLock();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 用户基础类
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class OnlineUser<TKey>
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
"Private Variables"#region "Private Variables"
InBlock.gif        
private TKey _U_Guid;
InBlock.gif        
private string _U_Name = "游客";
InBlock.gif        
private DateTime _U_StartTime = DateTime.Now;
InBlock.gif        
private DateTime _U_LastTime = DateTime.Now;
InBlock.gif        
private string _U_LastIP = Common.GetIPAddress();
InBlock.gif        
private bool _U_Type = false;
InBlock.gif        
private string _U_LastUrl;
InBlock.gif        
private double _U_OnlineSeconds;
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
"Public Variables"#region "Public Variables"
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 用户标识值
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public TKey U_Guid
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _U_Guid;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _U_Guid 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 用户名
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string U_Name
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _U_Name;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _U_Name 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 开始访问时间
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public DateTime U_StartTime
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _U_StartTime;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _U_StartTime 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 最后访问时间
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public DateTime U_LastTime
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _U_LastTime;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _U_LastTime 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 是否会员(True会员False游客)
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public bool U_Type
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _U_Type;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _U_Type 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 用户IP
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string U_LastIP
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _U_LastIP;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _U_LastIP 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 最后请求网址
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string U_LastUrl
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _U_LastUrl;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _U_LastUrl 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 在线时长(秒)
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public double U_OnlineSeconds
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _U_OnlineSeconds;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _U_OnlineSeconds 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

如何使用大家可以参考 基础平台管理系统(FrameWork) 中的源码( 下载地址)
下次再为大家介绍 基础平台管理系统(FrameWork) 中的Tab自定义控件 :) .

转载于:https://www.cnblogs.com/lzppcc/archive/2007/08/15/857015.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值