From 4fb7710faba349a75460efab54c5d677a801d09f Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Sun, 7 Jul 2024 18:56:04 +0200 Subject: [PATCH 1/4] Handling PageTitle shape tracing --- .../ShapeTracing/ShapeTracingShapeEvents.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs index c9fae732..0fc94cd5 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs @@ -22,6 +22,15 @@ public Task DisplayedAsync(ShapeDisplayContext context) var builder = new HtmlContentBuilder(6); var shapeMetadata = context.Shape.Metadata; + var isPageTitle = shapeMetadata.Type == "PageTitle"; + + // This is needed to have the shape info as a comment, otherwise it would be put in the title. + if (isPageTitle) + { + builder.AppendHtml(context.ChildContent); + builder.AppendHtmlLine(""); + } + builder.AppendLine(); builder.AppendHtmlLine(""); - builder.AppendHtml(context.ChildContent); + if (!isPageTitle) + { + builder.AppendHtml(context.ChildContent); + } context.ChildContent = builder; From ee9c32bd8ae54b543abf41a54839b96c0515b31d Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Mon, 8 Jul 2024 21:51:22 +0200 Subject: [PATCH 2/4] Updating PageTitle shape tracing solution --- .../ShapeTracing/ShapeTracingShapeEvents.cs | 60 ++++++++++++------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs index 0fc94cd5..5efa999b 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs @@ -1,8 +1,10 @@ using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; using OrchardCore.DisplayManagement.Implementation; using OrchardCore.DisplayManagement.Shapes; using System.Linq; +using System.Text.Encodings.Web; using System.Threading.Tasks; namespace Lombiq.HelpfulExtensions.Extensions.ShapeTracing; @@ -10,8 +12,13 @@ namespace Lombiq.HelpfulExtensions.Extensions.ShapeTracing; internal sealed class ShapeTracingShapeEvents : IShapeDisplayEvents { private readonly IHttpContextAccessor _hca; + private readonly ILogger _logger; - public ShapeTracingShapeEvents(IHttpContextAccessor hca) => _hca = hca; + public ShapeTracingShapeEvents(IHttpContextAccessor hca, ILogger logger) + { + _hca = hca; + _logger = logger; + } public Task DisplayedAsync(ShapeDisplayContext context) { @@ -20,48 +27,42 @@ public Task DisplayedAsync(ShapeDisplayContext context) // We could also use _orchardHelper.ConsoleLog(context.Shape) here but that causes an OutOfMemoryException. var builder = new HtmlContentBuilder(6); + var builderShapeInfo = new HtmlContentBuilder(6); var shapeMetadata = context.Shape.Metadata; - var isPageTitle = shapeMetadata.Type == "PageTitle"; - - // This is needed to have the shape info as a comment, otherwise it would be put in the title. - if (isPageTitle) - { - builder.AppendHtml(context.ChildContent); - builder.AppendHtmlLine(""); - } + var isPageTitle = shapeMetadata.Type == nameof(PageTitleShapes.PageTitle); builder.AppendLine(); builder.AppendHtmlLine(""); - if (!isPageTitle) + if (isPageTitle) + { + var log = string.Empty; + + using (var writer = new System.IO.StringWriter()) + { + builderShapeInfo.WriteTo(writer, HtmlEncoder.Default); + log = writer.ToString(); + } + + _logger.LogInformation("PageTitle Shape information:\n{ShapeInformation}", log); + } + else { builder.AppendHtml(context.ChildContent); + context.ChildContent = builder; } - context.ChildContent = builder; - return Task.CompletedTask; } From 3dabfd0944668765ef94a68c167b0ad5b865e084 Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Mon, 8 Jul 2024 21:51:50 +0200 Subject: [PATCH 3/4] Adding comment --- .../Extensions/ShapeTracing/ShapeTracingShapeEvents.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs index 5efa999b..b072ee5a 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs @@ -80,6 +80,7 @@ void AddIfNotNullOrEmpty(string name, string value) builder.AppendHtmlLine("-->"); + // This is needed to have the shape info as a comment, otherwise it would be put in the title. if (isPageTitle) { var log = string.Empty; From 5b05dd09bd9fdfb7b1cd20cf20a3c878f310a026 Mon Sep 17 00:00:00 2001 From: Szabolcs Deme Date: Tue, 9 Jul 2024 00:40:58 +0200 Subject: [PATCH 4/4] Addressing change requests --- .../ShapeTracing/ShapeTracingShapeEvents.cs | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs index b072ee5a..43d9873e 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs @@ -1,10 +1,10 @@ using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Localization; using Microsoft.Extensions.Logging; using OrchardCore.DisplayManagement.Implementation; using OrchardCore.DisplayManagement.Shapes; using System.Linq; -using System.Text.Encodings.Web; using System.Threading.Tasks; namespace Lombiq.HelpfulExtensions.Extensions.ShapeTracing; @@ -76,24 +76,14 @@ void AddIfNotNullOrEmpty(string name, string value) AddIfNotNullOrEmpty(nameof(ShapeMetadata.Prefix), shapeMetadata.Prefix); AddIfNotNullOrEmpty(nameof(ShapeMetadata.Tab), shapeMetadata.Tab); + _logger.LogInformation("Shape information:\n{ShapeInformation}", builderShapeInfo.Html()); + builder.AppendHtml(builderShapeInfo); builder.AppendHtmlLine("-->"); - // This is needed to have the shape info as a comment, otherwise it would be put in the title. - if (isPageTitle) - { - var log = string.Empty; - - using (var writer = new System.IO.StringWriter()) - { - builderShapeInfo.WriteTo(writer, HtmlEncoder.Default); - log = writer.ToString(); - } - - _logger.LogInformation("PageTitle Shape information:\n{ShapeInformation}", log); - } - else + // We are skipping the PageTitle shape, otherwise the shape information would be put in the title. + if (!isPageTitle) { builder.AppendHtml(context.ChildContent); context.ChildContent = builder;