public Task HandleAsync(SubmitCode command, KernelInvocationContext context)
        {
            var root = (Kernel)ParentKernel ?? this;

            var connectedKqlKernelNames = new HashSet <string>();

            root.VisitSubkernels(childKernel =>
            {
                if (_kernelNameFilter.Contains(childKernel.GetType().Name))
                {
                    connectedKqlKernelNames.Add(childKernel.Name);
                }
            });

            if (connectedKqlKernelNames.Count == 0)
            {
                context.Display(HTML(@"
<p>A KQL connection has not been established.</p>
<p>To connect to a database, first add the KQL extension package by running the following in a C# cell:</p>
<code>
    <pre>
    #r ""nuget:Microsoft.DotNet.Interactive.Kql,*-*""
    </pre>
</code>
Now, you can connect to a Microsoft Kusto Server database by running the following in a C# cell:
<code>
    <pre>
    #!connect kql --kernel-name mydatabase --cluster ""https://help.kusto.windows.net"" --database ""Samples""
    </pre>
</code>
<p>Once a connection is established, you can send KQL statements by prefixing them with the magic command for your connection.</p>
<code>
    <pre>
    #!kql-mydatabase
    tableName | take 10
    </pre>
</code>
"), "text/html");
            }
            else
            {
                PocketView view =
                    div(
                        p("You can send KQL statements to one of the following connected KQL kernels:"),
                        connectedKqlKernelNames.Select(
                            name =>
                            code(
                                pre($"    #!{name}\n tableName | take 10"))));

                context.Display(view);
            }

            return(Task.CompletedTask);
        }
Beispiel #2
0
        public Task HandleAsync(SubmitCode command, KernelInvocationContext context)
        {
            var root = (Kernel)ParentKernel ?? this;

            var connectedSqlKernelNames = new HashSet <string>();

            root.VisitSubkernels(childKernel =>
            {
                if (_kernelNameFilter.Contains(childKernel.GetType().Name))
                {
                    connectedSqlKernelNames.Add(childKernel.Name);
                }
            });

            if (connectedSqlKernelNames.Count == 0)
            {
                context.Display(HTML(@"
<p>A SQL connection has not been established.</p>
<p>To connect to a database, first add the SQL extension package by running the following in a C# cell:</p>
<code>
    <pre>
    #r ""nuget:Microsoft.DotNet.Interactive.SqlServer,*-*""
    </pre>
</code>
Now, you can connect to a Microsoft SQL Server database by running the following in a C# cell:
<code>
    <pre>
    #!connect mssql --kernel-name mydatabase ""Persist Security Info=False; Integrated Security=true; Initial Catalog=MyDatabase; Server=localhost""
    </pre>
</code>
<p>Once a connection is established, you can send SQL statements by prefixing them with the magic command for your connection.</p>
<code>
    <pre>
    #!sql-mydatabase
    SELECT * FROM MyDatabase.MyTable
    </pre>
</code>
"), "text/html");
            }
            else
            {
                PocketView view =
                    div(
                        p("You can send SQL statements to one of the following connected SQL kernels:"),
                        connectedSqlKernelNames.Select(
                            name =>
                            code(
                                pre($"    #!{name}\n    SELECT TOP * FROM ..."))));

                context.Display(view);
            }

            return(Task.CompletedTask);
        }
Beispiel #3
0
 public Task HandleAsync(SubmitCode command, KernelInvocationContext context)
 {
     context.Display(
         new HtmlString(command.Code),
         HtmlFormatter.MimeType);
     return(Task.CompletedTask);
 }
        public virtual Task ExecuteClientScript(string code, KernelInvocationContext context)
        {
            var scriptContent = new ScriptContent(code);

            context.Display(scriptContent);

            return(Task.CompletedTask);
        }
        public Task HandleAsync(
            SubmitCode command,
            KernelInvocationContext context)
        {
            var scriptContent = new ScriptContent(command.Code);

            context.Display(scriptContent);

            return(Task.CompletedTask);
        }
Beispiel #6
0
        public Task HandleAsync(SubmitCode command, KernelInvocationContext context)
        {
            var root = (Kernel)ParentKernel ?? this;

            var mssqlKernelNames = new HashSet <string>();


            root.VisitSubkernelsAndSelf(childKernel =>
            {
                if (_kernelNameFilter.Contains(childKernel.GetType().Name))
                {
                    mssqlKernelNames.Add(childKernel.Name);
                }
            });

            if (mssqlKernelNames.Count == 0)
            {
                context.Display(@"
A SQL kernel is not currently defined.

SQL kernels are provided as part of the `Microsoft.DotNet.Interactive.SqlServer` package, which can be installed by using the following nuget command:

`#r ""nuget:Microsoft.DotNet.Interactive.SqlServer,*-*""`

Once installed, you can find more info about creating a SQL kernel and running queries by running the following help command:

`#!connect mssql -h`
                ", "text/markdown");
            }
            else if (!string.IsNullOrWhiteSpace(command.Code))
            {
                context.Display($@"
Submit your SQL statements to one of the following SQL kernels.

- {string.Join("\n- ",mssqlKernelNames.Select(n => $"`#!{n}`"))}
", "text/markdown");
            }
            return(Task.CompletedTask);
        }