Ejemplo n.º 1
0
        public TestServiceProvider(
            IOmniSharpEnvironment environment,
            ILoggerFactory loggerFactory,
            ISharedTextWriter sharedTextWriter,
            IConfiguration configuration)
        {
            _logger = loggerFactory.CreateLogger <TestServiceProvider>();

            _services[typeof(IOptionsMonitor <OmniSharpOptions>)] = new OptionsMonitor <OmniSharpOptions>(
                new IConfigureOptions <OmniSharpOptions>[] {
                new ConfigureOptions <OmniSharpOptions>(c => ConfigurationBinder.Bind(configuration, c))
            },
                Enumerable.Empty <IOptionsChangeTokenSource <OmniSharpOptions> >()
                );

            var assemblyLoader = new AssemblyLoader(loggerFactory);
            var msbuildLocator = MSBuildLocator.CreateStandAlone(loggerFactory, assemblyLoader, allowMonoPaths: false);
            var memoryCache    = new MemoryCache(new MemoryCacheOptions());

            _services[typeof(ILoggerFactory)]        = loggerFactory;
            _services[typeof(IOmniSharpEnvironment)] = environment;
            _services[typeof(IAssemblyLoader)]       = assemblyLoader;
            _services[typeof(IMemoryCache)]          = memoryCache;
            _services[typeof(ISharedTextWriter)]     = sharedTextWriter;
            _services[typeof(IMSBuildLocator)]       = msbuildLocator;
        }
Ejemplo n.º 2
0
        public void Configure(IApplicationBuilder app,
                              ILoggerFactory loggerFactory,
                              IOmnisharpEnvironment env,
                              ISharedTextWriter writer)
        {
            Func <string, LogLevel, bool> logFilter = (category, type) =>
                                                      (category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) || string.Equals(category, typeof(ErrorHandlerMiddleware).FullName, StringComparison.OrdinalIgnoreCase)) &&
                                                      env.TraceType <= type;

            if (env.TransportType == TransportType.Stdio)
            {
                loggerFactory.AddStdio(writer, logFilter);
            }
            else
            {
                loggerFactory.AddConsole(logFilter);
            }

            var logger = loggerFactory.CreateLogger <Startup>();

            app.UseRequestLogging();

            app.UseErrorHandler("/error");

            app.UseMvc();

            if (env.TransportType == TransportType.Stdio)
            {
                logger.LogInformation($"Omnisharp server running using stdio at location '{env.Path}' on host {env.HostPID}.");
            }
            else
            {
                logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
            }

            // Forward workspace events
            app.ApplicationServices.GetRequiredService <ProjectEventForwarder>();

            // Initialize everything!
            var projectSystems = app.ApplicationServices.GetRequiredServices <IProjectSystem>();

            foreach (var projectSystem in projectSystems)
            {
                try
                {
                    projectSystem.Initalize();
                }
                catch (Exception e)
                {
                    //if a project system throws an unhandled exception
                    //it should not crash the entire server
                    logger.LogError($"The project system '{projectSystem.GetType().Name}' threw an exception.", e);
                }
            }

            // Mark the workspace as initialized
            Workspace.Initialized = true;

            logger.LogInformation("Solution has finished loading");
        }
        private TestServiceProvider(
            IOmniSharpEnvironment environment,
            ILoggerFactory loggerFactory,
            IAssemblyLoader assemblyLoader,
            IAnalyzerAssemblyLoader analyzerAssemblyLoader,
            IMemoryCache memoryCache,
            ISharedTextWriter sharedTextWriter,
            IMSBuildLocator msbuildLocator,
            IEventEmitter eventEmitter,
            IDotNetCliService dotNetCliService,
            IConfigurationRoot configuration,
            IOptionsMonitor <OmniSharpOptions> optionsMonitor)
        {
            _logger = loggerFactory.CreateLogger <TestServiceProvider>();

            AddService(environment);
            AddService(loggerFactory);
            AddService(assemblyLoader);
            AddService(memoryCache);
            AddService(sharedTextWriter);
            AddService(msbuildLocator);
            AddService(eventEmitter);
            AddService(dotNetCliService);
            AddService(configuration);
            AddService(optionsMonitor);
            AddService(analyzerAssemblyLoader);
        }
