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

Contains a set of commands and events supported by a ICommandable object. The CommandSet supports command interceptors to extend and the command call chain. CommandSets can be used as alternative commandable interface to a business object. It can be used to auto generate multiple external services for the business object without writing much code. More...

Public Member Functions

 CommandSet ()
 Creates an empty CommandSet object. More...
 
ICommand FindCommand (string command)
 Searches for a command by its name. More...
 
IEvent FindEvent (string ev)
 Searches for an event by its name in this command set. More...
 
void AddCommand (ICommand command)
 Adds a ICommand command to this command set. More...
 
void AddCommands (IEnumerable< ICommand > commands)
 Adds multiple ICommand commands to this command set. More...
 
void AddEvent (IEvent ev)
 Adds an IEvent event to this command set. More...
 
void AddEvents (IEnumerable< IEvent > events)
 Adds multiple IEvent events to this command set. More...
 
void AddCommandSet (CommandSet commandSet)
 Adds all of the commands and events from specified CommandSet command set into this one. More...
 
void AddInterceptor (ICommandInterceptor intercepter)
 Adds a ICommandInterceptor command interceptor to this command set. More...
 
Task< object > ExecuteAsync (string correlationId, string command, Parameters args)
 Executes a ICommand command specificed by its name. More...
 
IList< ValidationResultValidate (string command, Parameters args)
 Validates Parameters args for command specified by its name using defined schema.If validation schema is not defined than the methods returns no errors.It returns validation error if the command is not found. More...
 
void AddListener (IEventListener listener)
 Adds a IEventListener listener to receive notifications on fired events. More...
 
void RemoveListener (IEventListener listener)
 Removes previosly added IEventListener listener. More...
 
async Task NotifyAsync (string correlationId, string ev, Parameters value)
 Fires event specified by its name and notifies all registered IEventListener listeners More...
 

Properties

List< ICommandCommands [get]
 Gets all commands registered in this command set. More...
 
List< IEventEvents [get]
 Gets all events registred in this command set. More...
 

Private Member Functions

void BuildCommandChain (ICommand command)
 
void RebuildAllCommandChains ()
 

Private Attributes

List< ICommand_commands = new List<ICommand>()
 
List< IEvent_events = new List<IEvent>()
 
readonly Dictionary< string, ICommand_commandsByName = new Dictionary<string, ICommand>()
 
readonly Dictionary< string, IEvent_eventsByName = new Dictionary<string, IEvent>()
 
readonly List< ICommandInterceptor_intercepters = new List<ICommandInterceptor>()
 

Detailed Description

Contains a set of commands and events supported by a ICommandable object. The CommandSet supports command interceptors to extend and the command call chain. CommandSets can be used as alternative commandable interface to a business object. It can be used to auto generate multiple external services for the business object without writing much code.

public class MyDataCommandSet: CommandSet
{
private IMyDataController _controller;
public MyDataCommandSet(IMyDataController controller) // Any data controller interface
{
base();
this._controller = controller;
this.addCommand(this.MakeGetMyDataCommand()); }
private ICommand MakeGetMyDataCommand()
{
return new Command(
'get_mydata',
null,
async(correlationId, args)=> {
String param = args.getAsString('param');
return this._controller.getMyData(correlationId, param); });
}
}

See ICommandable, Command, Event

Constructor & Destructor Documentation

◆ CommandSet()

PipServices3.Commons.Commands.CommandSet.CommandSet ( )

Creates an empty CommandSet object.

Member Function Documentation

◆ AddCommand()

void PipServices3.Commons.Commands.CommandSet.AddCommand ( ICommand  command)

Adds a ICommand command to this command set.

Parameters
commandThe command to add.

See ICommand

◆ AddCommands()

void PipServices3.Commons.Commands.CommandSet.AddCommands ( IEnumerable< ICommand commands)

Adds multiple ICommand commands to this command set.

Parameters
commandsThe commands to add.

See ICommand

◆ AddCommandSet()

void PipServices3.Commons.Commands.CommandSet.AddCommandSet ( CommandSet  commandSet)

Adds all of the commands and events from specified CommandSet command set into this one.

Parameters
commandSetThe commands set to add.

◆ AddEvent()

void PipServices3.Commons.Commands.CommandSet.AddEvent ( IEvent  ev)

Adds an IEvent event to this command set.

Parameters
evThe event to add.

See IEvent

◆ AddEvents()

void PipServices3.Commons.Commands.CommandSet.AddEvents ( IEnumerable< IEvent events)

Adds multiple IEvent events to this command set.

Parameters
eventsThe events to add.

See IEvent

◆ AddInterceptor()

void PipServices3.Commons.Commands.CommandSet.AddInterceptor ( ICommandInterceptor  intercepter)

Adds a ICommandInterceptor command interceptor to this command set.

Parameters
intercepterThe intercepter to add.

See ICommandInterceptor

◆ AddListener()

void PipServices3.Commons.Commands.CommandSet.AddListener ( IEventListener  listener)

Adds a IEventListener listener to receive notifications on fired events.

Parameters
listenerThe listener to add.

◆ ExecuteAsync()

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

Executes a ICommand command specificed by its name.

Parameters
correlationIdUnique correlation/transaction id.
commandCommand name.
argsCommand arguments.
Exceptions
ValidationExceptionwhen execution fails for validation reason.
Returns
Execution result.

See ICommand, Parameters

◆ FindCommand()

ICommand PipServices3.Commons.Commands.CommandSet.FindCommand ( string  command)

Searches for a command by its name.

Parameters
commandThe command name.
Returns
A command with the given name.

See ICommand

◆ FindEvent()

IEvent PipServices3.Commons.Commands.CommandSet.FindEvent ( string  ev)

Searches for an event by its name in this command set.

Parameters
evthe name of the event to search for.
Returns
An event with the given name.

See IEvent

◆ NotifyAsync()

async Task PipServices3.Commons.Commands.CommandSet.NotifyAsync ( string  correlationId,
string  ev,
Parameters  value 
)

Fires event specified by its name and notifies all registered IEventListener listeners

Parameters
correlationIdoptional transaction id to trace calls across components.
evthe name of the event that is to be fired.
valuethe event arguments (parameters).

◆ RemoveListener()

void PipServices3.Commons.Commands.CommandSet.RemoveListener ( IEventListener  listener)

Removes previosly added IEventListener listener.

Parameters
listenerThe listener to remove.

◆ Validate()

IList<ValidationResult> PipServices3.Commons.Commands.CommandSet.Validate ( string  command,
Parameters  args 
)

Validates Parameters args for command specified by its name using defined schema.If validation schema is not defined than the methods returns no errors.It returns validation error if the command is not found.

Parameters
commandthe name of the command for which the 'args' must be validated.
argsthe parameters (arguments) to validate.
Returns
a list of ValidationResults. If no command is found by the given name, then the returned array of ValidationResults will contain a single entry, whose type will be ValidationResultType.Error.

See Command, Parameters, ValidationResult

Property Documentation

◆ Commands

List<ICommand> PipServices3.Commons.Commands.CommandSet.Commands
get

Gets all commands registered in this command set.

Returns
a list of commands.

See ICommand

◆ Events

List<IEvent> PipServices3.Commons.Commands.CommandSet.Events
getprivate

Gets all events registred in this command set.

Returns
a list of events.

See IEvent


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