Skip to content

Commit 3cf32ac

Browse files
committed
Merge remote-tracking branch 'remotes/origin/MagicCommandFixes' into v0.1.10-Pre
# Conflicts: # NuGet.config # notebooks/01_Introduction.ipynb # src/DwC-A_dotnet.Interactive/Commands/DwcaCodegenCommand.cs # src/DwC-A_dotnet.Interactive/Commands/TermsCommand.cs # src/DwC-A_dotnet.Interactive/DwC-A_dotnet.Interactive.csproj
2 parents 541fa44 + 6dfacf8 commit 3cf32ac

16 files changed

+144
-131
lines changed

NuGet.config

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<solution>
4-
<add key="disableSourceControlIntegration" value="true" />
5-
</solution>
63
<packageSources>
7-
8-
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
9-
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
10-
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
11-
<add key="dotnet-libraries" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json" />
12-
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
13-
<add key="MachineLearning" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/MachineLearning/nuget/v3/index.json" />
14-
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
4+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
155
</packageSources>
16-
<disabledPackageSources />
176
</configuration>

notebooks/01_Introduction.ipynb

Lines changed: 3 additions & 42 deletions
Large diffs are not rendered by default.

notebooks/06_DataMapping.ipynb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
"metadata": {
1919
"dotnet_interactive": {
2020
"language": "csharp"
21+
},
22+
"vscode": {
23+
"languageId": "dotnet-interactive.csharp"
2124
}
2225
},
2326
"outputs": [],
2427
"source": [
25-
"#r \"nuget:DwC-A_dotnet.Interactive,0.1.9-Pre\"\n",
28+
"#r \"nuget:DwC-A_dotnet.Interactive,0.1.10-Pre\"\n",
2629
"#r \"nuget:DwC-A_dotnet.Mapping,0.6.3\"\n",
2730
"#r \"nuget:Microsoft.ML\""
2831
]
@@ -52,6 +55,9 @@
5255
"metadata": {
5356
"dotnet_interactive": {
5457
"language": "csharp"
58+
},
59+
"vscode": {
60+
"languageId": "dotnet-interactive.csharp"
5561
}
5662
},
5763
"outputs": [],
@@ -85,6 +91,9 @@
8591
"metadata": {
8692
"dotnet_interactive": {
8793
"language": "csharp"
94+
},
95+
"vscode": {
96+
"languageId": "dotnet-interactive.csharp"
8897
}
8998
},
9099
"outputs": [],
@@ -108,6 +117,9 @@
108117
"metadata": {
109118
"dotnet_interactive": {
110119
"language": "csharp"
120+
},
121+
"vscode": {
122+
"languageId": "dotnet-interactive.csharp"
111123
}
112124
},
113125
"outputs": [],
@@ -136,6 +148,9 @@
136148
"metadata": {
137149
"dotnet_interactive": {
138150
"language": "csharp"
151+
},
152+
"vscode": {
153+
"languageId": "dotnet-interactive.csharp"
139154
}
140155
},
141156
"outputs": [],
@@ -186,6 +201,9 @@
186201
"metadata": {
187202
"dotnet_interactive": {
188203
"language": "csharp"
204+
},
205+
"vscode": {
206+
"languageId": "dotnet-interactive.csharp"
189207
}
190208
},
191209
"outputs": [],
@@ -199,6 +217,7 @@
199217
" m.Type = row[\"http://purl.org/dc/terms/type\"];\n",
200218
" m.Identifier = row[\"http://purl.org/dc/terms/identifier\"];\n",
201219
" m.Created = row.Convert<DateTime>(\"http://purl.org/dc/terms/created\");\n",
220+
" m.Creator = row[\"http://purl.org/dc/terms/creator\"];\n",
202221
"});\n",
203222
"\n",
204223
"archive.Extensions\n",
@@ -222,6 +241,9 @@
222241
"metadata": {
223242
"dotnet_interactive": {
224243
"language": "csharp"
244+
},
245+
"vscode": {
246+
"languageId": "dotnet-interactive.csharp"
225247
}
226248
},
227249
"outputs": [],

src/DwC-A_dotnet.Interactive/Commands/DwcaCodegenCommand.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,57 @@
33
using Core::DwC_A;
44
using DwC_A.Config;
55
using DwC_A.Generator;
6+
using DwC_A.Interactive.Extensions;
67
using DwC_A.Interactive.Mapping;
78
using Microsoft.DotNet.Interactive;
89
using Microsoft.DotNet.Interactive.Events;
9-
using Microsoft.DotNet.Interactive.ValueSharing;
1010
using System;
1111
using System.CommandLine;
1212
using System.IO;
1313
using System.Threading.Tasks;
1414

