Esempio n. 1
0
        public void OnReceivedRequest(INodeEndpointProtocolRequest request)
        {
            string requestMessage = request.RequestMessage();

            if (requestMessage.StartsWith("[REQUEST]"))
            {
                Guid   guid;
                string method;
                string message;
                if (ProtocolEnabledHelper.SplitRequest(requestMessage, out guid, out method, out message))
                {
                    try
                    {
                        XElement body    = XElement.Parse(message);
                        Request  wrapper = new Request(this.tracerBroadcaster, this.endpoint, request, guid, method, body);
                        this.tracerBroadcaster.OnReceivedRequest(wrapper);
                        this.endpoint.QueueRequest(wrapper);
                    }
                    catch (Exception exception)
                    {
                        throw new NodeEndpointMessageException("Cannot understand the request format.", exception);
                    }
                }
            }
        }
Esempio n. 2
0
 public void Respond(Stream stream)
 {
     if (!this.waitingForResponse)
     {
         throw new InvalidOperationException("Cannot respond more than once.");
     }
     this.waitingForResponse = false;
     stream.Seek(0, SeekOrigin.Begin);
     byte[] bytes = stream.ReadAllBytesAndClose();
     byte[] body  = ProtocolEnabledHelper.BuildResponse(this.guid, bytes);
     this.request.Respond(body);
     this.tracerBroadcaster.OnResponded(bytes);
 }
 private void Receive(string protocolMessage, byte[] stream)
 {
     lock (this.responses)
     {
         Guid guid;
         if (ProtocolEnabledHelper.SplitResponse(protocolMessage, out guid))
         {
             ClientResponse response;
             if (this.responses.TryGetValue(guid, out response))
             {
                 this.responses.Remove(guid);
                 response.SetResponse(stream);
             }
         }
     }
 }
        public INodeEndpointResponse Send(string method, XElement body)
        {
            if (this.Protocol == null)
            {
                throw new InvalidOperationException("Cannot send message when procotol has not been set.");
            }
            if (!this.Protocol.Connected)
            {
                throw new InvalidOperationException("Cannot send message when protocol does not connected to server.");
            }

            Guid   guid            = Guid.NewGuid();
            string protocolMessage = ProtocolEnabledHelper.BuildRequest(guid, method, body.ToString());

            ClientResponse response = new ClientResponse();

            lock (this.responses)
            {
                this.responses.Add(guid, response);
            }
            this.Protocol.Send(protocolMessage);
            return(response);
        }
Esempio n. 5
0
            private void Respond(string message)
            {
                string protocolMessage = ProtocolEnabledHelper.BuildResponse(this.guid, message);

                this.request.Respond(protocolMessage);
            }