Пример #1
0
        public override async Task <Kernel> CreateKernelAsync(
            MsSqlConnectionOptions options,
            KernelInvocationContext context)
        {
            var resolvedPackageReferences = ((ISupportNuget)context.HandlingKernel).ResolvedPackageReferences;
            // Walk through the packages looking for the package that endswith the name "Microsoft.SqlToolsService"
            // and grab the packageroot
            var    runtimePackageIdSuffix = "native.Microsoft.SqlToolsService";
            var    root          = resolvedPackageReferences.FirstOrDefault(p => p.PackageName.EndsWith(runtimePackageIdSuffix, StringComparison.OrdinalIgnoreCase));
            string pathToService = "";

            if (root != null)
            {
                // Extract the platform 'osx-x64' from the package name 'runtime.osx-x64.native.microsoft.sqltoolsservice'
                string[] packageNameSegments = root.PackageName.Split(".");
                if (packageNameSegments.Length > 2)
                {
                    string platform = packageNameSegments[1];

                    // Build the path to the MicrosoftSqlToolsServiceLayer executable by reaching into the resolve nuget package
                    // assuming a convention for native binaries.
                    pathToService = Path.Combine(
                        root.PackageRoot,
                        "runtimes",
                        platform,
                        "native",
                        "MicrosoftSqlToolsServiceLayer");

                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        pathToService += ".exe";
                    }
                }
            }

            var sqlClient = new MsSqlServiceClient(pathToService);

            var kernel = new MsSqlKernel(
                $"sql-{options.KernelName}",
                options.ConnectionString,
                sqlClient);

            await kernel.ConnectAsync();

            if (options.CreateDbContext)
            {
                await InitializeDbContextAsync(options, context);
            }

            return(kernel);
        }
Пример #2
0
        public async Task <Kernel> ConnectKernelAsync(KernelInfo kernelInfo)
        {
            if (string.IsNullOrWhiteSpace(PathToService))
            {
                throw new InvalidOperationException($"{nameof(PathToService)} cannot be null or whitespace.");
            }

            var sqlClient = new ToolsServiceClient(PathToService, $"--parent-pid {Environment.ProcessId}");

            var kernel = new MsSqlKernel(
                $"sql-{kernelInfo}",
                ConnectionString,
                sqlClient)
                         .UseValueSharing();

            kernel.RegisterForDisposal(sqlClient);

            await kernel.ConnectAsync();

            return(kernel);
        }