コード例 #1
0
        private static void Dispatch(Stream inputStream, Stream outputStream)
        {
            V8ServerProtocol protocol = new V8ServerProtocol(inputStream, outputStream);

            protocol.TRACE = trace_requests;
            protocol.TRACE_RESPONSE = trace_responses;

            IDebugSession debugSession = null;

            var r = protocol.Start((string command, dynamic args, IResponder responder) => {

                if (args == null) {
                    args = new { };
                }

                if (command == "initialize") {
                    string adapterID = Utilities.GetString(args, "adapterID");
                    if (adapterID == null) {
                        responder.SetBody(new ErrorResponseBody(new Message(1101, "initialize: property 'adapterID' is missing or empty")));
                        return;
                    }

                    debugSession = EngineFactory.CreateDebugSession(adapterID, (e) => protocol.SendEvent(e.type, e));
                    if (debugSession == null) {
                        responder.SetBody(new ErrorResponseBody(new Message(1103, "initialize: can't create debug session for adapter '{_id}'", new { _id = adapterID })));
                        return;
                    }
                }

                if (debugSession != null) {

                    try {
                        DebugResult dr = debugSession.Dispatch(command, args);
                        if (dr != null) {
                            responder.SetBody(dr.Body);

                            if (dr.Events != null) {
                                foreach (var e in dr.Events) {
                                    responder.AddEvent(e.type, e);
                                }
                            }
                        }
                    }
                    catch (Exception e) {
                        responder.SetBody(new ErrorResponseBody(new Message(1104, "error while processing request '{_request}' (exception: {_exception})", new { request = command, exception = e.Message })));
                    }

                    if (command == "disconnect") {
                        protocol.Stop();
                    }
                }

            }).Result;
        }
コード例 #2
0
		public Responder(V8ServerProtocol protocol, V8Response0 response) {
			_protocol = protocol;
			_response = response;
		}