public override void ReaderExecuting( System.Data.Common.DbCommand command, DbCommandInterceptionContext<System.Data.Common.DbDataReader> interceptionContext )
{
if ( RockContext != null && !interceptionContext.DbContexts.Any( a => a == RockContext ) )
{
return;
}
DebugHelper._callCounts++;
System.Diagnostics.Debug.WriteLine( "\n" );
StackTrace st = new StackTrace( 1, true );
var frames = st.GetFrames().Where( a => a.GetFileName() != null );
System.Diagnostics.Debug.WriteLine( string.Format( "/* Call# {0}*/", DebugHelper._callCounts ) );
System.Diagnostics.Debug.WriteLine( string.Format( "/*\n{0}*/", frames.ToList().AsDelimited( "" ) ) );
System.Diagnostics.Debug.WriteLine( "BEGIN\n" );
var declares = command.Parameters.OfType<System.Data.SqlClient.SqlParameter>()
.Select( p =>
{
if ( p.SqlDbType == System.Data.SqlDbType.NVarChar )
{
return string.Format( "@{0} {1}({2}) = '{3}'", p.ParameterName, p.SqlDbType, p.Size, p.SqlValue.ToString().Replace( "'", "''" ) );
}
if ( p.SqlDbType == System.Data.SqlDbType.Int )
{
return string.Format( "@{0} {1} = {2}", p.ParameterName, p.SqlDbType, p.SqlValue ?? "null" );
}
else if ( p.SqlDbType == System.Data.SqlDbType.Udt )
{
return string.Format( "@{0} {1} = '{2}'", p.ParameterName, p.UdtTypeName, p.SqlValue );
}
else
{
return string.Format( "@{0} {1} = '{2}'", p.ParameterName, p.SqlDbType, p.SqlValue );
}
} ).ToList().AsDelimited( ",\n" );
if ( !string.IsNullOrEmpty( declares ) )
{
System.Diagnostics.Debug.WriteLine( "DECLARE\n" + declares + "\n\n" );
}
System.Diagnostics.Debug.WriteLine( command.CommandText );
System.Diagnostics.Debug.WriteLine( "\nEND\nGO\n\n" );
if ( interceptionContext.UserState == null )
{
interceptionContext.UserState = new DebugHelperUserState { CallNumber = DebugHelper._callCounts, Stopwatch = Stopwatch.StartNew() };
}
}