EMSm 1.4.0

.NET Standard 2.1 .NET Framework 3.5
dotnet add package EMSm --version 1.4.0
NuGet\Install-Package EMSm -Version 1.4.0
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="EMSm" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EMSm --version 1.4.0
#r "nuget: EMSm, 1.4.0"
#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 EMSm as a Cake Addin
#addin nuget:?package=EMSm&version=1.4.0

// Install EMSm as a Cake Tool
#tool nuget:?package=EMSm&version=1.4.0

EMSm-Logo

Build Status NuGet Badge License: MIT

A simple, TDD-testable hierarchical state machine for .Net

Changelog

  • v1.1.0: intial version.
  • v1.2.0: support of older .Net-Frameworks implemented.
  • v1.3.0: strong-name-signing implemented
  • v1.4.0: Fix: Exit()-Methods weren't executed during state-transitions via setting the state path.

Features

  • Entry-/Exit- Implementation.
  • Synchronous-/Asynchronous- Mode.
  • Perfect to realize the behavior of embedded systems.
  • UML-statechart-applicability.
  • Use of transitions-tables to define the hierarchical structure.
  • Great overview of all states because every state is represented with a separate class.
  • Each state is TDD-testable.
  • Full flexible due to state-logic-implementation in Do()-method.
  • Command-injection can be accomplished from any thread.
  • Variable-injection provides clarity and great testability.
  • States can be designed for reusability.
  • Supports Done-Flag-Pattern.
  • Current-state-restoring using state-paths.
  • Simple to learn 😃.

Quick Start

StateChart

class InnerState1 : State
{
    private int counter;
 
    protected override void Entry()
    {
        /*Do some stuff here, which should run once
         a transition to this state occurs*/
        this.counter = 0;
        base.Entry();
    }
    protected override Enum Do()
    {
        /*This method is excuted on every RunCycle 
         as long as this state is the active one.
         Returns a transition for switching to another state*/
        if (this.counter++ >= 5)
            return Transitions.Transition1;
        return base.Do();
    }
    protected override void Exit()
    {
        /*Here you can do some cleanup,
         which run before a transition to
         another state happens*/
        base.Exit();
    }
}
class InnerState2 : State
{
    private int counter;
 
    protected override void Entry()
    {
        /*Do some stuff here, which should run once
         a transition to this state occurs*/
        this.counter = 0;
        base.Entry();
    }
    protected override Enum Do()
    {
        /*This method is excuted on every RunCycle 
         as long as this state is the active one.
         Returns a transition for switching to another state*/
        if (this.counter++ >= 99)
            return Transitions.Transition2;
        return base.Do();
    }
    protected override void Exit()
    {
        /*Here you can do some cleanup,
         which run before a transition to
         another state happens*/
        base.Exit();
    }
}
class OuterState : State
{
    public override TransitionsTable TransitionsTable
    {
        get => new TransitionsTable {
        //Initialtransition which should endup to InnerState 1
        new TransitionEntry{    
            Transition=Transitions.Initial,
            StateType=typeof(InnerState1),
            StateName="InnerState 1"},
        //Transition 1, which should endup to InnerState 2
        new TransitionEntry{
            Transition=Transitions.Transition1,
            StateType=typeof(InnerState2),
            StateName="Innerstate 2"},
        //Transition 2, which should endup to InnerState 1
        new TransitionEntry{
            Transition=Transitions.Transition2,
            StateType=typeof(InnerState1),
            StateName="Innerstate 1"},
        };
    }
 
    protected override void Entry()
    {
        /*Do some stuff here, which should run once
         a transition to this state occurs*/
        base.Entry();
    }
    protected override Enum Do()
    {
        /*This method is excuted on every RunCycle 
         if this state is the active one*/
        return base.Do();
    }
    protected override void Exit()
    {
        /*Here you can do some cleanup,
         which run before a transition to
         another state happens*/
        base.Exit();
    }
}

RunCycle:

OuterState outerState = new OuterState();
outerState.RunCycle();

StateChart-sync-async

Please visit https://www.eforge.net/EMSm for further documentation and tutorials

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
.NET Framework net35 net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 3.5

    • No dependencies.
  • .NETStandard 2.1

    • 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
1.4.0 448 6/29/2020
1.3.0 335 5/24/2020
1.2.0 399 5/23/2020
1.1.0 410 12/10/2019
1.0.1-beta 323 9/19/2019
1.0.0-beta 433 9/16/2019