void AddWatcher(FilePath directory)
        {
            var env     = new OmnisharpEnvironment(directory);
            var watcher = new FileSystemWatcherWrapper(env);

            watchers.Add(watcher);
        }
Ejemplo n.º 2
0
        public void OmnisharpEnvironmentHasNullSolutionFilePathIfDirectorySet()
        {
            var environment = new OmnisharpEnvironment(@"c:\foo\src\", 1000, TraceType.Information);

            Assert.Null(environment.SolutionFilePath);
            Assert.Equal(@"c:\foo\src\", environment.Path);
            Assert.Equal(1000, environment.Port);
        }
Ejemplo n.º 3
0
        public void OmnisharpEnvironmentSetsPathsCorrectly()
        {
            var environment = new OmnisharpEnvironment(@"c:\foo\src\foo.sln", 1000, TraceType.Information);

            Assert.Equal(@"c:\foo\src\foo.sln", environment.SolutionFilePath);
            Assert.Equal(@"c:\foo\src", environment.Path);
            Assert.Equal(1000, environment.Port);
        }
Ejemplo n.º 4
0
        public DnxProjectSystem CreateProjectSystem(
            Solution solution,
            IApplicationLifetime appLifetime,
            DnxContext context)
        {
            var workspace     = new OmnisharpWorkspace();
            var env           = new OmnisharpEnvironment(solution.BaseDirectory);
            var options       = new OmniSharpOptionsWrapper();
            var loggerFactory = new LoggerFactory();
            var cache         = new MetadataFileReferenceCache();
            var emitter       = new EventEmitter();
            var watcher       = new FileSystemWatcherWrapper(env);

            return(new DnxProjectSystem(
                       workspace,
                       env,
                       options,
                       loggerFactory,
                       cache,
                       appLifetime,
                       watcher,
                       emitter,
                       context));
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            Console.WriteLine($"OmniSharp: {string.Join(" ", args)}");

            var applicationRoot = Directory.GetCurrentDirectory();
            var serverPort      = 2000;
            var logLevel        = LogLevel.Information;
            var hostPID         = -1;
            var transportType   = TransportType.Http;
            var otherArgs       = new List <string>();
            var plugins         = new List <string>();

            var enumerator = args.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var arg = (string)enumerator.Current;
                if (arg == "-s")
                {
                    enumerator.MoveNext();
                    applicationRoot = Path.GetFullPath((string)enumerator.Current);
                }
                else if (arg == "-p")
                {
                    enumerator.MoveNext();
                    serverPort = int.Parse((string)enumerator.Current);
                }
                else if (arg == "-v")
                {
                    logLevel = LogLevel.Debug;
                }
                else if (arg == "--hostPID")
                {
                    enumerator.MoveNext();
                    hostPID = int.Parse((string)enumerator.Current);
                }
                else if (arg == "--stdio")
                {
                    transportType = TransportType.Stdio;
                }
                else if (arg == "--plugin")
                {
                    enumerator.MoveNext();
                    plugins.Add((string)enumerator.Current);
                }
                else
                {
                    otherArgs.Add((string)enumerator.Current);
                }
            }

            Environment = new OmnisharpEnvironment(applicationRoot, serverPort, hostPID, logLevel, transportType, otherArgs.ToArray());

            var config = new ConfigurationBuilder()
                         .AddCommandLine(new[] { "--server.urls", "http://localhost:" + serverPort });

            var writer = new SharedConsoleWriter();

            var builder = new WebHostBuilder()
                          .UseConfiguration(config.Build())
                          .UseEnvironment("OmniSharp")
                          .UseStartup(typeof(Startup))
                          .ConfigureServices(serviceCollection =>
            {
                serviceCollection.AddSingleton <IOmnisharpEnvironment>(Environment);
                serviceCollection.AddSingleton <ISharedTextWriter>(writer);
                serviceCollection.AddSingleton <PluginAssemblies>(new PluginAssemblies(plugins));
                serviceCollection.AddSingleton <IOmnisharpAssemblyLoader>(new OmnisharpAssemblyLoader());
            });

            if (transportType == TransportType.Stdio)
            {
                builder.UseServer(new StdioServer(Console.In, writer));
            }
            else
            {
                builder.UseServer("Microsoft.AspNetCore.Server.Kestrel");
            }

            using (var app = builder.Build())
            {
                app.Start();

                var appLifeTime = app.Services.GetRequiredService <IApplicationLifetime>();

                Console.CancelKeyPress += (sender, e) =>
                {
                    appLifeTime.StopApplication();
                    e.Cancel = true;
                };

                if (hostPID != -1)
                {
                    try
                    {
                        var hostProcess = Process.GetProcessById(hostPID);
                        hostProcess.EnableRaisingEvents = true;
                        hostProcess.OnExit(() => appLifeTime.StopApplication());
                    }
                    catch
                    {
                        // If the process dies before we get here then request shutdown
                        // immediately
                        appLifeTime.StopApplication();
                    }
                }

                appLifeTime.ApplicationStopping.WaitHandle.WaitOne();
            }
        }
Ejemplo n.º 6
0
        public void Main(string[] args)
        {
            var applicationRoot = Directory.GetCurrentDirectory();
            var serverPort      = 2000;
            var logLevel        = LogLevel.Information;
            var hostPID         = -1;
            var transportType   = TransportType.Http;
            var otherArgs       = new List <string>();

            var enumerator = args.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var arg = (string)enumerator.Current;
                if (arg == "-s")
                {
                    enumerator.MoveNext();
                    applicationRoot = Path.GetFullPath((string)enumerator.Current);
                }
                else if (arg == "-p")
                {
                    enumerator.MoveNext();
                    serverPort = int.Parse((string)enumerator.Current);
                }
                else if (arg == "-v")
                {
                    logLevel = LogLevel.Verbose;
                }
                else if (arg == "--hostPID")
                {
                    enumerator.MoveNext();
                    hostPID = int.Parse((string)enumerator.Current);
                }
                else if (arg == "--stdio")
                {
                    transportType = TransportType.Stdio;
                }
                else
                {
                    otherArgs.Add((string)enumerator.Current);
                }
            }

            Environment = new OmnisharpEnvironment(applicationRoot, serverPort, hostPID, logLevel, transportType, otherArgs.ToArray());

            var config = new Configuration()
                         .AddCommandLine(new[] { "--server.urls", "http://localhost:" + serverPort });

            var serviceCollection = HostingServices.Create(_serviceProvider, config);

            serviceCollection.AddSingleton <ISharedTextWriter, SharedConsoleWriter>();

            var services   = serviceCollection.BuildServiceProvider();
            var hostingEnv = services.GetRequiredService <IHostingEnvironment>();
            var appEnv     = services.GetRequiredService <IApplicationEnvironment>();

            var context = new HostingContext()
            {
                Services        = services,
                Configuration   = config,
                ServerName      = "Kestrel",
                ApplicationName = appEnv.ApplicationName,
                EnvironmentName = hostingEnv.EnvironmentName,
            };

            if (transportType == TransportType.Stdio)
            {
                context.ServerName    = null;
                context.ServerFactory = new Stdio.StdioServerFactory(Console.In, services.GetRequiredService <ISharedTextWriter>());
            }

            var engine             = services.GetRequiredService <IHostingEngine>();
            var appShutdownService = services.GetRequiredService <IApplicationShutdown>();
            var shutdownHandle     = new ManualResetEvent(false);

            var serverShutdown = engine.Start(context);

            appShutdownService.ShutdownRequested.Register(() =>
            {
                serverShutdown.Dispose();
                shutdownHandle.Set();
            });

#if ASPNETCORE50
            var ignored = Task.Run(() =>
            {
                Console.WriteLine("Started");
                Console.ReadLine();
                appShutdownService.RequestShutdown();
            });
#else
            Console.CancelKeyPress += (sender, e) =>
            {
                appShutdownService.RequestShutdown();
            };
#endif

            if (hostPID != -1)
            {
                try
                {
                    var hostProcess = Process.GetProcessById(hostPID);
                    hostProcess.EnableRaisingEvents = true;
                    hostProcess.OnExit(() => appShutdownService.RequestShutdown());
                }
                catch
                {
                    // If the process dies before we get here then request shutdown
                    // immediately
                    appShutdownService.RequestShutdown();
                }
            }

            shutdownHandle.WaitOne();
        }
