Skip to content

mguinness/microwf

 
 

Repository files navigation

build NuGet Release BuitlWithDot.Net shield

microwf

A simple finite state machine (FSM) with workflow character where you define your workflows in code.

Holiday approval sample

Holiday Aproval

In code it looks like:

public class HolidayApprovalWorkflow : WorkflowDefinitionBase
{
  public const string TYPE = "HolidayApprovalWorkflow";

  public override string Type
  {
    get { return TYPE; }
  }

  public override List<Transition> Transitions
  {
    get
    {
      return new List<Transition>
      {
        new Transition {
          State = "New",
          Trigger = "Apply",
          TargetState ="Applied",
          CanMakeTransition = MeApplyingForHolidays
        },
        new Transition {
          State = "Applied",
          Trigger = "Approve",
          TargetState ="Approved",
          CanMakeTransition = BossIsApproving,
          AfterTransition = ThankBossForApproving
        },
        new Transition {
          State = "Applied",
          Trigger = "Reject",
          TargetState ="Rejected"
        }
      };
    }
  }

  private bool MeApplyingForHolidays(TransitionContext context)
  {
    var holiday = context.GetInstance<Holiday>();

    return holiday.Me == "Me";
  }

  private bool BossIsApproving(TransitionContext context)
  {
    var holiday = context.GetInstance<Holiday>();
    
    return holiday.Boss == "NiceBoss";
  }
  
  private void ThankBossForApproving(TransitionContext context)
  {
    // SendMail("Thank you!!!");
  }
}

Running the samples

Assuming you downloaded the sources and opened the directory with VS Code you should be good to go! Ahh and of course you need .NET Core and node.js installed on your development environment.

Running the WebApi backend

  1. Open the integrated terminal in VS Code and type

dotnet build

That ensures you are able to build the dotnet related stuff!

  1. Go to the VS Code Debug tab (Ctrl+Shift+D) and run the Security Token Server (STS = IdentityServer) project.

  2. After the STS is running change the dropdown to the WebApi project and run it.

You should see now the login screen.

Administrator Web UI

A web interface allows an administrator to search for workflow instances and have a look into the current state.

Admin

Happy poking!!

About

A simple finite state machine (FSM) with workflow character where you define your workflows in code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.2%
  • Other 0.8%