mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-19 09:35:36 -05:00
* Initial credential service files * Clean-up hostloader * Update build scripts to build credentials archive * Move hosting files to new assembly * Add credentials files to MS.SqlTools.Credentials * Remove duplicate files * Update namespace in program.cs * Fix test build breaks * Update extensions visibility. * Remove unused resource strings * Add xproj files to SLN for appveyor builds * Fix appveyor build break in test project * Fix extensibility tests * Fix various typos in latest iteration * Add settings for Integration build * Fix codecoverage.bat to use full pdb for new projects * Fix bug when packing in folder with native images * Fix typos in xproj * Reset XLF to fix build.cmd
87 lines
3.8 KiB
C#
87 lines
3.8 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SqlTools.ServiceLayer.Credentials;
|
|
using Microsoft.SqlTools.ServiceLayer.Extensibility;
|
|
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
|
|
|
namespace Microsoft.SqlTools.Credentials
|
|
{
|
|
/// <summary>
|
|
/// Provides support for starting up a service host. This is a common responsibility
|
|
/// for both the main service program and test driver that interacts with it
|
|
/// </summary>
|
|
public static class HostLoader
|
|
{
|
|
private static object lockObject = new object();
|
|
private static bool isLoaded;
|
|
|
|
internal static ServiceHost CreateAndStartServiceHost(SqlToolsContext sqlToolsContext)
|
|
{
|
|
ServiceHost serviceHost = ServiceHost.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;
|
|
}
|
|
|
|
private static void InitializeRequestHandlersAndServices(ServiceHost 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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Internal to support testing. Initializes <see cref="IHostedService"/> instances in the service,
|
|
/// and registers them for their preferred service type
|
|
/// </summary>
|
|
internal static void InitializeHostedServices(RegisteredServiceProvider provider, IProtocolEndpoint host)
|
|
{
|
|
// Pre-register all services before initializing. This ensures that if one service wishes to reference
|
|
// another one during initialization, it will be able to safely do so
|
|
foreach (IHostedService service in provider.GetServices<IHostedService>())
|
|
{
|
|
provider.RegisterSingleService(service.ServiceType, service);
|
|
}
|
|
|
|
foreach (IHostedService service in provider.GetServices<IHostedService>())
|
|
{
|
|
// Initialize all hosted services, and register them in the service provider for their requested
|
|
// service type. This ensures that when searching for the ConnectionService you can get it without
|
|
// searching for an IHostedService of type ConnectionService
|
|
service.InitializeService(host);
|
|
}
|
|
}
|
|
}
|
|
}
|