v10: Fix build warnings in Web.Common (#12349)
* 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>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -7,50 +7,48 @@ using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Logging;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
|
||||
namespace Umbraco.Cms.Web.Common.Profiler
|
||||
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>
|
||||
/// Initialized the web profiling. Ensures the boot process profiling is stopped.
|
||||
/// Initializes a new instance of the <see cref="InitializeWebProfiling" /> class.
|
||||
/// </summary>
|
||||
public class InitializeWebProfiling : INotificationHandler<UmbracoApplicationStartingNotification>
|
||||
public InitializeWebProfiling(IProfiler profiler, ILogger<InitializeWebProfiling> logger)
|
||||
{
|
||||
private readonly bool _profile;
|
||||
private readonly WebProfiler? _profiler;
|
||||
_profile = true;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InitializeWebProfiling"/> class.
|
||||
/// </summary>
|
||||
public InitializeWebProfiling(IProfiler profiler, ILogger<InitializeWebProfiling> logger)
|
||||
// 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)
|
||||
{
|
||||
_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;
|
||||
return;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Handle(UmbracoApplicationStartingNotification notification)
|
||||
// if VoidProfiler was registered, let it be known
|
||||
if (profiler is NoopProfiler)
|
||||
{
|
||||
if (_profile && notification.RuntimeLevel == RuntimeLevel.Run)
|
||||
{
|
||||
// Stop the profiling of the booting process
|
||||
_profiler?.StopBoot();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user