コード例 #1
0
            public CreateData()
            {
                var baseOptions = new JsonRpcServerOptions().WithPipe(new Pipe());

                void BaseDelegate(JsonRpcServerOptions o)
                {
                    o.WithPipe(new Pipe());
                }

                var serviceProvider = new ServiceCollection().BuildServiceProvider();

                Add(new ActionDelegate("create: options", () => JsonRpcServer.Create(baseOptions)));
                Add(new ActionDelegate("create: options, serviceProvider", () => JsonRpcServer.Create(baseOptions, serviceProvider)));
                Add(new ActionDelegate("create: action", () => JsonRpcServer.Create(BaseDelegate)));
                Add(new ActionDelegate("create: action, serviceProvider", () => JsonRpcServer.Create(BaseDelegate, serviceProvider)));

                Add(new ActionDelegate("from: options", () => JsonRpcServer.From(baseOptions)));
                Add(new ActionDelegate("from: options, cancellationToken", () => JsonRpcServer.From(baseOptions, CancellationToken.None)));
                Add(new ActionDelegate("from: options, serviceProvider, cancellationToken", () => JsonRpcServer.From(baseOptions, serviceProvider, CancellationToken.None)));
                Add(new ActionDelegate("from: options, serviceProvider", () => JsonRpcServer.From(baseOptions, serviceProvider)));
                Add(new ActionDelegate("from: action", () => JsonRpcServer.From(BaseDelegate)));
                Add(new ActionDelegate("from: action, cancellationToken", () => JsonRpcServer.From(BaseDelegate, CancellationToken.None)));
                Add(new ActionDelegate("from: action, serviceProvider, cancellationToken", () => JsonRpcServer.From(BaseDelegate, serviceProvider, CancellationToken.None)));
                Add(new ActionDelegate("from: action, serviceProvider", () => JsonRpcServer.From(BaseDelegate, serviceProvider)));
            }
コード例 #2
0
        /// <summary>
        /// Start the debug server listening.
        /// </summary>
        /// <returns>A task that completes when the server is ready.</returns>
        public async Task StartAsync()
        {
            _jsonRpcServer = await JsonRpcServer.From(options =>
            {
                options.Serializer    = new DapProtocolSerializer();
                options.Receiver      = new DapReceiver();
                options.LoggerFactory = _loggerFactory;
                ILogger logger        = options.LoggerFactory.CreateLogger("DebugOptionsStartup");

                // We need to let the PowerShell Context Service know that we are in a debug session
                // so that it doesn't send the powerShell/startDebugger message.
                _powerShellContextService = ServiceProvider.GetService <PowerShellContextService>();
                _powerShellContextService.IsDebugServerActive = true;

                // Needed to make sure PSReadLine's static properties are initialized in the pipeline thread.
                // This is only needed for Temp sessions who only have a debug server.
                if (_usePSReadLine && _useTempSession && Interlocked.Exchange(ref s_hasRunPsrlStaticCtor, 1) == 0)
                {
                    // This must be run synchronously to ensure debugging works
                    _powerShellContextService
                    .ExecuteScriptStringAsync("[System.Runtime.CompilerServices.RuntimeHelpers]::RunClassConstructor([Microsoft.PowerShell.PSConsoleReadLine].TypeHandle)")
                    .GetAwaiter()
                    .GetResult();
                }

                options.Services = new ServiceCollection()
                                   .AddPsesDebugServices(ServiceProvider, this, _useTempSession);

                options
                .WithInput(_inputStream)
                .WithOutput(_outputStream);

                logger.LogInformation("Adding handlers");

                options
                .WithHandler <InitializeHandler>()
                .WithHandler <LaunchHandler>()
                .WithHandler <AttachHandler>()
                .WithHandler <DisconnectHandler>()
                .WithHandler <SetFunctionBreakpointsHandler>()
                .WithHandler <SetExceptionBreakpointsHandler>()
                .WithHandler <ConfigurationDoneHandler>()
                .WithHandler <ThreadsHandler>()
                .WithHandler <SetBreakpointsHandler>()
                .WithHandler <StackTraceHandler>()
                .WithHandler <ScopesHandler>()
                .WithHandler <VariablesHandler>()
                .WithHandler <ContinueHandler>()
                .WithHandler <NextHandler>()
                .WithHandler <PauseHandler>()
                .WithHandler <StepInHandler>()
                .WithHandler <StepOutHandler>()
                .WithHandler <SourceHandler>()
                .WithHandler <SetVariableHandler>()
                .WithHandler <DebugEvaluateHandler>();

                logger.LogInformation("Handlers added");
            }).ConfigureAwait(false);
        }
