Created
December 15, 2011 15:34
-
-
Save taylonr/1481512 to your computer and use it in GitHub Desktop.
PetaPocoGlimpse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[GlimpsePlugin] | |
public class PetaPocoGlimpsePlugin : IGlimpsePlugin | |
{ | |
public object GetData(HttpContextBase context) | |
{ | |
if (context.Items[DataProfiler.PetaKey] == null) | |
return new List<object[]> { new[] { "Log" }, new[] { "No database requests or database logging not switched on (Compilation debug='true' or ForceLogging='true' on | |
PetaPoco.DatabaseWithLogging)", "warn" } }; | |
var sqls = new List<object[]> {new[] {"#", "Time(ms)", "Sql", "Parameters"}}; | |
var i = 1; | |
foreach (var item in DataProfiler.CurrentRequestInfo) | |
{ | |
var parameterHeadings = new List<object[]> {new[] {"Name", "Type", "Value"}}; | |
parameterHeadings.AddRange(item.Parameters.Cast<IDataParameter>().Select(pm => new[] { pm.ParameterName, pm.Value.GetType().Name, pm.Value })); | |
object parameters = parameterHeadings.Count > 1 ? parameterHeadings : null; | |
var formattedTime = item.Time.ToString("0.#0"); | |
var time = item.Time > 100 ? "*"+formattedTime+"*" : formattedTime; | |
sqls.Add(new[] { i++, time, item.Sql, parameters }); | |
} | |
return sqls; | |
} | |
public void SetupInit() | |
{ | |
} | |
public string Name | |
{ | |
get { return "PetaPoco"; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment