Esempio n. 1
0
        /// <summary>
        /// Gets the current <see cref="WorkflowExecutionFrame"/> for the specified
        /// <see cref="IWorkflowSubject"/>.
        /// </summary>
        /// <param name="workflowSubject">
        /// Workflow subject to get execution frame for.
        /// </param>
        /// <param name="serviceProvider">
        /// Interface to service provider.
        /// </param>
        /// <returns>
        /// A <see cref="WorkflowExecutionFrame"/> object containing the current workflow execution
        /// state information for the specified <see cref="IWorkflowSubject"/>.
        /// objects.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown when workflowSubject is null.
        /// </exception>
        /// <exception cref="StateNotFoundException">
        /// Thrown when the current state of the workflow subject cannot be
        /// found in the workflow.
        /// </exception>
        public WorkflowExecutionFrame GetExecutionFrame(IWorkflowSubject workflowSubject, IServiceProvider serviceProvider)
        {
            ///////////////////////////////////////////////////////////////////
            // Check arguments
            if (workflowSubject == null)
            {
                throw new ArgumentNullException("workflowSubject");
            }

            ///////////////////////////////////////////////////////////////////
            // Get the CURRENT state
            var currentStateName = workflowSubject.CurrentState;

            if (string.IsNullOrEmpty(currentStateName))
            {
                throw new StateNotFoundException(this, currentStateName);
            }

            var currentState = this.FindStateByName(currentStateName);

            if (currentState == null)
            {
                throw new StateNotFoundException(this, currentStateName);
            }

            var nextTransitions = currentState.Transitions.Select(t => new WorkflowTransitionDescriptor()
            {
                TransitionName = t.Name,
                IsAllowed      = t.IsAllowed(serviceProvider, workflowSubject.GetContextObject(serviceProvider))
            });

            return(WorkflowExecutionFrame.Create(workflowSubject, nextTransitions.ToList()));
        }
Esempio n. 2
0
        internal static WorkflowExecutionFrame Create(IWorkflowSubject subject,
                                                      IEnumerable <WorkflowTransitionDescriptor> nextTransitions)
        {
            var workflowExecutionFrame = new WorkflowExecutionFrame()
            {
                Subject         = subject,
                NextTransitions = nextTransitions
            };

            return(workflowExecutionFrame);
        }