CommandSet

Contains a set of commands and events supported by a commandable object. The CommandSet supports command interceptors and command call chains.

Description

The CommandSet class allows you to create a set of commands and events supported by a commandable object. In addition, it supports command interceptors and command call chains.

Important points

  • CommandSets can be used as an alternative commandable interface to a business object.
  • This class can be used to auto generate multiple external services for a business object.

Constructors

Creates an empty CommandSet object.

CommandSet()

Properties

Commands

Gets all commands registered in this command set. See ICommand.

public List<ICommand> Commands [ get ]

Events

Gets all events registred in this command set.
See IEvent

public List<IEvent> Events()

Instance methods

AddCommand

Adds a command to this command set.
See ICommand

public void AddCommand(ICommand command)

  • command: ICommand - the command to add.

AddCommandSet

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

public void AddCommandSet(CommandSet commandSet)

AddCommands

Adds multiple commands to this command set.
See ICommand

public void AddCommands(IEnumerable<ICommand> commands)

  • commands: IEnumerable<ICommand> - the array of commands to add.

AddEvent

Adds an event to this command set.
See IEvent

public void AddEvent(IEvent ev)

  • ev: IEvent - the event to add.

AddEvents

Adds multiple events to this command set.
See IEvent

public void AddEvents(IEnumerable<IEvent> events)

  • events: IEnumerable<IEvent> - the array of events to add.

AddInterceptor

Adds a command interceptor to this command set.

public void AddInterceptor(ICommandInterceptor intercepter)

AddListener

Adds a listener to receive notifications on fired events.
See IEventListener

public void AddListener(IEventListener listener)

ExecuteAsync

Executes a command specificed by its name.
See ICommand, Parameters

public Task<\object> ExecuteAsync(string correlationId, string command, Parameters args)

  • correlationId: string - (optional) transaction id to trace execution through call chain.
  • command: string - the name of that command that is to be executed.
  • args: Parameters - the parameters (arguments) to pass to the command for execution.
  • returns: Task<\object> - the execution result

FindCommand

Searches for a command by its name. See ICommand

public ICommand FindCommand(string command)

  • command: ICommand - the name of the command to search for.
  • returns: ICommand - the command, whose name matches the provided name.

FindEvent

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

public IEvent FindEvent(string ev)

  • ev: string - the name of the event to search for.
  • returns: IEvent - the event, whose name matches the provided name.

NotifyAsync

Fires event specified by its name and notifies all registered listeners

public Task NotifyAsync(correlationId: string, ev: string, args: Parameters)

  • correlationId: string - (optional) transaction id to trace execution through call chain.
  • ev: string - the name of the event that is to be fired.
  • args: Parameters - the event arguments (parameters).

RemoveListener

Removes previosly added listener.
See IEventListener

public void RemoveListener(IEventListener listener)

validate

Validates 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.

IList<ValidationResult> validate(string command, Parameters args)

  • command: string - the name of the command for which the ‘args’ must be validated.
  • args: Parameters - the parameters (arguments) to validate.
  • returns: IList<ValidationResult> - an array 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.

Examples

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 also