Esempio n. 1
0
        public void CreateExtensibleHost()
        {
            // Setup:
            // ... Create a mock hosted service that can initialize
            var hs       = new Mock <IHostedService>();
            var mockType = typeof(Mock <IHostedService>);

            hs.Setup(o => o.InitializeService(It.IsAny <IServiceHost>()));
            hs.SetupGet(o => o.ServiceType).Returns(mockType);

            // ... Create a service provider mock that will return some stuff
            var sp = new Mock <RegisteredServiceProvider>();

            sp.Setup(o => o.GetServices <IHostedService>())
            .Returns(new[] { hs.Object });
            sp.Setup(o => o.RegisterSingleService(mockType, hs.Object));

            // If: I create an extensible host with a custom provider
            var cb  = new Mock <ChannelBase>();
            var esh = new ExtensibleServiceHost(sp.Object, cb.Object);

            // Then:

            // ... The service should have been initialized
            hs.Verify(o => o.InitializeService(esh), Times.Once());
            // ... The service host should have it's provider exposed
            Assert.Equal(sp.Object, esh.ServiceProvider);
        }
Esempio n. 2
0
        public void CreateDefaultExtensibleHostNullAssemblyList()
        {
            // If: I create a default server extensible host with a null provider
            // Then: I should get an exception
            var cb = new Mock <ChannelBase>();

            Assert.Throws <ArgumentNullException>(() => ExtensibleServiceHost.CreateDefaultExtensibleServer(".", null));
        }
Esempio n. 3
0
        public void CreateDefaultExtensibleHost()
        {
            // If: I create a default server extensible host
            var esh = ExtensibleServiceHost.CreateDefaultExtensibleServer(".", new string[] { });

            // Then:
            // ... The service provider should be setup
            Assert.NotNull(esh.ServiceProvider);

            // ... The underlying rpc host should be using the stdio server channel
            var jh = esh.jsonRpcHost as JsonRpcHost;

            Assert.NotNull(jh);
            Assert.IsType <StdioServerChannel>(jh.protocolChannel);
            Assert.False(jh.protocolChannel.IsConnected);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            try
            {
                // read command-line arguments
                string         applicationName = Path.ChangeExtension(ServiceName, ".exe");
                CommandOptions commandOptions  = new CommandOptions(args, applicationName);
                if (commandOptions.ShouldExit)
                {
                    return;
                }

                // we are in debug mode
                if (commandOptions.WaitForDebugger)
                {
                    int maxWait   = 30;
                    int waitCount = 0;
                    while (!Debugger.IsAttached && waitCount < maxWait)
                    {
                        Thread.Sleep(500);
                        waitCount++;
                    }
                }

                // configure log file
                string logFilePath = ServiceName;
                if (!string.IsNullOrWhiteSpace(commandOptions.LoggingDirectory))
                {
                    logFilePath = Path.Combine(commandOptions.LoggingDirectory, logFilePath);
                }

                Logger.Instance.Initialize(logFilePath: logFilePath, minimumLogLevel: MinimumLogLevel, isEnabled: commandOptions.EnableLogging);
                Logger.Instance.Write(LogLevel.Normal, "Starting language server host");

                // list all service assemblies that should be loaded by the host
                string[] searchPath = new string[] {
                    "Microsoft.SqlTools.Hosting.v2.dll",
                    //"Microsoft.SqlTools.CoreServices.dll",
                    "Microsoft.SqlTools.LanguageServerProtocol.dll",
                    "Microsoft.SqlTools.Samples.LanguageServerHost.Services.dll",
                };

                ExtensionServiceProvider serviceProvider = ExtensionServiceProvider.CreateFromAssembliesInDirectory(Path.GetDirectoryName(typeof(Program).Assembly.Location), searchPath);
                serviceProvider.RegisterSingleService(SettingsService <LanguageServerSettings> .Instance);

                ExtensibleServiceHost host = new ExtensibleServiceHost(serviceProvider, new StdioServerChannel());

                // TODO: can server capabilities be automatically determined by the registered services?
                host.ServerCapabilities = new ServerCapabilities
                {
                    TextDocumentSync = TextDocumentSyncKind.Incremental
                };

                Logger.Instance.Write(LogLevel.Verbose, "Starting wait loop");

                host.Start();
                host.WaitForExit();
            }
            catch (Exception e)
            {
                Logger.Instance.Write(LogLevel.Error, string.Format("An unhandled exception occurred: {0}", e));
                Environment.Exit(1);
            }
        }