您目前尚未登陆,请选择【登陆】或【注册
首页->聊天计数->NChat简易聊天室源码(.Net 3.5,LINQ,AJAX)>>NChat.Common/StaticHelper.cs>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:NChat简易聊天室源码(.Net 3.5,LINQ,AJAX)


当前文件路径:NChat/NChat.Common/StaticHelper.cs 文件类型
普通视图
		            
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.Collections; 6//5_1_a_s_p_x.c_o_m 7 8namespace NChat.Common 9{ 10 public class StaticHelper 11 { 12 static StaticHelper() 13 { 14 MsgListStatic = new List<string>(); 15 UserListStatic = new List<string>(); 16 CurrentMsg = new Hashtable(); 17 ActiveTime = new List<ActiveUserModel>(); 18 } 19 20 public static List<string> MsgListStatic { get; set; } 21 public static List<string> UserListStatic { get; set; } 22 public static Hashtable CurrentMsg { get; set; } 23 public static List<ActiveUserModel> ActiveTime { get; set; } 24 25 static StaticHelper MsgLock = new StaticHelper(); 26 static StaticHelper UserLock = new StaticHelper(); 27 static StaticHelper CurrentLock = new StaticHelper(); 28 static StaticHelper ActiveLock = new StaticHelper(); 29 30 public static void MsgListAdd(string item) 31 { 32 lock (MsgLock) 33 { 34 if (MsgListStatic.Count > 100) 35 { 36 MsgListStatic.Clear(); 37 CurrentClear(); 38 } 39 MsgListStatic.Add(item); 40 } 41 } 42 43 public static void UserListAdd(string item) 44 { 45 lock (UserLock) 46 { 47 if (!UserListStatic.Contains(item)) 48 UserListStatic.Add(item); 49 } 50 } 51 52 public static void UserListRemove(string item) 53 { 54 lock (UserLock) 55 { 56 UserListStatic.Remove(item); 57 } 58 } 59 60 public static void CurrentAdd(object key, object value) 61 { 62 lock (CurrentLock) 63 { 64 CurrentMsg.Add(key, value); 65 } 66 } 67 68 public static void CurrentUpdate(object key, object value) 69 { 70 lock (CurrentLock) 71 { 72 CurrentMsg[key] = value; 73 } 74 } 75 76 public static void CurrentClear() 77 { 78 lock (CurrentLock) 79 { 80 CurrentMsg.Clear(); 81 } 82 } 83 84 public static void ActiceUserAdd(ActiveUserModel um) 85 { 86 lock (ActiveLock) 87 { 88 if (!ActiveTime.Contains(um)) 89 ActiveTime.Add(um); 90 } 91 } 92 93 public static void ActiveUserUpdate(ActiveUserModel um) 94 { 95 lock (ActiveLock) 96 { 97 ActiveTime.Remove(ActiveTime.Single(i => i.Name == um.Name)); 98 ActiveTime.Add(um); 99 } 100 } 101 102 public static void OnlineUserClear() 103 { 104 for (int i = 0; i < ActiveTime.Count; i++) 105 { 106 ActiveUserModel item = ActiveTime[i]; 107 if (item.Time.AddMinutes(20) < DateTime.Now) 108 { 109 UserListRemove(item.Name); 110 lock (ActiveLock) 111 { 112 ActiveTime.Remove(item); 113 } 114 } 115 } 116 } 117 118 public static IEnumerable<string> MsgList(int userid) 119 { 120 if (CurrentMsg.Count > 0 && CurrentMsg.ContainsKey(userid)) 121 { 122 int current = (int)CurrentMsg[userid]; 123 IEnumerable<string> results = MsgListStatic.Skip(current); 124 current = MsgListStatic.Count; 125 CurrentUpdate(userid, current); 126 return results; 127 } 128 else 129 { 130 int current = MsgListStatic.Count; 131 CurrentAdd(userid, current); 132 return (IEnumerable<string>)MsgListStatic; 133 } 134 } 135 } 136} 137
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:NChat简易聊天室源码(.Net 3.5,LINQ,AJAX)

- Asp.net2.0的电影在线点播系..

- C#发现之旅ASP.NET源码

- 掘客Digg新闻发掘系统源码

- BugNet0.7.881.0汉化免安装版..

- Asp.net物业管理系统源码

- ASP.NET经典案例源码之学生管..

- 网博新闻管理系统0.1版源码文件

- NBear+NBear开发BBS系统源码

51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号