IegTools.Sequencer 2.0.2-beta2

This is a prerelease version of IegTools.Sequencer.
There is a newer version of this package available.
See the version list below for details.
dotnet add package IegTools.Sequencer --version 2.0.2-beta2                
NuGet\Install-Package IegTools.Sequencer -Version 2.0.2-beta2                
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="IegTools.Sequencer" Version="2.0.2-beta2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IegTools.Sequencer --version 2.0.2-beta2                
#r "nuget: IegTools.Sequencer, 2.0.2-beta2"                
#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 IegTools.Sequencer as a Cake Addin
#addin nuget:?package=IegTools.Sequencer&version=2.0.2-beta2&prerelease

// Install IegTools.Sequencer as a Cake Tool
#tool nuget:?package=IegTools.Sequencer&version=2.0.2-beta2&prerelease                

IegTools.Sequencer in a Nutshell

IegTools.Sequencer provides a fluent interface for creating easy-to-read and extensible sequences, eliminating the need for lengthy if/else statements.

Define transition jobs:
from state → to state, when it should be triggerd and the action that should be invoked

Force state on specified conditions

Invoke Actions on specified states

Usage

Configure, build and run a sequence

Configuration .NET 6 style

A simple example configuration for an OnTimer-sequence:

public class OnTimerExample
{
    private ISequenceBuilder SequenceConfig =>
        SequenceBuilder.Create()
            .AddForceState(">Off", () => !LastValue)
            .AddTransition(">Off", "PrepareOn", () => LastValue, () => _sequence.Stopwatch.Restart())
            .AddTransition("PrepareOn", "!On", () => _sequence.Stopwatch.Expired(MyTimeSpan));

Build the sequence

public class OnTimerExample
{
    private ISequence _sequence;
	
    public OnTimerExample() =>
        _sequence = SequenceConfig.Build();
}

Run the sequence

The sequence will be executed in the configuration order .

public class OnTimerExample
{
    public void In(bool value)
    {
        LastValue = value;
        _sequence.Run();
        // or await _sequence.RunAsync();
    }
}

Configuration .NET 5 style

A more complex example configuration for a pump-anti-sticking-sequence:

 private ISequenceBuilder SequenceConfig =>
        SequenceBuilder.Configure(builder =>
        {
            builder.AddForceState(">Paused", () => !_onTimer.Out);
            
            builder.AddTransition(">Paused", "Activated",
                () => _onTimer.Out,
                () => _countStarts = 1);
            
            builder.AddTransition("Activated", "Pump on",
                () => true,
                () => Stopwatch.Restart());
            
            builder.AddTransition("Pump on", "Pump off",
                () => Stopwatch.Expired(_settings.RunTime * _countStarts.Factorial()),
                () =>
                {
                    Stopwatch.Restart();
                    _countStarts++;
                });

            builder.AddTransition("Pump off", "Pump on",
                () => Stopwatch.Expired(_settings.PauseTime) && !sequenceDone());

            builder.AddTransition("Pump off", ">Paused",
                () => Stopwatch.Expired(_settings.PauseTime) && sequenceDone(),
                () => _onTimer.In(false));

            bool sequenceDone() => _countStarts > _settings.PumpStartQuantity;
        });

Config in Detail

  • Force state on condition: builder.AddForceState("ForceState", constraint)

  • State transition on condition (with optional action) builder.AddTransition("FromState", "ToState", constraint, action)

  • Action on state: builder.AddStateAction("State", action)

TODO Documentation

States

States can be defined as strings or enums, internally they will be stored as strings.

State Tags

State-Tags can only be used with string-states. For enum-states there are other possibilities. (link to ...)

There are available two state tags as prefix for states

  • the IgnoreTag '!'
  • and the InitialStateTag '>'

IgnoreTag

Use the IgnoreTag as prefix for an state to tell the Validator not to check this state for counterpart-plausibility.

Example:

 .AddTransition("PrepareOff", "!Off", () => Stopwatch.Expired(MyTimeSpan));

InitialStateTag

Use the InitialStateTag as prefix for an state to tell the Sequence what state to start from.

Example:

 builder.AddForceState(">Paused", () => !_onTimer.Out);

Validation

The sequence will be validated when build. _sequence = builder.Build();

Validation Rules:

  • InitialState must be defined
  • The InitialState must have an counterpart in a StateTransition
  • The Sequence must have at least two steps
  • Each 'NextStep' must have a counterpart StateTransition with an matching 'CurrentState'
  • Each 'CurrentState' must have a counterpart StateTransition with an matching 'NextStep' or ForceState

Validation could be disabled completely:

builder.DisableValidation()

or with specifing states that shouldn't be validated:

builder.DisableValidationForStates("state1", "state2", ...)

or with the IgnoreTag: TODO Documentation

Extensibility

Write your own customized

  • Rules
  • Sequence
  • and Validator

TODO Documentation

Rules

Internally the Framework is working with Rules (you can write your own customized rules). The Rules describe what they are supposed to do within the sequence.

There are five default rule:

  • The StateTransitionRule
  • The ContainsStateTransitionRule
  • The AnyStateTransitionRule
  • The ForceStateRule
  • The StateActionRule

TODO Documentation

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
3.0.0 85 9/30/2024
3.0.0-rc.3 49 9/26/2024
3.0.0-rc.2 143 12/26/2023
3.0.0-rc.1 85 12/24/2023
3.0.0-alpha.5 80 12/23/2023
3.0.0-alpha.4 92 12/17/2023
3.0.0-alpha.3 71 12/17/2023
3.0.0-alpha.2 88 12/14/2023
3.0.0-alpha.1 73 12/13/2023
2.2.2-alpha.4 87 12/11/2023
2.2.2-alpha.3 82 12/10/2023
2.2.2-alpha.2 78 12/10/2023
2.2.2-alpha 313 12/9/2023
2.2.1 451 12/7/2023
2.2.0 330 12/7/2023
2.1.0 397 11/2/2023
2.0.2 615 4/13/2023
2.0.2-rc.1 101 4/10/2023
2.0.2-beta2 528 3/28/2023
2.0.2-beta1 499 3/27/2023
2.0.2-beta.3 98 4/4/2023
1.10.1 638 3/18/2023
1.10.0 644 3/18/2023
1.9.0 651 2/21/2023
1.8.0 729 1/9/2023
1.7.0 834 8/2/2022
1.6.0 788 8/1/2022
1.5.0 817 6/16/2022

Bugfix AnyStateTransitionRule, ContainsStateTransitionRule, extend SequenceValidator