AlinSpace.Commands 6.1.8

Prefix Reserved
dotnet add package AlinSpace.Commands --version 6.1.8                
NuGet\Install-Package AlinSpace.Commands -Version 6.1.8                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AlinSpace.Commands" Version="6.1.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AlinSpace.Commands --version 6.1.8                
#r "nuget: AlinSpace.Commands, 6.1.8"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AlinSpace.Commands as a Cake Addin
#addin nuget:?package=AlinSpace.Commands&version=6.1.8

// Install AlinSpace.Commands as a Cake Tool
#tool nuget:?package=AlinSpace.Commands&version=6.1.8                

AlinSpace.Commands

NuGet version (AlinSpace.Commands)

An asynchronous command and command manager implementation.

NuGet package

Why?

When you need or have complex concurrent command locking rules, this library is something for you.

Asynchronous Commands

Examples - AsyncCommand

This is the AsyncCommand:

var command = AsyncCommand
   .New()
   .SetCanChange(_ => canExecute)
   .SEtExecuteAsync(ExecuteSomethingAsync);
   
var genericCommand = AsyncCommand
   .New<int>()
   .SetCanChange(_ => canExecute)
   .SetExecuteAsync(ExecuteSomethingWithIntAsync);
   

Examples - AbstractAsyncCommand

This is the AbstractAsyncCommand:

public class MyAsyncCommand : AbstractAsyncCommand
{
   ...
   public async Task ExecuteAsync(object? parameter = null)
   {
       await DoSomethingAsync(parameter);
   }
   ...
}

public class MyGenericAsyncCommand<int> : AbstractAsyncCommand
{
   ...
   public async Task ExecuteAsync(int? parameter = null)
   {
       await DoSomethingWithIntAsync(parameter);
   }
   ...
}

Asynchronous Command Manager

The AsyncManager allows you to create command execution groups. Command execution groups dictate the availability of command execution. Commands are registered to one (or more) command groups. When registering a IAsyncCommand to a group, it will return a new instance of IAsyncCommand. This instance can be passed to the view that will act on the the command. The command manager will hide all the logic for locking, unlocking, and notifying commands for you. Additionally, each registered asynchronous command can also add command-specific logic for CanExecute.

Examples - AsyncManager

Here are some examples:

AsyncManager
    .New()
    .LockAll(e => 
    {
       SaveCommand = e.Register(SaveCommand);
       DeleteCommand = e.Register(DeleteCommand);
    });

Each command group defines a group lock behavior. This behavior defines how the group will affect other groups when it gets locked. On default the command group lock is set to LockAllGroups, meaning all groups will be locked when a command is executed from this group. When an group is locked by at least one group, all commands registered to this group will not be able to execute until released by all groups.

These are the currently supported group lock behaviors:

  • LockAllGroups: Locks all groups when executing a command registered to this group.
  • LockOtherGroups: Locks all other groups when executing a command registered to this group.
  • LockThisGroup: Locks this group when executing a command registered to this group.

In the following example, SaveCommand and DeleteCommand will lock all commands registered to the command manager when executed. However, the SearchCommand will lock all commands registered to the command manager except itself when executed.

AsyncManager
   .New()
   .LockAll(eg => 
   {
      SaveCommand = eg.Register(SaveCommand);
      DeleteCommand = eg.Register(DeleteCommand);
   })
   .LockAllOthers(eg => 
   {
      SearchCommand = eg.Register(SearchCommand);
   });

An important detail is that locking requirements can overlap. Here is an example: The Block10Command will do 10 seconds of work. The Block20Command will do 20 seconds of work.

AsyncManager
    .New()
    .LockThis(eg => Block10Command = eg.Register(Block10Command))
    .LockAll(eg => Block20Command = eg.Register(Block20Command));

When you press the Block10Command the command manager will lock the Block10Command for 10 seconds. If you wait 5 seconds and then execute the Block20Command command, all commands will be locked for another 20 seconds. After waiting for 5 seconds the Block10Command will be done and unlock its group, but because the other command group still blocks all groups for another 15 seconds, Block10Command will stay blocked for 15 seconds. Block10Command and Block20Command will both be unlocked at the same time.

AsyncManager Settings

There are a couple of manager settings:

  • VerifyCanExecuteBeforeExecution: This will force the manager to call CanExecute before any command execution.
  • IgnoreIndividualCanExecute: This will ignore the CanExecute method of the command itself and only listen to the command manager.
  • IgnoreExceptionsFromCommands: This will ignore any exceptions thrown by any given command. This is useful when you never ever want to crash your application and instead ignore it silently.
  • ContinueOnCapturedContext: Whether or not to continue on the captured context.
  • RaiseCanExecuteChangedOnAllCommandsAfterAnyCommandExecution: Raise CanExeucteChanged on all commands after any command executed.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.1.8 835 11/9/2022
6.1.5 723 11/8/2022
6.1.3 754 11/1/2022
6.1.2 766 11/1/2022
6.1.1 767 10/12/2022
6.0.8 823 10/11/2022
6.0.6 867 2/9/2022
6.0.5 866 2/3/2022