viewStartPages)
{
var razorTextWriter = new RazorTextWriter(context.Writer, context.Writer.Encoding, _htmlEncoder);
- var writer = (TextWriter)razorTextWriter;
- var bufferedWriter = (IBufferedTextWriter)razorTextWriter;
-
- if (EnableInstrumentation)
- {
- writer = _pageExecutionFeature.DecorateWriter(razorTextWriter);
- bufferedWriter = writer as IBufferedTextWriter;
- if (bufferedWriter == null)
- {
- var message = Resources.FormatInstrumentation_WriterMustBeBufferedTextWriter(
- nameof(TextWriter),
- _pageExecutionFeature.GetType().FullName,
- typeof(IBufferedTextWriter).FullName);
- throw new InvalidOperationException(message);
- }
- }
// The writer for the body is passed through the ViewContext, allowing things like HtmlHelpers
// and ViewComponents to reference it.
var oldWriter = context.Writer;
var oldFilePath = context.ExecutingFilePath;
- context.Writer = writer;
+ context.Writer = razorTextWriter;
context.ExecutingFilePath = page.Path;
try
@@ -147,24 +120,19 @@ namespace Microsoft.AspNet.Mvc.Razor
}
await RenderPageCoreAsync(page, context);
- return bufferedWriter;
+ return razorTextWriter;
}
finally
{
context.Writer = oldWriter;
context.ExecutingFilePath = oldFilePath;
- writer.Dispose();
+ razorTextWriter.Dispose();
}
}
private Task RenderPageCoreAsync(IRazorPage page, ViewContext context)
{
page.ViewContext = context;
- if (EnableInstrumentation)
- {
- page.PageExecutionContext = _pageExecutionFeature.GetContext(page.Path, context.Writer);
- }
-
_pageActivator.Activate(page, context);
return page.ExecuteAsync();
}
@@ -201,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.Razor
private async Task RenderLayoutAsync(
ViewContext context,
- IBufferedTextWriter bodyWriter)
+ RazorTextWriter bodyWriter)
{
// A layout page can specify another layout page. We'll need to continue
// looking for layout pages until they're no longer specified.
diff --git a/src/Microsoft.AspNet.Mvc.Razor/project.json b/src/Microsoft.AspNet.Mvc.Razor/project.json
index 2024a158b6..0d951debbe 100644
--- a/src/Microsoft.AspNet.Mvc.Razor/project.json
+++ b/src/Microsoft.AspNet.Mvc.Razor/project.json
@@ -13,7 +13,6 @@
"Microsoft.AspNet.Mvc.Razor.Host": "6.0.0-*",
"Microsoft.AspNet.Mvc.ViewFeatures": "6.0.0-*",
"Microsoft.AspNet.Razor.Runtime.Precompilation": "4.0.0-*",
- "Microsoft.AspNet.PageExecutionInstrumentation.Interfaces": "1.0.0-*",
"Microsoft.Extensions.HashCodeCombiner.Sources": {
"version": "1.0.0-*",
"type": "build"
diff --git a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/IBufferedTextWriter.cs b/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/IBufferedTextWriter.cs
deleted file mode 100644
index be0b32ab7b..0000000000
--- a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/IBufferedTextWriter.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-// 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.IO;
-using System.Threading.Tasks;
-
-namespace Microsoft.AspNet.Mvc.Razor
-{
- ///
- /// Specifies the contracts for a that buffers its content.
- ///
- public interface IBufferedTextWriter
- {
- ///
- /// Gets a flag that determines if content is currently being buffered.
- ///
- bool IsBuffering { get; }
-
- ///
- /// Copies the buffered content to the .
- ///
- /// The to copy the contents to.
- void CopyTo(TextWriter writer);
-
- ///
- /// Asynchronously copies the buffered content to the .
- ///
- /// The to copy the contents to.
- /// A representing the copy operation.
- Task CopyToAsync(TextWriter writer);
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/IPageExecutionContext.cs b/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/IPageExecutionContext.cs
deleted file mode 100644
index 9df196152d..0000000000
--- a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/IPageExecutionContext.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-// 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.
-
-namespace Microsoft.AspNet.PageExecutionInstrumentation
-{
- ///
- /// Specifies the contracts for a execution context that instruments web page execution.
- ///
- public interface IPageExecutionContext
- {
- ///
- /// Invoked at the start of a write operation.
- ///
- /// The absolute character position of the expression or text in the Razor file.
- /// The character length of the expression or text in the Razor file.
- /// A flag that indicates if the operation is for a literal text and not for a
- /// language expression.
- void BeginContext(int position, int length, bool isLiteral);
-
- ///
- /// Invoked at the end of a write operation.
- ///
- void EndContext();
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/IPageExecutionListenerFeature.cs b/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/IPageExecutionListenerFeature.cs
deleted file mode 100644
index 6cf9fe147a..0000000000
--- a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/IPageExecutionListenerFeature.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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.IO;
-
-namespace Microsoft.AspNet.PageExecutionInstrumentation
-{
- ///
- /// Specifies the contracts for a HTTP feature that provides the context to instrument a web page.
- ///
- public interface IPageExecutionListenerFeature
- {
- ///
- /// Decorates the used by web page instances to
- /// write the result to.
- ///
- /// The output for the web page.
- /// A that wraps .
- TextWriter DecorateWriter(TextWriter writer);
-
- ///
- /// Creates a for the specified .
- ///
- /// The path of the page.
- /// The obtained from .
- ///
- /// The .
- IPageExecutionContext GetContext(string sourceFilePath, TextWriter writer);
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces.xproj b/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces.xproj
deleted file mode 100644
index 8311f5fa73..0000000000
--- a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces.xproj
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
- 14.0
- $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
-
-
-
- 4da2d7c1-a7b6-4c01-b57d-89e6ea4609de
- ..\..\artifacts\obj\$(MSBuildProjectName)
- ..\..\artifacts\bin\$(MSBuildProjectName)\
-
-
- 2.0
-
-
-
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/Properties/AssemblyInfo.cs
deleted file mode 100644
index b2437d9ad6..0000000000
--- a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-// 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.Reflection;
-using System.Resources;
-
-[assembly: AssemblyMetadata("Serviceable", "True")]
-[assembly: NeutralResourcesLanguage("en-us")]
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/project.json b/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/project.json
deleted file mode 100644
index b204a52a67..0000000000
--- a/src/Microsoft.AspNet.PageExecutionInstrumentation.Interfaces/project.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
- "description": "Abstractions for page instrumentation.",
- "version": "1.0.0-*",
- "repository": {
- "type": "git",
- "url": "git://github.com/aspnet/mvc"
- },
- "compilationOptions": {
- "warningsAsErrors": true,
- "keyFile": "../../tools/Key.snk"
- },
- "frameworks": {
- "net451": {},
- "dotnet5.4": {
- "dependencies": {
- "System.IO": "4.0.11-*",
- "System.Resources.ResourceManager": "4.0.1-*"
- }
- }
- }
-}
diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/RazorPageExecutionInstrumentationWebSite.Home.ViewWithPartial.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/RazorPageExecutionInstrumentationWebSite.Home.ViewWithPartial.html
index 061fd827a1..81cbd4fb84 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/RazorPageExecutionInstrumentationWebSite.Home.ViewWithPartial.html
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/RazorPageExecutionInstrumentationWebSite.Home.ViewWithPartial.html
@@ -1,27 +1,20 @@
-
-2147483647
-viewstart-content
-view-with-partial-content
-
partial-content
-
partial-content
-
- /Views/_ViewStart.cshtml: Non-literal at 96 contains 16 characters.
- /Views/_ViewStart.cshtml: Literal at 112 contains 2 characters.
- /Views/Home/ViewWithPartial.cshtml: Literal at 0 contains 27 characters.
- /Views/Home/ViewWithPartial.cshtml: Non-literal at 28 contains 39 characters.
- /Views/Home/_PartialView.cshtml: Literal at 31 contains 2 characters.
- /Views/Home/_PartialView.cshtml: Literal at 33 contains 8 characters.
- /Views/Home/_PartialView.cshtml: Non-literal at 41 contains 4 characters.
- /Views/Home/_PartialView.cshtml: Literal at 45 contains 1 characters.
- /Views/Home/_PartialView.cshtml: Literal at 46 contains 20 characters.
- /Views/Home/_PartialView.cshtml: Literal at 67 contains 2 characters.
- /Views/Home/_PartialView.cshtml: Literal at 31 contains 2 characters.
- /Views/Home/_PartialView.cshtml: Literal at 33 contains 8 characters.
- /Views/Home/_PartialView.cshtml: Non-literal at 41 contains 4 characters.
- /Views/Home/_PartialView.cshtml: Literal at 45 contains 1 characters.
- /Views/Home/_PartialView.cshtml: Literal at 46 contains 20 characters.
- /Views/_Layout.cshtml: Literal at 82 contains 7 characters.
- /Views/_Layout.cshtml: Non-literal at 90 contains 12 characters.
- /Views/_Layout.cshtml: Literal at 102 contains 2 characters.
- /Views/_Layout.cshtml: Non-literal at 105 contains 12 characters.
- /Views/_Layout.cshtml: Literal at 117 contains 10 characters.
+/Views/_ViewStart.cshtml: Non-literal at 96 contains 16 characters.
+/Views/_ViewStart.cshtml: Literal at 112 contains 2 characters.
+/Views/Home/ViewWithPartial.cshtml: Literal at 0 contains 27 characters.
+/Views/Home/ViewWithPartial.cshtml: Non-literal at 28 contains 39 characters.
+/Views/Home/_PartialView.cshtml: Literal at 31 contains 2 characters.
+/Views/Home/_PartialView.cshtml: Literal at 33 contains 8 characters.
+/Views/Home/_PartialView.cshtml: Non-literal at 41 contains 4 characters.
+/Views/Home/_PartialView.cshtml: Literal at 45 contains 1 characters.
+/Views/Home/_PartialView.cshtml: Literal at 46 contains 20 characters.
+/Views/Home/ViewWithPartial.cshtml: Literal at 67 contains 2 characters.
+/Views/Home/_PartialView.cshtml: Literal at 31 contains 2 characters.
+/Views/Home/_PartialView.cshtml: Literal at 33 contains 8 characters.
+/Views/Home/_PartialView.cshtml: Non-literal at 41 contains 4 characters.
+/Views/Home/_PartialView.cshtml: Literal at 45 contains 1 characters.
+/Views/Home/_PartialView.cshtml: Literal at 46 contains 20 characters.
+/Views/_Layout.cshtml: Literal at 0 contains 7 characters.
+/Views/_Layout.cshtml: Non-literal at 8 contains 12 characters.
+/Views/_Layout.cshtml: Literal at 20 contains 2 characters.
+/Views/_Layout.cshtml: Non-literal at 23 contains 12 characters.
+/Views/_Layout.cshtml: Literal at 35 contains 10 characters.
diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs
index 20417bb812..c1bde016d8 100644
--- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs
@@ -15,7 +15,6 @@ using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
-using Microsoft.AspNet.PageExecutionInstrumentation;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.AspNet.Routing;
@@ -659,93 +658,6 @@ namespace Microsoft.AspNet.Mvc.Razor
Assert.Same(HtmlString.Empty, actual);
}
- [Fact]
- public async Task WriteAttribute_CallsBeginAndEndContext_OnPageExecutionContext()
- {
- // Arrange
- var page = CreatePage(p =>
- {
- p.HtmlEncoder = new HtmlTestEncoder();
- p.BeginWriteAttribute("href", "prefix", 0, "suffix", 34, 2);
- p.WriteAttributeValue("prefix", 0, "attr1-value", 8, 14, true);
- p.WriteAttributeValue("prefix2", 22, "attr2", 29, 5, false);
- p.EndWriteAttribute();
- });
- var context = new Mock(MockBehavior.Strict);
- var sequence = new MockSequence();
- context.InSequence(sequence).Setup(f => f.BeginContext(0, 6, true)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- context.InSequence(sequence).Setup(f => f.BeginContext(0, 6, true)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- context.InSequence(sequence).Setup(f => f.BeginContext(8, 14, true)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- context.InSequence(sequence).Setup(f => f.BeginContext(22, 7, true)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- context.InSequence(sequence).Setup(f => f.BeginContext(29, 5, false)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- context.InSequence(sequence).Setup(f => f.BeginContext(34, 6, true)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- page.PageExecutionContext = context.Object;
-
- // Act
- await page.ExecuteAsync();
-
- // Assert
- context.Verify();
- }
-
- [Fact]
- public async Task WriteAttribute_WithBoolValue_CallsBeginAndEndContext_OnPageExecutionContext()
- {
- // Arrange
- var page = CreatePage(p =>
- {
- p.HtmlEncoder = new HtmlTestEncoder();
- p.BeginWriteAttribute("href", "prefix", 0, "suffix", 10, 1);
- p.WriteAttributeValue("", 6, "true", 6, 4, false);
- p.EndWriteAttribute();
- });
- var context = new Mock(MockBehavior.Strict);
- var sequence = new MockSequence();
- context.InSequence(sequence).Setup(f => f.BeginContext(0, 6, true)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- context.InSequence(sequence).Setup(f => f.BeginContext(6, 4, false)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- context.InSequence(sequence).Setup(f => f.BeginContext(10, 6, true)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- page.PageExecutionContext = context.Object;
-
- // Act
- await page.ExecuteAsync();
-
- // Assert
- context.Verify();
- }
-
- [Fact]
- public async Task WriteAttribute_CallsBeginAndEndContext_OnPrefixAndSuffixValues()
- {
- // Arrange
- var page = CreatePage(p =>
- {
- p.BeginWriteAttribute("href", "prefix", 0, "tail", 7, 0);
- p.EndWriteAttribute();
- });
- var context = new Mock(MockBehavior.Strict);
- var sequence = new MockSequence();
- context.InSequence(sequence).Setup(f => f.BeginContext(0, 6, true)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- context.InSequence(sequence).Setup(f => f.BeginContext(7, 4, true)).Verifiable();
- context.InSequence(sequence).Setup(f => f.EndContext()).Verifiable();
- page.PageExecutionContext = context.Object;
-
- // Act
- await page.ExecuteAsync();
-
- // Assert
- context.Verify();
- }
-
[Fact]
public async Task WriteAttribute_WritesBeginAndEndEvents_ToDiagnosticSource()
{
diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewTest.cs
index 35520ef053..93e1fa39c0 100644
--- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewTest.cs
@@ -12,7 +12,6 @@ using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewFeatures;
-using Microsoft.AspNet.PageExecutionInstrumentation;
using Microsoft.AspNet.Routing;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.WebEncoders.Testing;
@@ -54,7 +53,7 @@ namespace Microsoft.AspNet.Mvc.Razor
// Assert
Assert.NotSame(expected, actual);
- Assert.IsAssignableFrom(actual);
+ Assert.IsType(actual);
Assert.Equal("HtmlEncode[[Hello world]]", viewContext.Writer.ToString());
}
@@ -1373,163 +1372,6 @@ namespace Microsoft.AspNet.Mvc.Razor
Assert.Equal(expected, ex.Message);
}
- [Fact]
- public async Task RenderAsync_UsesPageExecutionFeatureFromRequest_ToWrapWriter()
- {
- // Arrange
- var pageWriter = CreateBufferedWriter();
- var layoutWriter = CreateBufferedWriter();
-
- var layoutExecuted = false;
- var count = -1;
- var feature = new Mock(MockBehavior.Strict);
- feature
- .Setup(f => f.DecorateWriter(It.IsAny()))
- .Returns(() =>
- {
- count++;
- if (count == 0)
- {
- return pageWriter;
- }
- else if (count == 1)
- {
- return layoutWriter;
- }
- throw new Exception();
- })
- .Verifiable();
-
- var pageContext = Mock.Of();
- feature
- .Setup(f => f.GetContext("/MyPage.cshtml", pageWriter))
- .Returns(pageContext)
- .Verifiable();
-
- var layoutContext = Mock.Of();
- feature
- .Setup(f => f.GetContext("/Layout.cshtml", layoutWriter))
- .Returns(layoutContext)
- .Verifiable();
-
- var page = new TestableRazorPage(v =>
- {
- v.HtmlEncoder = new HtmlTestEncoder();
- v.Layout = "Layout";
- Assert.Same(pageWriter, v.Output);
- Assert.Same(pageContext, v.PageExecutionContext);
- });
- page.Path = "/MyPage.cshtml";
-
- var layout = new TestableRazorPage(v =>
- {
- v.HtmlEncoder = new HtmlTestEncoder();
- Assert.Same(layoutWriter, v.Output);
- Assert.Same(layoutContext, v.PageExecutionContext);
- v.RenderBodyPublic();
-
- layoutExecuted = true;
- });
- layout.Path = "/Layout.cshtml";
-
- var viewEngine = new Mock(MockBehavior.Strict);
- viewEngine
- .Setup(p => p.GetPage("/MyPage.cshtml", "Layout"))
- .Returns(new RazorPageResult("Layout", Enumerable.Empty()));
- viewEngine
- .Setup(p => p.FindPage(It.IsAny(), "Layout"))
- .Returns(new RazorPageResult("/Layout.cshtml", layout));
-
- var view = new RazorView(
- viewEngine.Object,
- Mock.Of(),
- new IRazorPage[0],
- page,
- new HtmlTestEncoder());
- var viewContext = CreateViewContext(view);
- viewContext.HttpContext.Features.Set(feature.Object);
-
- // Act
- await view.RenderAsync(viewContext);
-
- // Assert
- feature.Verify();
- Assert.True(layoutExecuted);
- }
-
- [Fact]
- public async Task RenderAsync_UsesPageExecutionFeatureFromRequest_ToGetExecutionContext()
- {
- // Arrange
- var writer = new StringWriter();
- var executed = false;
- var feature = new Mock(MockBehavior.Strict);
-
- var pageContext = Mock.Of();
- feature.Setup(f => f.GetContext("/MyPartialPage.cshtml", It.IsAny()))
- .Returns(pageContext)
- .Verifiable();
-
- feature.Setup(f => f.DecorateWriter(It.IsAny()))
- .Returns((RazorTextWriter r) => r)
- .Verifiable();
-
- var page = new TestableRazorPage(v =>
- {
- v.HtmlEncoder = new HtmlTestEncoder();
- Assert.IsType(v.Output);
- Assert.Same(pageContext, v.PageExecutionContext);
- executed = true;
-
- v.Write("Hello world");
- });
- page.Path = "/MyPartialPage.cshtml";
-
- var view = new RazorView(
- Mock.Of(),
- Mock.Of(),
- new IRazorPage[0],
- page,
- new HtmlTestEncoder());
- var viewContext = CreateViewContext(view);
- viewContext.Writer = writer;
- viewContext.HttpContext.Features.Set(feature.Object);
-
- // Act
- await view.RenderAsync(viewContext);
-
- // Assert
- feature.Verify();
- Assert.True(executed);
- Assert.Equal("HtmlEncode[[Hello world]]", viewContext.Writer.ToString());
- }
-
- [Fact]
- public async Task RenderAsync_DoesNotSetExecutionContextWhenListenerIsNotRegistered()
- {
- // Arrange
- var executed = false;
- var page = new TestableRazorPage(v =>
- {
- Assert.Null(v.PageExecutionContext);
- executed = true;
- });
-
- var view = new RazorView(
- Mock.Of(),
- Mock.Of(),
- new IRazorPage[0],
- page,
- new HtmlTestEncoder());
- var viewContext = CreateViewContext(view);
-
- // Act
- await view.RenderAsync(viewContext);
-
- // Assert
- Assert.True(executed);
- }
-
[Fact]
public async Task RenderAsync_CopiesLayoutPropertyFromViewStart()
{
@@ -1718,15 +1560,6 @@ namespace Microsoft.AspNet.Mvc.Razor
Assert.Equal(expected, viewContext.Writer.ToString());
}
- private static TextWriter CreateBufferedWriter()
- {
- var mockWriter = new Mock();
- var bufferedWriter = mockWriter.As();
- bufferedWriter.SetupGet(b => b.IsBuffering)
- .Returns(true);
- return mockWriter.Object;
- }
-
private static ViewContext CreateViewContext(RazorView view)
{
var httpContext = new DefaultHttpContext();
diff --git a/test/WebSites/RazorPageExecutionInstrumentationWebSite/IHoldInstrumentationData.cs b/test/WebSites/RazorPageExecutionInstrumentationWebSite/IHoldInstrumentationData.cs
deleted file mode 100644
index 67e90f7ce2..0000000000
--- a/test/WebSites/RazorPageExecutionInstrumentationWebSite/IHoldInstrumentationData.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-// 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.Collections.Generic;
-
-namespace RazorPageExecutionInstrumentationWebSite
-{
- public interface IHoldInstrumentationData
- {
- IEnumerable Values { get; }
-
- void IgnoreFurtherData();
- }
-}
diff --git a/test/WebSites/RazorPageExecutionInstrumentationWebSite/InstrumentationData.cs b/test/WebSites/RazorPageExecutionInstrumentationWebSite/InstrumentationData.cs
deleted file mode 100644
index a3de66fbb5..0000000000
--- a/test/WebSites/RazorPageExecutionInstrumentationWebSite/InstrumentationData.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-// 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.
-
-namespace RazorPageExecutionInstrumentationWebSite
-{
- public class InstrumentationData
- {
- public InstrumentationData(string filePath, int position, int length, bool isLiteral)
- {
- FilePath = filePath;
- Position = position;
- Length = length;
- IsLiteral = isLiteral;
- }
-
- public string FilePath { get; }
-
- public int Position { get; }
-
- public int Length { get; }
-
- public bool IsLiteral { get; }
-
- public override string ToString()
- {
- var literal = IsLiteral ? "Literal" : "Non-literal";
-
- return $"{FilePath}: {literal} at {Position} contains {Length} characters.";
- }
- }
-}
diff --git a/test/WebSites/RazorPageExecutionInstrumentationWebSite/RazorPageDiagnosticListener.cs b/test/WebSites/RazorPageExecutionInstrumentationWebSite/RazorPageDiagnosticListener.cs
new file mode 100644
index 0000000000..b441d09411
--- /dev/null
+++ b/test/WebSites/RazorPageExecutionInstrumentationWebSite/RazorPageDiagnosticListener.cs
@@ -0,0 +1,29 @@
+// 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.IO;
+using Microsoft.AspNet.Http;
+using Microsoft.Extensions.DiagnosticAdapter;
+
+namespace RazorPageExecutionInstrumentationWebSite
+{
+ public class RazorPageDiagnosticListener
+ {
+ public static readonly object WriterKey = new object();
+
+ [DiagnosticName("Microsoft.AspNet.Mvc.Razor.BeginInstrumentationContext")]
+ public virtual void OnBeginPageInstrumentationContext(
+ HttpContext httpContext,
+ string path,
+ int position,
+ int length,
+ bool isLiteral)
+ {
+ var literal = isLiteral ? "Literal" : "Non-literal";
+ var text = $"{path}: {literal} at {position} contains {length} characters.";
+
+ var writer = (TextWriter)httpContext.Items[WriterKey];
+ writer.WriteLine(text);
+ }
+ }
+}
diff --git a/test/WebSites/RazorPageExecutionInstrumentationWebSite/Startup.cs b/test/WebSites/RazorPageExecutionInstrumentationWebSite/Startup.cs
index 8e26a5e9b1..5ef676e8af 100644
--- a/test/WebSites/RazorPageExecutionInstrumentationWebSite/Startup.cs
+++ b/test/WebSites/RazorPageExecutionInstrumentationWebSite/Startup.cs
@@ -1,13 +1,10 @@
// 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.Threading.Tasks;
+using System.Diagnostics;
+using System.IO;
using Microsoft.AspNet.Builder;
-using Microsoft.AspNet.Http;
-using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Mvc.Razor.Compilation;
-using Microsoft.AspNet.PageExecutionInstrumentation;
using Microsoft.Extensions.DependencyInjection;
namespace RazorPageExecutionInstrumentationWebSite
@@ -22,24 +19,24 @@ namespace RazorPageExecutionInstrumentationWebSite
// Add MVC services to the services container.
services.AddMvc();
-
- // Make instrumentation data available in views.
- services.AddScoped();
- services.AddScoped(
- provider => provider.GetRequiredService().Holder);
}
public void Configure(IApplicationBuilder app)
{
+ var listener = new RazorPageDiagnosticListener();
+ var diagnosticSource = app.ApplicationServices.GetRequiredService();
+ diagnosticSource.SubscribeWithAdapter(listener);
+
app.UseCultureReplacer();
- // Execute views with instrumentation enabled.
- app.Use((HttpContext context, Func next) =>
+ app.Use(async (context, next) =>
{
- var listenerFeature = context.RequestServices.GetRequiredService();
- context.Features.Set(listenerFeature);
-
- return next();
+ using (var writer = new StreamWriter(context.Response.Body))
+ {
+ context.Items[RazorPageDiagnosticListener.WriterKey] = writer;
+ context.Response.Body = Stream.Null;
+ await next();
+ }
});
// Add MVC to the request pipeline
diff --git a/test/WebSites/RazorPageExecutionInstrumentationWebSite/TestPageExecutionListenerFeature.cs b/test/WebSites/RazorPageExecutionInstrumentationWebSite/TestPageExecutionListenerFeature.cs
deleted file mode 100644
index 4d3d5482f8..0000000000
--- a/test/WebSites/RazorPageExecutionInstrumentationWebSite/TestPageExecutionListenerFeature.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-// 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.Collections.Generic;
-using System.IO;
-using Microsoft.AspNet.PageExecutionInstrumentation;
-
-namespace RazorPageExecutionInstrumentationWebSite
-{
- public class TestPageExecutionListenerFeature : IPageExecutionListenerFeature
- {
- private readonly TestPageExecutionContext _executionContext = new TestPageExecutionContext();
-
- public IHoldInstrumentationData Holder => _executionContext;
-
- public TextWriter DecorateWriter(TextWriter writer)
- {
- return writer;
- }
-
- public IPageExecutionContext GetContext(string sourceFilePath, TextWriter writer)
- {
- _executionContext.FilePath = sourceFilePath;
-
- return _executionContext;
- }
-
- private class TestPageExecutionContext : IHoldInstrumentationData, IPageExecutionContext
- {
- private readonly List _values = new List();
- private bool _ignoreNewData;
-
- public string FilePath { get; set; }
-
- public IEnumerable Values => _values;
-
- public void IgnoreFurtherData()
- {
- _ignoreNewData = true;
- }
-
- public void BeginContext(int position, int length, bool isLiteral)
- {
- if (_ignoreNewData)
- {
- return;
- }
-
- _values.Add(new InstrumentationData(FilePath, position, length, isLiteral));
- }
-
- public void EndContext()
- {
- }
- }
- }
-}
\ No newline at end of file
diff --git a/test/WebSites/RazorPageExecutionInstrumentationWebSite/Views/_Layout.cshtml b/test/WebSites/RazorPageExecutionInstrumentationWebSite/Views/_Layout.cshtml
index 9fd7ce212b..23e469ccc9 100644
--- a/test/WebSites/RazorPageExecutionInstrumentationWebSite/Views/_Layout.cshtml
+++ b/test/WebSites/RazorPageExecutionInstrumentationWebSite/Views/_Layout.cshtml
@@ -1,12 +1,4 @@
-@inject RazorPageExecutionInstrumentationWebSite.IHoldInstrumentationData Holder
-
+
@int.MaxValue
@RenderBody()
-@{
- Holder.IgnoreFurtherData();
- foreach (var data in Holder.Values)
- {
-
@data.ToString()
- }
-}
\ No newline at end of file
diff --git a/test/WebSites/RazorPageExecutionInstrumentationWebSite/project.json b/test/WebSites/RazorPageExecutionInstrumentationWebSite/project.json
index 14c1cb9408..aef9eb01eb 100644
--- a/test/WebSites/RazorPageExecutionInstrumentationWebSite/project.json
+++ b/test/WebSites/RazorPageExecutionInstrumentationWebSite/project.json
@@ -1,18 +1,19 @@
{
- "commands": {
- "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001",
- "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000"
- },
- "dependencies": {
- "Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
- "Microsoft.AspNet.Mvc": "6.0.0-*",
- "Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
- "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
- "Microsoft.AspNet.StaticFiles": "1.0.0-*"
- },
- "frameworks": {
- "dnx451": { },
- "dnxcore50": { }
- },
- "webroot": "wwwroot"
+ "commands": {
+ "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001",
+ "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000"
+ },
+ "dependencies": {
+ "Microsoft.AspNet.Mvc": "6.0.0-*",
+ "Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
+ "Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
+ "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
+ "Microsoft.AspNet.StaticFiles": "1.0.0-*",
+ "Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*"
+ },
+ "frameworks": {
+ "dnx451": { },
+ "dnxcore50": { }
+ },
+ "webroot": "wwwroot"
}