Ejemplo n.º 4
0
 public Startup(IOmniSharpEnvironment environment, IEventEmitter eventEmitter, ISharedTextWriter writer)
 {
     _environment   = environment;
     _eventEmitter  = eventEmitter;
     _writer        = writer;
     _configuration = new ConfigurationBuilder(environment).Build();
 }
Ejemplo n.º 5
0
        public StdioServer(TextReader input, ISharedTextWriter writer, Func<object, Task> next)
        {
            _input = input;
            _writer = writer;
            _next = next;
            _cancellation = new CancellationTokenSource();

            var ignored = Run();
        }
        private IServer BuildTestServerAndStart(TextReader reader,
                                                ISharedTextWriter writer,
                                                IHttpApplication<int> application)
        {
            var server = new StdioServer(reader, writer);
            server.Start(application);

            return server;
        }
Ejemplo n.º 7
0
        public StdioServer(TextReader input, ISharedTextWriter writer, Func <IFeatureCollection, Task> next)
        {
            _input        = input;
            _writer       = writer;
            _next         = next;
            _cancellation = new CancellationTokenSource();

            Run();
        }
Ejemplo n.º 8
0
        public StdioServer(TextReader input, ISharedTextWriter writer, Func <object, Task> next)
        {
            _input        = input;
            _writer       = writer;
            _next         = next;
            _cancellation = new CancellationTokenSource();

            var ignored = Run();
        }
Ejemplo n.º 9
0
        public StdioServer(TextReader input, ISharedTextWriter writer, Func<IFeatureCollection, Task> next)
        {
            _input = input;
            _writer = writer;
            _next = next;
            _cancellation = new CancellationTokenSource();

            Run();
        }
Ejemplo n.º 10
0
        private IServer BuildTestServerAndStart(TextReader reader,
                                                ISharedTextWriter writer,
                                                IHttpApplication <int> application)
        {
            var server = new StdioServer(reader, writer);

            server.Start(application);

            return(server);
        }
Ejemplo n.º 11
0
        public TestServiceProvider(IOmniSharpEnvironment environment, ILoggerFactory loggerFactory, ISharedTextWriter sharedTextWriter)
        {
            _logger = loggerFactory.CreateLogger <TestServiceProvider>();

            _services[typeof(ILoggerFactory)]        = loggerFactory;
            _services[typeof(IOmniSharpEnvironment)] = environment;
            _services[typeof(IAssemblyLoader)]       = new AssemblyLoader(loggerFactory);
            _services[typeof(IMemoryCache)]          = new MemoryCache(new MemoryCacheOptions());
            _services[typeof(ISharedTextWriter)]     = sharedTextWriter;
        }
Ejemplo n.º 12
0
        private IServer BuildTestServerAndStart(TextReader reader,
                                                ISharedTextWriter writer,
                                                IHttpApplication<int> application)
        {
            var factory = new StdioServerFactory(reader, writer);
            var server = factory.CreateServer(new ConfigurationBuilder().Build());
            server.Start(application);

            return server;
        }
Ejemplo n.º 13
0
        public Plugin(ISharedTextWriter writer, PluginConfig config)
        {
            _writer       = writer;
            _cancellation = new CancellationTokenSource();
            Config        = config;

            Key        = Config.Name;
            Language   = Config.Language;
            Extensions = Config.Extensions;
        }
Ejemplo n.º 14
0
        private IServer BuildTestServerAndStart(TextReader reader,
                                                ISharedTextWriter writer,
                                                IHttpApplication <int> application)
        {
            var factory = new StdioServerFactory(reader, writer);
            var server  = factory.CreateServer(new ConfigurationBuilder().Build());

            server.Start(application);

            return(server);
        }
Ejemplo n.º 15
0
 public CompositionHostBuilder(
     IServiceProvider serviceProvider,
     IOmniSharpEnvironment environment,
     ISharedTextWriter writer,
     IEventEmitter eventEmitter,
     IEnumerable <Assembly> assemblies = null)
 {
     _serviceProvider = serviceProvider;
     _environment     = environment;
     _writer          = writer;
     _eventEmitter    = eventEmitter;
     _assemblies      = assemblies ?? Array.Empty <Assembly>();
 }
Ejemplo n.º 16
0
 public Host(
     IOmniSharpEnvironment environment,
     ISharedTextWriter sharedTextWriter,
     PluginAssemblies commandLinePlugins,
     int serverPort,
     string serverInterface)
 {
     _environment        = environment;
     _sharedTextWriter   = sharedTextWriter;
     _commandLinePlugins = commandLinePlugins;
     _serverPort         = serverPort;
     _serverInterface    = serverInterface;
 }
