Updated MiniProfiler to v2

This commit is contained in:
Mark McDowall 2012-07-27 14:31:33 -07:00
commit 216bf08ced
16 changed files with 2407 additions and 123 deletions

View file

@ -1,23 +1,25 @@
using System;
using System.Web;
using System.Web.Mvc;
using System.Linq;
using MvcMiniProfiler;
using MvcMiniProfiler.MVCHelpers;
using StackExchange.Profiling;
using StackExchange.Profiling.MVCHelpers;
using Microsoft.Web.Infrastructure;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using NzbDrone.Common;
using NzbDrone.Web.Helpers;
//using System.Data;
//using System.Data.Entity;
//using System.Data.Entity.Infrastructure;
//using StackExchange.Profiling.Data.EntityFramework;
//using StackExchange.Profiling.Data.Linq2Sql;
//using MvcMiniProfiler.Data.Linq2Sql;
[assembly: WebActivator.PreApplicationStartMethod(
typeof(NzbDrone.Web.App_Start.MiniProfilerPackage), "PreStart")]
[assembly: WebActivator.PreApplicationStartMethod(typeof(NzbDrone.Web.App_Start.MiniProfilerPackage), "PreStart")]
[assembly: WebActivator.PostApplicationStartMethod(typeof(NzbDrone.Web.App_Start.MiniProfilerPackage), "PostStart")]
[assembly: WebActivator.PostApplicationStartMethod(
typeof(NzbDrone.Web.App_Start.MiniProfilerPackage), "PostStart")]
namespace NzbDrone.Web.App_Start
namespace NzbDrone.Web.App_Start
{
public static class MiniProfilerPackage
{
@ -27,23 +29,37 @@ namespace NzbDrone.Web.App_Start
// Be sure to restart you ASP.NET Developement server, this code will not run until you do that.
//TODO: See - _MINIPROFILER UPDATED Layout.cshtml
// For profiling to display in the UI you will have to include the line @MvcMiniProfiler.MiniProfiler.RenderIncludes()
// For profiling to display in the UI you will have to include the line @StackExchange.Profiling.MiniProfiler.RenderIncludes()
// in your master layout
//TODO: Non SQL Server based installs can use other formatters like: new MvcMiniProfiler.SqlFormatters.InlineFormatter()
MiniProfiler.Settings.SqlFormatter = new MvcMiniProfiler.SqlFormatters.SqlServerFormatter();
//TODO: Non SQL Server based installs can use other formatters like: new StackExchange.Profiling.SqlFormatters.InlineFormatter()
MiniProfiler.Settings.SqlFormatter = new StackExchange.Profiling.SqlFormatters.SqlServerFormatter();
//TODO: To profile a standard DbConnection:
// var profiled = new ProfiledDbConnection(cnn, MiniProfiler.Current);
//TODO: To profile a standard DbConnection:
// var profiled = new ProfiledDbConnection(cnn, MiniProfiler.Current);
//TODO: If you are profiling EF code first try:
// MiniProfilerEF.Initialize();
// MiniProfilerEF.Initialize();
//Make sure the MiniProfiler handles BeginRequest and EndRequest
DynamicModuleUtility.RegisterModule(typeof(MiniProfilerStartupModule));
//Setup profiler for Controllers via a Global ActionFilter
GlobalFilters.Filters.Add(new ProfilingActionFilter());
// You can use this to check if a request is allowed to view results
//MiniProfiler.Settings.Results_Authorize = (request) =>
//{
// you should implement this if you need to restrict visibility of profiling on a per request basis
// return !DisableProfilingResults;
//};
// the list of all sessions in the store is restricted by default, you must return true to alllow it
//MiniProfiler.Settings.Results_List_Authorize = (request) =>
//{
// you may implement this if you need to restrict visibility of profiling lists on a per request basis
//return true; // all requests are kosher
//};
}
public static void PostStart()
@ -65,33 +81,28 @@ namespace NzbDrone.Web.App_Start
{
context.BeginRequest += (sender, e) =>
{
//var request = ((HttpApplication)sender).Request;
var request = ((HttpApplication)sender).Request;
//TODO: By default only local requests are profiled, optionally you can set it up
// so authenticated users are always profiled
//if (request.IsLocal) { MiniProfiler.Start(); }
if (!EnvironmentProvider.IsProduction || ProfilerHelper.Enabled())
{
var requestPath = ((HttpApplication)sender).Request.AppRelativeCurrentExecutionFilePath.ToLower();
if (!requestPath.StartsWith("~/signalr") && !requestPath.EndsWith("notification/comet"))
{
MiniProfiler.Start();
}
}
if (request.IsLocal) { MiniProfiler.Start(); }
};
// TODO: You can control who sees the profiling information
/*
context.AuthenticateRequest += (sender, e) =>
{
if (!CurrentUserIsAllowedToSeeProfiler())
{
MvcMiniProfiler.MiniProfiler.Stop(discardResults: true);
StackExchange.Profiling.MiniProfiler.Stop(discardResults: true);
}
};
*/
context.EndRequest += (sender, e) => MiniProfiler.Stop();
context.EndRequest += (sender, e) =>
{
MiniProfiler.Stop();
};
}
public void Dispose() { }