private void OnResponse(byte[] data) { bool recvSucc = false; byte[] respData = null; string method = string.Empty; string errMsg = string.Empty; if (data != null && data.Length > 0) { Packet.Response resp = DataTranslater.Deserialize <Packet.Response>(data); method = resp.method; respData = resp.return_data; errMsg = resp.error; recvSucc = !string.IsNullOrEmpty(resp.method) && resp.invoke; } Delegate callback = GetResponseCallback(method); if (callback != null) { ResponseHandlerDel respCompletion = callback as ResponseHandlerDel; if (respCompletion != null) { respCompletion(recvSucc, respData, errMsg); } } }
private void OnEstablishConnectionAck(byte[] data) { bool attachExisting = false; if (data != null && data.Length > 0) { Packet.ConnectAck connAck = DataTranslater.Deserialize <Packet.ConnectAck>(data); IsConnected = connAck.success; SessionId = connAck.session; attachExisting = connAck.attach_existing; } Delegate callback = GetResponseCallback(typeof(Packet.Connect).Name); if (callback != null) { string errMsg = !IsConnected ? "交易终端拒绝连接" : ""; Action <bool, string, bool> connCompletion = callback as Action <bool, string, bool>; if (connCompletion != null) { connCompletion(IsConnected, errMsg, attachExisting); } } if (IsConnected) { _heartbeatTimer.Change(0, HEARTBEAT_INTERVAL); } }
private void OnCallbackReq(byte[] callbackReqData) { byte[] paramData = null; string method = string.Empty; if (callbackReqData != null && callbackReqData.Length > 0) { Packet.CallbackReq cbReq = DataTranslater.Deserialize <Packet.CallbackReq>(callbackReqData); method = cbReq.method; paramData = cbReq.param_data; DispatchCallback(method, paramData); } }