Ejemplo n.º 17
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.");
        }
Ejemplo n.º 18
0
        public void ConfigureServices(IServiceCollection services, IApplicationLifetime liftime, ISharedTextWriter writer)
        {
            Workspace = new OmnisharpWorkspace();

            // Working around another bad bug in ASP.NET 5
            // https://github.com/aspnet/Hosting/issues/151
            services.AddInstance(liftime);
            services.AddInstance(writer);

            // This is super hacky by it's the easiest way to flow serivces from the 
            // hosting layer, this needs to be easier
            services.AddInstance<IOmnisharpEnvironment>(Program.Environment);

            services.AddMvc(Configuration);

            services.Configure<MvcOptions>(opt =>
            {
                opt.ApplicationModelConventions.Add(new FromBodyApplicationModelConvention());
                opt.Filters.Add(new UpdateBufferFilter(Workspace));
            });

            // Add the omnisharp workspace to the container
            services.AddInstance(Workspace);

            // Caching
            services.AddSingleton<IMemoryCache, MemoryCache>();
            services.AddSingleton<IMetadataFileReferenceCache, MetadataFileReferenceCache>();

            // Add the project systems
            services.AddInstance(new AspNet5Context());
            services.AddInstance(new MSBuildContext());

            services.AddSingleton<IProjectSystem, AspNet5ProjectSystem>();
            services.AddSingleton<IProjectSystem, MSBuildProjectSystem>();

            // Add the file watcher
            services.AddSingleton<IFileSystemWatcher, FileSystemWatcherWrapper>();

            // Add test command providers
            services.AddSingleton<ITestCommandProvider, AspNet5TestCommandProvider>();

            // Add the code action provider
            services.AddSingleton<ICodeActionProvider, EmptyCodeActionProvider>();
            
#if ASPNET50
            services.AddSingleton<ICodeActionProvider, NRefactoryCodeActionProvider>();
#endif

            // Setup the options from configuration
            services.Configure<OmniSharpOptions>(Configuration);
        }
Ejemplo n.º 19
0
        public StdioServer(TextReader input, ISharedTextWriter writer)
        {
            _input        = input;
            _writer       = writer;
            _cancellation = new CancellationTokenSource();

            _httpContextAccessor = new HttpContextAccessor();
            _httpContextFactory  = new HttpContextFactory(_httpContextAccessor);

            var features        = new FeatureCollection();
            var requestFeature  = new RequestFeature();
            var responseFeature = new ResponseFeature();

            features.Set <IHttpRequestFeature>(requestFeature);
            features.Set <IHttpResponseFeature>(responseFeature);
            Features = features;
        }
Ejemplo n.º 20
0
        public TestServiceProvider(IOmniSharpEnvironment environment, ILoggerFactory loggerFactory, ISharedTextWriter sharedTextWriter, IConfiguration configuration)
        {
            _logger = loggerFactory.CreateLogger <TestServiceProvider>();

            _services[typeof(IOptionsMonitor <OmniSharpOptions>)] = new OptionsMonitor <OmniSharpOptions>(
                new IConfigureOptions <OmniSharpOptions>[] {
                new ConfigureOptions <OmniSharpOptions>(c => ConfigurationBinder.Bind(configuration, c))
            },
                Enumerable.Empty <IOptionsChangeTokenSource <OmniSharpOptions> >()
                );

            _services[typeof(ILoggerFactory)]        = loggerFactory;
            _services[typeof(IOmniSharpEnvironment)] = environment;
            _services[typeof(IAssemblyLoader)]       = new AssemblyLoader(loggerFactory);
            _services[typeof(IMemoryCache)]          = new MemoryCache(new MemoryCacheOptions());
            _services[typeof(ISharedTextWriter)]     = sharedTextWriter;
        }
