protected void AddStep(IProcessStep step)
        {
            step.Complete += StepComplete;

            _steps.AddLast(step);
            CurrentStep = step;
        }
Exemple #2
0
        public void AddStep(IProcessStep processStep)
        {
            if (processStep == null)
            {
                throw new ArgumentNullException(nameof(processStep));
            }

            steps.Add(processStep);
        }
 public void SetNext(IProcessStep <T> step)
 {
     if (this.Next == null)
     {
         this.next = step;
     }
     else
     {
         this.Next.SetNext(step);
     }
 }
Exemple #4
0
        public void Step()
        {
            if (!OnLastStep())
            {
                var index = steps.FindIndex((test) => current == test);
                current = steps[index + 1];
                return;
            }

            if (RotateToStartWhenDone)
            {
                current = steps.First();
                return;
            }

            current = null;
        }
Exemple #5
0
 public void Start()
 {
     current = steps.First();
     Run();
 }
Exemple #6
0
 public void Cancel()
 {
     steps.ForEach(step => step?.Cancel());
     current = null;
 }
        public void ArchiveHistoryForStep(IProcessExecutionContext executionContext, IWorkSession session, IProcessStep processStep, bool isRolledBack = false)
        {
            var historyRecord = GetHistoryForStep(processStep) as StepHistory;
            var statusCode    = isRolledBack ? eProcessStepHistoryStatusEnum.RolledBack : eProcessStepHistoryStatusEnum.Archived;

            historyRecord.StepStatus = statusCode;
            DataConnector.UpdateStepHistoryStatus(executionContext.DataService, historyRecord, statusCode);
        }
        public void AddToHistory(IProcessExecutionContext executionContext, IWorkSession session, IProcessStep processStep, bool isExecuted)
        {
            if (executionContext is null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (session is null)
            {
                throw new ArgumentNullException("workSession");
            }
            if (processStep is null)
            {
                throw new ArgumentNullException("processStep");
            }

            var lastHistory        = this.Records.LastOrDefault();
            var lastCurrentHistory = this.Records.Where(r => r.StepStatus == eProcessStepHistoryStatusEnum.Current).LastOrDefault();

            //create a new history record for the passed in process step and
            //link it back to last current history step in the list.
            var newHistory = DataConnector.CreateStepHistoryRecord(
                executionContext.DataService,
                this.Transaction,
                processStep,
                lastCurrentHistory);

            this.Records.Add(new StepHistory(newHistory));

            // Update the starting history in the database.
            if (lastHistory != null)
            {
                //Update local copy.
                lastHistory.NextStepId    = newHistory;
                lastHistory.CompletedById = isExecuted ? session.Agent : null;
                lastHistory.CompletedAtId = isExecuted ? session.Location : null;

                //update database.
                DataConnector.UpdateStepHistoryRecord(
                    executionContext.DataService,
                    lastHistory,
                    newHistory,
                    isExecuted ? session.Agent : null,
                    isExecuted ? session.Location : null,
                    isExecuted ? (DateTime?)DateTime.Now : null);
            }
        }
 public IStepHistory GetHistoryForStep(IProcessStep processStep)
 {
     return(this.Records.Where(r =>
                               r.StepStatus == eProcessStepHistoryStatusEnum.Current &&
                               r.ProcessStepId.Id == processStep.Id).FirstOrDefault() ?? throw new Exception("Unable to find current history for specified step."));
 }
 public void ContinueTo(IProcessStep nextStep)
 {
     RemoveAllStepsAfterCurrent();
     AddStep(nextStep);
 }
 public void Reset()
 {
     CurrentStep = null;
     _steps.Clear();
     CreateFirstStep();
 }
Exemple #12
0
        public IProcessStep NavigateForward(IWorkSession session)
        {
            try
            {
                if (!this.CanNavigateForward(session))
                {
                    throw TransactionException.BuildException(TransactionException.ErrorCode.ActionNotAvailable);
                }

                // If the navigation gets blocked by a validation issue then the navigation process must fall back to the step
                // it started on.
                var fallbackStepId = this.CurrentStepId;

                IProcessStep startingStep = this.CurrentStep;
                IProcessStep nextStep     = null;
                bool         isBlocked    = false;

                while (true)
                {
                    // Get the step history record for the starting step. This record should always exist.
                    IStepHistory stepHistory = this.TransactionHistory.GetHistoryForStep(startingStep);
                    if (stepHistory is null)
                    {
                        throw TransactionException.BuildException(TransactionException.ErrorCode.StepHistoryNotFound);
                    }

                    bool hasExecuted = stepHistory.CompletedOn.HasValue;

                    if (!hasExecuted)
                    {
                        ExecutionContext.Trace("Getting next step by executing current step.");

                        // When the step has not been executed we need to execute it to find out what the next step in the
                        // processes is because steps with conditional branching do not know the next step until execution.
                        //
                        // Additionally, any validation requirements associated with the step will be evaluated and this could
                        // result in blocking forward navigation. In this case we still update the step history to show that the
                        // step was executed.
                        var executionResult = startingStep.Execute(ExecutionContext, session, this, RequirementEvaluator);
                        nextStep  = executionResult.NextStep;
                        isBlocked = executionResult.StepIsBlocked; //validation requirements may block further advancement.

                        this.TransactionHistory.AddToHistory(this.ExecutionContext, session, nextStep, true);
                    }
                    else
                    {
                        ExecutionContext.Trace("Getting next step from step history");

                        if (stepHistory.NextStepId is null)
                        {
                            throw TransactionException.BuildException(TransactionException.ErrorCode.StepHistoryInvalid);
                        }

                        var nextStepId = this.TransactionHistory.GetHistoryById(stepHistory.NextStepId).ProcessStepId;

                        // When the step has executed then we just get the next step based on history.
                        nextStep = this.CurrentProcess.ProcessSteps.Where(r => Id == nextStepId.Id).FirstOrDefault();
                    }

                    // Stop moving forward when a UI step is found or when the step represents the last step in the process or
                    // when additional execution is blocked.
                    if (isBlocked || nextStep is null || nextStep.IsLastStep() || nextStep.Type.IsUIStep)
                    {
                        break;
                    }

                    // advance to the next process step and run through the loop again
                    startingStep = nextStep;
                }

                // When any execution in this step is blocked because of validation then the process falls back to
                // the step that was current before we started. However any items that were completed in the above loop
                if (isBlocked)
                {
                    this.CurrentStepId = fallbackStepId;
                    return(this.CurrentStep);
                }

                // save the current step to the data base.
                this.CurrentStepId = nextStep;
                this.TransactionService.SaveTransactionCurrentStep(this.ExecutionContext, this, this.CurrentStepId);

                return(this.CurrentStep);
            }
            catch (Exception ex)
            {
                throw TransactionException.BuildException(TransactionException.ErrorCode.ProcessNavigationError, ex);
            }
        }
 private ActionResult RedirectTo(IProcessStep step)
 {
     return new RedirectToRouteResult(step.RouteValues);
 }
 internal GoToNextStepCommand(IProcessStep nextStep)
 {
     _nextStep = nextStep;
 }