AlinSpace.Commands 6.0.0

Install-Package AlinSpace.Commands -Version 6.0.0
dotnet add package AlinSpace.Commands --version 6.0.0
<PackageReference Include="AlinSpace.Commands" Version="6.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AlinSpace.Commands --version 6.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AlinSpace.Commands, 6.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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.0.0

// Install AlinSpace.Commands as a Cake Tool
#tool nuget:?package=AlinSpace.Commands&version=6.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

<img src="https://github.com/onixion/AlinSpace.Commands/blob/main/Assets/Icon.png" width="200" height="200">

AsyncCommands

NuGet version (AsyncCommands)

A simple Async library for command and command manager patterns.

The IAsyncCommand interface is very similar to the ICommand interface, but they are not the same. The Async interface is a fully asynchronous command interface, whereas ICommand is not.

NuGet package

Examples - AsyncCommand

This is the AsyncCommand:

var asyncCommand = AsyncCommand
   .New()
   .OnCanChange(_ => canExecute)
   .OnExecuteAsync(ExecuteSomethingAsync);
   
var genericAsyncCommand = AsyncCommand
   .New<int>()
   .OnCanChange(_ => canExecute)
   .OnExecuteAsync(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);
   }
   ...
}

Examples - AsyncCommandManager

The AsyncCommandManager allows to create command groups. Command groups dictate the availability of command execution. Async commands are registered to one command group. When registering a AsyncCommand to a group, it will return an ICommand instance. This instance can be passed to the view that consumes the command. The command manager will hide all the logic for locking, unlocking, and notifying commands for you. Additionally, each registered Async command can also add instance-specific logic for CanExecute.

Here are some examples:

AsyncCommandManager
    .New()
    .LockAll(e => 
    {
       SaveCommand = e.Register(SaveAsyncCommand);
       DeleteCommand = e.Register(DeleteAsyncCommand);
    });

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.

AsyncCommandManager
   .New()
   .LockAll(eg => 
   {
      SaveCommand = eg.Register(SaveAsyncCommand);
      DeleteCommand = eg.Register(DeleteAsyncCommand);
   })
   .LockAllOthers(eg => 
   {
      SearchCommand = eg.Register(SearchAsyncCommand);
   });

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.

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

  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.

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.0.0 506 11/19/2021
5.0.2 150 7/31/2021
5.0.1 162 7/31/2021
5.0.0 90 7/30/2021