Ejemplo n.º 7
0
        public void Main(string[] args)
        {
            var applicationRoot = Directory.GetCurrentDirectory();
            var serverPort      = 2000;
            var traceType       = TraceType.Information;

            var enumerator = args.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var arg = (string)enumerator.Current;
                if (arg == "-s")
                {
                    enumerator.MoveNext();
                    applicationRoot = Path.GetFullPath((string)enumerator.Current);
                }
                else if (arg == "-p")
                {
                    enumerator.MoveNext();
                    serverPort = int.Parse((string)enumerator.Current);
                }
                else if (arg == "-v")
                {
                    traceType = TraceType.Verbose;
                }
            }

            var environment = new OmnisharpEnvironment(applicationRoot, serverPort, traceType);
            var hostingEnv  = new HostingEnvironment {
                EnvironmentName = "Development"
            };

            var config = new Configuration()
                         .AddCommandLine(new[] { "--server.urls", "http://localhost:" + serverPort });

            var serviceCollection = new ServiceCollection();

            serviceCollection.Add(HostingServices.GetDefaultServices(config));
            serviceCollection.AddInstance <IOmnisharpEnvironment>(environment);
            serviceCollection.AddInstance <IHostingEnvironment>(hostingEnv);

            var services = serviceCollection
                           .BuildServiceProvider(_serviceProvider);

            var appEnv = services.GetRequiredService <IApplicationEnvironment>();

            var context = new HostingContext()
            {
                Services        = services,
                Configuration   = config,
                ServerName      = "Kestrel",
                ApplicationName = appEnv.ApplicationName,
                EnvironmentName = hostingEnv.EnvironmentName,
            };

            var engine             = services.GetRequiredService <IHostingEngine>();
            var appShutdownService = _serviceProvider.GetRequiredService <IApplicationShutdown>();
            var shutdownHandle     = new ManualResetEventSlim(false);

            var serverShutdown = engine.Start(context);

            appShutdownService.ShutdownRequested.Register(() =>
            {
                serverShutdown.Dispose();
                shutdownHandle.Set();
            });

