public IList <IWorkflowInstance> ListInstances()
        {
            var workflowInstances    = new List <IWorkflowInstance>();
            var allWorkflowInstances = TheWorkflowInstanceRepository.List();

            foreach (var instance in allWorkflowInstances)
            {
                if (instance.Started && !instance.Ended)
                {
                    try
                    {
                        var i = TheWorkflowInstanceRepository.RestoreState(instance);
                        workflowInstances.Add(i);
                    }
                    catch (System.Exception ex)
                    {
                        Log.Warn("Restoring instance", ex);
                    }
                }
                else
                {
                    workflowInstances.Add(instance);
                }
            }
            return(workflowInstances);
        }
Exemple #2
0
        private bool Run()
        {
            var workflowInstances = TheWorkflowInstanceRepository.List();
            var actions           = 0;

            foreach (var workflowInstance in workflowInstances)
            {
                var hydratedInstance = TheWorkflowInstanceRepository.RestoreState(workflowInstance);

                if (hydratedInstance.Ended)
                {
                    Log.Debug(string.Format("Ending workflow '{0}' and removing from runtime.", hydratedInstance.Id.ToString(CultureInfo.InvariantCulture)));
                    TheWorkflowInstanceRepository.Delete(hydratedInstance);
                }

                var task = hydratedInstance.CurrentTask;
                if (task == null)
                {
                    continue;
                }
                Log.Debug(string.Format("Checking task '{0}' for runnable", task.Name));

                if (task is IRunnableWorkflowTask)
                {
                    try
                    {
                        ((IRunnableWorkflowTask)task).Run(hydratedInstance, this);
                        actions++;
                    }
                    catch (System.Exception ex)
                    {
                        Log.Error("An error occured during a runnable task (workflow will terminate) - " + task.GetType().FullName, ex);
                        Log.Error(ex.StackTrace);

                        EndWorkflow(hydratedInstance);
                        TheWorkflowInstanceRepository.Update(hydratedInstance);

                        actions++;
                    }
                }
                else if (task is IDelayWorkflowTask)
                {
                    if (((IDelayWorkflowTask)task).IsComplete())
                    {
                        Log.Debug("Delay task completed");
                        Transition(hydratedInstance, task, task.AvailableTransitions[0]);
                        actions++;
                    }
                }
                else if (task is EndWorkflowTask || typeof(EndWorkflowTask) == task.GetType())
                {
                    Log.Debug(string.Format("Workflow {0} will end as it entered an end task", hydratedInstance.Id));
                    EndWorkflow(hydratedInstance);
                    TheWorkflowInstanceRepository.Update(hydratedInstance);
                    actions++;
                }
            }

            return(actions > 0);
        }
        public IList <IWorkflowInstance> ListInstances()
        {
            var workflowInstances    = new List <IWorkflowInstance>();
            var allWorkflowInstances = TheWorkflowInstanceRepository.List();

            foreach (var instance in allWorkflowInstances)
            {
                if (instance.Started && !instance.Ended)
                {
                    workflowInstances.Add(TheWorkflowInstanceRepository.RestoreState(instance));
                }
                else
                {
                    workflowInstances.Add(instance);
                }
            }
            return(workflowInstances);
        }