Remove usages of obsolete APIs
This commit is contained in:
parent
d995b0418a
commit
bfbd286ab6
|
|
@ -2,6 +2,9 @@
|
|||
// 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.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc.Razor.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages.Internal;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
|
|
@ -12,7 +15,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
|||
{
|
||||
public static class PageDirectiveFeature
|
||||
{
|
||||
private static readonly RazorEngine PageDirectiveEngine = RazorEngine.Create(builder =>
|
||||
private static readonly RazorProjectEngine PageDirectiveEngine = RazorProjectEngine.Create(RazorConfiguration.Default, new EmptyRazorProjectFileSystem(), builder =>
|
||||
{
|
||||
for (var i = builder.Phases.Count - 1; i >= 0; i--)
|
||||
{
|
||||
|
|
@ -35,24 +38,14 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
|||
throw new ArgumentNullException(nameof(projectItem));
|
||||
}
|
||||
|
||||
var sourceDocument = RazorSourceDocument.ReadFrom(projectItem);
|
||||
return TryGetPageDirective(logger, sourceDocument, out template);
|
||||
}
|
||||
|
||||
static bool TryGetPageDirective(
|
||||
ILogger logger,
|
||||
RazorSourceDocument sourceDocument,
|
||||
out string template)
|
||||
{
|
||||
var codeDocument = RazorCodeDocument.Create(sourceDocument);
|
||||
PageDirectiveEngine.Process(codeDocument);
|
||||
var codeDocument = PageDirectiveEngine.Process(projectItem);
|
||||
|
||||
var documentIRNode = codeDocument.GetDocumentIntermediateNode();
|
||||
if (PageDirective.TryGetPageDirective(documentIRNode, out var pageDirective))
|
||||
{
|
||||
if (pageDirective.DirectiveNode is MalformedDirectiveIntermediateNode malformedNode)
|
||||
{
|
||||
logger.MalformedPageDirective(sourceDocument.FilePath, malformedNode.Diagnostics);
|
||||
logger.MalformedPageDirective(projectItem.FilePath, malformedNode.Diagnostics);
|
||||
}
|
||||
|
||||
template = pageDirective.RouteTemplate;
|
||||
|
|
@ -72,5 +65,47 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
|||
options.ParseLeadingDirectives = true;
|
||||
}
|
||||
}
|
||||
|
||||
private class EmptyRazorProjectFileSystem : RazorProjectFileSystem
|
||||
{
|
||||
public override IEnumerable<RazorProjectItem> EnumerateItems(string basePath)
|
||||
{
|
||||
return Enumerable.Empty<RazorProjectItem>();
|
||||
}
|
||||
|
||||
public override IEnumerable<RazorProjectItem> FindHierarchicalItems(string basePath, string path, string fileName)
|
||||
{
|
||||
return Enumerable.Empty<RazorProjectItem>();
|
||||
}
|
||||
|
||||
public override RazorProjectItem GetItem(string path)
|
||||
{
|
||||
return new NotFoundProjectItem(string.Empty, path);
|
||||
}
|
||||
|
||||
private class NotFoundProjectItem : RazorProjectItem
|
||||
{
|
||||
public NotFoundProjectItem(string basePath, string path)
|
||||
{
|
||||
BasePath = basePath;
|
||||
FilePath = path;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string BasePath { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FilePath { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Exists => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string PhysicalPath => throw new NotSupportedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Stream Read() => throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
{
|
||||
// Arrange
|
||||
var viewPath = "/Views/Home/Index.cshtml";
|
||||
var razorEngine = RazorEngine.Create();
|
||||
|
||||
var fileSystem = new VirtualRazorProjectFileSystem();
|
||||
fileSystem.Add(new TestRazorProjectItem(viewPath, "<span name=\"@(User.Id\">"));
|
||||
|
||||
var razorEngine = RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine;
|
||||
|
||||
var templateEngine = new MvcRazorTemplateEngine(razorEngine, fileSystem);
|
||||
var codeDocument = templateEngine.CreateCodeDocument(viewPath);
|
||||
|
||||
|
|
@ -52,7 +53,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
var fileSystem = new VirtualRazorProjectFileSystem();
|
||||
fileSystem.Add(new TestRazorProjectItem(viewPath, "<span name=\"@(User.Id\">", physicalPath: physicalPath));
|
||||
|
||||
var razorEngine = RazorEngine.Create();
|
||||
var razorEngine = RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine;
|
||||
var templateEngine = new MvcRazorTemplateEngine(razorEngine, fileSystem);
|
||||
|
||||
var codeDocument = templateEngine.CreateCodeDocument(viewPath);
|
||||
|
|
@ -79,9 +80,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
}
|
||||
</span>";
|
||||
|
||||
var razorEngine = RazorEngine.Create();
|
||||
var fileSystem = new VirtualRazorProjectFileSystem();
|
||||
fileSystem.Add(new TestRazorProjectItem(viewPath, fileContent));
|
||||
|
||||
var razorEngine = RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine;
|
||||
var templateEngine = new MvcRazorTemplateEngine(razorEngine, fileSystem);
|
||||
|
||||
var codeDocument = templateEngine.CreateCodeDocument(viewPath);
|
||||
|
|
@ -108,7 +110,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
fileSystem.Add(new TestRazorProjectItem(viewPath, fileContent));
|
||||
fileSystem.Add(new TestRazorProjectItem("/Views/_MyImports.cshtml", importsContent));
|
||||
|
||||
var razorEngine = RazorEngine.Create();
|
||||
var razorEngine = RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine;
|
||||
var templateEngine = new MvcRazorTemplateEngine(razorEngine, fileSystem)
|
||||
{
|
||||
Options =
|
||||
|
|
|
|||
|
|
@ -26,9 +26,10 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
|||
.Returns(Mock.Of<IChangeToken>());
|
||||
var accessor = Mock.Of<IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider.Object);
|
||||
|
||||
var fileSystem = new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment);
|
||||
var templateEngine = new RazorTemplateEngine(
|
||||
RazorEngine.Create(),
|
||||
new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment));
|
||||
RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine,
|
||||
fileSystem);
|
||||
var options = Options.Create(new RazorPagesOptions());
|
||||
var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);
|
||||
|
||||
|
|
@ -50,9 +51,10 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
|||
.Returns(Mock.Of<IChangeToken>());
|
||||
var accessor = Mock.Of<IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider.Object);
|
||||
|
||||
var fileSystem = new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment);
|
||||
var templateEngine = new RazorTemplateEngine(
|
||||
RazorEngine.Create(),
|
||||
new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment));
|
||||
RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine,
|
||||
fileSystem);
|
||||
var options = Options.Create(new RazorPagesOptions());
|
||||
options.Value.RootDirectory = rootDirectory;
|
||||
|
||||
|
|
@ -74,9 +76,10 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
|||
.Returns(Mock.Of<IChangeToken>());
|
||||
var accessor = Mock.Of<IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider.Object);
|
||||
|
||||
var fileSystem = new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment);
|
||||
var templateEngine = new RazorTemplateEngine(
|
||||
RazorEngine.Create(),
|
||||
new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment));
|
||||
RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine,
|
||||
fileSystem);
|
||||
var options = Options.Create(new RazorPagesOptions { AllowAreas = true });
|
||||
var changeProvider = new PageActionDescriptorChangeProvider(templateEngine, accessor, options);
|
||||
|
||||
|
|
@ -94,9 +97,10 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
|||
var fileProvider = new TestFileProvider();
|
||||
var accessor = Mock.Of<IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);
|
||||
|
||||
var fileSystem = new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment);
|
||||
var templateEngine = new RazorTemplateEngine(
|
||||
RazorEngine.Create(),
|
||||
new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment));
|
||||
RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine,
|
||||
fileSystem);
|
||||
templateEngine.Options.ImportsFileName = "_ViewImports.cshtml";
|
||||
var options = Options.Create(new RazorPagesOptions());
|
||||
options.Value.RootDirectory = "/dir1/dir2";
|
||||
|
|
@ -118,9 +122,10 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
|||
var fileProvider = new TestFileProvider();
|
||||
var accessor = Mock.Of<IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);
|
||||
|
||||
var fileSystem = new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment);
|
||||
var templateEngine = new RazorTemplateEngine(
|
||||
RazorEngine.Create(),
|
||||
new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment));
|
||||
RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine,
|
||||
fileSystem);
|
||||
templateEngine.Options.ImportsFileName = "_ViewImports.cshtml";
|
||||
var options = Options.Create(new RazorPagesOptions());
|
||||
options.Value.RootDirectory = "/dir1/dir2";
|
||||
|
|
@ -144,9 +149,10 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
|||
var fileProvider = new TestFileProvider();
|
||||
var accessor = Mock.Of<IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);
|
||||
|
||||
var fileSystem = new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment);
|
||||
var templateEngine = new RazorTemplateEngine(
|
||||
RazorEngine.Create(),
|
||||
new FileProviderRazorProjectFileSystem(accessor, _hostingEnvironment));
|
||||
RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem).Engine,
|
||||
fileSystem);
|
||||
templateEngine.Options.ImportsFileName = "_ViewImports.cshtml";
|
||||
var options = Options.Create(new RazorPagesOptions { AllowAreas = false });
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue