Nate 1.0.3

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

// Install Nate as a Cake Tool
#tool nuget:?package=Nate&version=1.0.3

Nate

Tiny little fluent state machine for .NET

Full documentation coming soon

Inspired by Martin Fowler's DSL Book, Ruby's ActsAsStateMachine gem, and Workflow Foundation's bloat.

  • Simple, embeddable
    • Does not ask application to conform to its framework. Just drops into any class to give it simple state machine abilities.
    • Fast and efficient - Designed to be instantiated statically. A given StateMachine is itself stateless, and transforms the state of StateModels passed to it.
    • Keeps the state where it belongs, on the model itself. Not serialized elsewhere.
    • Provides all the plumbing necessary: states, transitions, triggers, callbacks, machines
  • Fluent API
    • Describe your state machine, it's transitions, triggers, callbacks, etc. in a minimal, readable, english-like C# syntax, all without repeating yourself.
    • Fluent API is implemented with a Nate state machine, itself.
  • Flexible
    • Support for multiple identical triggers per state with varying targets, chosen from at runtime via lambda expression guards
    • Support for globally-available transitions which provide a pragmatic way to always allow short-circuits
    • Exposure of Underlying State Machine model allows for more advanced possibilities

Full documentation coming soon

An example implementing Martin Fowler's Gothic Security DSL Sample, demonstrating a portion of the Fluent API.
http://martinfowler.com/dslwip/Intro.html#TheStateMachineFramework

The state machine is described succinctly and embedded directly within the StateModel, which holds (and probably persists) the current state.

public class MissGrantController : IStateModel
{
    /* state is stored on the model */
    public object CurrentState { get; set; }
    public MissGrantController() { CurrentState = securityControllerStateMachine.InitialState; }

    /* state machine is described once, statically */
    private static IFluentStateMachine<MissGrantController> 
    securityControllerStateMachine = FluentStateMachine<MissGrantController>.Describe()
        .State("idle")
            .AfterEntry(e => {
                e.Model.UnlockDoor();
                e.Model.LockPanel(); })
            .TransitionsTo("active").On("doorClosed")
            .Initiates()
        .State("active")
            .TransitionsTo("waitingForLight").On("drawOpened")
            .TransitionsTo("waitingForDraw").On("lightOn")
        .State("waitingForLight")
            .TransitionsTo("unlockedPanel").On("lightOn")
        .State("waitingForDraw")
            .TransitionsTo("unlockedPanel").On("drawOpened")
        .State("unlockedPanel")
            .AfterEntry(e => {
                e.Model.UnlockPanel();
                e.Model.LockDoor(); })
            .TransitionsTo("idle").On("panelClosed")
        .GloballyTransitionsTo("idle").On("doorOpened")
        .Compile();

    /* external controls */
    public void DoorClosed() { securityControllerStateMachine.Trigger("doorClosed", this); }
    public void DrawOpened() { securityControllerStateMachine.Trigger("drawOpened", this); }
    public void LightOn() { securityControllerStateMachine.Trigger("lightOn", this); }
    public void DoorOpened() { securityControllerStateMachine.Trigger("doorOpened", this); }
    public void PanelClosed() { securityControllerStateMachine.Trigger("panelClosed", this); }

    /* locking/unlocking actions */
    private void UnlockPanel() { Console.WriteLine("Unlocking Panel"); }
    private void LockPanel() { Console.WriteLine("Locking Panel"); }
    private void LockDoor() { Console.WriteLine("Locking Door"); }
    private void UnlockDoor() { Console.WriteLine("Unlocking Door"); }
}

Full documentation coming soon

License

The MIT License

Copyright (c) 2009-2011 Michael Monteleone

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  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.
  • .NETFramework 4.5

    • No dependencies.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.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
1.0.3 366 1/2/2022
1.0.2 635 8/31/2019
1.0.1 1,480 4/18/2014

Version 1.0.3
     - Added support for .Net 5.0 and 6.0
     - Code cleanup and changing locks to instance level