protected void Return(ILowProtocol sender, LowRequestArgs request, Error error, params RemoteArg[] args) { RemoteResult remoteResult = new RemoteResult(error, args); byte[] result = m_serializer.Serialize(remoteResult); EnqueueResponse(sender, request.Id, result); }
protected void Call(RemoteCall rpc, Action <Error, RemoteResult> callback) { RemoteCall.Proc proc = rpc.Procedure; byte[] rpcSerialized = m_serializer.Serialize(rpc); m_protocol.BeginRequest(rpcSerialized, null, (requestError, response, userState) => { RemoteResult result; Error error; if (requestError == LowProtocol <Socket> .ErrorOK) { try { result = m_serializer.Deserialize <RemoteResult>(response); error = result.Error; } catch (Exception e) { result = new RemoteResult(); error = new Error(StatusCode.UnhandledException) { Message = string.Format("Procedure {0}", proc) + " " + e.ToString() }; } } else { result = new RemoteResult(); if (requestError == LowProtocol <Socket> .ErrorTimeout) { error = new Error(StatusCode.RequestTimeout); error.Message = string.Format("Request Timeout - Procedure {0}", proc); } else if (requestError == LowProtocol <Socket> .ErrorClosed) { error = new Error(StatusCode.ConnectionClosed); error.Message = string.Format("Request Error - Procedure {0}", proc); } else { throw new NotSupportedException("unknow requestError"); } } callback(error, result); }, requestSent => { if (!requestSent) { callback(new Error(StatusCode.ConnectionClosed), new RemoteResult()); } }); }
private void Call(RemoteCall rpc, Action <Error, RemoteResult> callback) { byte[] rpcSerialized = m_serializer.Serialize(rpc); m_protocol.BeginRequest(rpcSerialized, null, (requestError, response, userState) => { RemoteResult result; Error error; if (requestError == LowProtocol <ClientSocket> .ErrorOK) { try { result = m_serializer.Deserialize <RemoteResult>(response); error = result.Error; } catch (Exception e) { result = new RemoteResult(); error = new Error(StatusCode.UnhandledException) { Message = e.ToString() }; } } else { result = new RemoteResult(); if (requestError == LowProtocol <ClientSocket> .ErrorTimeout) { error = new Error(StatusCode.RequestTimeout); } else if (requestError == LowProtocol <ClientSocket> .ErrorClosed) { error = new Error(StatusCode.ConnectionClosed); } else { throw new NotSupportedException("unknow requestError"); } } callback(error, result); }, requestSent => { }); }