/// <summary>
 /// Initializes a new instance of the <see cref="JsonRpcSubscription" /> class.
 /// </summary>
 /// <param name="channel">The channel.</param>
 /// <param name="group">The subscription group</param>
 /// <param name="server">The server.</param>
 /// <param name="withReplyMessage">If set to false, no reply message will be sent back to the subscription thorugh NATS. Use false for subscriptions that do not have to send a response, just process whatever is in the queue. Default is true. </param>
 public JsonRpcSubscription(string channel, string group, IJsonRpcServer server, ILogger logger = null)
 {
     _server = server;
     _server = server;
     _sInfo  = new SubscriptionInfo(channel, group);
     _logger = logger;
 }
Esempio n. 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);
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the specified req.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="server">The server.</param>
        /// <param name="req">The req.</param>
        /// <returns></returns>
        /// <exception cref="Exception">
        /// </exception>
        public static async Task <T> Execute <T>(this IJsonRpcServer server, JsonRpcRequest req)
        {
            var resp = await server.ServeAsync(req);

            if (resp.HasError())
            {
                throw new Exception(resp.Error.Message, new Exception(resp.Error.Data));
            }
            return(JsonConvert.DeserializeObject <T>(resp.Result));
        }
        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");
            });
        }
 public DebugEventHandlerService(
     ILoggerFactory factory,
     PowerShellContextService powerShellContextService,
     DebugService debugService,
     DebugStateService debugStateService,
     IJsonRpcServer jsonRpcServer)
 {
     _logger = factory.CreateLogger <DebugEventHandlerService>();
     _powerShellContextService = powerShellContextService;
     _debugService             = debugService;
     _debugStateService        = debugStateService;
     _jsonRpcServer            = jsonRpcServer;
 }
Esempio n. 6
0
 public AttachHandler(
     ILoggerFactory factory,
     IJsonRpcServer jsonRpcServer,
     DebugService debugService,
     PowerShellContextService powerShellContextService,
     DebugStateService debugStateService,
     DebugEventHandlerService debugEventHandlerService)
 {
     _logger                   = factory.CreateLogger <AttachHandler>();
     _jsonRpcServer            = jsonRpcServer;
     _debugService             = debugService;
     _powerShellContextService = powerShellContextService;
     _debugStateService        = debugStateService;
     _debugEventHandlerService = debugEventHandlerService;
 }
Esempio n. 7
0
 public LaunchHandler(
     ILoggerFactory factory,
     IJsonRpcServer jsonRpcServer,
     DebugService debugService,
     PowerShellContextService powerShellContextService,
     DebugStateService debugStateService,
     DebugEventHandlerService debugEventHandlerService,
     RemoteFileManagerService remoteFileManagerService)
 {
     _logger                   = factory.CreateLogger <LaunchHandler>();
     _jsonRpcServer            = jsonRpcServer;
     _debugService             = debugService;
     _powerShellContextService = powerShellContextService;
     _debugStateService        = debugStateService;
     _debugEventHandlerService = debugEventHandlerService;
     _remoteFileManagerService = remoteFileManagerService;
 }
 public ConfigurationDoneHandler(
     ILoggerFactory loggerFactory,
     IJsonRpcServer jsonRpcServer,
     DebugService debugService,
     DebugStateService debugStateService,
     DebugEventHandlerService debugEventHandlerService,
     PowerShellContextService powerShellContextService,
     WorkspaceService workspaceService)
 {
     _logger                   = loggerFactory.CreateLogger <SetFunctionBreakpointsHandler>();
     _jsonRpcServer            = jsonRpcServer;
     _debugService             = debugService;
     _debugStateService        = debugStateService;
     _debugEventHandlerService = debugEventHandlerService;
     _powerShellContextService = powerShellContextService;
     _workspaceService         = workspaceService;
 }
 public HelloWorldServiceProxy(IJsonRpcServer server)
 {
     this.server = server;
 }