/// <summary> /// Initializes a new instance of the BaseCommand class. /// </summary> /// <param name="groupName">A name used to identify a group of similar or related commands.</param> /// <param name="commandName">The name of the command.</param> /// <param name="commandProperties">Defines the properties for this command.</param> internal BaseCommand(string groupName, string commandName, CommandProperties commandProperties) { Throw.IfArgumentNullOrWhitespace(groupName, "groupName"); Throw.IfArgumentNull(commandProperties, "commandProperties"); this.GroupName = groupName; this.CommandName = string.IsNullOrWhiteSpace(commandName) ? BaseCommand <TResponse> .GetCommandName(this.GetType()) : commandName; this.CommandProperties = commandProperties; this.CommandKey = new CommandKey(this.GroupName, this.CommandName); }
/// <summary> /// Executes an action as a command using the current context's scheduler. /// </summary> /// <param name="groupName">A name used to identify a group of similar or related commands.</param> /// <param name="commandName">The name of the command.</param> /// <param name="commandProperties">Defines the properties for this command.</param> /// <param name="executeCommand">An action that will be executed as command.</param> /// <returns>A task encapsulating the executing command.</returns> public Task <CommandResult> Execute(string groupName, string commandName, CommandProperties commandProperties, Action executeCommand) { return (this.Execute( new DelegateCommand <Unit>( groupName, commandName, commandProperties, () => { executeCommand(); return null; })) .ContinueWith <CommandResult>(task => task.Result, TaskContinuationOptions.OnlyOnRanToCompletion)); }
/// <summary> /// Initializes a new instance of the DelegateCommand class. /// </summary> /// <param name="groupName">A name used to identify a group of similar or related commands.</param> /// <param name="commandName">The name of the command.</param> /// <param name="commandProperties">Defines the properties for this command.</param> /// <param name="executeCommand">A function that will be executed as command.</param> public DelegateCommand(string groupName, string commandName, CommandProperties commandProperties, Func <TResponse> executeCommand) : base(groupName, commandName, commandProperties) { Throw.IfArgumentNull(executeCommand, nameof(executeCommand)); this.executeCommand = executeCommand; }
/// <summary> /// Initializes a new instance of the AsyncCommand class. /// </summary> /// <param name="groupName">A name used to identify a group of similar or related commands.</param> /// <param name="commandName">The name of the command.</param> /// <param name="commandProperties">Defines the properties for this command.</param> protected AsyncCommand(string groupName, string commandName, CommandProperties commandProperties) : base(groupName, commandName, commandProperties) { }
/// <summary> /// Initializes a new instance of the AsyncCommand class. /// </summary> /// <param name="groupName">A name used to identify a group of similar or related commands.</param> /// <param name="commandProperties">Defines the properties for this command.</param> protected AsyncCommand(string groupName, CommandProperties commandProperties) : this(groupName, null, commandProperties) { }
/// <summary> /// Executes a function as a command using the current context's scheduler. /// </summary> /// <param name="groupName">A name used to identify a group of similar or related commands.</param> /// <param name="commandName">The name of the command.</param> /// <param name="commandProperties">Defines the properties for this command.</param> /// <param name="executeCommand">A function that will be executed as command.</param> /// <returns>A task encapsulating the executing command.</returns> public Task <CommandResult <TResponse> > Execute <TResponse>(string groupName, string commandName, CommandProperties commandProperties, Func <Task <TResponse> > executeCommand) { return(this.Execute(new AsyncDelegateCommand <TResponse>(groupName, commandName, commandProperties, executeCommand))); }