From 11ee402eecb768662e7186c52a583d375476fb31 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 8 Sep 2014 12:45:50 -0700 Subject: [PATCH] Reviving support for instrumentation in CSharpCodeVisitor Fixes #42 --- .../CodeBuilder/CSharp/CSharpCodeWriter.cs | 77 ++++-- .../CSharp/Visitors/CSharpCodeVisitor.cs | 68 ++++- .../Compiler/CodeTree/CodeTreeBuilder.cs | 18 +- .../Generator/CSharpRazorCodeGeneratorTest.cs | 18 +- .../Generator/CodeTree/CodeTreeBuilderTest.cs | 79 ++++++ .../Generator/RazorCodeGeneratorTest.cs | 5 +- .../CodeGenerator/CS/Output/Await.cs | 48 ++++ .../CodeGenerator/CS/Output/Blocks.cs | 44 +++ .../CS/Output/ConditionalAttributes.cs | 22 ++ .../CS/Output/ExplicitExpression.cs | 4 + .../CS/Output/ExpressionsInCode.cs | 12 + .../CodeGenerator/CS/Output/FunctionsBlock.cs | 6 + .../CS/Output/FunctionsBlock_Tabs.cs | 6 + .../CS/Output/Helpers.Instance.cs | 18 ++ .../CodeGenerator/CS/Output/Helpers.cs | 18 ++ .../CS/Output/HelpersMissingCloseParen.cs | 8 + .../CS/Output/HelpersMissingOpenBrace.cs | 10 + .../CS/Output/HelpersMissingOpenParen.cs | 10 + .../CS/Output/HtmlCommentWithQuote_Double.cs | 4 + .../CS/Output/HtmlCommentWithQuote_Single.cs | 4 + .../CS/Output/ImplicitExpression.cs | 6 + .../CodeGenerator/CS/Output/Imports.cs | 10 + .../CS/Output/Inherits.Runtime.cs | 4 + .../CodeGenerator/CS/Output/InlineBlocks.cs | 8 + .../CodeGenerator/CS/Output/Instrumented.cs | 261 ++++++++++++++++++ .../CS/Output/MarkupInCodeBlock.cs | 8 + .../CodeGenerator/CS/Output/NestedHelpers.cs | 16 ++ .../CodeGenerator/CS/Output/NoLinePragmas.cs | 44 +++ .../CodeGenerator/CS/Output/RazorComments.cs | 14 + .../CodeGenerator/CS/Output/ResolveUrl.cs | 44 +++ .../CodeGenerator/CS/Output/Sections.cs | 8 + .../CodeGenerator/CS/Output/Templates.cs | 44 +++ .../CS/Source/Instrumented.cshtml | 42 +++ 33 files changed, 934 insertions(+), 54 deletions(-) create mode 100644 test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CodeTreeBuilderTest.cs create mode 100644 test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Instrumented.cs create mode 100644 test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/Instrumented.cshtml diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeWriter.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeWriter.cs index 4cd4a3ce25..4242e1228b 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeWriter.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeWriter.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; +using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Text; namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp @@ -144,7 +145,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp { Write(String.Format("using {0}", name)); - if(endLine) + if (endLine) { WriteLine(";"); } @@ -353,35 +354,35 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp { switch (literal[i]) { - case '\r': - Write("\\r"); - break; - case '\t': - Write("\\t"); - break; - case '\"': - Write("\\\""); - break; - case '\'': - Write("\\\'"); - break; - case '\\': - Write("\\\\"); - break; - case '\0': - Write("\\\0"); - break; - case '\n': - Write("\\n"); - break; - case '\u2028': - case '\u2029': - Write("\\u"); - Write(((int)literal[i]).ToString("X4", CultureInfo.InvariantCulture)); - break; - default: - Write(literal[i].ToString()); - break; + case '\r': + Write("\\r"); + break; + case '\t': + Write("\\t"); + break; + case '\"': + Write("\\\""); + break; + case '\'': + Write("\\\'"); + break; + case '\\': + Write("\\\\"); + break; + case '\0': + Write("\\\0"); + break; + case '\n': + Write("\\n"); + break; + case '\u2028': + case '\u2029': + Write("\\u"); + Write(((int)literal[i]).ToString("X4", CultureInfo.InvariantCulture)); + break; + default: + Write(literal[i].ToString()); + break; } if (i > 0 && i % 80 == 0) { @@ -403,5 +404,21 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp } Write("\""); } + + public void WriteStartInstrumentationContext(CodeGeneratorContext context, SyntaxTreeNode syntaxNode, bool isLiteral) + { + WriteStartMethodInvocation(context.Host.GeneratedClassContext.BeginContextMethodName); + Write(syntaxNode.Start.AbsoluteIndex.ToString(CultureInfo.InvariantCulture)); + WriteParameterSeparator(); + Write(syntaxNode.Length.ToString(CultureInfo.InvariantCulture)); + WriteParameterSeparator(); + Write(isLiteral ? "true" : "false"); + WriteEndMethodInvocation(); + } + + public void WriteEndInstrumentationContext(CodeGeneratorContext context) + { + WriteMethodInvocation(context.Host.GeneratedClassContext.EndContextMethodName); + } } } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs index 7ab0992a7f..ef32591f24 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs @@ -59,7 +59,14 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp return; } - // TODO: Add instrumentation + var generateInstrumentation = ShouldGenerateInstrumentationForExpressions(); + + if (generateInstrumentation) + { + // Add a non-literal context call (non-literal because the expanded URL will not match the source + // character-by-character) + Writer.WriteStartInstrumentationContext(Context, chunk.Association, isLiteral: false); + } if (!String.IsNullOrEmpty(chunk.Url) && !Context.Host.DesignTimeMode) { @@ -86,6 +93,11 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp Writer.WriteEndMethodInvocation(); } } + + if (generateInstrumentation) + { + Writer.WriteEndInstrumentationContext(Context); + } } protected override void Visit(LiteralChunk chunk) @@ -95,7 +107,10 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp return; } - // TODO: Add instrumentation + if (Context.Host.EnableInstrumentation) + { + Writer.WriteStartInstrumentationContext(Context, chunk.Association, isLiteral: true); + } if (!String.IsNullOrEmpty(chunk.Text) && !Context.Host.DesignTimeMode) { @@ -114,13 +129,14 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp .WriteEndMethodInvocation(); } - // TODO: Add instrumentation + if (Context.Host.EnableInstrumentation) + { + Writer.WriteEndInstrumentationContext(Context); + } } protected override void Visit(ExpressionBlockChunk chunk) { - // TODO: Handle instrumentation - if (Context.Host.DesignTimeMode) { RenderDesignTimeExpressionBlockChunk(chunk); @@ -280,21 +296,19 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp var currentTargetWriterName = Context.TargetWriterName; Context.TargetWriterName = TemplateWriterName; - + using (Writer.BuildLambda(endLine: false, parameterNames: TemplateWriterName)) { Accept(chunk.Children); } Context.TargetWriterName = currentTargetWriterName; - + Writer.WriteEndMethodInvocation(endLine: false); Writer.WriteEndMethodInvocation(); } public void RenderDesignTimeExpressionBlockChunk(ExpressionBlockChunk chunk) { - // TODO: Handle instrumentation - var firstChild = (ExpressionChunk)chunk.Children.FirstOrDefault(); if (firstChild != null) @@ -329,7 +343,28 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp public void RenderRuntimeExpressionBlockChunk(ExpressionBlockChunk chunk) { - // TODO: Handle instrumentation + var generateInstrumentation = ShouldGenerateInstrumentationForExpressions(); + Span contentSpan = null; + + if (generateInstrumentation) + { + // For expression chunks, such as @value, @(value) etc, pick the first Code or Markup span + // from the expression (in this case "value") and use that to calculate the length. This works + // accurately for most parts. The scenarios that don't work are + // (a) Expressions with inline comments (e.g. @(a @* comment *@ b)) - these have multiple code spans + // (b) Expressions with inline templates (e.g. @Foo(@

