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

Concrete implementation of ICommand interface. Command allows to call a method or function using Command pattern. More...

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

Public Member Functions

 Command (string name, Schema schema, ExecutableDelegate function)
 Creates a new command object and assigns it's parameters. More...
 
async Task< object > ExecuteAsync (string correlationId, Parameters args)
 Executes the command. Before execution is validates Parameters args using the defined schema.The command execution intercepts exceptions raised by the called function and calls them as an error. More...
 
IList< ValidationResultValidate (Parameters args)
 Validates the command Parameters args before execution using the defined schema. More...
 

Properties

string Name [get]
 Gets the command name. More...
 
Schema Schema [get]
 Gets the command schema. 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 ExecutableDelegate _function
 

Detailed Description

Concrete implementation of ICommand interface. Command allows to call a method or function using Command pattern.

var command = new Command("add", null, async(args) => {
var param1 = args.GetAsFloat("param1");
var param2 = args.GetAsFloat("param2");
return param1 + param2; });
var result = command.ExecuteAsync("123", Parameters.fromTuples(
"param1", 2,
"param2", 2 ));
Console.WriteLine(result.ToString());
// Console output: 4

See ICommand, CommandSet

Constructor & Destructor Documentation

◆ Command()

PipServices3.Commons.Commands.Command.Command ( string  name,
Schema  schema,
ExecutableDelegate  function 
)

Creates a new command object and assigns it's parameters.

Parameters
nameCommand name.
schemaCommand schema.
functionExecutable function.

Member Function Documentation

◆ ExecuteAsync()

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

Executes the command. Before execution is validates Parameters args using the defined schema.The command execution intercepts exceptions raised by the called function and calls them as an error.

Parameters
correlationIdUnique correlation/transaction id.
argsCommand arguments.
Returns
Execution result.

See Parameters

Implements PipServices3.Commons.Run.IExecutable.

◆ Validate()

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

Validates the command Parameters args before execution using the defined schema.

Parameters
argsCommand arguments.
Returns
a list of ValidationResults or an empty array (if no schema is set).

See Parameters, ValidationResult

Implements PipServices3.Commons.Commands.ICommand.

Property Documentation

◆ Name

string PipServices3.Commons.Commands.Command.Name
get

Gets the command name.

◆ Schema

Schema PipServices3.Commons.Commands.Command.Schema
get

Gets the command schema.


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