From bc57363a06900642bce260d36cfd92d855a1e978 Mon Sep 17 00:00:00 2001
From: Ahmed Seref Guneysu <949232+guneysus@users.noreply.github.com>
Date: Fri, 15 Nov 2024 22:38:10 +0300
Subject: [PATCH 1/8] bulk
---
.../AspnetCoreExtensions.cs | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/NanoDbProfiler.AspNetCore/AspnetCoreExtensions.cs b/src/NanoDbProfiler.AspNetCore/AspnetCoreExtensions.cs
index d2895a8..221fd8a 100644
--- a/src/NanoDbProfiler.AspNetCore/AspnetCoreExtensions.cs
+++ b/src/NanoDbProfiler.AspNetCore/AspnetCoreExtensions.cs
@@ -16,7 +16,7 @@ public static IServiceCollection AddNanoDbProfiler(this IServiceCollection _)
var h = new Harmony("id");
- Assembly [] assemblies = AppDomain.CurrentDomain.GetAssemblies();
+ Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
var diagnosticsLoggerTypes = (
from t in assemblies.SelectMany(t => t.GetTypes())
@@ -28,14 +28,14 @@ from asm in assemblies
where asm.GetName().Name == EfCoreRelationalAssemblyString
select asm).Single();
- Type [] efCoreRelationalTypes = efCoreRelationAsm.GetTypes();
+ Type[] efCoreRelationalTypes = efCoreRelationAsm.GetTypes();
var diagnosticsLoggerType = (
from t in efCoreRelationalTypes
where t.FullName == DiagnosticLoggerFullname
select t).Single();
- MethodInfo [] diagnosticsLoggerMethods = diagnosticsLoggerType.GetMethods(AccessTools.all);
+ MethodInfo[] diagnosticsLoggerMethods = diagnosticsLoggerType.GetMethods(AccessTools.all);
var diagLoggerMethods = (
from m in diagnosticsLoggerMethods
@@ -76,6 +76,11 @@ private static void patch(string name, string hookName, IEnumerable
ArgumentNullException.ThrowIfNull(replacement);
}
+ public static IApplicationBuilder UseNanoDbProfilerPage(this IApplicationBuilder builder, string route = "query-log")
+ {
+ throw new NotImplementedException();
+ }
+
public static WebApplication UseNanoDbProfilerPage(this WebApplication app, string route = "query-log")
{
QueryLogMiddleware.QUERY_LOG_ROUTE = "/" + route;
@@ -85,7 +90,7 @@ public static WebApplication UseNanoDbProfilerPage(this WebApplication app, stri
app.MapGet(route, (HttpRequest h) =>
{
var metrics = EfCoreMetrics.GetInstance();
- MediaTypeHeaderValue.TryParseList(h.Headers ["Accept"], out var accept);
+ MediaTypeHeaderValue.TryParseList(h.Headers["Accept"], out var accept);
IResult resp = accept switch
{
From 452f4911b1d358fc07358b35907bcc355b7b159e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ahmed=20=C5=9Eeref?=
<949232+guneysus@users.noreply.github.com>
Date: Sun, 3 Nov 2024 13:40:17 +0300
Subject: [PATCH 2/8] ascii art
- and other changes
---
README.md | 11 +-
pakefile.ps1 | 5 +-
src/Directory.Build.props | 1 +
src/Example/Example.csproj | 2 +-
.../NanoDbProfilerEfCoreQueryInterceptor.cs | 9 -
.../AspnetCoreExtensions.cs | 170 +++++++++---------
.../DashboardData.cs | 55 +-----
...EfCoreDbContextOptionsBuilderExtensions.cs | 38 +++-
.../NanoDbProfiler.AspNetCore.csproj | 2 +-
.../NanoDbProfilerEfCoreQueryInterceptor.cs | 122 +++++++++++++
.../packages.lock.json | 104 -----------
11 files changed, 253 insertions(+), 266 deletions(-)
delete mode 100644 src/Example/NanoDbProfilerEfCoreQueryInterceptor.cs
create mode 100644 src/NanoDbProfiler.AspNetCore/NanoDbProfilerEfCoreQueryInterceptor.cs
diff --git a/README.md b/README.md
index 555ffbd..b64822b 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,6 @@
# Entity Framework Profiler for ASP.Net Core
-A tiny profiler without hassle.
-
-
-
```
┌────────────────────────────────────────────────────────────────────────────────┐
│ │
@@ -35,10 +31,15 @@ A tiny profiler without hassle.
└────────────────────────────────────────────────────────────────────────────────┘
```
+
+A tiny profiler without hassle.
+
+
+
## Installation
```
-dotnet add package NanoDbProfiler.AspNetCore --version 0.1.23-alpha-g1a0a4554d2 --source https://www.myget.org/F/guneysu/api/v3/index.json
+dotnet add package NanoDbProfiler.AspNetCore --version 8.0.10 --source https://www.myget.org/F/guneysu/api/v3/index.json
```
```csharp
diff --git a/pakefile.ps1 b/pakefile.ps1
index a033262..304ee4d 100644
--- a/pakefile.ps1
+++ b/pakefile.ps1
@@ -1,5 +1,5 @@
-$msbuild = "C:\Program Files\Microsoft Visual Studio\2022\Community\\MSBuild\Current\Bin\amd64\MSBuild.exe"
-$msbuild = "C:\Program Files\Microsoft Visual Studio\2022\Preview\\MSBuild\Current\Bin\amd64\MSBuild.exe"
+$msbuild = "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.exe"
+$msbuild = "C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\amd64\MSBuild.exe"
function Init {
# dotnet tool install -g nbgv
@@ -42,7 +42,6 @@ function Patch-Version {
function Build {
-
. "${msbuild}" /bl `
.\src\NanoDbProfiler.AspNetCore\NanoDbProfiler.AspNetCore.csproj `
-p:Configuration=Release `
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index a02f3fe..652485a 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -4,6 +4,7 @@
enable
enable
true
+ 8.0.11
$(MSBuildThisFileDirectory)
diff --git a/src/Example/Example.csproj b/src/Example/Example.csproj
index fdfeb03..36a788b 100644
--- a/src/Example/Example.csproj
+++ b/src/Example/Example.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/src/Example/NanoDbProfilerEfCoreQueryInterceptor.cs b/src/Example/NanoDbProfilerEfCoreQueryInterceptor.cs
deleted file mode 100644
index 0918e4a..0000000
--- a/src/Example/NanoDbProfilerEfCoreQueryInterceptor.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-
-using System.Data.Common;
-
-using Microsoft.EntityFrameworkCore.Diagnostics;
-
-using NanoDbProfiler.AspNetCore;
-
-namespace Example;
-
diff --git a/src/NanoDbProfiler.AspNetCore/AspnetCoreExtensions.cs b/src/NanoDbProfiler.AspNetCore/AspnetCoreExtensions.cs
index d2895a8..d73684b 100644
--- a/src/NanoDbProfiler.AspNetCore/AspnetCoreExtensions.cs
+++ b/src/NanoDbProfiler.AspNetCore/AspnetCoreExtensions.cs
@@ -1,116 +1,112 @@
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.EntityFrameworkCore;
+namespace Microsoft.Extensions.DependencyInjection;
-namespace Microsoft.Extensions.DependencyInjection
+public static class AspnetCoreExtensions
{
- public static class AspnetCoreExtensions
+ public static IServiceCollection AddNanoDbProfiler(this IServiceCollection _)
{
- public static IServiceCollection AddNanoDbProfiler(this IServiceCollection _)
- {
- const string EfCoreRelationalAssemblyString = "Microsoft.EntityFrameworkCore.Relational";
- const string DiagnosticLoggerFullname = "Microsoft.EntityFrameworkCore.Diagnostics.Internal.RelationalCommandDiagnosticsLogger";
- const string DiagnosticLoggerInterfaceName = "IRelationalCommandDiagnosticsLogger";
+ const string EfCoreRelationalAssemblyString = "Microsoft.EntityFrameworkCore.Relational";
+ const string DiagnosticLoggerFullname = "Microsoft.EntityFrameworkCore.Diagnostics.Internal.RelationalCommandDiagnosticsLogger";
+ const string DiagnosticLoggerInterfaceName = "IRelationalCommandDiagnosticsLogger";
- var efCoreRelationalAsm = Assembly.Load(EfCoreRelationalAssemblyString);
- ArgumentNullException.ThrowIfNull(efCoreRelationalAsm);
+ var efCoreRelationalAsm = Assembly.Load(EfCoreRelationalAssemblyString);
+ ArgumentNullException.ThrowIfNull(efCoreRelationalAsm);
- var h = new Harmony("id");
+ var h = new Harmony("id");
- Assembly [] assemblies = AppDomain.CurrentDomain.GetAssemblies();
+ Assembly [] assemblies = AppDomain.CurrentDomain.GetAssemblies();
- var diagnosticsLoggerTypes = (
- from t in assemblies.SelectMany(t => t.GetTypes())
- where t.GetInterfaces().Any(t => t.Name.Contains(DiagnosticLoggerInterfaceName))
- select t);
+ var diagnosticsLoggerTypes = (
+ from t in assemblies.SelectMany(t => t.GetTypes())
+ where t.GetInterfaces().Any(t => t.Name.Contains(DiagnosticLoggerInterfaceName))
+ select t);
- var efCoreRelationAsm = (
- from asm in assemblies
- where asm.GetName().Name == EfCoreRelationalAssemblyString
- select asm).Single();
+ var efCoreRelationAsm = (
+ from asm in assemblies
+ where asm.GetName().Name == EfCoreRelationalAssemblyString
+ select asm).Single();
- Type [] efCoreRelationalTypes = efCoreRelationAsm.GetTypes();
+ Type [] efCoreRelationalTypes = efCoreRelationAsm.GetTypes();
- var diagnosticsLoggerType = (
- from t in efCoreRelationalTypes
- where t.FullName == DiagnosticLoggerFullname
- select t).Single();
+ var diagnosticsLoggerType = (
+ from t in efCoreRelationalTypes
+ where t.FullName == DiagnosticLoggerFullname
+ select t).Single();
- MethodInfo [] diagnosticsLoggerMethods = diagnosticsLoggerType.GetMethods(AccessTools.all);
+ MethodInfo [] diagnosticsLoggerMethods = diagnosticsLoggerType.GetMethods(AccessTools.all);
- var diagLoggerMethods = (
- from m in diagnosticsLoggerMethods
- where m.Name.Contains("Executed")
- select m);
+ var diagLoggerMethods = (
+ from m in diagnosticsLoggerMethods
+ where m.Name.Contains("Executed")
+ select m);
- patch("CommandReaderExecuted", nameof(Hooks.CommandReaderExecuted), diagLoggerMethods, h);
- patch("CommandScalarExecuted", nameof(Hooks.CommandScalarExecuted), diagLoggerMethods, h);
- patch("CommandNonQueryExecuted", nameof(Hooks.CommandNonQueryExecuted), diagLoggerMethods, h);
- patch("CommandReaderExecutedAsync", nameof(Hooks.CommandReaderExecutedAsync), diagLoggerMethods, h);
- patch("CommandScalarExecutedAsync", nameof(Hooks.CommandScalarExecutedAsync), diagLoggerMethods, h);
- patch("CommandNonQueryExecutedAsync", nameof(Hooks.CommandNonQueryExecutedAsync), diagLoggerMethods, h);
+ patch("CommandReaderExecuted", nameof(Hooks.CommandReaderExecuted), diagLoggerMethods, h);
+ patch("CommandScalarExecuted", nameof(Hooks.CommandScalarExecuted), diagLoggerMethods, h);
+ patch("CommandNonQueryExecuted", nameof(Hooks.CommandNonQueryExecuted), diagLoggerMethods, h);
+ patch("CommandReaderExecutedAsync", nameof(Hooks.CommandReaderExecutedAsync), diagLoggerMethods, h);
+ patch("CommandScalarExecutedAsync", nameof(Hooks.CommandScalarExecutedAsync), diagLoggerMethods, h);
+ patch("CommandNonQueryExecutedAsync", nameof(Hooks.CommandNonQueryExecutedAsync), diagLoggerMethods, h);
- var relationCommandType = efCoreRelationalTypes.Single(x => x.Name == "RelationalCommand");
- var methods = relationCommandType.GetMethods(AccessTools.all);
+ var relationCommandType = efCoreRelationalTypes.Single(x => x.Name == "RelationalCommand");
+ var methods = relationCommandType.GetMethods(AccessTools.all);
- patch("ExecuteReader", methods, h,
- prefix: new HarmonyMethod(typeof(Hooks).GetMethod(nameof(Hooks.ExecuteReaderPrefix))),
- postfix: new HarmonyMethod(typeof(Hooks).GetMethod(nameof(Hooks.ExecuteReaderPostfix))));
+ patch("ExecuteReader", methods, h,
+ prefix: new HarmonyMethod(typeof(Hooks).GetMethod(nameof(Hooks.ExecuteReaderPrefix))),
+ postfix: new HarmonyMethod(typeof(Hooks).GetMethod(nameof(Hooks.ExecuteReaderPostfix))));
- return _;
- }
+ return _;
+ }
- private static void patch(string name, IEnumerable methods, Harmony harmony, HarmonyMethod prefix, HarmonyMethod postfix)
- {
- var method = (
- from m in methods
- where m.Name == name
- select m).Single();
+ private static void patch(string name, IEnumerable methods, Harmony harmony, HarmonyMethod prefix, HarmonyMethod postfix)
+ {
+ var method = (
+ from m in methods
+ where m.Name == name
+ select m).Single();
- var replacement = harmony.Patch(method, prefix: prefix, postfix: postfix);
- ArgumentNullException.ThrowIfNull(replacement);
- }
+ var replacement = harmony.Patch(method, prefix: prefix, postfix: postfix);
+ ArgumentNullException.ThrowIfNull(replacement);
+ }
- private static void patch(string name, string hookName, IEnumerable methods, Harmony harmony)
- {
- var replacement = harmony.Patch(methods.Single(x => x.Name == name), new HarmonyMethod(typeof(Hooks).GetMethod(name)));
- ArgumentNullException.ThrowIfNull(replacement);
- }
+ private static void patch(string name, string hookName, IEnumerable methods, Harmony harmony)
+ {
+ var replacement = harmony.Patch(methods.Single(x => x.Name == name), new HarmonyMethod(typeof(Hooks).GetMethod(name)));
+ ArgumentNullException.ThrowIfNull(replacement);
+ }
- public static WebApplication UseNanoDbProfilerPage(this WebApplication app, string route = "query-log")
- {
- QueryLogMiddleware.QUERY_LOG_ROUTE = "/" + route;
+ public static WebApplication UseNanoDbProfilerPage(this WebApplication app, string route = "query-log")
+ {
+ QueryLogMiddleware.QUERY_LOG_ROUTE = "/" + route;
- EfQueryLog.ServiceScopeFactory = app.Services.GetRequiredService();
+ EfQueryLog.ServiceScopeFactory = app.Services.GetRequiredService();
- app.MapGet(route, (HttpRequest h) =>
- {
- var metrics = EfCoreMetrics.GetInstance();
- MediaTypeHeaderValue.TryParseList(h.Headers ["Accept"], out var accept);
-
- IResult resp = accept switch
- {
- null => EfQueryLog.TextResult(metrics),
- var a when a.Any(x => x.MatchesMediaType("text/html")) => EfQueryLog.HtmlResult(metrics),
- var a when a.Any(x => x.MatchesMediaType("text/plain")) => EfQueryLog.TextResult(metrics),
- var a when a.Any(x => x.MatchesMediaType("application/json")) => EfQueryLog.JsonResult(metrics),
- _ => EfQueryLog.TextResult(metrics)
- };
-
- return resp;
- });
-
- app.MapDelete(route, (HttpRequest h) =>
+ app.MapGet(route, (HttpRequest h) =>
+ {
+ var metrics = EfCoreMetrics.GetInstance();
+ MediaTypeHeaderValue.TryParseList(h.Headers ["Accept"], out var accept);
+
+ IResult resp = accept switch
{
- var metrics = EfCoreMetrics.GetInstance();
+ null => EfQueryLog.TextResult(metrics),
+ var a when a.Any(x => x.MatchesMediaType("text/html")) => EfQueryLog.HtmlResult(metrics),
+ var a when a.Any(x => x.MatchesMediaType("text/plain")) => EfQueryLog.TextResult(metrics),
+ var a when a.Any(x => x.MatchesMediaType("application/json")) => EfQueryLog.JsonResult(metrics),
+ _ => EfQueryLog.TextResult(metrics)
+ };
+
+ return resp;
+ });
- metrics.Clear();
- return Results.NoContent();
- });
+ app.MapDelete(route, (HttpRequest h) =>
+ {
+ var metrics = EfCoreMetrics.GetInstance();
+ metrics.Clear();
+ return Results.NoContent();
+ });
- return app;
- }
- public static void UseNanoDbProfilerToolbar(this WebApplication app) => app.UseMiddleware();
+ return app;
}
+
+ public static void UseNanoDbProfilerToolbar(this WebApplication app) => app.UseMiddleware();
}
\ No newline at end of file
diff --git a/src/NanoDbProfiler.AspNetCore/DashboardData.cs b/src/NanoDbProfiler.AspNetCore/DashboardData.cs
index 3de34b2..9b35bc5 100644
--- a/src/NanoDbProfiler.AspNetCore/DashboardData.cs
+++ b/src/NanoDbProfiler.AspNetCore/DashboardData.cs
@@ -1,57 +1,4 @@
-
-using System.Data.Common;
-
-using Microsoft.EntityFrameworkCore.Diagnostics;
-
-namespace NanoDbProfiler.AspNetCore;
-
-internal class NanoDbProfilerEfCoreQueryInterceptor : DbCommandInterceptor
-{
- private static Metric metricFactory(CommandExecutedEventData eventData)
- {
- return new Metric()
- {
- Duration = eventData.Duration.TotalMilliseconds,
- Query = eventData.Command.CommandText
- };
- }
-
- public override int NonQueryExecuted(DbCommand command, CommandExecutedEventData eventData, int result)
- {
- EfCoreMetrics.GetInstance().Add(metricFactory(eventData));
- return base.NonQueryExecuted(command, eventData, result);
- }
-
- public override ValueTask NonQueryExecutedAsync(DbCommand command, CommandExecutedEventData eventData, int result, CancellationToken cancellationToken = default)
- {
- EfCoreMetrics.GetInstance().Add(metricFactory(eventData));
- return base.NonQueryExecutedAsync(command, eventData, result, cancellationToken);
- }
-
- public override DbDataReader ReaderExecuted(DbCommand command, CommandExecutedEventData eventData, DbDataReader result)
- {
- EfCoreMetrics.GetInstance().Add(metricFactory(eventData));
- return base.ReaderExecuted(command, eventData, result);
- }
-
- public override ValueTask
+
+
+
+
+", $"{toolbarHtml}");
+ body = body.Replace("", $"{toolbarHtml}", StringComparison.OrdinalIgnoreCase);
}
else
{
body += toolbarHtml;
}
+
+ var bodyBytes = Encoding.UTF8.GetBytes(body);
+
+ // Reset the response body
+ context.Response.ContentLength = bodyBytes.Length;
+ newBodyStream.SetLength(0);
+ await newBodyStream.WriteAsync(bodyBytes, 0, bodyBytes.Length);
+ await newBodyStream.FlushAsync();
+ newBodyStream.Seek(0, SeekOrigin.Begin);
}
- context.Response.Body = originalBodyStream;
- context.Response.Headers.ContentLength = body.Length;
- await context.Response.WriteAsync(body);
+ // Copy the modified or original response body back to the original stream
+ newBodyStream.Seek(0, SeekOrigin.Begin);
+ await newBodyStream.CopyToAsync(originalBodyStream);
}
- catch (Exception)
+ catch (Exception ex)
{
+ Console.Error.WriteLine($"Error in QueryLogMiddleware: {ex}");
throw;
}
finally
{
- if (!context.Response.HasStarted)
- await _next(context);
+ context.Response.Body = originalBodyStream;
}
}
-}
\ No newline at end of file
+}
From 9ccd94b83b8ae6336214be482b9b01bfc8764228 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ahmed=20=C5=9Eeref?=
<949232+guneysus@users.noreply.github.com>
Date: Tue, 17 Dec 2024 21:49:44 +0300
Subject: [PATCH 5/8] bulk
---
src/NanoDbProfiler.AspNetCore/QueryLogMiddleware.cs | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/NanoDbProfiler.AspNetCore/QueryLogMiddleware.cs b/src/NanoDbProfiler.AspNetCore/QueryLogMiddleware.cs
index 48e947c..88e49c3 100644
--- a/src/NanoDbProfiler.AspNetCore/QueryLogMiddleware.cs
+++ b/src/NanoDbProfiler.AspNetCore/QueryLogMiddleware.cs
@@ -1,6 +1,4 @@
-using System.IO.Compression;
-
-namespace Microsoft.Extensions.DependencyInjection;
+namespace Microsoft.Extensions.DependencyInjection;
public class QueryLogMiddleware
{
From 9567a6b8700445a8eb849442e4b7985fb320cdfb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ahmed=20=C5=9Eeref?=
<949232+guneysus@users.noreply.github.com>
Date: Mon, 6 Jan 2025 23:58:10 +0300
Subject: [PATCH 6/8] bulk
---
src/Example/Example.csproj | 10 +++++--
src/Example/Example.sln | 25 ++++++++++++++++
src/Example/Pages/Index.cshtml | 7 +++++
src/Example/Pages/Index.cshtml.cs | 12 ++++++++
src/Example/Program.cs | 33 +++++++++++++++-------
src/Example/Properties/launchSettings.json | 21 +++++++++++++-
src/Example/pakefile.ps1 | 3 ++
src/NanoDbProfiler.sln | 6 ++++
8 files changed, 104 insertions(+), 13 deletions(-)
create mode 100644 src/Example/Example.sln
create mode 100644 src/Example/Pages/Index.cshtml
create mode 100644 src/Example/Pages/Index.cshtml.cs
create mode 100644 src/Example/pakefile.ps1
diff --git a/src/Example/Example.csproj b/src/Example/Example.csproj
index 36a788b..d745bdd 100644
--- a/src/Example/Example.csproj
+++ b/src/Example/Example.csproj
@@ -1,4 +1,4 @@
-
+
net8.0
@@ -17,8 +17,14 @@
-
+
+
+
+
+
+
+
diff --git a/src/Example/Example.sln b/src/Example/Example.sln
new file mode 100644
index 0000000..30ce4c3
--- /dev/null
+++ b/src/Example/Example.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.002.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "Example.csproj", "{FB0C2DC9-B030-4E94-933E-4D57671CEE08}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {FB0C2DC9-B030-4E94-933E-4D57671CEE08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FB0C2DC9-B030-4E94-933E-4D57671CEE08}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FB0C2DC9-B030-4E94-933E-4D57671CEE08}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FB0C2DC9-B030-4E94-933E-4D57671CEE08}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {2FD7FBBB-C0F2-4F98-BAD9-BCD8B35FA502}
+ EndGlobalSection
+EndGlobal
diff --git a/src/Example/Pages/Index.cshtml b/src/Example/Pages/Index.cshtml
new file mode 100644
index 0000000..eb2d2dd
--- /dev/null
+++ b/src/Example/Pages/Index.cshtml
@@ -0,0 +1,7 @@
+@page
+@model Example.Pages.IndexModel
+@{
+}
+
+
+Hello!
\ No newline at end of file
diff --git a/src/Example/Pages/Index.cshtml.cs b/src/Example/Pages/Index.cshtml.cs
new file mode 100644
index 0000000..d2466e2
--- /dev/null
+++ b/src/Example/Pages/Index.cshtml.cs
@@ -0,0 +1,12 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace Example.Pages
+{
+ public class IndexModel : PageModel
+ {
+ public void OnGet()
+ {
+ }
+ }
+}
diff --git a/src/Example/Program.cs b/src/Example/Program.cs
index cf9cea9..03c25a8 100644
--- a/src/Example/Program.cs
+++ b/src/Example/Program.cs
@@ -8,21 +8,32 @@ public class Program
public static void Main(string [] args)
{
var builder = WebApplication.CreateBuilder(args);
-
+
+ builder.Services.AddRazorPages();
+
builder.Services
.AddDbContext(o => o
.UseSqlite("Data Source=db.sqlite"))
- .AddNanoDbProfiler()
+#if NANODBPROFILER
+ .AddNanoDbProfiler()
+#endif
;
var app = builder.Build();
+#if NANODBPROFILER
app.UseNanoDbProfiler(x =>
{
x.ToolbarEnabled = true;
x.ProfilerPageUrl = "query-log";
});
+#endif
+
+
+#if EFCORE_PROFILER_TOOLBAR
+ app.UseEfCoreQueryToolbar();
+#endif
#if ALTERNATIVES
app.UseNanoDbProfiler(x =>
@@ -34,10 +45,14 @@ public static void Main(string [] args)
app.UseNanoDbProfiler(x => x.ToolbarEnabled = true);
#endif
+ app.UseRouting();
+
+ app.MapRazorPages();
+
app.MapGet("/", async (HttpContext h, [FromServices] TodoContext db) =>
{
await db.Database.EnsureCreatedAsync();
- return Results.Text("Hello World!", "text/html");
+ return Results.Text("Hello World!
", "text/html; charset=utf-8");
});
app.MapGet("/insert", (HttpContext h, [FromServices] TodoContext db) =>
@@ -97,13 +112,11 @@ public static void Main(string [] args)
return Results.Ok();
});
- app
- .Services
- .CreateScope()
- .ServiceProvider
- .GetRequiredService()
- .Database
- .EnsureCreated();
+ using (var scope = app.Services.CreateScope())
+ {
+ var db = scope.ServiceProvider.GetRequiredService();
+ db.Database.EnsureCreated();
+ }
app.Run();
}
diff --git a/src/Example/Properties/launchSettings.json b/src/Example/Properties/launchSettings.json
index 1625bb2..609c4d4 100644
--- a/src/Example/Properties/launchSettings.json
+++ b/src/Example/Properties/launchSettings.json
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
- "http": {
+ "http (query-log)": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
@@ -10,6 +10,25 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
+ },
+ "http (/)": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "applicationUrl": "http://localhost:5042",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "http (no browser)": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": false,
+ "applicationUrl": "http://localhost:5042",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
}
+
}
}
diff --git a/src/Example/pakefile.ps1 b/src/Example/pakefile.ps1
new file mode 100644
index 0000000..9f3e19f
--- /dev/null
+++ b/src/Example/pakefile.ps1
@@ -0,0 +1,3 @@
+function Run {
+ dotnet run -c Debug /p:DefineConstants="EFCORE_PROFILER_TOOLBAR"
+}
diff --git a/src/NanoDbProfiler.sln b/src/NanoDbProfiler.sln
index 7a41a95..30c32d6 100644
--- a/src/NanoDbProfiler.sln
+++ b/src/NanoDbProfiler.sln
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NanoDbProfiler.Specs", "NanoDbProfiler.Specs\NanoDbProfiler.Specs.csproj", "{F7D821E9-7437-440D-AAAD-523D72BC8CBB}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EfCoreQueryToolbar", "..\..\github.com\guneysus\EfCoreQueryToolbar.git\src\EfCoreQueryToolbar\EfCoreQueryToolbar.csproj", "{1665DC2C-2441-7CB9-9668-CD2B80B0F8E5}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,10 @@ Global
{F7D821E9-7437-440D-AAAD-523D72BC8CBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7D821E9-7437-440D-AAAD-523D72BC8CBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7D821E9-7437-440D-AAAD-523D72BC8CBB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1665DC2C-2441-7CB9-9668-CD2B80B0F8E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1665DC2C-2441-7CB9-9668-CD2B80B0F8E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1665DC2C-2441-7CB9-9668-CD2B80B0F8E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1665DC2C-2441-7CB9-9668-CD2B80B0F8E5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
From becd1017c8b4290542e040bf4a31fb38c4a2035e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ahmed=20=C5=9Eeref?=
<949232+guneysus@users.noreply.github.com>
Date: Wed, 8 Jan 2025 00:03:25 +0300
Subject: [PATCH 7/8] bulk
---
src/Example/Example.csproj | 14 +-
src/Example/Pages/Index.cshtml | 230 +++++++++++++++++-
src/Example/Program.cs | 14 +-
src/Example/wwwroot/default.html | 224 +++++++++++++++++
.../AspnetCoreExtensions.cs | 12 +-
src/NanoDbProfiler.AspNetCore/Hooks.cs | 4 +-
.../{EfQueryLog.cs => QueryLog.cs} | 2 +-
7 files changed, 480 insertions(+), 20 deletions(-)
create mode 100644 src/Example/wwwroot/default.html
rename src/NanoDbProfiler.AspNetCore/{EfQueryLog.cs => QueryLog.cs} (97%)
diff --git a/src/Example/Example.csproj b/src/Example/Example.csproj
index d745bdd..b07581d 100644
--- a/src/Example/Example.csproj
+++ b/src/Example/Example.csproj
@@ -4,12 +4,13 @@
net8.0
enable
enable
+ $(DefineConstants);EFCORE_PROFILER_TOOLBAR
-
-
-
+
+
+
@@ -19,12 +20,15 @@
-
+
-
+
+
+
+
diff --git a/src/Example/Pages/Index.cshtml b/src/Example/Pages/Index.cshtml
index eb2d2dd..5b31fe2 100644
--- a/src/Example/Pages/Index.cshtml
+++ b/src/Example/Pages/Index.cshtml
@@ -4,4 +4,232 @@
}
-