Beispiel #1
0
        public void Configure(
            IApplicationBuilder app,
            IServiceProvider serviceProvider,
            ILoggerFactory loggerFactory,
            ISharedTextWriter writer,
            IAssemblyLoader loader,
            IOptionsMonitor <OmniSharpOptions> options)
        {
            if (_env.TransportType == TransportType.Stdio)
            {
                loggerFactory.AddStdio(writer, (category, level) => LogFilter(category, level, _env));
            }
            else
            {
                loggerFactory.AddConsole((category, level) => LogFilter(category, level, _env));
            }

            var logger     = loggerFactory.CreateLogger <Startup>();
            var assemblies = DiscoverOmniSharpAssemblies(loader, logger);

            PluginHost = CreateCompositionHost(serviceProvider, options.CurrentValue, assemblies);
            Workspace  = PluginHost.GetExport <OmniSharpWorkspace>();

            app.UseRequestLogging();
            app.UseExceptionHandler("/error");
            app.UseMiddleware <EndpointMiddleware>();
            app.UseMiddleware <StatusMiddleware>();
            app.UseMiddleware <StopServerMiddleware>();

            if (_env.TransportType == TransportType.Stdio)
            {
                logger.LogInformation($"Omnisharp server running using {nameof(TransportType.Stdio)} at location '{_env.TargetDirectory}' on host {_env.HostProcessId}.");
            }
            else
            {
                logger.LogInformation($"Omnisharp server running on port '{_env.Port}' at location '{_env.TargetDirectory}' on host {_env.HostProcessId}.");
            }

            var workspaceHelper = new WorkspaceHelper(PluginHost, Configuration, options.CurrentValue, loggerFactory);

            workspaceHelper.Initialize(Workspace);

            // when configuration options change
            // run workspace options providers automatically
            options.OnChange(o =>
            {
                workspaceHelper.ProvideOptions(Workspace, o);
            });

            logger.LogInformation("Configuration finished.");
        }