Ejemplo n.º 21
0
        public void Configure(IApplicationBuilder app,
                              ILoggerFactory loggerFactory,
                              IOmnisharpEnvironment env,
                              ISharedTextWriter writer)
        {
            Func <string, LogLevel, bool> logFilter = (category, type) =>
                                                      (category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) || string.Equals(category, typeof(ErrorHandlerMiddleware).FullName, StringComparison.OrdinalIgnoreCase)) &&
                                                      env.TraceType <= type;

            if (env.TransportType == TransportType.Stdio)
            {
                loggerFactory.AddStdio(writer, logFilter);
            }
            else
            {
                loggerFactory.AddConsole(logFilter);
            }

            var logger = loggerFactory.Create <Startup>();

            app.UseRequestLogging();

            app.UseErrorHandler("/error");

            app.UseMvc();

            logger.WriteInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");

            // Forward workspace events
            app.ApplicationServices.GetRequiredService <ProjectEventForwarder>();

            // Initialize everything!
            var projectSystems = app.ApplicationServices.GetRequiredService <IEnumerable <IProjectSystem> >();

            foreach (var projectSystem in projectSystems)
            {
                projectSystem.Initalize();
            }

            // Mark the workspace as initialized
            Workspace.Initialized = true;

            // This is temporary so that plugins work
            Console.WriteLine("Solution has finished loading");
        }
Ejemplo n.º 22
0
        public StdioServer(TextReader input, ISharedTextWriter writer)
        {
            _input        = input;
            _writer       = writer;
            _cancellation = new CancellationTokenSource();

            _httpContextAccessor = new HttpContextAccessor();
            _objectPoolProvider  = new DefaultObjectPoolProvider();
            _formOptions         = Microsoft.Extensions.Options.Options.Create(new FormOptions());
            _httpContextFactory  = new HttpContextFactory(_objectPoolProvider, _formOptions, _httpContextAccessor);

            var features        = new FeatureCollection();
            var requestFeature  = new RequestFeature();
            var responseFeature = new ResponseFeature();

            features.Set <IHttpRequestFeature>(requestFeature);
            features.Set <IHttpResponseFeature>(responseFeature);
            Features = features;
        }
Ejemplo n.º 23
0
        public Host(
            TextReader input, ISharedTextWriter writer, IOmniSharpEnvironment environment, IConfiguration configuration,
            IServiceProvider serviceProvider, CompositionHostBuilder compositionHostBuilder, ILoggerFactory loggerFactory, CancellationTokenSource cancellationTokenSource)
        {
            _cancellationTokenSource = cancellationTokenSource;
            _input           = input;
            _writer          = writer;
            _environment     = environment;
            _configuration   = configuration;
            _serviceProvider = serviceProvider;
            _loggerFactory   = loggerFactory.AddStdio(_writer, (category, level) => HostHelpers.LogFilter(category, level, _environment));

            _compositionHost     = compositionHostBuilder.Build();
            _cachedStringBuilder = new CachedStringBuilder();

            var handlers = Initialize();

            _endpointHandlers = handlers;
        }
Ejemplo n.º 24
0
        private Host BuildTestServerAndStart(TextReader reader, ISharedTextWriter writer, Action <Host> programDelegate = null)
        {
            var configuration          = new Microsoft.Extensions.Configuration.ConfigurationBuilder().Build();
            var environment            = new OmniSharpEnvironment();
            var serviceProvider        = CompositionHostBuilder.CreateDefaultServiceProvider(environment, configuration, NullEventEmitter.Instance);
            var cancelationTokenSource = new CancellationTokenSource();
            var host = new Host(reader, writer,
                                environment,
                                serviceProvider,
                                new CompositionHostBuilder(serviceProvider),
                                serviceProvider.GetRequiredService <ILoggerFactory>(),
                                cancelationTokenSource);

            programDelegate?.Invoke(host);

            host.Start();

            return(host);
        }
Ejemplo n.º 25
0
        public Host(
            TextReader input, ISharedTextWriter writer, IOmniSharpEnvironment environment,
            IServiceProvider serviceProvider, CompositionHostBuilder compositionHostBuilder, ILoggerFactory loggerFactory, CancellationTokenSource cancellationTokenSource)
        {
            _cancellationTokenSource = cancellationTokenSource;
            _input           = input;
            _writer          = writer;
            _environment     = environment;
            _serviceProvider = serviceProvider;
            _logger          = loggerFactory.CreateLogger <Host>();

            _logger.LogInformation($"Starting OmniSharp on {Platform.Current}");

            _compositionHost     = compositionHostBuilder.Build(_environment.TargetDirectory);
            _cachedStringBuilder = new CachedStringBuilder();

            var handlers = Initialize();

            _endpointHandlers = handlers;
        }
