示例#1
0
 public void Finish(TravelRequest travelRequest)
 {
     WithStateMachineFor(travelRequest).Fire(TravelRequestAction.Finish);
 }
示例#2
0
 public void Approve(TravelRequest travelRequest)
 {
     WithStateMachineFor(travelRequest).Fire(TravelRequestAction.Approve);
 }
示例#3
0
 public IEnumerable <TravelRequestAction> GetAllowedActions(TravelRequest travelRequest)
 {
     return(WithStateMachineFor(travelRequest).PermittedTriggers);
 }
示例#4
0
 public void Submit(TravelRequest travelRequest)
 {
     WithStateMachineFor(travelRequest).Fire(TravelRequestAction.Submit);
 }
示例#5
0
 public void Accept(TravelRequest travelRequest)
 {
     WithStateMachineFor(travelRequest).Fire(TravelRequestAction.Accept);
 }
示例#6
0
 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);
        }
示例#9
0
        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));
 }