private async Task AcceptAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { try { var token = await _transport.ReadAsync(cancellationToken).ConfigureAwait(false); var request = ProtocolMessage.Parse(token); Message message; try { message = await DispatchAsync(request, cancellationToken).ConfigureAwait(false); } #pragma warning disable CA1031 // Do not catch general exception types (catch any exception and return it in the message) catch (Exception error) #pragma warning restore CA1031 // Do not catch general exception types { message = Response.Fail(NextSeq, request, error.Message); } await SendAsync(message, cancellationToken).ConfigureAwait(false); } catch (Exception error) { _logger.LogError(error, error.Message); ResetOnDisconnect(); throw; } } }
public void ProtocolMessage_SwitchCase() { var writer = new JTokenWriter(); writer.WriteStartObject(); writer.WritePropertyName("type"); writer.WriteValue("request"); writer.WritePropertyName("command"); writer.WriteValue("launch"); writer.WriteEndObject(); var token = writer.Token; var request = ProtocolMessage.Parse(token); Assert.Equal("launch", request.Command); token["command"] = "setBreakpoints"; request = ProtocolMessage.Parse(token); Assert.Equal("setBreakpoints", request.Command); token["command"] = "setFunctionBreakpoints"; request = ProtocolMessage.Parse(token); Assert.Equal("setFunctionBreakpoints", request.Command); token["command"] = "setExceptionBreakpoints"; request = ProtocolMessage.Parse(token); Assert.Equal("setExceptionBreakpoints", request.Command); token["command"] = "configurationDone"; request = Debugging.Protocol.ProtocolMessage.Parse(token); Assert.Equal("configurationDone", request.Command); token["command"] = "stackTrace"; request = ProtocolMessage.Parse(token); Assert.Equal("stackTrace", request.Command); token["command"] = "scopes"; request = ProtocolMessage.Parse(token); Assert.Equal("scopes", request.Command); token["command"] = "variables"; request = ProtocolMessage.Parse(token); Assert.Equal("variables", request.Command); token["command"] = "setVariable"; request = ProtocolMessage.Parse(token); Assert.Equal("setVariable", request.Command); token["command"] = "evaluate"; request = ProtocolMessage.Parse(token); Assert.Equal("evaluate", request.Command); token["command"] = "continue"; request = ProtocolMessage.Parse(token); Assert.Equal("continue", request.Command); token["command"] = "pause"; request = ProtocolMessage.Parse(token); Assert.Equal("pause", request.Command); token["command"] = "stepIn"; request = ProtocolMessage.Parse(token); Assert.Equal("stepIn", request.Command); token["command"] = "stepOut"; request = ProtocolMessage.Parse(token); Assert.Equal("stepOut", request.Command); token["command"] = "terminate"; request = ProtocolMessage.Parse(token); Assert.Equal("terminate", request.Command); token["command"] = "disconnect"; request = ProtocolMessage.Parse(token); Assert.Equal("disconnect", request.Command); token["type"] = "other"; Assert.Throws <NotImplementedException>(() => ProtocolMessage.Parse(token)); }