private void ResolveResponse(DuplexResponse response) { DuplexWaitItem waitItem; lock (_Sync) { if (!_WaitDic.TryGetValue(response.MessageId, out waitItem)) { return; } } switch (response.ResponseType) { case ResponseType.OK: waitItem.SetResult(response.Result); break; case ResponseType.UnknownMethodType: waitItem.SetException(new ApplicationException("unknown message type")); break; case ResponseType.Exception: waitItem.SetException(new ApplicationException(response.Exception)); break; } }
private void CreateResponse(Session session, DuplexRequest request) { try { var message = SerializeManager.Current.Deserialize(request.Message); Action <object> sendResponse = (obj) => { var response = new DuplexResponse() { MessageId = request.MessageId, ResponseType = ResponseType.OK, Result = SerializeManager.Current.Serialize(obj) }; SendResponse(session, response); }; var isHandled = _HandlerList .Any(c => c.Handle(session, message, sendResponse)); if (isHandled) { return; } SendUnknownTypeResponse(session, request); } catch (Exception ex) { SendExceptionResponse(session, request, ex); } }
private void SendUnknownTypeResponse(Session session, DuplexRequest message) { var response = new DuplexResponse() { MessageId = message.MessageId, ResponseType = ResponseType.UnknownMethodType }; SendResponse(session, response); }
private void SendExceptionResponse(Session session, DuplexRequest message, Exception ex) { _CommunicationBase.OnException(session, ex, disconnect: false); var response = new DuplexResponse() { MessageId = message.MessageId, ResponseType = ResponseType.Exception, Exception = ex.Message }; SendResponse(session, response); }
private void SendResponse(Session session, DuplexResponse response) { var bytes = SerializeManager.Current.Serialize(response); _CommunicationBase.SendDataInternal(session, bytes); }