public void Finish(TravelRequest travelRequest) { WithStateMachineFor(travelRequest).Fire(TravelRequestAction.Finish); }
public void Approve(TravelRequest travelRequest) { WithStateMachineFor(travelRequest).Fire(TravelRequestAction.Approve); }
public IEnumerable <TravelRequestAction> GetAllowedActions(TravelRequest travelRequest) { return(WithStateMachineFor(travelRequest).PermittedTriggers); }
public void Submit(TravelRequest travelRequest) { WithStateMachineFor(travelRequest).Fire(TravelRequestAction.Submit); }
public void Accept(TravelRequest travelRequest) { WithStateMachineFor(travelRequest).Fire(TravelRequestAction.Accept); }
private ReusableTravelRequestStateMachine WithStateMachineFor(TravelRequest travelRequest) { // Potential for cross threading issues here... this may be a pipe dream _reusableTravelRequestStateMachine.CurrentTravelRequest = travelRequest; return(_reusableTravelRequestStateMachine); }
public StateMachine <TravelRequestState, TravelRequestAction> CreateStateMachineFor(TravelRequest travelRequest) { var stateMachine = new StateMachine <TravelRequestState, TravelRequestAction>(() => travelRequest.Status, ((ISupportWorkflowState <TravelRequestState>)travelRequest).SetStatus); _travelRequestWorkflowConfigurator.Configure(stateMachine, travelRequest); return(stateMachine); }
private StateMachine <TravelRequestState, TravelRequestAction> WithStateMachineFor(TravelRequest travelRequest) { var stateMachine = new StateMachine <TravelRequestState, TravelRequestAction>(() => travelRequest.Status, ((ISupportWorkflowState <TravelRequestState>)travelRequest).SetStatus); stateMachine.Configure(TravelRequestState.New) .Permit(TravelRequestAction.Init, TravelRequestState.Captured); stateMachine.Configure(TravelRequestState.Captured) .PermitIf(TravelRequestAction.Submit, TravelRequestState.TravelerReview, () => travelRequest.IsEmployee) .PermitIf(TravelRequestAction.Submit, TravelRequestState.HRApproval, () => !travelRequest.IsEmployee); stateMachine.Configure(TravelRequestState.TravelerReview) .PermitIf(TravelRequestAction.Accept, TravelRequestState.ManagerApproval, () => travelRequest.Traveller == _userSecurityContext.CurrentUser, "Traveller") .OnEntry(() => _notifier.Notify("NotifyTravellerOfReview", travelRequest), "Notify Traveller") .OnEntry(() => _notifier.Notify("NotifyTravelAdminOfReview", travelRequest), "Notify Travel Admin"); stateMachine.Configure(TravelRequestState.HRApproval) .PermitIf(TravelRequestAction.Approve, TravelRequestState.ProcurementApproval, () => travelRequest.Approver == _userSecurityContext.CurrentUser, "Approver"); stateMachine.Configure(TravelRequestState.ManagerApproval) .PermitIf(TravelRequestAction.Approve, TravelRequestState.ProcurementApproval, () => travelRequest.Approver == _userSecurityContext.CurrentUser, "Approver"); stateMachine.Configure(TravelRequestState.ProcurementApproval) .PermitIf(TravelRequestAction.Approve, TravelRequestState.HODApproval, () => travelRequest.Approver == _userSecurityContext.CurrentUser, "Approver"); stateMachine.Configure(TravelRequestState.HODApproval) .PermitIf(TravelRequestAction.Approve, TravelRequestState.BookTickets, () => travelRequest.Approver == _userSecurityContext.CurrentUser, "Approver") .OnEntryFrom(TravelRequestAction.Approve, transition => { if (travelRequest.IsEmployee) { stateMachine.Fire(TravelRequestAction.Approve); } }); stateMachine.Configure(TravelRequestState.BookTickets) .Permit(TravelRequestAction.Finish, TravelRequestState.BookingComplete); return(stateMachine); }
public void Configure(StateMachine <TravelRequestState, TravelRequestAction> stateMachine, TravelRequest travelRequest) { stateMachine.Configure(TravelRequestState.New) .Permit(TravelRequestAction.Init, TravelRequestState.Captured); stateMachine.Configure(TravelRequestState.Captured) .PermitIf(TravelRequestAction.Submit, TravelRequestState.TravelerReview, () => travelRequest.IsEmployee) .PermitIf(TravelRequestAction.Submit, TravelRequestState.HRApproval, () => !travelRequest.IsEmployee); stateMachine.Configure(TravelRequestState.TravelerReview) .PermitIf(TravelRequestAction.Accept, TravelRequestState.ManagerApproval, () => travelRequest.Traveller == _userSecurityContext.CurrentUser) .OnEntry(() => _notifier.Notify("NotifyTravellerOfReview", travelRequest), "Notify Traveller") .OnEntry(() => _notifier.Notify("NotifyTravelAdminOfReview", travelRequest), "Notify Travel Admin"); stateMachine.Configure(TravelRequestState.HRApproval) .PermitIf(TravelRequestAction.Approve, TravelRequestState.ProcurementApproval, () => travelRequest.Approver == _userSecurityContext.CurrentUser); stateMachine.Configure(TravelRequestState.ManagerApproval) .PermitIf(TravelRequestAction.Approve, TravelRequestState.ProcurementApproval, () => travelRequest.Approver == _userSecurityContext.CurrentUser); stateMachine.Configure(TravelRequestState.ProcurementApproval) .PermitIf(TravelRequestAction.Approve, TravelRequestState.HODApproval, () => travelRequest.Approver == _userSecurityContext.CurrentUser); stateMachine.Configure(TravelRequestState.HODApproval) .PermitIf(TravelRequestAction.Approve, TravelRequestState.BookTickets, () => travelRequest.Approver == _userSecurityContext.CurrentUser) .OnEntryFrom(TravelRequestAction.Approve, transition => { if (travelRequest.IsEmployee) { stateMachine.Fire(TravelRequestAction.Approve); } }); stateMachine.Configure(TravelRequestState.BookTickets) .Permit(TravelRequestAction.Finish, TravelRequestState.BookingComplete); }
private StateMachine <TravelRequestState, TravelRequestAction> WithStateMachineFor(TravelRequest travelRequest) { return(_stateMachineFactory.CreateStateMachineFor(travelRequest)); }