コード例 #3
0
        protected virtual async Task <(JsonRpcServer client, JsonRpcServer server)> Initialize(
            Action <JsonRpcServerOptions> clientOptionsAction,
            Action <JsonRpcServerOptions> serverOptionsAction
            )
        {
            var clientPipe = new Pipe(TestOptions.DefaultPipeOptions);
            var serverPipe = new Pipe(TestOptions.DefaultPipeOptions);

            var clientTask = JsonRpcServer.From(
                options => {
                options
                .WithLoggerFactory(TestOptions.ClientLoggerFactory)
                .WithServices(
                    services => services
                    .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                    .AddSingleton(ClientEvents as IRequestSettler)
                    .AddLogging(
                        x => {
                    x.SetMinimumLevel(LogLevel.Trace);
                }
                        )
                    );
                ConfigureClientInputOutput(serverPipe.Reader, clientPipe.Writer, options);
                clientOptionsAction(options);
            }, CancellationToken
                );

            var serverTask = JsonRpcServer.From(
                options => {
                options
                .WithServices(
                    services => services
                    .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                    .AddSingleton(ServerEvents as IRequestSettler)
                    .AddLogging(
                        x => {
                    x.SetMinimumLevel(LogLevel.Trace);
                    x.Services.AddSingleton(TestOptions.ServerLoggerFactory);
                }
                        )
                    );
                ConfigureServerInputOutput(clientPipe.Reader, serverPipe.Writer, options);
                serverOptionsAction(options);
            }, CancellationToken
                );

            await Task.WhenAll(clientTask, serverTask).ConfigureAwait(false);

#pragma warning disable VSTHRD103
            _client = clientTask.Result;
            _server = serverTask.Result;
#pragma warning restore VSTHRD103

            Disposable.Add(_client);
            Disposable.Add(_server);

            return(_client, _server);
        }
コード例 #4
0
        public async Task StartAsync(IServiceProvider languageServerServiceProvider, bool useTempSession)
        {
            _jsonRpcServer = await JsonRpcServer.From(options =>
            {
                options.Serializer    = new DapProtocolSerializer();
                options.Reciever      = new DapReciever();
                options.LoggerFactory = _loggerFactory;
                ILogger logger        = options.LoggerFactory.CreateLogger("DebugOptionsStartup");

                // We need to let the PowerShell Context Service know that we are in a debug session
                // so that it doesn't send the powerShell/startDebugger message.
                _powerShellContextService = languageServerServiceProvider.GetService <PowerShellContextService>();
                _powerShellContextService.IsDebugServerActive = true;

                // Needed to make sure PSReadLine's static properties are initialized in the pipeline thread.
                _powerShellContextService
                .ExecuteScriptStringAsync("[System.Runtime.CompilerServices.RuntimeHelpers]::RunClassConstructor([Microsoft.PowerShell.PSConsoleReadLine].TypeHandle)")
                .Wait();

                options.Services = new ServiceCollection()
                                   .AddPsesDebugServices(languageServerServiceProvider, this, useTempSession);

                options
                .WithInput(_inputStream)
                .WithOutput(_outputStream);

                logger.LogInformation("Adding handlers");

                options
                .WithHandler <InitializeHandler>()
                .WithHandler <LaunchHandler>()
                .WithHandler <AttachHandler>()
                .WithHandler <DisconnectHandler>()
                .WithHandler <SetFunctionBreakpointsHandler>()
                .WithHandler <SetExceptionBreakpointsHandler>()
                .WithHandler <ConfigurationDoneHandler>()
                .WithHandler <ThreadsHandler>()
                .WithHandler <SetBreakpointsHandler>()
                .WithHandler <StackTraceHandler>()
                .WithHandler <ScopesHandler>()
                .WithHandler <VariablesHandler>()
                .WithHandler <ContinueHandler>()
                .WithHandler <NextHandler>()
                .WithHandler <PauseHandler>()
                .WithHandler <StepInHandler>()
                .WithHandler <StepOutHandler>()
                .WithHandler <SourceHandler>()
                .WithHandler <SetVariableHandler>()
                .WithHandler <DebugEvaluateHandler>();

                logger.LogInformation("Handlers added");
            });
        }