#if ASPNETCORE50
            var ignored = Task.Run(() =>
            {
                Console.WriteLine("Started");
                Console.ReadLine();
                appShutdownService.RequestShutdown();
            });
#else
            Console.CancelKeyPress += (sender, e) =>
            {
                appShutdownService.RequestShutdown();
            };
#endif

            shutdownHandle.Wait();
        }
        public void OmnisharpEnvironmentHasNullSolutionFilePathIfDirectorySet()
        {
            var environment = new OmnisharpEnvironment(@"c:\foo\src\", 1000, -1, LogLevel.Information, TransportType.Http);

            Assert.Null(environment.SolutionFilePath);
        }
        public void OmnisharpEnvironmentSetsPortCorrectly()
        {
            var environment = new OmnisharpEnvironment(@"foo.sln", 1000, -1, LogLevel.Information, TransportType.Http);

            Assert.Equal(1000, environment.Port);
        }
        public void OmnisharpEnvironmentSetsSolutionPathCorrectly()
        {
            var environment = new OmnisharpEnvironment(@"foo.sln", 1000, -1, LogLevel.Information, TransportType.Http);

            Assert.Equal(@"foo.sln", environment.SolutionFilePath);
        }
Ejemplo n.º 11
0
        public void OmnisharpEnvironmentSetsPathCorrectly()
        {
            var environment = new OmnisharpEnvironment(@"foo.sln", 1000, LogLevel.Information);

            Assert.Equal(@"", environment.Path);
        }