Ejemplo n.º 26
0
        public void Configure(
            IApplicationBuilder app,
            IServiceProvider serviceProvider,
            ILoggerFactory loggerFactory,
            IEventEmitter eventEmitter,
            ISharedTextWriter writer,
            HttpEnvironment httpEnvironment,
            IOptionsMonitor <OmniSharpOptions> options)
        {
            var workspace = _compositionHost.GetExport <OmniSharpWorkspace>();
            var logger    = loggerFactory.CreateLogger <Startup>();

            loggerFactory.AddConsole((category, level) =>
            {
                if (HostHelpers.LogFilter(category, level, _environment))
                {
                    return(true);
                }

                if (string.Equals(category, typeof(ExceptionHandlerMiddleware).FullName, StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }

                return(false);
            });

            logger.LogInformation($"Starting OmniSharp on {Platform.Current}");

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

            WorkspaceInitializer.Initialize(serviceProvider, _compositionHost, _configuration, logger);

            logger.LogInformation($"Omnisharp server running on port '{httpEnvironment.Port}' at location '{_environment.TargetDirectory}' on host {_environment.HostProcessId}.");
        }
Ejemplo n.º 27
0
        private TestServiceProvider(
            IOmniSharpEnvironment environment,
            ILoggerFactory loggerFactory,
            IAssemblyLoader assemblyLoader,
            IAnalyzerAssemblyLoader analyzerAssemblyLoader,
            ISharedTextWriter sharedTextWriter,
            IMSBuildLocator msbuildLocator,
            IEventEmitter eventEmitter,
            IDotNetCliService dotNetCliService,
            IConfigurationRoot configuration)
        {
            _logger = loggerFactory.CreateLogger <TestServiceProvider>();
            var services = _services = new ServiceCollection();

            services
            .AddLogging()
            .AddOptions()
            .AddMemoryCache();

            services
            .AddSingleton(environment)
            .AddSingleton(loggerFactory)
            .AddSingleton(assemblyLoader)
            .AddSingleton(sharedTextWriter)
            .AddSingleton(msbuildLocator)
            .AddSingleton(eventEmitter)
            .AddSingleton(dotNetCliService)
            .AddSingleton(configuration)
            .AddSingleton(configuration as IConfiguration)
            .Configure <OmniSharpOptions>(configuration)
            .PostConfigure <OmniSharpOptions>(OmniSharpOptions.PostConfigure)
            .AddSingleton(analyzerAssemblyLoader);

            services.TryAddSingleton(_ => new ManualFileSystemWatcher());
            services.TryAddSingleton <IFileSystemNotifier>(_ => _.GetRequiredService <ManualFileSystemWatcher>());
            services.TryAddSingleton <IFileSystemWatcher>(_ => _.GetRequiredService <ManualFileSystemWatcher>());

            _serviceProvider = services.BuildServiceProvider();
        }
Ejemplo n.º 28
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ILoggerFactory loggerFactory,
            ISharedTextWriter writer)
        {
            if (_env.TransportType == TransportType.Stdio)
            {
                loggerFactory.AddStdio(writer, (category, level) => LogFilter(category, level, _env));
            }
            else
            {
                loggerFactory.AddConsole((category, level) => LogFilter(category, level, _env));
            }

            //loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddSerilog();

            app.UseExceptionHandler("/error");

            // Loading all endpoint middleware that implements BaseMiddleWare.
            app.UseEndpointMiddleware();

            app.UseMiddleware <StopServerMiddleware>();

            var logger = loggerFactory.CreateLogger <Startup>();

            if (_env.TransportType == TransportType.Stdio)
            {
                logger.LogInformation($"ILSpy.Host server running using {nameof(TransportType.Stdio)}.");
            }
            else
            {
                logger.LogInformation($"ILSpy.Host server running on port '{_env.Port}'.");
            }
        }
