Example #1
0
        public Execution <TContext> Run(TContext context)
        {
            var execution = new Execution <TContext> {
                State = WorkflowState.InProgress
            };
            var executor = new WorkflowExecutor <TContext>(execution, context, this, m_ActivityFactory, m_ActivityExecutor);

            accept(executor);
            m_Persister.Save(context, execution);
            return(execution);
        }
Example #2
0
        public virtual Execution <TContext> Run(TContext context)
        {
            var execution = new Execution <TContext> {
                State = WorkflowState.InProgress
            };
            var executor = new WorkflowExecutor <TContext>(
                execution,
                context,
                this,
                m_ActivityFactory,
                m_ExecutionObserver);

            try
            {
                Accept(executor);
            }
            catch (Exception e)
            {
                execution.Error = e.ToString();
                execution.State = WorkflowState.Corrupted;
            }
            m_Persister.Save(context, execution);
            return(execution);
        }
        /// <summary>
        /// Persists the specified work flow.
        /// </summary>
        /// <param name="workFlow">The work flow.</param>
        public void Save(IStateMachineContext workFlow)
        {
            if (workFlow == null)
            {
                throw new ArgumentNullException("workFlow");
            }

            bool isPersisted = workFlow.Id != Guid.Empty;

            if (isPersisted == false)
            {
                workFlow.Id = GuidCombGenerator.Generate();
            }

            string domainContextType = null;
            object domainContextId   = null;
            object domainContext     = GetDomainContext(workFlow);

            string domainContextStatusProperty = string.Empty;

            if (workFlow.DomainContext is ReflectiveDomainContextWrapper)
            {
                domainContextStatusProperty = ((ReflectiveDomainContextWrapper)workFlow.DomainContext).StateProperty.Name;
            }

            if (domainContext != null && _domainContextRepository != null)
            {
                _domainContextRepository.Save(domainContext);

                domainContextType = _domainContextRepository.GetTypeDescription(domainContext);
                domainContextId   = _domainContextRepository.GetId(domainContext);
            }

            IStateMachineState currentState = workFlow.CurrentState;

            IWorkflowEntity workflowEntity = isPersisted
                                                                ? _workflowPersister.Load(workFlow.Id)
                                                                : _workflowPersister.CreateEmptyWorkflowEntity(workFlow.Id);

            if (workflowEntity == null)
            {
                throw new Exception("The workflow persister returned a null object from the CreateEmptyWorkflowEntity call.");
            }

            workflowEntity.WorkflowId                   = workFlow.Id;
            workflowEntity.CurrentState                 = currentState != null ? currentState.StateName : string.Empty;
            workflowEntity.MachineConfiguration         = Convert.ToString(workFlow.StateMachine.Tag);
            workflowEntity.DomainContextTypeDescription = domainContextType;
            workflowEntity.DomainContextId              = domainContextId;
            workflowEntity.DomainContextStatusProperty  = domainContextStatusProperty;

            if (isPersisted && workFlow.IsComplete)
            {
                _workflowPersister.Complete(workflowEntity);
            }
            else if (isPersisted)
            {
                _workflowPersister.Update(workflowEntity);
            }
            else
            {
                _workflowPersister.Save(workflowEntity);
            }
        }