public void Archive_WorkflowIsMoved()
        {
            IWorkflowStore store = GetStore();
            BasicWorkflow  wf    = new BasicWorkflow(BasicWorkflow.State.Start);

            store.Save(wf);

            store.Archive(wf);
            Assert.IsNull(store.GetOrDefault(wf.Id));
            Assert.IsNotNull(store.GetCompletedOrDefault(wf.Id));
        }
        public void GetCompletedCount_OnExecute_ReturnsAccurateCount()
        {
            // Set up a store with some basic workflows
            IWorkflowStore store = GetStore();
            int            count = new Random().Next(2, 10);

            for (int i = 0; i < count; i++)
            {
                Workflow wf = new BasicWorkflow(BasicWorkflow.State.Start);
                store.Save(wf);
                store.Archive(wf);
            }

            long result = store.GetCompletedCount();

            Assert.AreEqual(count, result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Executes a workflow.
        /// </summary>
        /// <param name="workflow"></param>
        public void ExecuteWorkflow(Workflow workflow)
        {
            if (workflow == null)
            {
                throw new NullReferenceException("Workflow server asked to execute null workflow object");
            }

            // set the dependency resolver on the workflow to allow for dependency injection
            workflow.DependencyResolver = this.DependencyResolver;

            string initialState = workflow.CurrentState;

            try
            {
                workflow.LastException = null;
                workflow.RetryCount   += 1;
                workflow.Fire(workflow.ResumeTrigger);

                workflow.RetryCount = 0;    // success!  make sure the RetryCount is reset
            }
            catch (Exception ex)
            {
                workflow.CurrentState = initialState;
                _exceptionHandler.HandleWorkflowException(workflow, ex);

                // raise the exception handler
                workflow.OnError(ex);

                // if the workflow is suspended, raise the events
                if (workflow.IsSuspended)
                {
                    workflow.OnSuspend();
                    if (this.WorkflowSuspended != null)
                    {
                        this.WorkflowSuspended(this, new WorkflowEventArgs(workflow));
                    }
                }

                // exit out, nothing else to do here
                return;
            }
            finally
            {
                // the workflow should always save, no matter what happens
                _workflowStore.Save(workflow);
            }
            // if the workflow is complete, finish off
            if (workflow.IsComplete)
            {
                _workflowStore.Archive(workflow);
                workflow.OnComplete();
                if (this.WorkflowCompleted != null)
                {
                    this.WorkflowCompleted(this, new WorkflowEventArgs(workflow));
                }
                return;
            }

            // if the workflow is ready to resume immediately, just execute immediately instead of waiting for polling
            if (!workflow.IsSuspended && !String.IsNullOrWhiteSpace(workflow.ResumeTrigger) && workflow.ResumeOn <= DateTime.UtcNow)
            {
                this.ExecuteWorkflow(workflow);
            }
        }