Skip to content

Commit

Permalink
moving namedpipeconnetor to separate project
Browse files Browse the repository at this point in the history
remove it from tool project

add notebook

rename
  • Loading branch information
colombod committed Nov 20, 2023
1 parent 7047d36 commit d76e371
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 23 deletions.
30 changes: 30 additions & 0 deletions dotnet-interactive.sln
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Interactiv
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Interactive.AIUtilities.Tests", "src\Microsoft.DotNet.Interactive.AIUtilities.Tests\Microsoft.DotNet.Interactive.AIUtilities.Tests.csproj", "{B711649D-0397-4B2F-A367-8101823DE481}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Interactive.NamedPipeConnector", "src\Microsoft.DotNet.Interactive.NamedPipeConnector\Microsoft.DotNet.Interactive.NamedPipeConnector.csproj", "{BF68D266-500C-49AB-80EB-1B673E37E13A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Interactive.NamedPipeConnector.Tests", "src\Microsoft.DotNet.Interactive.NamedPipeConnector.Tests\Microsoft.DotNet.Interactive.NamedPipeConnector.Tests.csproj", "{B12834B8-373E-4932-852B-90E332A4BCED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -709,6 +713,30 @@ Global
{B711649D-0397-4B2F-A367-8101823DE481}.Release|x64.Build.0 = Release|Any CPU
{B711649D-0397-4B2F-A367-8101823DE481}.Release|x86.ActiveCfg = Release|Any CPU
{B711649D-0397-4B2F-A367-8101823DE481}.Release|x86.Build.0 = Release|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Debug|x64.ActiveCfg = Debug|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Debug|x64.Build.0 = Debug|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Debug|x86.ActiveCfg = Debug|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Debug|x86.Build.0 = Debug|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Release|Any CPU.Build.0 = Release|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Release|x64.ActiveCfg = Release|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Release|x64.Build.0 = Release|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Release|x86.ActiveCfg = Release|Any CPU
{BF68D266-500C-49AB-80EB-1B673E37E13A}.Release|x86.Build.0 = Release|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Debug|x64.ActiveCfg = Debug|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Debug|x64.Build.0 = Debug|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Debug|x86.ActiveCfg = Debug|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Debug|x86.Build.0 = Debug|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Release|Any CPU.Build.0 = Release|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Release|x64.ActiveCfg = Release|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Release|x64.Build.0 = Release|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Release|x86.ActiveCfg = Release|Any CPU
{B12834B8-373E-4932-852B-90E332A4BCED}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -762,6 +790,8 @@ Global
{DA0B3BFC-ED19-4754-A9A0-0F831DBCC9C4} = {B95A8485-8C53-4F56-B0CE-19C0726B5805}
{C874F96E-AC54-4AEF-A2E7-F6679378662A} = {B95A8485-8C53-4F56-B0CE-19C0726B5805}
{B711649D-0397-4B2F-A367-8101823DE481} = {11BA3480-4584-435C-BA9A-8C554DB60E9F}
{BF68D266-500C-49AB-80EB-1B673E37E13A} = {B95A8485-8C53-4F56-B0CE-19C0726B5805}
{B12834B8-373E-4932-852B-90E332A4BCED} = {11BA3480-4584-435C-BA9A-8C554DB60E9F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6D05A9AF-CFFB-4187-8599-574387B76727}
Expand Down
1 change: 1 addition & 0 deletions eng/publish/PublishVSCodeExtension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ try {
"Microsoft.DotNet.Interactive.Journey",
"Microsoft.DotNet.Interactive.Kql",
"Microsoft.DotNet.Interactive.Mermaid",
"Microsoft.DotNet.Interactive.NamedPipeConnector",
"Microsoft.DotNet.Interactive.PackageManagement",
"Microsoft.DotNet.Interactive.PowerShell",
"Microsoft.DotNet.Interactive.SQLite",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>

<PropertyGroup>
<UseBetaVersion>true</UseBetaVersion>
</PropertyGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<AssetTargetFallback>portable-net45+win8+wp8+wpa81</AssetTargetFallback>
<NoWarn>$(NoWarn);8002</NoWarn><!-- Assent isn't strongly signed -->
<NoWarn>$(NoWarn);CS8524</NoWarn><!-- The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. -->
<NoWarn>$(NoWarn);VSTHRD002</NoWarn><!-- Ignore: Avoid problematic synchronous waits -->
<NoWarn>$(NoWarn);VSTHRD003</NoWarn><!-- Ignore: Avoid awaiting foreign Tasks -->
<NoWarn>$(NoWarn);VSTHRD103</NoWarn><!-- Ignore: Call async methods when in an async method -->
<NoWarn>$(NoWarn);VSTHRD105</NoWarn><!-- Ignore: Avoid method overloads that assume TaskScheduler.Current -->
<NoWarn>$(NoWarn);VSTHRD110</NoWarn><!-- Ignore: Observe result of async calls -->
<NoWarn>$(NoWarn);VSTHRD200</NoWarn><!-- Ignore: Use "Async" suffix for async methods -->
<NoWarn>$(NoWarn);CS0219</NoWarn><!-- Ignore: The variable is assigned but its value is never used -->
</PropertyGroup>

<ItemGroup>
<Compile Remove="TestResults\**" />
<EmbeddedResource Remove="TestResults\**" />
<None Remove="TestResults\**" />
</ItemGroup>



<ItemGroup>
<PackageReference Include="Pocket.Disposable" Version="1.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PocketLogger" Version="0.8.2">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="PocketLogger.For.Xunit" Version="0.6.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="PocketLogger.Subscribe" Version="0.8.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\dotnet-interactive\dotnet-interactive.csproj" />
<ProjectReference Include="..\Microsoft.DotNet.Interactive.NamedPipeConnector\Microsoft.DotNet.Interactive.NamedPipeConnector.csproj" />
<ProjectReference Include="..\Microsoft.DotNet.Interactive.Tests\Microsoft.DotNet.Interactive.Tests.csproj" />
<ProjectReference Include="..\Microsoft.DotNet.Interactive\Microsoft.DotNet.Interactive.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="xunit.runner.visualstudio" Version="$(xunitrunnervisualstudioVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
using System.Diagnostics.CodeAnalysis;
using System.IO.Pipes;
using System.Threading.Tasks;
using FluentAssertions;

using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.Connection;
using Microsoft.DotNet.Interactive.CSharp;
using Microsoft.DotNet.Interactive.FSharp;
using Microsoft.DotNet.Interactive.Tests;

using Xunit;
using Xunit.Abstractions;

namespace Microsoft.DotNet.Interactive.Tests;
namespace Microsoft.DotNet.Interactive.NamedPipeConnectorConnector.Tests;

public class NamedPipeConnectionTests : ProxyKernelConnectionTestsBase
{
Expand All @@ -23,6 +26,18 @@ public NamedPipeConnectionTests(ITestOutputHelper output) : base(output)
{
}

[Fact]
public void connect_command_is_available_when_a_user_adds_a_kernel_connection_type()
{
using var compositeKernel = new CompositeKernel();

compositeKernel.AddKernelConnector(new ConnectNamedPipeCommand());

compositeKernel.Directives
.Should()
.Contain(c => c.Name == "#!connect");
}

protected override Func<string, Task<ProxyKernel>> CreateConnector()
{
CreateRemoteKernelTopology(_pipeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading.Tasks;
using Microsoft.DotNet.Interactive.Connection;

namespace Microsoft.DotNet.Interactive.Connection;
namespace Microsoft.DotNet.Interactive.NamedPipeConnectorConnector;

public class ConnectNamedPipeCommand : ConnectKernelCommand
{
Expand All @@ -15,6 +16,12 @@ public class ConnectNamedPipeCommand : ConnectKernelCommand
AddOption(PipeNameOption);
}

public static void AddToRootKernel()
{
var compositeKernel = Kernel.Root as CompositeKernel;
compositeKernel!.AddKernelConnector(new ConnectNamedPipeCommand());
}

public Option<string> PipeNameOption { get; } =
new("--pipe-name", "The name of the named pipe")
{
Expand All @@ -27,12 +34,12 @@ public override async Task<IEnumerable<Kernel>> ConnectKernelsAsync(
{
var pipeName = commandLineContext.ParseResult.GetValueForOption(PipeNameOption);

var connector = new NamedPipeKernelConnector(pipeName);
var connector = new NamedPipeKernelConnector(pipeName!);

var localName = commandLineContext.ParseResult.GetValueForOption(KernelNameOption);

var proxyKernel = await connector.CreateKernelAsync(localName);
var proxyKernel = await connector.CreateKernelAsync(localName!);

return new [] {proxyKernel};
return new Kernel[] {proxyKernel};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>

<PropertyGroup>
<UseBetaVersion>true</UseBetaVersion>
</PropertyGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<PackageId Condition="'$(PackageId)'==''">Microsoft.DotNet.Interactive.NamedPipeConnectorConnector</PackageId>
</PropertyGroup>

<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageDescription Condition="'$(PackageDescription)'==''">Extension that allows connecting via namedpaipes</PackageDescription>
<PackageTags Condition="'$(PackageTags)'==''">polyglot notebook dotnet interactive namedpipe</PackageTags>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.DotNet.Interactive\Microsoft.DotNet.Interactive.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="PocketLogger" Version="0.8.2">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<None Include="extension.dib" Pack="true" PackagePath="interactive-extensions/dotnet" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable enable

using System;
using System.IO.Pipes;
using System.Reactive.Disposables;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.DotNet.Interactive.Commands;
using CompositeDisposable = Pocket.CompositeDisposable;
using Microsoft.DotNet.Interactive.Connection;

#nullable enable

namespace Microsoft.DotNet.Interactive.Connection;
namespace Microsoft.DotNet.Interactive.NamedPipeConnectorConnector;

public class NamedPipeKernelConnector : IDisposable
{
private KernelCommandAndEventReceiver? _receiver;
private KernelCommandAndEventSender? _sender;
private NamedPipeClientStream? _clientStream;
private RefCountDisposable? _refCountDisposable = null;
private RefCountDisposable? _refCountDisposable;

public NamedPipeKernelConnector(string pipeName)
{
Expand All @@ -31,6 +31,7 @@ public NamedPipeKernelConnector(string pipeName)

public Uri RemoteHostUri { get; }


public async Task<ProxyKernel> CreateKernelAsync(string localName)
{
ProxyKernel? proxyKernel;
Expand All @@ -55,8 +56,8 @@ public async Task<ProxyKernel> CreateKernelAsync(string localName)

_refCountDisposable = new RefCountDisposable(new CompositeDisposable
{
() => _clientStream.Dispose(),
() => _receiver.Dispose()
Disposable.Create( () => _clientStream.Dispose()),
Disposable.Create( () => _receiver.Dispose())
});

proxyKernel = new ProxyKernel(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!csharp

Microsoft.DotNet.Interactive.NamedPipeConnector.ConnectNamedPipeCommand.AddToRootKernel();
10 changes: 0 additions & 10 deletions src/Microsoft.DotNet.Interactive.Tests/ConnectDirectiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,7 @@ public void connect_command_is_not_available_by_default()
.NotContain(c => c.Name == "#!connect");
}

[Fact]
public void connect_command_is_available_when_a_user_adds_a_kernel_connection_type()
{
using var compositeKernel = new CompositeKernel();

compositeKernel.AddKernelConnector(new ConnectNamedPipeCommand());

compositeKernel.Directives
.Should()
.Contain(c => c.Name == "#!connect");
}

[Fact]
public async Task When_a_kernel_is_connected_then_information_about_it_is_displayed()
Expand Down
1 change: 0 additions & 1 deletion src/dotnet-interactive/CommandLine/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ private static CompositeKernel CreateKernel(
.UseImportMagicCommand()
.UseNuGetExtensions(telemetrySender);

kernel.AddKernelConnector(new ConnectNamedPipeCommand());
kernel.AddKernelConnector(new ConnectSignalRCommand());
kernel.AddKernelConnector(new ConnectStdIoCommand(startupOptions.KernelHost));

Expand Down

0 comments on commit d76e371

Please sign in to comment.