2016-09-08 18:43:58 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Web;
|
2018-11-19 21:23:08 +11:00
|
|
|
|
using Umbraco.Core;
|
2016-09-08 18:43:58 +02:00
|
|
|
|
using Umbraco.Core.Components;
|
2018-11-19 21:23:08 +11:00
|
|
|
|
using Umbraco.Core.Logging;
|
2016-09-08 18:43:58 +02:00
|
|
|
|
|
2018-11-19 21:23:08 +11:00
|
|
|
|
namespace Umbraco.Web.Logging
|
2016-09-08 18:43:58 +02:00
|
|
|
|
{
|
2019-01-03 21:00:28 +01:00
|
|
|
|
internal class WebProfilerComponent : IComponent
|
2016-09-08 18:43:58 +02:00
|
|
|
|
{
|
|
|
|
|
|
// the profiler is too important to be composed in a component,
|
|
|
|
|
|
// it is composed first thing in WebRuntime.Compose - this component
|
|
|
|
|
|
// only initializes it if needed.
|
|
|
|
|
|
//
|
2016-10-07 14:34:55 +02:00
|
|
|
|
//public override void Compose(Composition Composition)
|
2016-09-08 18:43:58 +02:00
|
|
|
|
//{
|
2016-10-07 14:34:55 +02:00
|
|
|
|
// composition.Container.RegisterSingleton<IProfiler, WebProfiler>();
|
2016-09-08 18:43:58 +02:00
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
private WebProfiler _profiler;
|
|
|
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
|
public WebProfilerComponent(IProfiler profiler, ILogger logger, IRuntimeState runtime)
|
2016-09-08 18:43:58 +02:00
|
|
|
|
{
|
2017-07-20 11:21:28 +02:00
|
|
|
|
// although registered in WebRuntime.Compose, ensure that we have not
|
2016-11-03 10:31:44 +01:00
|
|
|
|
// been replaced by another component, and we are still "the" profiler
|
2016-09-08 18:43:58 +02:00
|
|
|
|
_profiler = profiler as WebProfiler;
|
2016-11-03 10:31:44 +01:00
|
|
|
|
if (_profiler == null)
|
2016-09-08 18:43:58 +02:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
// if VoidProfiler was registered, let it be known
|
|
|
|
|
|
var vp = profiler as VoidProfiler;
|
|
|
|
|
|
if (vp != null)
|
|
|
|
|
|
logger.Info<WebProfilerComponent>("Profiler is VoidProfiler, not profiling (must run debug mode to profile).");
|
|
|
|
|
|
return;
|
2016-09-08 18:43:58 +02:00
|
|
|
|
}
|
2016-11-03 10:31:44 +01:00
|
|
|
|
|
|
|
|
|
|
// bind to ApplicationInit - ie execute the application initialization for *each* application
|
|
|
|
|
|
// it would be a mistake to try and bind to the current application events
|
|
|
|
|
|
UmbracoApplicationBase.ApplicationInit += InitializeApplication;
|
2016-09-08 18:43:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void InitializeApplication(object sender, EventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
var app = sender as HttpApplication;
|
|
|
|
|
|
if (app == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
// for *each* application (this will run more than once)
|
|
|
|
|
|
app.BeginRequest += (s, a) => _profiler.UmbracoApplicationBeginRequest(s, a);
|
|
|
|
|
|
app.EndRequest += (s, a) => _profiler.UmbracoApplicationEndRequest(s, a);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|