Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace StackExchange.Profiling.Data
{
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity.Core.Common;
using System.Data.Entity.Core.Common.CommandTrees;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Spatial;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using StackExchange.Profiling;

Expand Down Expand Up @@ -160,5 +163,74 @@ private static DbConnection GetRealConnection(DbConnection connection)

return connection;
}

private static DbDataReader GetSpatialDataReader(DbDataReader fromReader)
{
var profiled = fromReader as ProfiledDbDataReader;
if (profiled != null)
{
fromReader = profiled.WrappedReader;
}
return fromReader;
}

public override object GetService(Type type, object key)
{
return _tail.GetService(type, key);
}

public override IEnumerable<object> GetServices(Type type, object key)
{
return _tail.GetServices(type, key);
}

protected override DbSpatialDataReader GetDbSpatialDataReader(DbDataReader fromReader, string manifestToken)
{
var setDbParameterValueMethod =
_tail.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).FirstOrDefault(f => f.Name.Equals("GetDbSpatialDataReader"));

var reader = GetSpatialDataReader(fromReader);


if (setDbParameterValueMethod == null)
{
return base.GetDbSpatialDataReader(reader, manifestToken);
}

var result = setDbParameterValueMethod.Invoke(_tail, new object[] { reader, manifestToken });
return result as DbSpatialDataReader;
}

protected override DbSpatialServices DbGetSpatialServices(string manifestToken)
{
var dbGetSpatialServices =
_tail.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).FirstOrDefault(f => f.Name.Equals("DbGetSpatialServices"));

return dbGetSpatialServices.Invoke(_tail, new[] { manifestToken }) as DbSpatialServices;
}




protected override void SetDbParameterValue(DbParameter parameter, TypeUsage parameterType, object value)
{
// if this is available in _tail, use it
var setDbParameterValueMethod = _tail.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).FirstOrDefault(f => f.Name.Equals("SetDbParameterValue"));
if (setDbParameterValueMethod != null)
{
setDbParameterValueMethod.Invoke(_tail, new[] { parameter, parameterType, value });
return;
}

// this should never need to be called, but just in case get the Provider Value
if (value is DbGeography)
{
value = ((DbGeography)value).ProviderValue;
}

base.SetDbParameterValue(parameter, parameterType, value);
}


}
}
5 changes: 5 additions & 0 deletions StackExchange.Profiling/Data/ProfiledDbDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public override int RecordsAffected
get { return _reader.RecordsAffected; }
}

public DbDataReader WrappedReader
{
get { return _reader; }
}

/// <summary>
/// The
/// </summary>
Expand Down