-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProfiledDbProviderServices.cs
80 lines (69 loc) · 3.15 KB
/
ProfiledDbProviderServices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Data.Common;
using ServiceStack.MiniProfiler.Data;
namespace ServiceStack.MiniProfiler.EntityFramework
{
class ProfiledDbProviderServices : DbProviderServices
{
private DbProviderServices wrapped;
private IDbProfiler profiler;
public ProfiledDbProviderServices(DbProviderServices tail, IDbProfiler profiler)
{
this.wrapped = tail;
this.profiler = profiler;
}
protected override DbProviderManifest GetDbProviderManifest(string manifestToken)
{
return wrapped.GetProviderManifest(manifestToken);
}
protected override string GetDbProviderManifestToken(DbConnection connection)
{
var wrappedConnection = connection;
var profiled = connection as ProfiledDbConnection;
if (profiled != null)
{
wrappedConnection = profiled.WrappedConnection;
}
return wrapped.GetProviderManifestToken(wrappedConnection);
}
protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, System.Data.Common.CommandTrees.DbCommandTree commandTree)
{
var cmdDef = wrapped.CreateCommandDefinition(providerManifest, commandTree);
var cmd = cmdDef.CreateCommand();
return CreateCommandDefinition(new ProfiledDbCommand(cmd, cmd.Connection, profiler));
}
private static DbConnection GetRealConnection(DbConnection cnn)
{
var profiled = cnn as ProfiledDbConnection;
if (profiled != null)
{
cnn = profiled.WrappedConnection;
}
return cnn;
}
protected override void DbCreateDatabase(DbConnection connection, int? commandTimeout, System.Data.Metadata.Edm.StoreItemCollection storeItemCollection)
{
wrapped.CreateDatabase(GetRealConnection(connection), commandTimeout, storeItemCollection);
}
protected override void DbDeleteDatabase(DbConnection connection, int? commandTimeout, System.Data.Metadata.Edm.StoreItemCollection storeItemCollection)
{
wrapped.DeleteDatabase(GetRealConnection(connection), commandTimeout, storeItemCollection);
}
protected override string DbCreateDatabaseScript(string providerManifestToken, System.Data.Metadata.Edm.StoreItemCollection storeItemCollection)
{
return wrapped.CreateDatabaseScript(providerManifestToken, storeItemCollection);
}
protected override bool DbDatabaseExists(DbConnection connection, int? commandTimeout, System.Data.Metadata.Edm.StoreItemCollection storeItemCollection)
{
return wrapped.DatabaseExists(GetRealConnection(connection), commandTimeout, storeItemCollection);
}
/// <summary>
/// Get DB command definition
/// </summary>
/// <param name="prototype"></param>
/// <returns></returns>
public override DbCommandDefinition CreateCommandDefinition(DbCommand prototype)
{
return wrapped.CreateCommandDefinition(prototype);
}
}
}