Esempio n. 1
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            // Todo: 解析命令
            var userId = context.Request["userid"];
            var action = context.Request["action"];

            // 生成IAsyncResult对象,调用callback回调,EndProcessRequest才被触发
            var result = new CometResult(context, cb, extraData);

            if (string.IsNullOrEmpty(userId))
            {
                result.CallRefresh();
                return(result);
            }

            if (!string.IsNullOrEmpty(action))
            {
                switch (action)
                {
                case "logout":
                    CometRequestManager.Instance.Release(userId);
                    result.CallLogout();
                    return(result);

                default:
                    break;
                }
            }
            // 保存IAsyncResult对象
            CometRequestManager.Instance.UpdateComet(userId, result);
            return(result);
        }
Esempio n. 2
0
 public void UpdateComet(string userId, CometResult result)
 {
     if (TokenTable.ContainsKey(userId))
     {
         TokenTable[userId] = new CometRequestLifetimeItem(userId, DateTime.Now.AddMinutes(CometLifeTimeMinute),
                                                           result);
     }
     else
     {
         TokenTable.Add(userId, new CometRequestLifetimeItem(userId, DateTime.Now.AddMinutes(CometLifeTimeMinute), result));
     }
 }
Esempio n. 3
0
 public CometRequestLifetimeItem(string userId, DateTime lifeTime, CometResult result)
 {
     UserId      = userId;
     LifeTime    = lifeTime;
     CometResult = result;
 }