void IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) { //将消息发送到客户端 ResponsesListener asyncResult = result as ResponsesListener; asyncResult.Send(m_Context); }
IAsyncResult IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData) { this.m_Context = context; string sessionId = context.Request.Params["SessionID"]; string str2 = context.Request.Params["ClientVersion"]; string str3 = context.Request.Params["ServerVersion"]; ResponsesListener listener = new ResponsesListener(sessionId, cb, extraData); try { if (str3 != ServerImpl.Instance.Version) { throw new IncompatibleException(); } if (!(string.IsNullOrEmpty(str2) || !(str2 != "1.0.1.7"))) { throw new IncompatibleException(); } string userName = ServerImpl.Instance.GetUserName(context); if (string.IsNullOrEmpty(userName)) { throw new UnauthorizedException(); } if (SessionManagement.Instance.GetAccountState(userName).Receive(sessionId, listener)) { ThreadPool.QueueUserWorkItem(new WaitCallback(listener.Complete)); } } catch (Exception exception) { listener.Cache(Utility.RenderHashJson(new object[] { "IsSucceed", false, "Exception", exception })); ThreadPool.QueueUserWorkItem(new WaitCallback(listener.Complete)); } return(listener); }
public bool Receive(string sessionId, ResponsesListener listener) { AccountSession session = null; bool flag = false; lock (this) { if (!this.m_Sessions.ContainsKey(sessionId)) { this.m_Sessions[sessionId] = new AccountSession(this.m_User, sessionId); flag = true; } this.m_LastAccessTime = DateTime.Now; session = this.m_Sessions[sessionId] as AccountSession; } if (flag) { ServerImpl.Instance.WriteLog(string.Format("Reset Session:SessionID = \"{0}\", UserName='******'", sessionId, this.m_User)); session.Send("GLOBAL:SessionReset", "null"); } if (session != null) { SessionManagement.Instance.Insert(session); } return(session.Receive(listener)); }
IAsyncResult IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) { m_Context = context; string sessionId = context.Request.Params["SessionID"]; string clientVersion = context.Request.Params["ClientVersion"]; string serverVersion = context.Request.Params["ServerVersion"]; ResponsesListener asyncResult = new ResponsesListener(sessionId, cb, extraData); try { if (serverVersion != ServerImpl.Instance.Version) { throw new IncompatibleException(); } if (!String.IsNullOrEmpty(clientVersion) && clientVersion != Custom.ApplicationInfo.ReleaseVersion) { throw new IncompatibleException(); } int userid = ServerImpl.Instance.GetUserID(context); if (userid == 0) { throw new UnauthorizedException(); } try { if (context.Request.Params["State"] != null) { Hashtable hash_state = Utility.ParseJson(context.Request.Params["State"]) as Hashtable; if (hash_state != null && hash_state.ContainsKey("Status")) { SessionManagement.Instance.MarkStatus(userid, hash_state["Status"].ToString()); } } } catch { } if (SessionManagement.Instance.Receive(userid, sessionId, asyncResult)) { ThreadPool.QueueUserWorkItem(asyncResult.Complete); } } catch (Exception ex) { asyncResult.Cache(Utility.RenderHashJson("IsSucceed", false, "Exception", ex)); ThreadPool.QueueUserWorkItem(asyncResult.Complete); } return(asyncResult); }
public bool Receive(ResponsesListener listener) { lock (this._lock) { this._createdTime = DateTime.Now; if (this._cache.Count > 0) { string content = Utility.RenderHashJson(new object[] { "IsSucceed", true, "Responses", this._cache }); listener.Cache(content); this._cache.Clear(); return(true); } this._listener = listener; return(false); } }
public void SendCache() { lock (_lock) { if (_listener != null) { try { String json = Utility.RenderHashJson("IsSucceed", true, "Responses", _cache); _listener.Cache(json); _cache.Clear(); } finally { ThreadPool.QueueUserWorkItem(_listener.Complete); _listener = null; } } } }
public bool Receive(ResponsesListener listener) { lock (_lock) { _createdTime = DateTime.Now; if (_cache.Count > 0) { String json = Utility.RenderHashJson("IsSucceed", true, "Responses", _cache); listener.Cache(json); _cache.Clear(); return(true); } else { _listener = listener; return(false); } } }
public void SendCache() { lock (this._lock) { if (this._listener != null) { try { string content = Utility.RenderHashJson(new object[] { "IsSucceed", true, "Responses", this._cache }); this._listener.Cache(content); this._cache.Clear(); } finally { ThreadPool.QueueUserWorkItem(new WaitCallback(this._listener.Complete)); this._listener = null; } } } }