Ejemplo n.º 29
0
        public void Configure(IApplicationBuilder app,
                              ILoggerFactory loggerFactory,
                              IOmnisharpEnvironment env,
                              ISharedTextWriter writer)
        {
            Func<string, LogLevel, bool> logFilter = (category, type) =>
                (category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) || string.Equals(category, typeof(ErrorHandlerMiddleware).FullName, StringComparison.OrdinalIgnoreCase))
                && env.TraceType <= type;
                    
            if (env.TransportType == TransportType.Stdio)
            {
                loggerFactory.AddStdio(writer, logFilter);
            }
            else
            {
                loggerFactory.AddConsole(logFilter);
            }

            var logger = loggerFactory.Create<Startup>();

            app.UseRequestLogging();

            app.UseErrorHandler("/error");

            app.UseMvc();

            logger.WriteInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");

            // Initialize everything!
            var projectSystems = app.ApplicationServices.GetRequiredService<IEnumerable<IProjectSystem>>();

            foreach (var projectSystem in projectSystems)
            {
                projectSystem.Initalize();
            }

            // Mark the workspace as initialized
            Workspace.Initialized = true;

            // This is temporary so that plugins work
            Console.WriteLine("Solution has finished loading");
        }
Ejemplo n.º 30
0
 internal StdioLogger(ISharedTextWriter writer, string name, Func<string, LogLevel, bool> filter)
 {
     _writer = writer;
     _name = name;
     _filter = filter;
 }
Ejemplo n.º 31
0
        public void Configure(IApplicationBuilder app,
                              IServiceProvider serviceProvider,
                              IOmnisharpEnvironment env,
                              ILoggerFactory loggerFactory,
                              ISharedTextWriter writer,
                              IOmnisharpAssemblyLoader loader,
                              IOptions<OmniSharpOptions> optionsAccessor)
        {
            Func<RuntimeLibrary, bool> shouldLoad = lib => lib.Dependencies.Any(dep => dep.Name == "OmniSharp.Abstractions" ||
                                                                                       dep.Name == "OmniSharp.Roslyn");
                       
            var assemblies = DependencyContext.Default
                                              .RuntimeLibraries
                                              .Where(shouldLoad)
                                              .SelectMany(lib => lib.Assemblies)
                                              .Select(each => loader.Load(each.Name))
                                              .ToList();

            PluginHost = ConfigureMef(serviceProvider, optionsAccessor.Value, assemblies);

            Workspace = PluginHost.GetExport<OmnisharpWorkspace>();

            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>();
            foreach (var assembly in assemblies)
            {
                logger.LogDebug($"Loaded {assembly.FullName}");
            }

            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.Path}' on host {env.HostPID}.");
            }
            else
            {
                logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
            }

            // ProjectEventForwarder register event to OmnisharpWorkspace during instantiation
            PluginHost.GetExport<ProjectEventForwarder>();
            
            // Initialize all the project systems
            foreach (var projectSystem in PluginHost.GetExports<IProjectSystem>())
            {
                try
                {
                    projectSystem.Initalize(Configuration.GetSection(projectSystem.Key));
                }
                catch (Exception e)
                {
                    var message = $"The project system '{projectSystem.GetType().Name}' threw exception during initialization.\n{e.Message}\n{e.StackTrace}";
                    // if a project system throws an unhandled exception it should not crash the entire server
                    logger.LogError(message);
                }
            }

            // Mark the workspace as initialized
            Workspace.Initialized = true;

            logger.LogInformation("Configuration finished.");
        }
 public StdioEventEmitter(ISharedTextWriter writer)
 {
     _writer = writer;
 }
Ejemplo n.º 33
0
        public void Configure(IApplicationBuilder app,
                              IServiceProvider serviceProvider,
                              IOmnisharpEnvironment env,
                              ILoggerFactory loggerFactory,
                              ISharedTextWriter writer,
                              IOptions <OmniSharpOptions> optionsAccessor)
        {
            var assemblies = DnxPlatformServices.Default.LibraryManager.GetReferencingLibraries("OmniSharp.Abstractions")
                             .SelectMany(libraryInformation => libraryInformation.Assemblies)
                             .Concat(
                DnxPlatformServices.Default.LibraryManager.GetReferencingLibraries("OmniSharp.Roslyn")
                .SelectMany(libraryInformation => libraryInformation.Assemblies)
                )
                             .Select(assemblyName => Assembly.Load(assemblyName));

            PluginHost = ConfigureMef(serviceProvider, optionsAccessor.Value, assemblies);

            Workspace = PluginHost.GetExport <OmnisharpWorkspace>();

            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>();

            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 stdio at location '{env.Path}' on host {env.HostPID}.");
            }
            else
            {
                logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
            }

            // Forward workspace events
            PluginHost.GetExport <ProjectEventForwarder>();
            foreach (var projectSystem in PluginHost.GetExports <IProjectSystem>())
            {
                try
                {
                    projectSystem.Initalize(Configuration.GetSection(projectSystem.Key));
                }
                catch (Exception e)
                {
                    //if a project system throws an unhandled exception
                    //it should not crash the entire server
                    logger.LogError($"The project system '{projectSystem.GetType().Name}' threw an exception.", e);
                }
            }

            // Mark the workspace as initialized
            Workspace.Initialized = true;

            logger.LogInformation("Solution has finished loading");
        }
