internal static DialogDebugAdapter MakeDebugger(IDebugTransport transport) { var codeModel = new CodeModel(); var sourceMap = new DebuggerSourceMap(codeModel); var events = new Events <DialogEvents>(); var coercion = new Coercion(); var dataModel = new DataModel(coercion); var debugger = new DialogDebugAdapter(transport, sourceMap, sourceMap, () => { }, events, codeModel, dataModel, NullLogger.Instance, coercion); return(debugger); }
public DialogDebugAdapter(IDebugTransport transport, ISourceMap sourceMap, IBreakpoints breakpoints, Action terminate, IEvents events = null, ICodeModel codeModel = null, IDataModel dataModel = null, ILogger logger = null, ICoercion coercion = null) { _transport = transport ?? throw new ArgumentNullException(nameof(transport)); _events = events ?? new Events <DialogEvents>(); _codeModel = codeModel ?? new CodeModel(); _dataModel = dataModel ?? new DataModel(coercion ?? new Coercion()); _sourceMap = sourceMap ?? throw new ArgumentNullException(nameof(sourceMap)); _breakpoints = breakpoints ?? throw new ArgumentNullException(nameof(breakpoints)); _terminate = terminate ?? (() => Environment.Exit(0)); _logger = logger ?? NullLogger.Instance; _arenas.Add(_output); // lazily complete circular dependency _transport.Accept = AcceptAsync; }
public async Task ListenAsync(IPEndPoint point, CancellationToken cancellationToken) { var listener = new TcpListener(point); listener.Start(); using (cancellationToken.Register(listener.Stop)) { var local = (IPEndPoint)listener.LocalEndpoint; // output is parsed on launch by "vscode-dialog-debugger\src\ts\extension.ts" Console.WriteLine($"{nameof(DebugTransport)}\t{local.Address}\t{local.Port}"); Trace.TraceInformation($"{nameof(DebugTransport)}\t{local.Address}\t{local.Port}"); while (!cancellationToken.IsCancellationRequested) { try { using (var client = await listener.AcceptTcpClientAsync().ConfigureAwait(false)) { using (var stream = client.GetStream()) { using (_reader = new StreamReader(stream, Encoding)) { using (_writer = new StreamWriter(stream, Encoding)) { using (cancellationToken.Register(() => { stream.Close(); _reader.Close(); _writer.Close(); client.Close(); })) { _connected.ExitWrite(); try { IDebugTransport transport = this; await transport.Accept(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) when(cancellationToken.IsCancellationRequested) { } finally { await _connected.EnterWriteAsync(cancellationToken).ConfigureAwait(false); } } } } } } } #pragma warning disable CA1031 // Do not catch general exception types (we just log the exception and we continue the execution) catch (Exception error) #pragma warning restore CA1031 // Do not catch general exception types { _logger.LogError(error, error.Message); } } } }