snzip / microwf

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

Home Page:http://www.tomware.ch/2018/04/30/building-a-simple-workflow-system-with-asp-net-core/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

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!!!");
  }
}

About

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

http://www.tomware.ch/2018/04/30/building-a-simple-workflow-system-with-asp-net-core/

License:MIT License


Languages

Language:C# 98.8%Language:Shell 1.0%Language:Dockerfile 0.2%