Ejemplo n.º 1
0
        /// <summary>
        /// Sends <see cref="IDbCommandInterceptor.ReaderExecuting" /> and
        /// <see cref="IDbCommandInterceptor.ReaderExecuted" /> to any <see cref="IDbCommandInterceptor" />
        /// registered on <see cref="DbInterception" /> before/after making a
        /// call to <see cref="DbCommand.ExecuteReaderAsync(CommandBehavior, CancellationToken)" />.
        /// </summary>
        /// <remarks>
        /// Note that the result of executing the command is returned by this method. The result is not available
        /// in the interception context passed into this method since the interception context is cloned before
        /// being passed to interceptors.
        /// </remarks>
        /// <param name="command">The command on which the operation will be executed.</param>
        /// <param name="interceptionContext">Optional information about the context of the call being made.</param>
        /// <param name="cancellationToken">The cancellation token for the asynchronous operation.</param>
        /// <returns>The result of the operation, which may have been modified by interceptors.</returns>
        public virtual Task <DbDataReader> ReaderAsync(
            DbCommand command, DbCommandInterceptionContext interceptionContext, CancellationToken cancellationToken)
        {
            Check.NotNull(command, "command");
            Check.NotNull(interceptionContext, "interceptionContext");

            cancellationToken.ThrowIfCancellationRequested();

            var clonedInterceptionContext = new DbCommandInterceptionContext <DbDataReader>(interceptionContext);

            if (!clonedInterceptionContext.IsAsync)
            {
                clonedInterceptionContext = clonedInterceptionContext.AsAsync();
            }

            return(_internalDispatcher.DispatchAsync(
                       () => command.ExecuteReaderAsync(clonedInterceptionContext.CommandBehavior, cancellationToken),
                       clonedInterceptionContext,
                       i => i.ReaderExecuting(command, clonedInterceptionContext),
                       i => i.ReaderExecuted(command, clonedInterceptionContext)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends <see cref="IDbCommandInterceptor.NonQueryExecuting" /> and
        /// <see cref="IDbCommandInterceptor.NonQueryExecuted" /> to any <see cref="IDbCommandInterceptor" />
        /// registered on <see cref="DbInterception" /> before/after making a
        /// call to <see cref="DbCommand.ExecuteNonQueryAsync(CancellationToken)" />.
        /// </summary>
        /// <remarks>
        /// Note that the result of executing the command is returned by this method. The result is not available
        /// in the interception context passed into this method since the interception context is cloned before
        /// being passed to interceptors.
        /// </remarks>
        /// <param name="command">The command on which the operation will be executed.</param>
        /// <param name="interceptionContext">Optional information about the context of the call being made.</param>
        /// <param name="cancellationToken">The cancellation token for the asynchronous operation.</param>
        /// <returns>The result of the operation, which may have been modified by interceptors.</returns>
        public virtual Task <int> NonQueryAsync(
            DbCommand command, DbCommandInterceptionContext interceptionContext, CancellationToken cancellationToken)
        {
            Check.NotNull(command, "command");
            Check.NotNull(interceptionContext, "interceptionContext");

            cancellationToken.ThrowIfCancellationRequested();

            var clonedInterceptionContext = new DbCommandInterceptionContext <int>(interceptionContext);

            if (!clonedInterceptionContext.IsAsync)
            {
                clonedInterceptionContext = clonedInterceptionContext.AsAsync();
            }

            return(_internalDispatcher.DispatchAsync(
                       () => command.ExecuteNonQueryAsync(cancellationToken),
                       clonedInterceptionContext,
                       i => i.NonQueryExecuting(command, clonedInterceptionContext),
                       i => i.NonQueryExecuted(command, clonedInterceptionContext)));
        }