Pip-Services-Commons-Dotnet
Public Member Functions | Public Attributes | Properties | Private Attributes | List of all members
PipServices3.Commons.Commands.InterceptedCommand Class Reference

Implements a ICommand command wrapped by an interceptor. It allows to build command call chains.The interceptor can alter execution and delegate calls to a next command, which can be intercepted or concrete. More...

Inheritance diagram for PipServices3.Commons.Commands.InterceptedCommand:
PipServices3.Commons.Commands.ICommand PipServices3.Commons.Run.IExecutable

Public Member Functions

 InterceptedCommand (ICommandInterceptor interceptor, ICommand next)
 Creates a new InterceptedCommand, which serves as a link in an execution chain.Contains information about the interceptor that is being used and the next command in the chain. More...
 
Task< object > ExecuteAsync (string correlationId, Parameters args)
 Executes the next command in the execution chain using the given Parameters parameters(arguments). More...
 
IList< ValidationResultValidate (Parameters args)
 Validates the Parameters args that are to be passed to the command that is next in the execution chain. More...
 

Public Attributes

Schema Schema => _next?.Schema
 Gets the command schema. More...
 

Properties

string Name [get]
 Gets the command name. More...
 
- Properties inherited from PipServices3.Commons.Commands.ICommand
string Name [get]
 Gets the command name. More...
 
Schema Schema [get]
 Gets the command schema. More...
 

Private Attributes

readonly ICommandInterceptor _interceptor
 
readonly ICommand _next
 

Detailed Description

Implements a ICommand command wrapped by an interceptor. It allows to build command call chains.The interceptor can alter execution and delegate calls to a next command, which can be intercepted or concrete.

public class CommandLogger: ICommandInterceptor
{
public String GetName(ICommand command)
{
return command.GetName();
}
public Task<object> ExecuteAsync(string correlationId, ICommand command, Parameters args)
{
Console.WriteLine("Executed command " + command.getName());
return command.ExecuteAsync(correlationId, args);
}
private IList<ValidationResult> validate(ICommand command, Parameters args)
{
return command.validate(args);
}
}
var logger = new CommandLogger();
var loggedCommand = new InterceptedCommand(logger, command);
// Each called command will output: Executed command <command name>

See ICommand, ICommandInterceptor

Constructor & Destructor Documentation

◆ InterceptedCommand()

PipServices3.Commons.Commands.InterceptedCommand.InterceptedCommand ( ICommandInterceptor  interceptor,
ICommand  next 
)

Creates a new InterceptedCommand, which serves as a link in an execution chain.Contains information about the interceptor that is being used and the next command in the chain.

Parameters
interceptorthe interceptor that is intercepting the command.
nextNext intercepter or command in the chain.

Member Function Documentation

◆ ExecuteAsync()

Task<object> PipServices3.Commons.Commands.InterceptedCommand.ExecuteAsync ( string  correlationId,
Parameters  args 
)

Executes the next command in the execution chain using the given Parameters parameters(arguments).

Parameters
correlationIdunique transaction id to trace calls across components.
argsthe parameters (arguments) to pass to the command for execution.
Returns
Execution result.

See Parameters

Implements PipServices3.Commons.Run.IExecutable.

◆ Validate()

IList<ValidationResult> PipServices3.Commons.Commands.InterceptedCommand.Validate ( Parameters  args)

Validates the Parameters args that are to be passed to the command that is next in the execution chain.

Parameters
argsthe parameters (arguments) to validate for the next command.
Returns
A list of errors or an empty list if validation was successful.

See Parameters, ValidationResult

Implements PipServices3.Commons.Commands.ICommand.

Member Data Documentation

◆ Schema

Schema PipServices3.Commons.Commands.InterceptedCommand.Schema => _next?.Schema

Gets the command schema.

Property Documentation

◆ Name

string PipServices3.Commons.Commands.InterceptedCommand.Name
get

Gets the command name.

Returns
the name of the command that is being intercepted.

The documentation for this class was generated from the following file: