Ejemplo n.º 1
0
        private void Dispatch(string req)
        {
            var request = JsonConvert.DeserializeObject <DispatcherRequest>(req);

            if (request != null && request.type == "request")
            {
                TraceCallback?.Invoke(string.Format("C {0}: {1}", request.command, JsonConvert.SerializeObject(request.arguments)));

                if (_callback != null)
                {
                    try
                    {
                        lock (_lock)
                        {
                            _isDispatchingData = true;
                        }

                        var response  = new DispatcherResponse(request.seq, request.command);
                        var responder = new DispatchResponder(this, response);

                        _callback(request.command, request.arguments, responder);

                        SendMessage(response);
                    }
                    finally
                    {
                        lock (_lock)
                        {
                            _isDispatchingData = false;
                        }

                        DispatcherEvent e;
                        while (_queuedEvent.TryDequeue(out e))
                        {
                            SendMessage(e);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public DispatchResponder(DispatcherProtocol protocol, DispatcherResponse response)
 {
     _protocol = protocol;
     _response = response;
 }