1515
namespace DwC_A.Interactive.Commands
1616
{
17-
internal static class DwcaCodegenCommandFactory
17+
internal class DwcaCodegenCommand : Command
1818
{
19-
public static Command Create()
19+
public DwcaCodegenCommand()
20+
: base("#!dwca-codegen", "Generate strongly typed class files for Darwin Core Archive")
2021
{
21-
var command = new Command("#!dwca-codegen", "Generate strongly typed class files for Darwin Core Archive");
22-
command.AddArgument(new Argument<string>()
22+
var archivePathArg = new Argument<string>()
2323
{
2424
Name = "archivePath",
2525
Description = "Path to archive folder or zip file"
26-
});
26+
};
27+
AddArgument(archivePathArg);
2728

28-
command.AddOption(new Option<string>(
29-
aliases: new[] {"-c", "--configName"},
29+
var cfgOption = new Option<string>(
30+
aliases: new[] { "-c", "--configName" },
3031
description: "Name of configuration variable",
3132
getDefaultValue: () => ""
32-
));
33+
);
34+
AddOption(cfgOption);
3335

34-
command.SetHandler((Func<KernelInvocationContext, string, string, Task>)(async (context, archivePath, configName) =>
36+
System.CommandLine.Handler.SetHandler(this,async (context) =>
3537
{
38+
var archivePath = context.ParseResult.GetValueForArgument(archivePathArg);
39+
var configName = context.ParseResult.GetValueForOption(cfgOption);
3640
var archive = new ArchiveReader(archivePath);
3741

38-
var csharpKernel = (ISupportGetValue)context.HandlingKernel.FindKernel("csharp");
39-
if (!csharpKernel.TryGetValue<IGeneratorConfiguration>(configName, out IGeneratorConfiguration config))
40-
{
41-
config = new GeneratorConfigurationBuilder().Build();
42-
}
43-
context.Display($"Opening archive {archive.FileName} using configuration", new[] { "text/html" });
44-
context.Display(config, new[] { "text/html" });
42+
var csharpKernel = KernelInvocationContext.Current.HandlingKernel.FindKernelByName("csharp");
43+
var (success, value) = await csharpKernel.TryRequestValueAsync(configName);
44+
IGeneratorConfiguration config = success ?
45+
value.Value as IGeneratorConfiguration :
46+
null ??
47+
new GeneratorConfigurationBuilder().Build();
48+
KernelInvocationContext.Current.Display($"Opening archive {archive.FileName} using configuration", new[] { "text/html" });
49+
KernelInvocationContext.Current.Display(config, new[] { "text/html" });
4550

46-
await DwcaCodegenCommandFactory.GenerateClass(context, archive.CoreFile, config);
47-
foreach(var extension in archive.Extensions.GetFileReaders())
51+
await GenerateClass(KernelInvocationContext.Current, archive.CoreFile, config);
52+
foreach (var extension in archive.Extensions.GetFileReaders())
4853
{
49-
await DwcaCodegenCommandFactory.GenerateClass(context, extension, config);
54+
await GenerateClass(KernelInvocationContext.Current, extension, config);
5055
}
51-
}));
52-
53-
return command;
56+
});
5457
}
5558

