Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Commit

Permalink
Remove DesignTimeHost dependency.
Browse files Browse the repository at this point in the history
- 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
NTaylorMullen committed Dec 9, 2015
1 parent 9987905 commit 3b920e0
Show file tree
Hide file tree
Showing 21 changed files with 298 additions and 697 deletions.
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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System;
using Microsoft.Dnx.Runtime.Common.CommandLine;

namespace Microsoft.AspNet.Tooling.Razor
namespace Microsoft.AspNet.Tooling.Razor.Internal
{
internal static class ResolveProtocolCommand
public static class ResolveProtocolCommand
{
public static void Register(CommandLineApplication app)
internal static void Register(CommandLineApplication app)
{
app.Command("resolve-protocol", config =>
{
Expand All @@ -20,7 +20,7 @@ public static void Register(CommandLineApplication app)
config.OnExecute(() =>
{
var pluginProtocol = new RazorPlugin(messageBroker: null).Protocol;
var pluginProtocol = new AssemblyTagHelperDescriptorResolver().Protocol;
var clientProtocolString = clientProtocolArgument.Value;
var clientProtocol = int.Parse(clientProtocolString);
var resolvedProtocol = ResolveProtocol(clientProtocol, pluginProtocol);
Expand All @@ -35,7 +35,7 @@ public static void Register(CommandLineApplication app)
/// <summary>
/// Internal for testing.
/// </summary>
internal static int ResolveProtocol(int clientProtocol, int pluginProtocol)
public static int ResolveProtocol(int clientProtocol, int pluginProtocol)
{
// Protocols start at 1 and increase.
clientProtocol = Math.Max(1, clientProtocol);
Expand Down
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; }
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions src/Microsoft.AspNet.Tooling.Razor/Models/RazorPluginMessage.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/Microsoft.AspNet.Tooling.Razor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

using System;
using System.Reflection;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.AspNet.Tooling.Razor.Internal;
using Microsoft.Dnx.Runtime.Common.CommandLine;
using Microsoft.Extensions.PlatformAbstractions;

namespace Microsoft.AspNet.Tooling.Razor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
using System.Resources;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Microsoft.AspNet.Tooling.Razor.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: NeutralResourcesLanguage("en-us")]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 0 additions & 109 deletions src/Microsoft.AspNet.Tooling.Razor/RazorPlugin.cs

This file was deleted.

Loading

0 comments on commit 3b920e0

Please sign in to comment.