* Run code cleanup * Run dotnet format * Start manual cleanup in Web.Common * Finish up manual cleanup * Fix tests * Fix up InMemoryModelFactory.cs * Inject proper macroRenderer * Update src/Umbraco.Web.Common/Filters/JsonDateTimeFormatAttribute.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Web.Common/Filters/ValidateUmbracoFormRouteStringAttribute.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix based on review Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Events;
|
|
using Umbraco.Cms.Core.Logging;
|
|
using Umbraco.Cms.Core.Notifications;
|
|
|
|
namespace Umbraco.Cms.Web.Common.Profiler;
|
|
|
|
/// <summary>
|
|
/// Initialized the web profiling. Ensures the boot process profiling is stopped.
|
|
/// </summary>
|
|
public class InitializeWebProfiling : INotificationHandler<UmbracoApplicationStartingNotification>
|
|
{
|
|
private readonly bool _profile;
|
|
private readonly WebProfiler? _profiler;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="InitializeWebProfiling" /> class.
|
|
/// </summary>
|
|
public InitializeWebProfiling(IProfiler profiler, ILogger<InitializeWebProfiling> logger)
|
|
{
|
|
_profile = true;
|
|
|
|
// although registered in UmbracoBuilderExtensions.AddUmbraco, ensure that we have not
|
|
// been replaced by another component, and we are still "the" profiler
|
|
_profiler = profiler as WebProfiler;
|
|
if (_profiler != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// if VoidProfiler was registered, let it be known
|
|
if (profiler is NoopProfiler)
|
|
{
|
|
logger.LogInformation(
|
|
"Profiler is VoidProfiler, not profiling (must run debug mode to profile).");
|
|
}
|
|
|
|
_profile = false;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Handle(UmbracoApplicationStartingNotification notification)
|
|
{
|
|
if (_profile && notification.RuntimeLevel == RuntimeLevel.Run)
|
|
{
|
|
// Stop the profiling of the booting process
|
|
_profiler?.StopBoot();
|
|
}
|
|
}
|
|
}
|