这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
420f1a5
Move the directory accessor below in the dependency graph
akshita31 Aug 27, 2019
4882760
Moe adding usings for moved stuff
akshita31 Aug 27, 2019
d95faaf
Use .Roslyn suffix
akshita31 Aug 27, 2019
7830ed8
Add the unit classes and the tests
akshita31 Aug 27, 2019
5e324b8
Use the load assembly from the handleLoadExtension
akshita31 Aug 27, 2019
250ca23
add the command for loading the c# extension
akshita31 Aug 28, 2019
1146d66
call the loadfromnugetpackage
akshita31 Aug 28, 2019
28186e3
add something
akshita31 Aug 28, 2019
5c94058
tests are passing
akshita31 Aug 29, 2019
77b3eee
add tools references
akshita31 Aug 29, 2019
1a46dca
Add various classes to do specific stuff
akshita31 Aug 29, 2019
4fac550
use tryget pattern
akshita31 Aug 29, 2019
0d3882f
Fix failing nuget package adding test
akshita31 Aug 29, 2019
6cdffe6
Fix another failing test
akshita31 Aug 29, 2019
e398066
add a test for loading the extneion in a nuget package
akshita31 Aug 29, 2019
93f65e4
Add null checks and rename
akshita31 Aug 30, 2019
c102080
All tests passing
akshita31 Aug 30, 2019
48382d3
Refactor to get the createExtension functionality in one place
akshita31 Aug 30, 2019
bfdbc1f
use random file name for the extension
akshita31 Aug 30, 2019
6348524
Use the name of the class to randomise
akshita31 Aug 30, 2019
d848153
check if extensionloaded event is produced
akshita31 Aug 30, 2019
78cfa3d
add null check
akshita31 Aug 30, 2019
6652f25
Use pattern match
akshita31 Aug 30, 2019
37b137a
Each kernel should define its implementation for loading the kernels
akshita31 Aug 30, 2019
39f8dc4
clean up
akshita31 Aug 30, 2019
759fd84
PR feedback
akshita31 Sep 3, 2019
afc4505
Use Microsoft.Extensions.Logging
akshita31 Sep 3, 2019
ec7b101
remove next call
akshita31 Sep 3, 2019
626f6ba
add null check and do not call next
akshita31 Sep 3, 2019
0c4c9ee
Rename method and clean up
akshita31 Sep 3, 2019
4759b66
add bracket
akshita31 Sep 3, 2019
4bed9c7
Check if it is an interface
akshita31 Sep 3, 2019
a94e294
simplify the call
akshita31 Sep 3, 2019
a0c25a2
use the correct path --> interactive-extensions/dotnet/cs
akshita31 Sep 3, 2019
7264096
merge
akshita31 Sep 3, 2019
4812f7f
Use extension method for canbeinstantiated
akshita31 Sep 4, 2019
c9eed93
only use can be instantiated
akshita31 Sep 4, 2019
7c9cca2
Handle if exception is thrown on load of the extension
akshita31 Sep 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MLS.Agent.Tools.Tests/InMemoryDirectoryAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public IEnumerable<RelativeFilePath> GetAllFiles()
{
return _files.Keys
.OfType<FileInfo>()
.Where(key => key.Directory.FullName == WorkingDirectory.FullName)
.Where(key => FileSystemInfoComparer.Instance.Equals(key.Directory, WorkingDirectory))
.Select(key => new RelativeFilePath(
Path.GetRelativePath(WorkingDirectory.FullName, key.FullName)));
}
Expand Down
11 changes: 11 additions & 0 deletions MLS.Agent.Tools/DirectoryAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ public static bool DirectoryExists(
string relativePath) =>
directoryAccessor.DirectoryExists(new RelativeDirectoryPath(relativePath));

public static bool RootDirectoryExists(
this IDirectoryAccessor directoryAccessor) =>
directoryAccessor.DirectoryExists(new RelativeDirectoryPath("."));

public static void EnsureDirectoryExists(
this IDirectoryAccessor directoryAccessor,
string relativePath) =>
directoryAccessor.EnsureDirectoryExists(new RelativeDirectoryPath(relativePath));

public static void EnsureRootDirectoryExists(
this IDirectoryAccessor directoryAccessor) =>
directoryAccessor.EnsureDirectoryExists(new RelativeDirectoryPath("."));

