Esempio n. 1
0
        public void run()
        {
            if (this.State != ProcessInstanceEnum.INITIALIZED)
            {
                throw new EngineException(this.Id,
                        this.WorkflowProcess,
                        this.ProcessId, "The state of the process instance is " + this.State + ",can not run it ");
            }

            INetInstance netInstance = (INetInstance)this.RuntimeContext.KernelManager.getNetInstance(this.ProcessId, this.Version);
            if (netInstance == null)
            {
                throw new EngineException(this.Id,
                        this.WorkflowProcess,
                        this.ProcessId, "The net instance for the  workflow process [Id=" + this.ProcessId + "] is Not found");
            }
            //触发事件
            ProcessInstanceEvent pevent = new ProcessInstanceEvent();
            pevent.EventType = ProcessInstanceEventEnum.BEFORE_PROCESS_INSTANCE_RUN;
            pevent.Source=this;
            this.fireProcessInstanceEvent(pevent);

            this.State=ProcessInstanceEnum.RUNNING;
            this.StartedTime=this.RuntimeContext.CalendarService.getSysDate();
            this.RuntimeContext.PersistenceService.SaveOrUpdateProcessInstance(this);
            netInstance.run(this);
        }
Esempio n. 2
0
        /// <summary>触发process instance相关的事件</summary>
        /// <param name="e"></param>
        protected void fireProcessInstanceEvent(ProcessInstanceEvent e)
        {
            WorkflowProcess workflowProcess = this.WorkflowProcess;
            if (workflowProcess == null)
            {
                return;
            }

            List<EventListener> listeners = workflowProcess.EventListeners;
            for (int i = 0; i < listeners.Count; i++)
            {
                EventListener listener = (EventListener)listeners[i];
                Object obj = this.RuntimeContext.getBeanByName(listener.ClassName);
                if (obj != null)
                {
                    ((IProcessInstanceEventListener)obj).onProcessInstanceEventFired(e);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// <para>正常结束工作流</para>
        /// <para>1、首先检查有无活动的token,如果有则直接返回,如果没有则结束当前流程</para>
        /// <para>2、执行结束流程的操作,将state的值设置为结束状态</para>
        /// 3、然后检查parentTaskInstanceId是否为null,如果不为null则,调用父taskinstance的complete操作。
        /// </summary>
        public void complete()
        {
            List<IToken> tokens = this.RuntimeContext.PersistenceService.FindTokensForProcessInstance(this.Id, null);
            Boolean canBeCompleted = true;
            for (int i = 0; tokens != null && i < tokens.Count; i++)
            {
                IToken token = tokens[i];
                if (token.IsAlive)
                {
                    canBeCompleted = false;
                    break;
                }
            }
            if (!canBeCompleted)
            {
                return;
            }

            this.State=ProcessInstanceEnum.COMPLETED;
            //记录结束时间
            this.EndTime=this.RuntimeContext.CalendarService.getSysDate();
            this.RuntimeContext.PersistenceService.SaveOrUpdateProcessInstance(this);

            //删除所有的token
            for (int i = 0; tokens != null && i < tokens.Count; i++)
            {
                IToken token = tokens[i];
                this.RuntimeContext.PersistenceService.DeleteToken(token);
            }

            //触发事件
            ProcessInstanceEvent pevent = new ProcessInstanceEvent();
            pevent.EventType=ProcessInstanceEventEnum.AFTER_PROCESS_INSTANCE_COMPLETE;
            pevent.Source=this;
            this.fireProcessInstanceEvent(pevent);
            if ( !String.IsNullOrEmpty(this.ParentTaskInstanceId.Trim()))
            {
                ITaskInstance taskInstance = this.RuntimeContext.PersistenceService.FindAliveTaskInstanceById(this.ParentTaskInstanceId);
                ((IRuntimeContextAware)taskInstance).RuntimeContext=this.RuntimeContext;
                ((IWorkflowSessionAware)taskInstance).CurrentWorkflowSession = this.CurrentWorkflowSession;
                ((TaskInstance)taskInstance).complete(null);
            }
        }