Hello world

)). + // Tracked via https://github.com/aspnet/Razor/issues/153 + + var block = (Block)chunk.Association; + contentSpan = block.Children + .OfType() + .FirstOrDefault(s => s.Kind == SpanKind.Code || s.Kind == SpanKind.Markup); + + if (contentSpan != null) + { + Writer.WriteStartInstrumentationContext(Context, contentSpan, isLiteral: false); + } + } if (Context.ExpressionRenderingMode == ExpressionRenderingMode.InjectCode) { @@ -353,6 +388,11 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp Writer.WriteEndMethodInvocation() .WriteLine(); } + + if (contentSpan != null) + { + Writer.WriteEndInstrumentationContext(Context); + } } public void CreateExpressionCodeMapping(string code, Chunk chunk) @@ -385,5 +425,13 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp Writer.Write(code); } } + + private bool ShouldGenerateInstrumentationForExpressions() + { + // Only generate instrumentation for expression blocks if instrumentation is enabled and we're generating a + // "Write()" statement. + return Context.Host.EnableInstrumentation && + Context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput; + } } } diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/CodeTreeBuilder.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/CodeTreeBuilder.cs index 829eb0901c..1f1be5f723 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/CodeTreeBuilder.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/CodeTreeBuilder.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using Microsoft.AspNet.Razor.Parser.SyntaxTree; namespace Microsoft.AspNet.Razor.Generator.Compiler @@ -40,9 +41,22 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler public void AddLiteralChunk(string literal, SyntaxTreeNode association) { - if (_lastChunk is LiteralChunk) + // If the previous chunk was also a LiteralChunk, append the content of the current node to the previous one. + var literalChunk = _lastChunk as LiteralChunk; + if (literalChunk != null) { - ((LiteralChunk)_lastChunk).Text += literal; + // Literal chunks are always associated with Spans + var lastSpan = (Span)literalChunk.Association; + var currentSpan = (Span)association; + + var builder = new SpanBuilder(lastSpan); + foreach (var symbol in currentSpan.Symbols) + { + builder.Accept(symbol); + } + + literalChunk.Association = builder.Build(); + literalChunk.Text += literal; } else { diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs index 8dc4527b31..f78caa5f65 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs @@ -393,16 +393,14 @@ namespace Microsoft.AspNet.Razor.Test.Generator RunTest("Helpers", baselineName: "Helpers.Instance", hostConfig: h => h.StaticHelpers = false); } - // TODO: This should be re-added once instrumentation support has been added - //[Fact] - //public void CSharpCodeGeneratorCorrectlyInstrumentsRazorCodeWhenInstrumentationRequested() - //{ - // RunTest("Instrumented", hostConfig: host => - // { - // host.EnableInstrumentation = true; - // host.InstrumentedSourceFilePath = String.Format("~/{0}.cshtml", host.DefaultClassName); - // }); - //} + [Fact] + public void CSharpCodeGeneratorCorrectlyInstrumentsRazorCodeWhenInstrumentationRequested() + { + RunTest("Instrumented", hostConfig: host => + { + host.InstrumentedSourceFilePath = string.Format("~/{0}.cshtml", host.DefaultClassName); + }); + } [Fact] public void CSharpCodeGeneratorGeneratesUrlsCorrectlyWithCommentsAndQuotes() diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CodeTreeBuilderTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CodeTreeBuilderTest.cs new file mode 100644 index 0000000000..d702391738 --- /dev/null +++ b/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CodeTreeBuilderTest.cs @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Razor.Generator.Compiler; +using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.AspNet.Razor.Test.Framework; +using System.Linq; +using Xunit; + +namespace Microsoft.AspNet.Razor +{ + public class CodeTreeBuilderTest + { + [Fact] + public void AddLiteralChunk_AddsChunkToCodeTree() + { + // Arrange + var spanFactory = SpanFactory.CreateCsHtml(); + var previousSpan = spanFactory.EmptyHtml().Builder.Build(); + var builder = new CodeTreeBuilder(); + + // Act + builder.AddLiteralChunk("some text", previousSpan); + + // Assert + var chunk = Assert.Single(builder.CodeTree.Chunks); + var literalChunk = Assert.IsType(chunk); + Assert.Equal("some text", literalChunk.Text); + Assert.Same(previousSpan, literalChunk.Association); + } + + [Fact] + public void AddLiteralChunk_AppendsToPreviousChunk_IfChunkWasLiteral() + { + // Arrange + var spanFactory = SpanFactory.CreateCsHtml(); + var previousSpan = spanFactory.Markup("").Builder.Build(); + var newSpan = spanFactory.Markup("

").Builder.Build(); + var builder = new CodeTreeBuilder(); + + // Act + builder.AddLiteralChunk("", previousSpan); + builder.AddLiteralChunk("

", newSpan); + + // Assert + var chunk = Assert.Single(builder.CodeTree.Chunks); + var literalChunk = Assert.IsType(chunk); + Assert.Equal("

", literalChunk.Text); + var span = Assert.IsType(literalChunk.Association); + Assert.Equal(previousSpan.Symbols.Concat(newSpan.Symbols), span.Symbols); + } + + [Fact] + public void AddLiteralChunk_AddsChunkToCodeTree_IfPreviousChunkWasNotLiteral() + { + // Arrange + var spanFactory = SpanFactory.CreateCsHtml(); + var codeSpan = spanFactory.Code("int a = 10;") + .AsStatement() + .Builder.Build(); + var literalSpan = spanFactory.Markup("

").Builder.Build(); + var builder = new CodeTreeBuilder(); + + // Act + builder.AddStatementChunk("int a = 10;", codeSpan); + builder.AddLiteralChunk("

", literalSpan); + + // Assert + var chunks = builder.CodeTree.Chunks; + Assert.Equal(2, chunks.Count); + var statementChunk = Assert.IsType(chunks[0]); + Assert.Equal("int a = 10;", statementChunk.Code); + Assert.Same(codeSpan, statementChunk.Association); + var literalChunk = Assert.IsType(chunks[1]); + Assert.Equal("

", literalChunk.Text); + Assert.Same(literalSpan, literalChunk.Association); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs index a798413e58..9fc495ed10 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs @@ -118,8 +118,8 @@ namespace Microsoft.AspNet.Razor.Test.Generator "WriteLiteralTo", "Template", "DefineSection", - "BeginContext", - "EndContext") + "Instrumentation.BeginContext", + "Instrumentation.EndContext") { LayoutPropertyName = "Layout", ResolveUrlMethodName = "Href" @@ -130,6 +130,7 @@ namespace Microsoft.AspNet.Razor.Test.Generator } host.IsIndentingWithTabs = withTabs; + host.EnableInstrumentation = true; RazorTemplateEngine engine = new RazorTemplateEngine(host); diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Await.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Await.cs index 0de02b096c..daeee101d8 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Await.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Await.cs @@ -22,8 +22,11 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(91, 100, true); WriteLiteral("\r\n