Ejemplo n.º 34
0
 public StdioLoggerProvider(ISharedTextWriter writer)
 {
     _writer = writer;
 }
Ejemplo n.º 35
0
 internal StdioLoggerProvider(ISharedTextWriter writer, Func<string, LogLevel, bool> filter)
 {
     _writer = writer;
     _filter = filter;
 }
Ejemplo n.º 36
0
        public void Configure(IApplicationBuilder app,
                              IServiceProvider serviceProvider,
                              IOmnisharpEnvironment env,
                              ILoggerFactory loggerFactory,
                              ISharedTextWriter writer,
                              IOmnisharpAssemblyLoader loader,
                              IOptions <OmniSharpOptions> optionsAccessor)
        {
            Func <RuntimeLibrary, bool> shouldLoad = lib => lib.Dependencies.Any(dep => dep.Name == "OmniSharp.Abstractions" ||
                                                                                 dep.Name == "OmniSharp.Roslyn");

            var dependencyContext = DependencyContext.Default;
            var assemblies        = dependencyContext.RuntimeLibraries
                                    .Where(shouldLoad)
                                    .SelectMany(lib => lib.GetDefaultAssemblyNames(dependencyContext))
                                    .Select(each => loader.Load(each.Name))
                                    .ToList();

            PluginHost = ConfigureMef(serviceProvider, optionsAccessor.Value, assemblies);

            Workspace = PluginHost.GetExport <OmnisharpWorkspace>();

            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>();

            foreach (var assembly in assemblies)
            {
                logger.LogDebug($"Loaded {assembly.FullName}");
            }

            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.Path}' on host {env.HostPID}.");
            }
            else
            {
                logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
            }

            // ProjectEventForwarder register event to OmnisharpWorkspace during instantiation
            PluginHost.GetExport <ProjectEventForwarder>();

            // Initialize all the project systems
            foreach (var projectSystem in PluginHost.GetExports <IProjectSystem>())
            {
                try
                {
                    projectSystem.Initalize(Configuration.GetSection(projectSystem.Key));
                }
                catch (Exception e)
                {
                    var message = $"The project system '{projectSystem.GetType().Name}' threw exception during initialization.\n{e.Message}\n{e.StackTrace}";
                    // if a project system throws an unhandled exception it should not crash the entire server
                    logger.LogError(message);
                }
            }

            // Mark the workspace as initialized
            Workspace.Initialized = true;

            logger.LogInformation("Configuration finished.");
        }
Ejemplo n.º 37
0
 public StdioEventEmitter(ISharedTextWriter writer)
 {
     _writer = writer;
 }
 public static ILoggerFactory AddStdio(this ILoggerFactory factory, ISharedTextWriter writer, Func<string, LogLevel, bool> filter)
 {
     factory.AddProvider(new StdioLoggerProvider(writer, filter));
     return factory;
 }
Ejemplo n.º 39
0
 private IServer BuildTestServerAndStart(TextReader reader, ISharedTextWriter writer)
 {
     return BuildTestServerAndStart(reader, writer, new MockHttpApplication());
 }
Ejemplo n.º 40
0
 public Startup(IOmniSharpEnvironment environment, IEventEmitter eventEmitter, ISharedTextWriter writer)
 {
     _environment  = environment;
     _eventEmitter = eventEmitter;
 }