5659
private static async Task GenerateClass(KernelInvocationContext context,
@@ -59,7 +62,7 @@ private static async Task GenerateClass(KernelInvocationContext context,
5962
{
6063
var classGenerator = new ClassGenerator();
6164
var className = Path.GetFileNameWithoutExtension(fileReader.FileName);
62-
className = char.ToUpper(className[0]) + className.Substring(1);
65+
className = char.ToUpper(className[0]) + className[1..];
6366
context.Display($"Generating class {className}", new[] { "text/html" });
6467
var source = classGenerator.GenerateFile(fileReader.FileMetaData, config);
6568
var result = await context.HandlingKernel.SubmitCodeAsync(source);

src/DwC-A_dotnet.Interactive/Commands/TermsCommand.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44

55
namespace DwC_A.Interactive.Commands
66
{
7-
internal static class TermsCommandFactory
7+
internal class TermsCommand : Command
88
{
9-
public static Command Create()
9+
public TermsCommand() : base("#!terms", "Display Darwin Core standard terms")
1010
{
11-
var termsCmd = new Command("#!terms", "Display Darwin Core standard terms");
12-
termsCmd.SetHandler((KernelInvocationContext invocationContext) =>
11+
System.CommandLine.Handler.SetHandler(this, (invocationContext) =>
1312
{
1413
var defaultTerms = new DefaultTerms();
15-
invocationContext.Display(defaultTerms);
14+
KernelInvocationContext.Current.Display(defaultTerms);
1615
});
17-
return termsCmd;
1816
}
1917
}
2018
}

src/DwC-A_dotnet.Interactive/DwC-A_dotnet.Interactive.csproj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<RootNamespace>DwC_A.Interactive</RootNamespace>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Copyright>Copyright © Paul Joiner 2021</Copyright>
@@ -11,10 +11,10 @@
1111
<PackageTags>DwC-A darwin-core Biodiversity</PackageTags>
1212
<Authors>Paul Joiner</Authors>
1313
<Company>Paul Joiner</Company>
14-
<Version>0.1.12-Pre</Version>
14+
<Version>0.1.10-Pre</Version>
1515
<Description>.NET Interactive Extensions for Darwin Core Archive file reader</Description>
16-
<AssemblyVersion>0.1.12.0</AssemblyVersion>
17-
<FileVersion>0.1.12.0</FileVersion>
16+
<AssemblyVersion>0.1.10.0</AssemblyVersion>
17+
<FileVersion>0.1.10.0</FileVersion>
1818
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1919
<PackageReadmeFile>README.md</PackageReadmeFile>
2020
</PropertyGroup>
@@ -24,9 +24,8 @@
2424
<Aliases>Core</Aliases>
2525
</PackageReference>
2626
<PackageReference Include="DwC-A_dotnet.Mapping" Version="0.6.3" />
27-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
28-
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.22070.1" />
29-
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta3.22114.1" />
27+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
28+
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.22553.7" />
3029
</ItemGroup>
3130

3231
<ItemGroup>

src/DwC-A_dotnet.Interactive/DwCKernelExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public Task OnLoadAsync(Kernel kernel)
2222
Formatter.Register<IEnumerable<IRow>>(RowFormatter.Register, "text/html");
2323
Formatter.Register<IGeneratorConfiguration>(GeneratorConfigFormatter.Register, "text/html");
2424

25-
kernel.AddDirective(TermsCommandFactory.Create());
26-
kernel.AddDirective(DwcaCodegenCommandFactory.Create());
25+
kernel.AddDirective(new TermsCommand());
26+
kernel.AddDirective(new DwcaCodegenCommand());
2727

2828
return Task.CompletedTask;
2929
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.DotNet.Interactive;
2+
using Microsoft.DotNet.Interactive.Commands;
3+
using Microsoft.DotNet.Interactive.Events;
4+
using System.Linq;
5+
using System.Reactive.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace DwC_A.Interactive.Extensions
9+
{
10+
//Shamelessly copied from the dotnet.interactive test utilities.
11+
//See https://github.com/dotnet/interactive/blob/3c5637d513f0f3c406b449435b245e699f82a989/src/Microsoft.DotNet.Interactive.Tests/Utility/KernelExtensions.cs
12+
internal static class KernelExtensions
13+
{
14+
public static async Task<(bool success, ValueProduced valueProduced)> TryRequestValueAsync(this Kernel kernel, string valueName)
15+
{
16+
if (kernel.SupportsCommandType(typeof(RequestValue)))
17+
{
18+
var commandResult = await kernel.SendAsync(new RequestValue(valueName));
19+
20+
if (await commandResult.KernelEvents.OfType<ValueProduced>().FirstOrDefaultAsync() is { } valueProduced)
21+
{
22+
return (true, valueProduced);
23+
}
24+
}
25+
26+
return (false, default);
27+
}
28+
}
29+
}
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1-
using Xunit;
21
using DwC_A;
32
using DwC_A.Interactive.Formatters;
4-
using System.IO;
53

64
[assembly: CollectionBehavior(DisableTestParallelization = true)]
75

86
namespace UnitTests
97
{
10-
public class ArchiveReaderTests
8+
[UsesVerify]
9+
public class ArchiveReaderTests : IClassFixture<VerifyFixture>
1110
{
12-
string whalesArchive = "./Resources/whales";
11+
readonly string whalesArchive = "./Resources/whales";
1312

1413
[Fact]
15-
public void ShouldPrintArchiveMetaDataTable()
14+
public async Task ShouldPrintArchiveMetaDataTable()
1615
{
17-
var expected = File.ReadAllText("./Resources/html/archive.html");
18-
using (var archive = new ArchiveReader(whalesArchive))
19-
{
20-
using(var writer = new StringWriter())
21-
{
22-
ArchiveMetaData.Register(archive.MetaData, writer);
23-
var actual = writer.ToString();
24-
Assert.Equal(expected, actual);
25-
}
26-
}
16+
using var archive = new ArchiveReader(whalesArchive);
17+
using var writer = new StringWriter();
18+
ArchiveMetaData.Register(archive.MetaData, writer);
19+
var actual = writer.ToString();
20+
await Verify(actual);
2721
}
2822
}
2923
}
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
using DwC_A;
22
using DwC_A.Interactive.Formatters;
3-
using System.IO;
4-
using Xunit;
53

64
namespace UnitTests
75
{
8-
public class FileReaderMetaDataTests
6+
[UsesVerify]
7+
public class FileReaderMetaDataTests : IClassFixture<VerifyFixture>
98
{
10-
string whalesArchive = "./Resources/whales";
9+
readonly string whalesArchive = "./Resources/whales";
1110

1211
[Fact]
13-
public void ShouldPrintFileReaderTable()
12+
public async Task ShouldPrintFileReaderTable()
1413
{
15-
var expected = File.ReadAllText("./Resources/html/filereader.html");
16-
using (var archive = new ArchiveReader(whalesArchive))
17-
{
18-
using (var writer = new StringWriter())
19-
{
20-
FileReaderMetaData.Register(archive.CoreFile, writer);
21-
var actual = writer.ToString();
22-
Assert.Equal(expected, actual);
23-
}
24-
}
14+
using var archive = new ArchiveReader(whalesArchive);
15+
using var writer = new StringWriter();
16+
FileReaderMetaData.Register(archive.CoreFile, writer);
17+
var actual = writer.ToString();
18+
await Verify(actual);
2519
}
2620
}
2721
}

0 commit comments

Comments
 (0)