예제 #1
0
        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;
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        private void SendUnknownTypeResponse(Session session, DuplexRequest message)
        {
            var response = new DuplexResponse()
            {
                MessageId    = message.MessageId,
                ResponseType = ResponseType.UnknownMethodType
            };

            SendResponse(session, response);
        }
예제 #4
0
        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);
        }
예제 #5
0
        private void SendResponse(Session session, DuplexResponse response)
        {
            var bytes = SerializeManager.Current.Serialize(response);

            _CommunicationBase.SendDataInternal(session, bytes);
        }