Ejemplo n.º 41
0
        public void Configure(IApplicationBuilder app,
                              ILoggerFactory loggerFactory,
                              IOmnisharpEnvironment env,
                              ISharedTextWriter writer)
        {
            Func<string, LogLevel, bool> logFilter = (category, type) =>
                (category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) || string.Equals(category, typeof(ErrorHandlerMiddleware).FullName, StringComparison.OrdinalIgnoreCase))
                && env.TraceType <= type;

            if (env.TransportType == TransportType.Stdio)
            {
                loggerFactory.AddStdio(writer, logFilter);
            }
            else
            {
                loggerFactory.AddConsole(logFilter);
            }

            var logger = loggerFactory.CreateLogger<Startup>();

            app.UseRequestLogging();

            app.UseErrorHandler("/error");

            app.UseMvc();

            if (env.TransportType == TransportType.Stdio)
            {
                logger.LogInformation($"Omnisharp server running using stdio at location '{env.Path}' on host {env.HostPID}.");
            }
            else
            {
                logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
            }

            // Forward workspace events
            app.ApplicationServices.GetRequiredService<ProjectEventForwarder>();

            // Initialize everything!
            var projectSystems = app.ApplicationServices.GetRequiredServices<IProjectSystem>();

            foreach (var projectSystem in projectSystems)
            {
                try
                {
                    projectSystem.Initalize();
                }
                catch (Exception e)
                {
                    //if a project system throws an unhandled exception
                    //it should not crash the entire server
                    logger.LogError($"The project system '{projectSystem.GetType().Name}' threw an exception.", e);
                }
            }

            // Mark the workspace as initialized
            Workspace.Initialized = true;

            logger.LogInformation("Solution has finished loading");
        }
 public StdioServerFactory(TextReader input, ISharedTextWriter output)
 {
     _input = input;
     _output = output;
 }
Ejemplo n.º 43
0
        public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider, ILibraryManager manager,
            IOmnisharpEnvironment env, ILoggerFactory loggerFactory, ISharedTextWriter writer, IOptions<OmniSharpOptions> optionsAccessor)
        {
            var assemblies = manager.GetReferencingLibraries("OmniSharp.Abstractions")
                .SelectMany(libraryInformation => libraryInformation.LoadableAssemblies)
                .Concat(
                    manager.GetReferencingLibraries("OmniSharp.Roslyn")
                        .SelectMany(libraryInformation => libraryInformation.LoadableAssemblies)
                )
                .Select(assemblyName => Assembly.Load(assemblyName));

            PluginHost = ConfigureMef(serviceProvider, optionsAccessor.Options, assemblies);

            Workspace = PluginHost.GetExport<OmnisharpWorkspace>();

            Func<string, LogLevel, bool> logFilter = (category, type) =>
                (category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) || string.Equals(category, typeof(ErrorHandlerMiddleware).FullName, StringComparison.OrdinalIgnoreCase))
                && env.TraceType <= type;

            if (env.TransportType == TransportType.Stdio)
            {
                loggerFactory.AddStdio(writer, logFilter);
            }
            else
            {
                loggerFactory.AddConsole(logFilter);
            }

            var logger = loggerFactory.CreateLogger<Startup>();

            app.UseRequestLogging();

            app.UseErrorHandler("/error");

            app.UseMiddleware<EndpointMiddleware>();
            app.UseMiddleware<StatusMiddleware>();
            app.UseMiddleware<StopServerMiddleware>();

            if (env.TransportType == TransportType.Stdio)
            {
                logger.LogInformation($"Omnisharp server running using stdio at location '{env.Path}' on host {env.HostPID}.");
            }
            else
            {
                logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
            }

            // Forward workspace events
            PluginHost.GetExport<ProjectEventForwarder>();
            foreach (var projectSystem in PluginHost.GetExports<IProjectSystem>())
            {
                try
                {
                    projectSystem.Initalize(Configuration.GetSubKey(projectSystem.Key));
                }
                catch (Exception e)
                {
                    //if a project system throws an unhandled exception
                    //it should not crash the entire server
                    logger.LogError($"The project system '{projectSystem.GetType().Name}' threw an exception.", e);
                }
            }

            // Mark the workspace as initialized
            Workspace.Initialized = true;

            logger.LogInformation("Solution has finished loading");
        }
 public static ILoggingBuilder AddStdio(this ILoggingBuilder builder, ISharedTextWriter writer)
 {
     builder.AddProvider(new StdioLoggerProvider(writer));
     return(builder);
 }
 public StdioServerFactory(TextReader input, ISharedTextWriter output)
 {
     _serverFactory = () => new StdioServer(input, output);
 }
Ejemplo n.º 46
0
 public StdioLogger(ISharedTextWriter writer, string categoryName)
     : base(categoryName, addHeader: false)
 {
     _writer = writer;
 }