\r\n

Basic Asynchronous Expression Test

\r\n

Basic Asynch" + "ronous Expression: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(192, 11, false); Write( #line 10 "Await.cshtml" await Foo() @@ -32,7 +35,11 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(203, 42, true); WriteLiteral("

\r\n

Basic Asynchronous Template: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(247, 11, false); Write( #line 11 "Await.cshtml" await Foo() @@ -41,14 +48,20 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(259, 43, true); WriteLiteral("

\r\n

Basic Asynchronous Statement: "); + Instrumentation.EndContext(); #line 12 "Await.cshtml" await Foo(); #line default #line hidden + Instrumentation.BeginContext(319, 54, true); WriteLiteral("

\r\n

Basic Asynchronous Statement Nested: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(376, 11, false); Write( #line 13 "Await.cshtml" await Foo() @@ -57,14 +70,20 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(387, 5, true); WriteLiteral(" "); + Instrumentation.EndContext(); #line 13 "Await.cshtml" #line default #line hidden + Instrumentation.BeginContext(393, 54, true); WriteLiteral("

\r\n

Basic Incomplete Asynchronous Statement: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(448, 5, false); Write( #line 14 "Await.cshtml" await @@ -73,8 +92,12 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(453, 124, true); WriteLiteral("

\r\n
\r\n\r\n
\r\n

Advanced Asynchronous Expression Test

" + "\r\n

Advanced Asynchronous Expression: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(578, 15, false); Write( #line 19 "Await.cshtml" await Foo(1, 2) @@ -83,7 +106,11 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(593, 56, true); WriteLiteral("

\r\n

Advanced Asynchronous Expression Extended: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(650, 19, false); Write( #line 20 "Await.cshtml" await Foo.Bar(1, 2) @@ -92,7 +119,11 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(669, 45, true); WriteLiteral("

\r\n

Advanced Asynchronous Template: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(716, 22, false); Write( #line 21 "Await.cshtml" await Foo("bob", true) @@ -101,21 +132,29 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(739, 46, true); WriteLiteral("

\r\n

Advanced Asynchronous Statement: "); + Instrumentation.EndContext(); #line 22 "Await.cshtml" await Foo(something, hello: "world"); #line default #line hidden + Instrumentation.BeginContext(827, 55, true); WriteLiteral("

\r\n

Advanced Asynchronous Statement Extended: "); + Instrumentation.EndContext(); #line 23 "Await.cshtml" await Foo.Bar(1, 2) #line default #line hidden + Instrumentation.BeginContext(906, 57, true); WriteLiteral("

\r\n

Advanced Asynchronous Statement Nested: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(966, 27, false); Write( #line 24 "Await.cshtml" await Foo(boolValue: false) @@ -124,14 +163,20 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(993, 5, true); WriteLiteral(" "); + Instrumentation.EndContext(); #line 24 "Await.cshtml" #line default #line hidden + Instrumentation.BeginContext(999, 57, true); WriteLiteral("

\r\n

Advanced Incomplete Asynchronous Statement: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(1057, 19, false); Write( #line 25 "Await.cshtml" await ("wrrronggg") @@ -140,7 +185,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(1076, 16, true); WriteLiteral("

\r\n
"); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Blocks.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Blocks.cs index efecf50c05..c75d890fef 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Blocks.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Blocks.cs @@ -20,14 +20,19 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(21, 4, true); WriteLiteral("\r\n\r\n"); + Instrumentation.EndContext(); #line 5 "Blocks.cshtml" while(i <= 10) { #line default #line hidden + Instrumentation.BeginContext(44, 23, true); WriteLiteral("

Hello from C#, #"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(69, 1, false); Write( #line 6 "Blocks.cshtml" i @@ -36,7 +41,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(71, 6, true); WriteLiteral("

\r\n"); + Instrumentation.EndContext(); #line 7 "Blocks.cshtml" i += 1; } @@ -44,21 +52,27 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(93, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); #line 10 "Blocks.cshtml" if(i == 11) { #line default #line hidden + Instrumentation.BeginContext(111, 31, true); WriteLiteral("

We wrote 10 lines!

\r\n"); + Instrumentation.EndContext(); #line 12 "Blocks.cshtml" } #line default #line hidden + Instrumentation.BeginContext(145, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); #line 14 "Blocks.cshtml" switch(i) { case 11: @@ -66,7 +80,9 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(175, 46, true); WriteLiteral("

No really, we wrote 10 lines!

\r\n"); + Instrumentation.EndContext(); #line 17 "Blocks.cshtml" break; default: @@ -74,7 +90,9 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(251, 39, true); WriteLiteral("

Actually, we didn\'t...

\r\n"); + Instrumentation.EndContext(); #line 20 "Blocks.cshtml" break; } @@ -82,14 +100,19 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(309, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); #line 23 "Blocks.cshtml" for(int j = 1; j <= 10; j += 2) { #line default #line hidden + Instrumentation.BeginContext(347, 29, true); WriteLiteral("

Hello again from C#, #"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(378, 1, false); Write( #line 24 "Blocks.cshtml" j @@ -98,28 +121,38 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(380, 6, true); WriteLiteral("

\r\n"); + Instrumentation.EndContext(); #line 25 "Blocks.cshtml" } #line default #line hidden + Instrumentation.BeginContext(389, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); #line 27 "Blocks.cshtml" try { #line default #line hidden + Instrumentation.BeginContext(399, 41, true); WriteLiteral("

That time, we wrote 5 lines!

\r\n"); + Instrumentation.EndContext(); #line 29 "Blocks.cshtml" } catch(Exception ex) { #line default #line hidden + Instrumentation.BeginContext(465, 33, true); WriteLiteral("

Oh no! An error occurred: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(500, 10, false); Write( #line 30 "Blocks.cshtml" ex.Message @@ -128,14 +161,20 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(511, 6, true); WriteLiteral("

\r\n"); + Instrumentation.EndContext(); #line 31 "Blocks.cshtml" } #line default #line hidden + Instrumentation.BeginContext(520, 14, true); WriteLiteral("\r\n

i is now "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(535, 1, false); Write( #line 33 "Blocks.cshtml" i @@ -144,14 +183,19 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(536, 8, true); WriteLiteral("

\r\n\r\n"); + Instrumentation.EndContext(); #line 35 "Blocks.cshtml" lock(new object()) { #line default #line hidden + Instrumentation.BeginContext(567, 53, true); WriteLiteral("

This block is locked, for your security!

\r\n"); + Instrumentation.EndContext(); #line 37 "Blocks.cshtml" } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ConditionalAttributes.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ConditionalAttributes.cs index c3f687ceb8..6d7efa5a3e 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ConditionalAttributes.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ConditionalAttributes.cs @@ -21,7 +21,9 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(46, 28, true); WriteLiteral("
\r\n ( #line 5 "ConditionalAttributes.cshtml" @@ -30,7 +32,9 @@ namespace TestOutput #line default #line hidden , 82), false)); + Instrumentation.BeginContext(87, 11, true); WriteLiteral(" />\r\n ( #line 6 "ConditionalAttributes.cshtml" @@ -39,7 +43,9 @@ namespace TestOutput #line default #line hidden , 110), false)); + Instrumentation.BeginContext(115, 11, true); WriteLiteral(" />\r\n ( #line 7 "ConditionalAttributes.cshtml" @@ -48,7 +54,9 @@ namespace TestOutput #line default #line hidden , 134), false), Tuple.Create(Tuple.Create(" ", 138), Tuple.Create("foo", 139), true)); + Instrumentation.BeginContext(143, 31, true); WriteLiteral(" />\r\n ( #line 8 "ConditionalAttributes.cshtml" @@ -57,7 +65,9 @@ namespace TestOutput #line default #line hidden , 184), false)); + Instrumentation.BeginContext(188, 31, true); WriteLiteral(" />\r\n ( #line 9 "ConditionalAttributes.cshtml" @@ -66,7 +76,9 @@ namespace TestOutput #line default #line hidden , 233), false)); + Instrumentation.BeginContext(237, 11, true); WriteLiteral(" />\r\n (new Template((__razor_attribute_value_writer) => { #line 10 "ConditionalAttributes.cshtml" @@ -75,6 +87,7 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(276, 3, false); WriteTo(__razor_attribute_value_writer, #line 10 "ConditionalAttributes.cshtml" cls @@ -83,6 +96,7 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); #line 10 "ConditionalAttributes.cshtml" } @@ -91,9 +105,13 @@ namespace TestOutput } ), 256), false)); + Instrumentation.BeginContext(282, 11, true); WriteLiteral(" />\r\n (Href("~/Foo"), 300), false)); + Instrumentation.BeginContext(306, 16, true); WriteLiteral(" />\r\n ( #line 12 "ConditionalAttributes.cshtml" @@ -102,7 +120,9 @@ namespace TestOutput #line default #line hidden , 328), false)); + Instrumentation.BeginContext(374, 46, true); WriteLiteral(" type=\"text/javascript\">\r\n ( #line 13 "ConditionalAttributes.cshtml" @@ -111,8 +131,10 @@ namespace TestOutput #line default #line hidden , 426), false)); + Instrumentation.BeginContext(488, 152, true); WriteLiteral(" type=\"text/javascript\">\r\n \r\n"); + Instrumentation.EndContext(); #line 15 "ConditionalAttributes.cshtml" #line default diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ExplicitExpression.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ExplicitExpression.cs index e9e2aef118..ac738c680a 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ExplicitExpression.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ExplicitExpression.cs @@ -13,7 +13,10 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(0, 8, true); WriteLiteral("1 + 1 = "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(10, 3, false); Write( #line 1 "ExplicitExpression.cshtml" 1+1 @@ -22,6 +25,7 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ExpressionsInCode.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ExpressionsInCode.cs index ff44ada871..5af9382bd2 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ExpressionsInCode.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ExpressionsInCode.cs @@ -21,7 +21,9 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(54, 4, true); WriteLiteral("\r\n\r\n"); + Instrumentation.EndContext(); #line 6 "ExpressionsInCode.cshtml" if(foo != null) { @@ -29,6 +31,7 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(83, 3, false); Write( #line 7 "ExpressionsInCode.cshtml" foo @@ -37,6 +40,7 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); #line 7 "ExpressionsInCode.cshtml" } else { @@ -44,14 +48,18 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(98, 25, true); WriteLiteral("

Foo is Null!

\r\n"); + Instrumentation.EndContext(); #line 10 "ExpressionsInCode.cshtml" } #line default #line hidden + Instrumentation.BeginContext(126, 7, true); WriteLiteral("\r\n

\r\n"); + Instrumentation.EndContext(); #line 13 "ExpressionsInCode.cshtml" if(!String.IsNullOrEmpty(bar)) { @@ -59,6 +67,7 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(174, 21, false); Write( #line 14 "ExpressionsInCode.cshtml" bar.Replace("F", "B") @@ -67,6 +76,7 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); #line 14 "ExpressionsInCode.cshtml" } @@ -74,7 +84,9 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(201, 4, true); WriteLiteral("

"); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/FunctionsBlock.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/FunctionsBlock.cs index 5928cc500f..4a1644370a 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/FunctionsBlock.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/FunctionsBlock.cs @@ -28,8 +28,13 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(19, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(140, 26, true); WriteLiteral("\r\nHere\'s a random number: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(167, 11, false); Write( #line 12 "FunctionsBlock.cshtml" RandomInt() @@ -38,6 +43,7 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/FunctionsBlock_Tabs.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/FunctionsBlock_Tabs.cs index bf2227c778..64f9065b14 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/FunctionsBlock_Tabs.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/FunctionsBlock_Tabs.cs @@ -28,8 +28,13 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(19, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(125, 26, true); WriteLiteral("\r\nHere\'s a random number: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(152, 11, false); Write( #line 12 "FunctionsBlock_Tabs.cshtml" RandomInt() @@ -38,6 +43,7 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Helpers.Instance.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Helpers.Instance.cs index dee64a8a3e..e2c6bcc35d 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Helpers.Instance.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Helpers.Instance.cs @@ -19,7 +19,10 @@ Bold(string s) { #line default #line hidden + Instrumentation.BeginContext(48, 12, true); WriteLiteralTo(__razor_helper_writer, " "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(61, 1, false); WriteTo(__razor_helper_writer, #line 3 "Helpers.cshtml" s @@ -28,7 +31,10 @@ Bold(string s) { #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(62, 11, true); WriteLiteralTo(__razor_helper_writer, "\r\n"); + Instrumentation.EndContext(); #line 4 "Helpers.cshtml" #line default @@ -56,7 +62,10 @@ Italic(string s) { #line default #line hidden + Instrumentation.BeginContext(128, 8, true); WriteLiteralTo(__razor_helper_writer, " "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(137, 1, false); WriteTo(__razor_helper_writer, #line 8 "Helpers.cshtml" s @@ -65,7 +74,10 @@ Italic(string s) { #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(138, 7, true); WriteLiteralTo(__razor_helper_writer, "\r\n"); + Instrumentation.EndContext(); #line 9 "Helpers.cshtml" #line default @@ -87,8 +99,13 @@ Italic(string s) { #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(76, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(148, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(151, 13, false); Write( #line 11 "Helpers.cshtml" Bold("Hello") @@ -97,6 +114,7 @@ Italic(string s) { #line hidden ); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Helpers.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Helpers.cs index 616647d9fc..981ee9c1c6 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Helpers.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Helpers.cs @@ -19,7 +19,10 @@ Bold(string s) { #line default #line hidden + Instrumentation.BeginContext(48, 12, true); WriteLiteralTo(__razor_helper_writer, " "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(61, 1, false); WriteTo(__razor_helper_writer, #line 3 "Helpers.cshtml" s @@ -28,7 +31,10 @@ Bold(string s) { #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(62, 11, true); WriteLiteralTo(__razor_helper_writer, "\r\n"); + Instrumentation.EndContext(); #line 4 "Helpers.cshtml" #line default @@ -56,7 +62,10 @@ Italic(string s) { #line default #line hidden + Instrumentation.BeginContext(128, 8, true); WriteLiteralTo(__razor_helper_writer, " "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(137, 1, false); WriteTo(__razor_helper_writer, #line 8 "Helpers.cshtml" s @@ -65,7 +74,10 @@ Italic(string s) { #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(138, 7, true); WriteLiteralTo(__razor_helper_writer, "\r\n"); + Instrumentation.EndContext(); #line 9 "Helpers.cshtml" #line default @@ -87,8 +99,13 @@ Italic(string s) { #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(76, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(148, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(151, 13, false); Write( #line 11 "Helpers.cshtml" Bold("Hello") @@ -97,6 +114,7 @@ Italic(string s) { #line hidden ); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingCloseParen.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingCloseParen.cs index 82549c21e8..bf3d7900ad 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingCloseParen.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingCloseParen.cs @@ -19,7 +19,10 @@ Bold(string s) { #line default #line hidden + Instrumentation.BeginContext(48, 12, true); WriteLiteralTo(__razor_helper_writer, " "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(61, 1, false); WriteTo(__razor_helper_writer, #line 3 "HelpersMissingCloseParen.cshtml" s @@ -28,7 +31,10 @@ Bold(string s) { #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(62, 11, true); WriteLiteralTo(__razor_helper_writer, "\r\n"); + Instrumentation.EndContext(); #line 4 "HelpersMissingCloseParen.cshtml" #line default @@ -58,7 +64,9 @@ Italic(string s #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(76, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingOpenBrace.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingOpenBrace.cs index 00cc25553d..5de0b57677 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingOpenBrace.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingOpenBrace.cs @@ -19,7 +19,10 @@ Bold(string s) { #line default #line hidden + Instrumentation.BeginContext(48, 12, true); WriteLiteralTo(__razor_helper_writer, " "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(61, 1, false); WriteTo(__razor_helper_writer, #line 3 "HelpersMissingOpenBrace.cshtml" s @@ -28,7 +31,10 @@ Bold(string s) { #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(62, 11, true); WriteLiteralTo(__razor_helper_writer, "\r\n"); + Instrumentation.EndContext(); #line 4 "HelpersMissingOpenBrace.cshtml" #line default @@ -57,7 +63,10 @@ Italic(string s) #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(76, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(106, 9, false); Write( #line 7 "HelpersMissingOpenBrace.cshtml" Italic(s) @@ -66,6 +75,7 @@ Italic(string s) #line hidden ); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingOpenParen.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingOpenParen.cs index e61cd1a1a7..745d6fb849 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingOpenParen.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HelpersMissingOpenParen.cs @@ -19,7 +19,10 @@ Bold(string s) { #line default #line hidden + Instrumentation.BeginContext(48, 12, true); WriteLiteralTo(__razor_helper_writer, " "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(61, 1, false); WriteTo(__razor_helper_writer, #line 3 "HelpersMissingOpenParen.cshtml" s @@ -28,7 +31,10 @@ Bold(string s) { #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(62, 11, true); WriteLiteralTo(__razor_helper_writer, "\r\n"); + Instrumentation.EndContext(); #line 4 "HelpersMissingOpenParen.cshtml" #line default @@ -57,7 +63,10 @@ Italic #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(76, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(95, 13, false); Write( #line 7 "HelpersMissingOpenParen.cshtml" Bold("Hello") @@ -66,6 +75,7 @@ Italic #line hidden ); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HtmlCommentWithQuote_Double.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HtmlCommentWithQuote_Double.cs index e3675fb0bf..642906dead 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HtmlCommentWithQuote_Double.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HtmlCommentWithQuote_Double.cs @@ -13,9 +13,13 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(0, 16, true); WriteLiteral("\r\n(Href("~/images/submit.png"), 22), false)); + Instrumentation.BeginContext(42, 3, true); WriteLiteral(" />"); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HtmlCommentWithQuote_Single.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HtmlCommentWithQuote_Single.cs index a7614d64cb..37eae1bf47 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HtmlCommentWithQuote_Single.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/HtmlCommentWithQuote_Single.cs @@ -13,9 +13,13 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(0, 16, true); WriteLiteral("\r\n(Href("~/images/submit.png"), 22), false)); + Instrumentation.BeginContext(42, 3, true); WriteLiteral(" />"); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ImplicitExpression.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ImplicitExpression.cs index aabe11373a..4114598df0 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ImplicitExpression.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ImplicitExpression.cs @@ -19,7 +19,10 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(33, 21, true); WriteLiteral("

This is item #"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(55, 1, false); Write( #line 2 "ImplicitExpression.cshtml" i @@ -28,7 +31,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(56, 6, true); WriteLiteral("

\r\n"); + Instrumentation.EndContext(); #line 3 "ImplicitExpression.cshtml" } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Imports.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Imports.cs index f993a078d3..d5350dac9b 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Imports.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Imports.cs @@ -30,7 +30,10 @@ using System #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(68, 30, true); WriteLiteral("\r\n

Path\'s full type name is "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(99, 21, false); Write( #line 5 "Imports.cshtml" typeof(Path).FullName @@ -39,7 +42,11 @@ using System #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(120, 40, true); WriteLiteral("

\r\n

Foo\'s actual full type name is "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(161, 20, false); Write( #line 6 "Imports.cshtml" typeof(Foo).FullName @@ -48,7 +55,10 @@ using System #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(181, 4, true); WriteLiteral("

"); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Inherits.Runtime.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Inherits.Runtime.cs index d53c7d08dd..55cb9e5ce1 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Inherits.Runtime.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Inherits.Runtime.cs @@ -13,6 +13,7 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(1, 5, false); Write( #line 1 "Inherits.cshtml" foo() @@ -21,7 +22,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(6, 4, true); WriteLiteral("\r\n\r\n"); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/InlineBlocks.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/InlineBlocks.cs index 84937b3058..d03351143b 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/InlineBlocks.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/InlineBlocks.cs @@ -18,7 +18,9 @@ Link(string link) { #line default #line hidden + Instrumentation.BeginContext(29, 6, true); WriteLiteralTo(__razor_helper_writer, " (new Template((__razor_attribute_value_writer) => { #line 2 "InlineBlocks.cshtml" @@ -27,6 +29,7 @@ Link(string link) { #line default #line hidden + Instrumentation.BeginContext(63, 4, false); WriteTo(__razor_attribute_value_writer, #line 2 "InlineBlocks.cshtml" link @@ -35,13 +38,16 @@ Link(string link) { #line hidden ); + Instrumentation.EndContext(); #line 2 "InlineBlocks.cshtml" } else { #line default #line hidden + Instrumentation.BeginContext(76, 3, true); WriteLiteralTo(__razor_attribute_value_writer, " # "); + Instrumentation.EndContext(); #line 2 "InlineBlocks.cshtml" } @@ -50,7 +56,9 @@ Link(string link) { } ), 42), false)); + Instrumentation.BeginContext(94, 5, true); WriteLiteralTo(__razor_helper_writer, " />\r\n"); + Instrumentation.EndContext(); #line 3 "InlineBlocks.cshtml" #line default diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Instrumented.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Instrumented.cs new file mode 100644 index 0000000000..6a4abae5be --- /dev/null +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Instrumented.cs @@ -0,0 +1,261 @@ +namespace TestOutput +{ + using System; + using System.Threading.Tasks; + + public class Instrumented + { +public static Template +#line 1 "Instrumented.cshtml" +Strong(string s) { + +#line default +#line hidden + return new Template((__razor_helper_writer) => { +#line 1 "Instrumented.cshtml" + + +#line default +#line hidden + + Instrumentation.BeginContext(28, 12, true); + WriteLiteralTo(__razor_helper_writer, " "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(41, 1, false); + WriteTo(__razor_helper_writer, +#line 2 "Instrumented.cshtml" + s + +#line default +#line hidden + ); + + Instrumentation.EndContext(); + Instrumentation.BeginContext(42, 11, true); + WriteLiteralTo(__razor_helper_writer, "\r\n"); + Instrumentation.EndContext(); +#line 3 "Instrumented.cshtml" + +#line default +#line hidden + + } + ); +#line 3 "Instrumented.cshtml" +} + +#line default +#line hidden + + #line hidden + public Instrumented() + { + } + + #pragma warning disable 1998 + public override async Task ExecuteAsync() + { + Instrumentation.BeginContext(56, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); +#line 5 "Instrumented.cshtml" + + int i = 1; + var foo = + +#line default +#line hidden + + item => new Template((__razor_template_writer) => { + Instrumentation.BeginContext(93, 10, true); + WriteLiteralTo(__razor_template_writer, "

Bar

"); + Instrumentation.EndContext(); + } + ) +#line 7 "Instrumented.cshtml" + ; + +#line default +#line hidden + + Instrumentation.BeginContext(106, 43, true); + WriteLiteral(" Hello, World\r\n

Hello, World

\r\n"); + Instrumentation.EndContext(); +#line 10 "Instrumented.cshtml" + +#line default +#line hidden + + Instrumentation.BeginContext(152, 4, true); + WriteLiteral("\r\n\r\n"); + Instrumentation.EndContext(); +#line 12 "Instrumented.cshtml" + while(i <= 10) { + +#line default +#line hidden + + Instrumentation.BeginContext(175, 23, true); + WriteLiteral("

Hello from C#, #"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(200, 1, false); + Write( +#line 13 "Instrumented.cshtml" + i + +#line default +#line hidden + ); + + Instrumentation.EndContext(); + Instrumentation.BeginContext(202, 6, true); + WriteLiteral("

\r\n"); + Instrumentation.EndContext(); +#line 14 "Instrumented.cshtml" + i += 1; +} + +#line default +#line hidden + + Instrumentation.BeginContext(224, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); +#line 17 "Instrumented.cshtml" + if(i == 11) { + +#line default +#line hidden + + Instrumentation.BeginContext(242, 31, true); + WriteLiteral("

We wrote 10 lines!

\r\n"); + Instrumentation.EndContext(); +#line 19 "Instrumented.cshtml" +} + +#line default +#line hidden + + Instrumentation.BeginContext(276, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); +#line 21 "Instrumented.cshtml" + switch(i) { + case 11: + +#line default +#line hidden + + Instrumentation.BeginContext(306, 46, true); + WriteLiteral("

No really, we wrote 10 lines!

\r\n"); + Instrumentation.EndContext(); +#line 24 "Instrumented.cshtml" + break; + default: + +#line default +#line hidden + + Instrumentation.BeginContext(382, 39, true); + WriteLiteral("

Actually, we didn\'t...

\r\n"); + Instrumentation.EndContext(); +#line 27 "Instrumented.cshtml" + break; +} + +#line default +#line hidden + + Instrumentation.BeginContext(440, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); +#line 30 "Instrumented.cshtml" + for(int j = 1; j <= 10; j += 2) { + +#line default +#line hidden + + Instrumentation.BeginContext(478, 29, true); + WriteLiteral("

Hello again from C#, #"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(509, 1, false); + Write( +#line 31 "Instrumented.cshtml" + j + +#line default +#line hidden + ); + + Instrumentation.EndContext(); + Instrumentation.BeginContext(511, 6, true); + WriteLiteral("

\r\n"); + Instrumentation.EndContext(); +#line 32 "Instrumented.cshtml" +} + +#line default +#line hidden + + Instrumentation.BeginContext(520, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); +#line 34 "Instrumented.cshtml" + try { + +#line default +#line hidden + + Instrumentation.BeginContext(530, 41, true); + WriteLiteral("

That time, we wrote 5 lines!

\r\n"); + Instrumentation.EndContext(); +#line 36 "Instrumented.cshtml" +} catch(Exception ex) { + +#line default +#line hidden + + Instrumentation.BeginContext(596, 33, true); + WriteLiteral("

Oh no! An error occurred: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(631, 10, false); + Write( +#line 37 "Instrumented.cshtml" + ex.Message + +#line default +#line hidden + ); + + Instrumentation.EndContext(); + Instrumentation.BeginContext(642, 6, true); + WriteLiteral("

\r\n"); + Instrumentation.EndContext(); +#line 38 "Instrumented.cshtml" +} + +#line default +#line hidden + + Instrumentation.BeginContext(651, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); +#line 40 "Instrumented.cshtml" + lock(new object()) { + +#line default +#line hidden + + Instrumentation.BeginContext(676, 53, true); + WriteLiteral("

This block is locked, for your security!

\r\n"); + Instrumentation.EndContext(); +#line 42 "Instrumented.cshtml" +} + +#line default +#line hidden + + } + #pragma warning restore 1998 + } +} diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/MarkupInCodeBlock.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/MarkupInCodeBlock.cs index ec740bec18..fb2a3ffe8e 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/MarkupInCodeBlock.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/MarkupInCodeBlock.cs @@ -20,7 +20,10 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(40, 27, true); WriteLiteral("

Hello from C#, #"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(69, 12, false); Write( #line 3 "MarkupInCodeBlock.cshtml" i.ToString() @@ -29,14 +32,19 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(82, 6, true); WriteLiteral("

\r\n"); + Instrumentation.EndContext(); #line 4 "MarkupInCodeBlock.cshtml" } #line default #line hidden + Instrumentation.BeginContext(96, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/NestedHelpers.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/NestedHelpers.cs index 6151e3750e..6a55c8d8ea 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/NestedHelpers.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/NestedHelpers.cs @@ -26,7 +26,10 @@ Italic(string s) { #line default #line hidden + Instrumentation.BeginContext(142, 8, true); WriteLiteralTo(__razor_helper_writer, " "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(151, 7, false); WriteTo(__razor_helper_writer, #line 7 "NestedHelpers.cshtml" Bold(s) @@ -35,7 +38,10 @@ Italic(string s) { #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(158, 7, true); WriteLiteralTo(__razor_helper_writer, "\r\n"); + Instrumentation.EndContext(); #line 8 "NestedHelpers.cshtml" #line default @@ -63,7 +69,10 @@ Bold(string s) { #line default #line hidden + Instrumentation.BeginContext(106, 16, true); WriteLiteralTo(__razor_helper_writer, " "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(123, 1, false); WriteTo(__razor_helper_writer, #line 5 "NestedHelpers.cshtml" s @@ -72,7 +81,10 @@ Bold(string s) { #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(124, 11, true); WriteLiteralTo(__razor_helper_writer, "\r\n"); + Instrumentation.EndContext(); #line 6 "NestedHelpers.cshtml" @@ -95,7 +107,10 @@ Bold(string s) { #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(168, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(171, 15, false); Write( #line 10 "NestedHelpers.cshtml" Italic("Hello") @@ -104,6 +119,7 @@ Bold(string s) { #line hidden ); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/NoLinePragmas.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/NoLinePragmas.cs index adf7c772be..54e97b4e37 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/NoLinePragmas.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/NoLinePragmas.cs @@ -20,14 +20,19 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(21, 4, true); WriteLiteral("\r\n\r\n"); + Instrumentation.EndContext(); #line 5 "" while(i <= 10) { #line default #line hidden + Instrumentation.BeginContext(44, 23, true); WriteLiteral("

Hello from C#, #"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(69, 1, false); Write( #line 6 "" i @@ -36,7 +41,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(71, 6, true); WriteLiteral("

\r\n"); + Instrumentation.EndContext(); #line 7 "" i += 1; } @@ -44,21 +52,27 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(93, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); #line 10 "" if(i == 11) { #line default #line hidden + Instrumentation.BeginContext(111, 31, true); WriteLiteral("

We wrote 10 lines!

\r\n"); + Instrumentation.EndContext(); #line 12 "" } #line default #line hidden + Instrumentation.BeginContext(145, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); #line 14 "" switch(i) { case 11: @@ -66,7 +80,9 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(175, 46, true); WriteLiteral("

No really, we wrote 10 lines!

\r\n"); + Instrumentation.EndContext(); #line 17 "" break; default: @@ -74,7 +90,9 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(251, 39, true); WriteLiteral("

Actually, we didn\'t...

\r\n"); + Instrumentation.EndContext(); #line 20 "" break; } @@ -82,14 +100,19 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(309, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); #line 23 "" for(int j = 1; j <= 10; j += 2) { #line default #line hidden + Instrumentation.BeginContext(347, 29, true); WriteLiteral("

Hello again from C#, #"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(378, 1, false); Write( #line 24 "" j @@ -98,28 +121,38 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(380, 6, true); WriteLiteral("

\r\n"); + Instrumentation.EndContext(); #line 25 "" } #line default #line hidden + Instrumentation.BeginContext(389, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); #line 27 "" try { #line default #line hidden + Instrumentation.BeginContext(399, 41, true); WriteLiteral("

That time, we wrote 5 lines!

\r\n"); + Instrumentation.EndContext(); #line 29 "" } catch(Exception ex) { #line default #line hidden + Instrumentation.BeginContext(465, 33, true); WriteLiteral("

Oh no! An error occurred: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(500, 10, false); Write( #line 30 "" ex.Message @@ -128,7 +161,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(511, 6, true); WriteLiteral("

\r\n"); + Instrumentation.EndContext(); #line 31 "" } @@ -142,7 +178,10 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(558, 12, true); WriteLiteral("

i is now "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(571, 1, false); Write( #line 34 "" i @@ -151,14 +190,19 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(572, 8, true); WriteLiteral("

\r\n\r\n"); + Instrumentation.EndContext(); #line 36 "" lock(new object()) { #line default #line hidden + Instrumentation.BeginContext(603, 53, true); WriteLiteral("

This block is locked, for your security!

\r\n"); + Instrumentation.EndContext(); #line 38 "" } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/RazorComments.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/RazorComments.cs index 1f4e7aac0d..db2e1ada96 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/RazorComments.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/RazorComments.cs @@ -13,7 +13,9 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(0, 34, true); WriteLiteral("\r\n

This should be shown

\r\n\r\n"); + Instrumentation.EndContext(); #line 4 "RazorComments.cshtml" @@ -37,14 +39,19 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(232, 4, true); WriteLiteral("\r\n\r\n"); + Instrumentation.EndContext(); #line 12 "RazorComments.cshtml" var bar = "@* bar *@"; #line default #line hidden + Instrumentation.BeginContext(263, 46, true); WriteLiteral("\r\n

But this should show the comment syntax: "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(310, 3, false); Write( #line 13 "RazorComments.cshtml" bar @@ -53,7 +60,11 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(313, 8, true); WriteLiteral("

\r\n\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(323, 1, false); Write( #line 15 "RazorComments.cshtml" a @@ -67,7 +78,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(330, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs index 1ae7a538bd..3fc278a1b5 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs @@ -13,9 +13,13 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(0, 2, true); WriteLiteral("(Href("~/Foo"), 9), false)); + Instrumentation.BeginContext(15, 12, true); WriteLiteral(">Foo
\r\n(Href("~/Products/"), 34), false), Tuple.Create(Tuple.Create("", 45), Tuple.Create( #line 2 "ResolveUrl.cshtml" @@ -24,7 +28,10 @@ namespace TestOutput #line default #line hidden , 45), false)); + Instrumentation.BeginContext(57, 1, true); WriteLiteral(">"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(59, 12, false); Write( #line 2 "ResolveUrl.cshtml" product.Name @@ -33,7 +40,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(71, 8, true); WriteLiteral("\r\n(Href("~/Products/"), 86), false), Tuple.Create(Tuple.Create("", 97), Tuple.Create( #line 3 "ResolveUrl.cshtml" @@ -42,7 +52,9 @@ namespace TestOutput #line default #line hidden , 97), false), Tuple.Create(Tuple.Create("", 108), Tuple.Create("/Detail", 108), true)); + Instrumentation.BeginContext(116, 16, true); WriteLiteral(">Details\r\n(Href("~/A+Really(Crazy),Url.Is:This/"), 139), false), Tuple.Create(Tuple.Create("", 169), Tuple.Create( #line 4 "ResolveUrl.cshtml" @@ -51,16 +63,22 @@ namespace TestOutput #line default #line hidden , 169), false), Tuple.Create(Tuple.Create("", 180), Tuple.Create("/Detail", 180), true)); + Instrumentation.BeginContext(188, 19, true); WriteLiteral(">Crazy Url!\r\n\r\n"); + Instrumentation.EndContext(); #line 6 "ResolveUrl.cshtml" #line default #line hidden + Instrumentation.BeginContext(211, 16, true); WriteLiteral(" \r\n (Href("~/Foo"), 240), false)); + Instrumentation.BeginContext(246, 20, true); WriteLiteral(">Foo\r\n (Href("~/Products/"), 273), false), Tuple.Create(Tuple.Create("", 284), Tuple.Create( #line 9 "ResolveUrl.cshtml" @@ -69,7 +87,10 @@ namespace TestOutput #line default #line hidden , 284), false)); + Instrumentation.BeginContext(296, 1, true); WriteLiteral(">"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(298, 12, false); Write( #line 9 "ResolveUrl.cshtml" product.Name @@ -78,7 +99,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(310, 16, true); WriteLiteral("\r\n (Href("~/Products/"), 333), false), Tuple.Create(Tuple.Create("", 344), Tuple.Create( #line 10 "ResolveUrl.cshtml" @@ -87,7 +111,9 @@ namespace TestOutput #line default #line hidden , 344), false), Tuple.Create(Tuple.Create("", 355), Tuple.Create("/Detail", 355), true)); + Instrumentation.BeginContext(363, 24, true); WriteLiteral(">Details\r\n (Href("~/A+Really(Crazy),Url.Is:This/"), 394), false), Tuple.Create(Tuple.Create("", 424), Tuple.Create( #line 11 "ResolveUrl.cshtml" @@ -96,17 +122,25 @@ namespace TestOutput #line default #line hidden , 424), false), Tuple.Create(Tuple.Create("", 435), Tuple.Create("/Detail", 435), true)); + Instrumentation.BeginContext(443, 23, true); WriteLiteral(">Crazy Url!\r\n \r\n"); + Instrumentation.EndContext(); #line 13 "ResolveUrl.cshtml" #line default #line hidden + Instrumentation.BeginContext(474, 4, true); WriteLiteral("\r\n\r\n"); + Instrumentation.EndContext(); DefineSection("Foo", new Template((__razor_template_writer) => { + Instrumentation.BeginContext(492, 8, true); WriteLiteralTo(__razor_template_writer, "\r\n (Href("~/Foo"), 507), false)); + Instrumentation.BeginContext(513, 16, true); WriteLiteralTo(__razor_template_writer, ">Foo\r\n (Href("~/Products/"), 536), false), Tuple.Create(Tuple.Create("", 547), Tuple.Create( #line 17 "ResolveUrl.cshtml" @@ -115,7 +149,10 @@ namespace TestOutput #line default #line hidden , 547), false)); + Instrumentation.BeginContext(559, 1, true); WriteLiteralTo(__razor_template_writer, ">"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(561, 12, false); WriteTo(__razor_template_writer, #line 17 "ResolveUrl.cshtml" product.Name @@ -124,7 +161,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(573, 12, true); WriteLiteralTo(__razor_template_writer, "\r\n (Href("~/Products/"), 592), false), Tuple.Create(Tuple.Create("", 603), Tuple.Create( #line 18 "ResolveUrl.cshtml" @@ -133,7 +173,9 @@ namespace TestOutput #line default #line hidden , 603), false), Tuple.Create(Tuple.Create("", 614), Tuple.Create("/Detail", 614), true)); + Instrumentation.BeginContext(622, 20, true); WriteLiteralTo(__razor_template_writer, ">Details\r\n (Href("~/A+Really(Crazy),Url.Is:This/"), 649), false), Tuple.Create(Tuple.Create("", 679), Tuple.Create( #line 19 "ResolveUrl.cshtml" @@ -142,7 +184,9 @@ namespace TestOutput #line default #line hidden , 679), false), Tuple.Create(Tuple.Create("", 690), Tuple.Create("/Detail", 690), true)); + Instrumentation.BeginContext(698, 17, true); WriteLiteralTo(__razor_template_writer, ">Crazy Url!\r\n"); + Instrumentation.EndContext(); } )); } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Sections.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Sections.cs index c14b9634c0..909916bb4a 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Sections.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Sections.cs @@ -20,14 +20,22 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(47, 33, true); WriteLiteral("\r\n\r\n
This is in the Body>\r\n\r\n"); + Instrumentation.EndContext(); DefineSection("Section2", new Template((__razor_template_writer) => { + Instrumentation.BeginContext(99, 39, true); WriteLiteralTo(__razor_template_writer, "\r\n
This is in Section 2
\r\n"); + Instrumentation.EndContext(); } )); + Instrumentation.BeginContext(141, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); DefineSection("Section1", new Template((__razor_template_writer) => { + Instrumentation.BeginContext(162, 39, true); WriteLiteralTo(__razor_template_writer, "\r\n
This is in Section 1
\r\n"); + Instrumentation.EndContext(); } )); } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Templates.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Templates.cs index 61d0fadf74..ca27a18e36 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Templates.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Templates.cs @@ -25,7 +25,9 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(280, 2, true); WriteLiteral("\r\n"); + Instrumentation.EndContext(); #line 11 "Templates.cshtml" Func foo = @@ -34,7 +36,10 @@ namespace TestOutput #line hidden item => new Template((__razor_template_writer) => { + Instrumentation.BeginContext(325, 11, true); WriteLiteralTo(__razor_template_writer, "This works "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(337, 4, false); WriteTo(__razor_template_writer, #line 12 "Templates.cshtml" item @@ -43,7 +48,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(341, 1, true); WriteLiteralTo(__razor_template_writer, "!"); + Instrumentation.EndContext(); } ) #line 12 "Templates.cshtml" @@ -53,6 +61,7 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(357, 7, false); Write( #line 13 "Templates.cshtml" foo("") @@ -61,13 +70,17 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); #line 13 "Templates.cshtml" #line default #line hidden + Instrumentation.BeginContext(367, 10, true); WriteLiteral("\r\n\r\n
    \r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(379, 11, false); Write( #line 17 "Templates.cshtml" Repeat(10, @@ -75,7 +88,10 @@ namespace TestOutput #line default #line hidden item => new Template((__razor_template_writer) => { + Instrumentation.BeginContext(391, 10, true); WriteLiteralTo(__razor_template_writer, "
  • Item #"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(402, 4, false); WriteTo(__razor_template_writer, #line 17 "Templates.cshtml" item @@ -84,7 +100,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(406, 5, true); WriteLiteralTo(__razor_template_writer, "
  • "); + Instrumentation.EndContext(); } ) #line 17 "Templates.cshtml" @@ -94,7 +113,11 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(413, 16, true); WriteLiteral("\r\n
\r\n\r\n

\r\n"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(430, 16, false); Write( #line 21 "Templates.cshtml" Repeat(10, @@ -103,7 +126,10 @@ namespace TestOutput #line default #line hidden item => new Template((__razor_template_writer) => { + Instrumentation.BeginContext(448, 14, true); WriteLiteralTo(__razor_template_writer, " This is line#"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(463, 4, false); WriteTo(__razor_template_writer, #line 22 "Templates.cshtml" item @@ -112,7 +138,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(467, 17, true); WriteLiteralTo(__razor_template_writer, " of markup
\r\n"); + Instrumentation.EndContext(); } ) #line 23 "Templates.cshtml" @@ -122,7 +151,11 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(485, 20, true); WriteLiteral("\r\n

\r\n\r\n
    \r\n "); + Instrumentation.EndContext(); + Instrumentation.BeginContext(506, 11, false); Write( #line 27 "Templates.cshtml" Repeat(10, @@ -130,7 +163,10 @@ namespace TestOutput #line default #line hidden item => new Template((__razor_template_writer) => { + Instrumentation.BeginContext(518, 20, true); WriteLiteralTo(__razor_template_writer, "
  • \r\n Item #"); + Instrumentation.EndContext(); + Instrumentation.BeginContext(539, 4, false); WriteTo(__razor_template_writer, #line 28 "Templates.cshtml" item @@ -139,7 +175,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(543, 2, true); WriteLiteralTo(__razor_template_writer, "\r\n"); + Instrumentation.EndContext(); #line 29 "Templates.cshtml" @@ -152,8 +191,10 @@ namespace TestOutput #line default #line hidden + Instrumentation.BeginContext(574, 93, true); WriteLiteralTo(__razor_template_writer, "\r\n
      \r\n
    • Child Items... ?
    • \r\n \r\n \r\n "); + Instrumentation.EndContext(); } ) #line 34 "Templates.cshtml" @@ -163,7 +204,10 @@ namespace TestOutput #line hidden ); + Instrumentation.EndContext(); + Instrumentation.BeginContext(715, 8, true); WriteLiteral("\r\n
    "); + Instrumentation.EndContext(); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/Instrumented.cshtml b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/Instrumented.cshtml new file mode 100644 index 0000000000..4d9b03eb84 --- /dev/null +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/Instrumented.cshtml @@ -0,0 +1,42 @@ +@helper Strong(string s) { + @s +} + +@{ + int i = 1; + var foo = @

    Bar

    ; + @:Hello, World +

    Hello, World

    +} + +@while(i <= 10) { +

    Hello from C#, #@(i)

    + i += 1; +} + +@if(i == 11) { +

    We wrote 10 lines!

    +} + +@switch(i) { + case 11: +

    No really, we wrote 10 lines!

    + break; + default: +

    Actually, we didn't...

    + break; +} + +@for(int j = 1; j <= 10; j += 2) { +

    Hello again from C#, #@(j)

    +} + +@try { +

    That time, we wrote 5 lines!

    +} catch(Exception ex) { +

    Oh no! An error occurred: @(ex.Message)

    +} + +@lock(new object()) { +

    This block is locked, for your security!

    +} \ No newline at end of file