This repository has been archived by the owner on Feb 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- This resulted in us decoupling ourselves from the `IPlugin` interface. It's going away. - Redesigned the `TagHelperDescriptor` resolver to be a glorified factory with a protocol. It used to serialize/deserialize messages as input because it was an `IPlugin`. #25
- Loading branch information
1 parent
9987905
commit 3b920e0
Showing
21 changed files
with
298 additions
and
697 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/Microsoft.AspNet.Tooling.Razor/AssemblyTagHelperDescriptorResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.AspNet.Razor; | ||
using Microsoft.AspNet.Razor.Compilation.TagHelpers; | ||
using Microsoft.AspNet.Razor.Runtime.TagHelpers; | ||
using Microsoft.Extensions.PlatformAbstractions; | ||
|
||
namespace Microsoft.AspNet.Tooling.Razor | ||
{ | ||
public class AssemblyTagHelperDescriptorResolver | ||
{ | ||
public int Protocol { get; set; } = 1; | ||
|
||
public IEnumerable<TagHelperDescriptor> Resolve( | ||
string assemblyName, | ||
IAssemblyLoadContext assemblyLoadContext, | ||
ErrorSink errorSink) | ||
{ | ||
if (assemblyName == null) | ||
{ | ||
throw new ArgumentNullException(nameof(assemblyName)); | ||
} | ||
|
||
if (assemblyLoadContext == null) | ||
{ | ||
throw new ArgumentNullException(nameof(assemblyLoadContext)); | ||
} | ||
|
||
if (Protocol == 1) | ||
{ | ||
var tagHelperTypeResolver = new AssemblyLoadContextTagHelperTypeResolver(assemblyLoadContext); | ||
var tagHelperTypes = tagHelperTypeResolver.Resolve(assemblyName, SourceLocation.Zero, errorSink); | ||
var tagHelperDescriptors = tagHelperTypes.SelectMany( | ||
type => TagHelperDescriptorFactory.CreateDescriptors( | ||
assemblyName, | ||
type, | ||
designTime: true, | ||
errorSink: errorSink)); | ||
|
||
return tagHelperDescriptors; | ||
} | ||
else | ||
{ | ||
// Unknown protocol | ||
throw new InvalidOperationException( | ||
Resources.FormatInvalidProtocolValue(typeof(TagHelperDescriptor).FullName, Protocol)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/Microsoft.AspNet.Tooling.Razor/Internal/ResolveTagHelpersCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.AspNet.Razor; | ||
using Microsoft.AspNet.Razor.Compilation.TagHelpers; | ||
using Microsoft.Dnx.Runtime.Common.CommandLine; | ||
using Microsoft.Extensions.PlatformAbstractions; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.AspNet.Tooling.Razor.Internal | ||
{ | ||
public static class ResolveTagHelpersCommand | ||
{ | ||
internal static void Register(CommandLineApplication app, IAssemblyLoadContext assemblyLoadContext) | ||
{ | ||
app.Command("resolve-taghelpers", config => | ||
{ | ||
config.Description = "Resolves TagHelperDescriptors in the specified assembly(s)."; | ||
config.HelpOption("-?|-h|--help"); | ||
var protocolOption = config.Option( | ||
"-p|--protocol", | ||
"Protocol to resolve TagHelperDescriptors with.", | ||
CommandOptionType.SingleValue); | ||
var assemblyNames = config.Argument( | ||
"[name]", | ||
"Assembly name to resolve TagHelperDescriptors in.", | ||
multipleValues: true); | ||
config.OnExecute(() => | ||
{ | ||
var protocol = int.Parse(protocolOption.Value()); | ||
var descriptorResolver = new AssemblyTagHelperDescriptorResolver | ||
{ | ||
Protocol = protocol | ||
}; | ||
var errorSink = new ErrorSink(); | ||
var resolvedDescriptors = new List<TagHelperDescriptor>(); | ||
for (var i = 0; i < assemblyNames.Values.Count; i++) | ||
{ | ||
var assemblyName = assemblyNames.Values[i]; | ||
var descriptors = descriptorResolver.Resolve(assemblyName, assemblyLoadContext, errorSink); | ||
resolvedDescriptors.AddRange(descriptors); | ||
} | ||
var resolvedResult = new ResolvedTagHelperDescriptorsResult | ||
{ | ||
Descriptors = resolvedDescriptors, | ||
Errors = errorSink.Errors | ||
}; | ||
var serializedResult = JsonConvert.SerializeObject(resolvedResult, Formatting.Indented); | ||
Console.WriteLine(serializedResult); | ||
return errorSink.Errors.Any() ? 1 : 0; | ||
}); | ||
}); | ||
} | ||
|
||
private class ResolvedTagHelperDescriptorsResult | ||
{ | ||
public IEnumerable<TagHelperDescriptor> Descriptors { get; set; } | ||
|
||
public IEnumerable<RazorError> Errors { get; set; } | ||
} | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
src/Microsoft.AspNet.Tooling.Razor/Models/IncomingMessages/RazorPluginRequestMessage.cs
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
...ft.AspNet.Tooling.Razor/Models/IncomingMessages/ResolveTagHelperDescriptorsRequestData.cs
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
...rosoft.AspNet.Tooling.Razor/Models/OutgoingMessages/ResolveTagHelperDescriptorsMessage.cs
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
...t.AspNet.Tooling.Razor/Models/OutgoingMessages/ResolveTagHelperDescriptorsResponseData.cs
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
src/Microsoft.AspNet.Tooling.Razor/Models/RazorPluginMessage.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/Microsoft.AspNet.Tooling.Razor/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.