-
Notifications
You must be signed in to change notification settings - Fork 217
Expand file tree
/
Copy pathProfiledDbProviderServices.cs
More file actions
98 lines (85 loc) · 3.81 KB
/
Copy pathProfiledDbProviderServices.cs
File metadata and controls
98 lines (85 loc) · 3.81 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System.Data.Common;
namespace StackExchange.Profiling.Data
{
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);
}
protected override System.Data.Spatial.DbSpatialServices DbGetSpatialServices(string manifestToken)
{
return wrapped.GetSpatialServices(manifestToken);
}
protected override System.Data.Spatial.DbSpatialDataReader GetDbSpatialDataReader(DbDataReader fromReader, string manifestToken)
{
return wrapped.GetSpatialDataReader(GetRealDataReader(fromReader), manifestToken);
}
private static DbDataReader GetRealDataReader(DbDataReader reader)
{
var profiled = reader as ProfiledDbDataReader;
if (profiled != null)
{
reader = profiled.WrappedReader;
}
return reader;
}
/// <summary>
/// Get DB command definition
/// </summary>
/// <param name="prototype"></param>
/// <returns></returns>
public override DbCommandDefinition CreateCommandDefinition(DbCommand prototype)
{
return wrapped.CreateCommandDefinition(prototype);
}
}
}