/// <summary> /// Main entry point into the Credentials Service Host /// </summary> internal static void Main(string[] args) { try { // read command-line arguments CommandOptions commandOptions = new CommandOptions(args); if (commandOptions.ShouldExit) { return; } // turn on Verbose logging during early development // we need to switch to Normal when preparing for public preview Logger.Initialize(minimumLogLevel: LogLevel.Verbose, isEnabled: commandOptions.EnableLogging); Logger.Write(LogLevel.Normal, "Starting SqlTools Credentials Provider"); // set up the host details and profile paths var hostDetails = new HostDetails( name: "SqlTools Credentials Provider", profileId: "Microsoft.SqlTools.Credentials", version: new Version(1, 0)); SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails); CredentialsServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext); serviceHost.WaitForExit(); } catch (Exception e) { Logger.Write(LogLevel.Error, string.Format("An unhandled exception occurred: {0}", e)); Environment.Exit(1); } }
private static void InitializeRequestHandlersAndServices(CredentialsServiceHost serviceHost, SqlToolsContext sqlToolsContext) { // Load extension provider, which currently finds all exports in current DLL. Can be changed to find based // on directory or assembly list quite easily in the future ExtensionServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider(); serviceProvider.RegisterSingleService(sqlToolsContext); serviceProvider.RegisterSingleService(serviceHost); CredentialService.Instance.InitializeService(serviceHost); serviceProvider.RegisterSingleService(CredentialService.Instance); InitializeHostedServices(serviceProvider, serviceHost); serviceHost.InitializeRequestHandlers(); }
internal static CredentialsServiceHost CreateAndStartServiceHost(SqlToolsContext sqlToolsContext) { CredentialsServiceHost serviceHost = CredentialsServiceHost.Instance; lock (lockObject) { if (!isLoaded) { // Grab the instance of the service host serviceHost.Initialize(); InitializeRequestHandlersAndServices(serviceHost, sqlToolsContext); // Start the service only after all request handlers are setup. This is vital // as otherwise the Initialize event can be lost - it's processed and discarded before the handler // is hooked up to receive the message serviceHost.Start().Wait(); isLoaded = true; } } return(serviceHost); }