/// <summary> /// The execute database data reader. /// </summary> /// <param name="behavior">The behaviour.</param> /// <returns>the resulting <see cref="DbDataReader"/>.</returns> protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { if (_profiler == null || !_profiler.IsActive) { return(_command.ExecuteReader(behavior)); } DbDataReader result = null; _profiler.ExecuteStart(this, SqlExecuteType.Reader); try { result = _command.ExecuteReader(behavior); result = new ProfiledDbDataReader(result, _connection, _profiler); } catch (Exception e) { _profiler.OnError(this, SqlExecuteType.Reader, e); throw; } finally { _profiler.ExecuteFinish(this, SqlExecuteType.Reader, result); } return(result); }
public override IMessage Invoke(IMessage msg) { IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)msg); ExecuteType executeType = GetExecuteType(methodMessage); if (executeType != ExecuteType.None) { profiler.ExecuteStart(instance, executeType); } object returnValue = methodMessage.MethodBase.Invoke(instance, methodMessage.Args); if (executeType == ExecuteType.Reader) { returnValue = new ProfiledDbDataReader((DbDataReader)returnValue, instance.Connection, profiler); } IMessage returnMessage = new ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage); if (executeType == ExecuteType.Reader) { profiler.ExecuteFinish(instance, executeType, (DbDataReader)returnValue); } else if (executeType != ExecuteType.None) { profiler.ExecuteFinish(instance, executeType, null); } return(returnMessage); }
/// <summary> /// profile with results. /// </summary> /// <param name="type">The type of execution.</param> /// <param name="func">A function to execute against the profile result.</param> /// <typeparam name="TResult">the type of result to return.</typeparam> private TResult ProfileWith <TResult>(SqlExecuteType type, Func <TResult> func) { if (_profiler?.IsActive != true) { return(func()); } TResult result; _profiler.ExecuteStart(this, type); try { result = func(); } catch (Exception e) { _profiler.OnError(this, type, e); throw; } finally { _profiler.ExecuteFinish(this, type, null); } return(result); }
public void ExecuteFinish(IDbCommand profiledDbCommand, SqlExecuteType executeType, DbDataReader reader) { if (reader == null) { _sw.Stop(); } _wrapped?.ExecuteFinish(profiledDbCommand, executeType, reader); }
/// <summary> /// Adds or updates rows in the <see cref="T:System.Data.DataSet"/> to match those in the data source using the <see cref="T:System.Data.DataSet"/> name, and creates a <see cref="T:System.Data.DataTable"/> named "Table". /// </summary> /// <param name="dataSet">A <see cref="T:System.Data.DataSet"/> to fill with records and, if necessary, schema.</param> /// <returns> /// The number of rows successfully added to or refreshed in the <see cref="T:System.Data.DataSet"/>. This does not include rows affected by statements that do not return rows. /// </returns> public new int Fill(DataSet dataSet) { /* * The SqlDataAdapter type requires that you use a SqlDataCommand for the various adapter commands and will throw an * exception if you attempt to pass it a ProfiledDbCommand instead. This method is a simple wrapper around the existing * Fill method and assumes that a single ExecuteReader method will eventually be called on the SelectCommand. This is * somewhat of a hack but appears to be working to give rough timings. * * While I have not tested this with an oracle DataAdapter, I would guess that it works in much the same way as the * SqlDataAdapter type and would thus work fine with this workaround. */ if (_profiler == null || !_profiler.IsActive || !(_selectCommand is DbCommand)) { return(_adapter.Fill(dataSet)); } int result; var cmd = (DbCommand)_selectCommand; _profiler.ExecuteStart(cmd, ExecuteType.Reader); try { result = _adapter.Fill(dataSet); } catch (Exception e) { _profiler.OnError(cmd, ExecuteType.Reader, e); throw; } finally { _profiler.ExecuteFinish(cmd, ExecuteType.Reader, TokenReader); } return(result); }
public void ExecuteFinish(IDbCommand profiledDbCommand, SqlExecuteType executeType, DbDataReader reader) { _wrapped.ExecuteFinish(profiledDbCommand, executeType, reader); }