public static bool FileExists(
this IDirectoryAccessor directoryAccessor,
string relativePath) =>
Expand Down Expand Up @@ -57,5 +65,8 @@ public static FileInfo GetFullyQualifiedFilePath(this IDirectoryAccessor directo

public static FileInfo GetFullyQualifiedFilePath(this IDirectoryAccessor directoryAccessor, RelativeFilePath relativePath) =>
(FileInfo) directoryAccessor.GetFullyQualifiedPath(relativePath);

public static DirectoryInfo GetFullyQualifiedDirectoryPath(this IDirectoryAccessor directoryAccessor, RelativeDirectoryPath relativePath) =>
(DirectoryInfo)directoryAccessor.GetFullyQualifiedPath(relativePath);
}
}
24 changes: 22 additions & 2 deletions MLS.Agent.Tools/PathUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

// adapted from http://source.roslyn.io/#System.Reflection.Metadata/System/Reflection/Internal/Utilities/PathUtilities.cs,36b27d7696df4d1e

Expand Down Expand Up @@ -511,6 +512,11 @@ public static string GetRelativePath(string directory, string fullPath)
return GetRelativeChildPath(directory, fullPath);
}

if (IsChildPath(fullPath, directory))
{
return GetRelativeParentPath(directory, fullPath);
}

var directoryPathParts = GetPathParts(directory);
var fullPathParts = GetPathParts(fullPath);

Expand Down Expand Up @@ -556,6 +562,20 @@ public static string GetRelativePath(string directory, string fullPath)
return relativePath;
}

private static string GetRelativeParentPath(string childPath, string parentPath)
{
var childPathParts = GetPathParts(childPath);
var parentPathParts = GetPathParts(parentPath);

var relativePath = new StringBuilder();
for (int i = 0; i < childPathParts.Length - parentPathParts.Length; i++)
{
relativePath.Append(ParentRelativeDirectory + DirectorySeparatorStr);
}

return relativePath.ToString();
}

/// <summary>
/// True if the child path is a child of the parent path.
/// </summary>
Expand Down Expand Up @@ -585,15 +605,15 @@ private static string GetRelativeChildPath(string parentPath, string childPath)

private static string[] GetPathParts(string path)
{
var pathParts = path.Split(s_pathChars);
var pathParts = path.Split(s_pathChars).Where(p => !string.IsNullOrWhiteSpace(p));

// remove references to self directories ('.')
if (pathParts.Contains(ThisDirectory))
{
pathParts = pathParts.Where(s => s != ThisDirectory).ToArray();
}

return pathParts;
return pathParts.ToArray();
}

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions MLS.Agent.Tools/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@ public static string ReadManifestResource(this Type type, string resourceName)
return reader.ReadToEnd();
}
}

