IegTools.Sequencer
2.0.2-beta.3
See the version list below for details.
dotnet add package IegTools.Sequencer --version 2.0.2-beta.3
NuGet\Install-Package IegTools.Sequencer -Version 2.0.2-beta.3
<PackageReference Include="IegTools.Sequencer" Version="2.0.2-beta.3" />
paket add IegTools.Sequencer --version 2.0.2-beta.3
#r "nuget: IegTools.Sequencer, 2.0.2-beta.3"
// Install IegTools.Sequencer as a Cake Addin #addin nuget:?package=IegTools.Sequencer&version=2.0.2-beta.3&prerelease // Install IegTools.Sequencer as a Cake Tool #tool nuget:?package=IegTools.Sequencer&version=2.0.2-beta.3&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 | Versions 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. |
-
.NETStandard 2.0
- FluentValidation (>= 11.5.1)
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 | 82 | 9/30/2024 |
3.0.0-rc.3 | 46 | 9/26/2024 |
3.0.0-rc.2 | 140 | 12/26/2023 |
3.0.0-rc.1 | 82 | 12/24/2023 |
3.0.0-alpha.5 | 77 | 12/23/2023 |
3.0.0-alpha.4 | 87 | 12/17/2023 |
3.0.0-alpha.3 | 68 | 12/17/2023 |
3.0.0-alpha.2 | 85 | 12/14/2023 |
3.0.0-alpha.1 | 70 | 12/13/2023 |
2.2.2-alpha.4 | 84 | 12/11/2023 |
2.2.2-alpha.3 | 79 | 12/10/2023 |
2.2.2-alpha.2 | 75 | 12/10/2023 |
2.2.2-alpha | 310 | 12/9/2023 |
2.2.1 | 448 | 12/7/2023 |
2.2.0 | 325 | 12/7/2023 |
2.1.0 | 394 | 11/2/2023 |
2.0.2 | 610 | 4/13/2023 |
2.0.2-rc.1 | 98 | 4/10/2023 |
2.0.2-beta2 | 525 | 3/28/2023 |
2.0.2-beta1 | 496 | 3/27/2023 |
2.0.2-beta.3 | 95 | 4/4/2023 |
1.10.1 | 635 | 3/18/2023 |
1.10.0 | 641 | 3/18/2023 |
1.9.0 | 648 | 2/21/2023 |
1.8.0 | 726 | 1/9/2023 |
1.7.0 | 831 | 8/2/2022 |
1.6.0 | 785 | 8/1/2022 |
1.5.0 | 814 | 6/16/2022 |
Bugfix AnyStateTransitionRule, ContainsStateTransitionRule, extend SequenceValidator