EMSm 1.4.0

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 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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net35 is compatible.  net40 was computed.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  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 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.
  • .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 617 6/29/2020
1.3.0 458 5/24/2020
1.2.0 516 5/23/2020
1.1.0 508 12/10/2019
1.0.1-beta 419 9/19/2019
1.0.0-beta 525 9/16/2019 1.0.0-beta is deprecated because it is no longer maintained.