public static bool CanBeInstantiated(this Type type)
{
return !type.IsAbstract
&& !type.IsGenericTypeDefinition
&& !type.IsInterface;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.DotNet.Interactive\Microsoft.DotNet.Interactive.csproj" />
<ProjectReference Include="..\MLS.Agent.Tools.Tests\MLS.Agent.Tools.Tests.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.2.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Xunit;
using MLS.Agent.Tools;
using Microsoft.DotNet.Interactive;
using FluentAssertions;
using System.Linq;
using MLS.Agent.Tools.Tests;
using System.IO;
using System.Runtime.InteropServices.ComTypes;
using System.ComponentModel.DataAnnotations;

namespace Microsoft.DotNet.Interactive.Tests
{
public class NuGetPackagePathResolverTests
{
[Fact]
public void Can_find_path_of_nuget_package()
{
var firstPackageRef = new NugetPackageReference("first", "2.0.0");
var secondPackageRef = new NugetPackageReference("second", "3.0.0");
var directory = new InMemoryDirectoryAccessor()
{
($"{firstPackageRef.PackageName}/{firstPackageRef.PackageVersion}/lib/netstandard2.0/{firstPackageRef.PackageName}.dll", ""),
($"{secondPackageRef.PackageName}/{secondPackageRef.PackageVersion}/lib/netstandard2.0/{secondPackageRef.PackageName}.dll", "")
};

NuGetPackagePathResolver.TryGetNuGetPackageBasePath(firstPackageRef, directory.GetAllFilesRecursively().Select(file => directory.GetFullyQualifiedFilePath(file)), out var nugetPackageDirectory);

nugetPackageDirectory.GetFullyQualifiedRoot().FullName.Should().Be(directory.GetFullyQualifiedPath(new RelativeDirectoryPath($"{firstPackageRef.PackageName}/{firstPackageRef.PackageVersion}")).FullName);
}
}
}
6 changes: 2 additions & 4 deletions Microsoft.DotNet.Interactive/CommandDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Reflection;
using Microsoft.DotNet.Interactive.Commands;
using MLS.Agent.Tools;
using Newtonsoft.Json.Linq;

namespace Microsoft.DotNet.Interactive
Expand All @@ -19,10 +20,7 @@ public CommandDeserializer()
_map = Assembly
.GetExecutingAssembly()
.GetTypes()
.Where(t => typeof(IKernelCommand).IsAssignableFrom(t)
&& !t.IsAbstract
&& !t.IsGenericTypeDefinition
&& !t.IsInterface)
.Where(t => t.CanBeInstantiated() && (typeof(IKernelCommand).IsAssignableFrom(t)))
.ToDictionary(t => t.Name, t => t, StringComparer.InvariantCultureIgnoreCase);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

namespace Microsoft.DotNet.Interactive.Commands
{
public class LoadExtensionFromNuGetPackage : KernelCommandBase
{
public LoadExtensionFromNuGetPackage(NugetPackageReference nugetPackageReference, IEnumerable<FileInfo> metadataReferences)
{
NugetPackageReference = nugetPackageReference ?? throw new ArgumentNullException(nameof(nugetPackageReference));
MetadataReferences = metadataReferences ?? throw new ArgumentNullException(nameof(metadataReferences));
}

public NugetPackageReference NugetPackageReference { get; }
public IEnumerable<FileInfo> MetadataReferences { get; }
}
}
18 changes: 0 additions & 18 deletions Microsoft.DotNet.Interactive/Events/ExtensionLoading.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.

using Microsoft.DotNet.Interactive.Commands;

namespace Microsoft.DotNet.Interactive.Events
{
public class KernelExtensionLoadException : KernelEventBase
{
public KernelExtensionLoadException(string message)
{
Message = message ?? throw new System.ArgumentNullException(nameof(message));
}

public string Message { get; }

public override string ToString() => $"{base.ToString()}: {Message}";
}
}
9 changes: 8 additions & 1 deletion Microsoft.DotNet.Interactive/Events/NuGetPackageAdded.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// 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.

using Microsoft.DotNet.Interactive.Commands;

namespace Microsoft.DotNet.Interactive.Events
{
public class NuGetPackageAdded : KernelEventBase
{
public NuGetPackageAdded(NugetPackageReference packageReference)
public NuGetPackageAdded(AddNugetPackage addNugetPackage, NugetPackageReference packageReference): base(addNugetPackage)
{
if (addNugetPackage == null)
{
throw new System.ArgumentNullException(nameof(addNugetPackage));
}

PackageReference = packageReference;
}

Expand Down
19 changes: 19 additions & 0 deletions Microsoft.DotNet.Interactive/ExtensionLoaded.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.

using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.Events;
using System.IO;

namespace Microsoft.DotNet.Interactive
{
public class ExtensionLoaded : KernelEventBase
{
public ExtensionLoaded(FileInfo extensionPath)
{
ExtensionPath = extensionPath ?? throw new System.ArgumentNullException(nameof(extensionPath));
}

public FileInfo ExtensionPath { get; }
}
}
13 changes: 13 additions & 0 deletions Microsoft.DotNet.Interactive/IExtensibleKernel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

using MLS.Agent.Tools;
using System.Threading.Tasks;

namespace Microsoft.DotNet.Interactive
{
public interface IExtensibleKernel
{
public Task LoadExtensionsInDirectory(IDirectoryAccessor directory, KernelInvocationContext invocationContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will there always be an invocation context? What about extensions that we want to load on startup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to "Publish" an event saying that the extension has been loaded and we need the context for that. If we would like to load extensions at startup, how would we "Publish" that event if we dont have the KernelInvocationContext ?

I think once we have that scenario, it would not be a hard change to make this method maybe return a list of extensions that it loaded(so that it can be called at startup) and then the caller can do whatever necessary. Thoughts ?

}
}
1 change: 1 addition & 0 deletions Microsoft.DotNet.Interactive/IKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.Events;
using MLS.Agent.Tools;

namespace Microsoft.DotNet.Interactive
{
Expand Down
Loading