Пример #1
0
        bool IProcessService.CanRollback(Process process, User previousActioner, out ActivityInstanceBase previous, out string reason)
        {
            //TODO:是否要为rollback引入代理逻辑?
            reason   = string.Empty;
            previous = null;
            if (!this.IsStatusOrSchedulingSafe(process, ProcessStatus.Active))
            {
                if (this._log.IsDebugEnabled)
                {
                    this._log.DebugFormat("不允许回滚:{0}", reason = "只有处于活动状态的流程才允许回滚");
                }
                return(false);
            }

            previous = (this as IProcessService).GetPreviousActivityInstance(process);

            #region 常规判断
            if (previous == null)
            {
                if (this._log.IsDebugEnabled)
                {
                    this._log.DebugFormat("不允许回滚:{0}", reason = "没有找到上一个节点信息");
                }
                return(false);
            }
            if (!(previous is HumanActivityInstance))
            {
                if (this._log.IsDebugEnabled)
                {
                    this._log.DebugFormat("不允许回滚:{0}", reason = "上一个节点不是人工节点");
                }
                return(false);
            }
            if (process.ProcessType.GetActivitySetting(previous.ActivityName).IsChildOfActivity)
            {
                if (this._log.IsDebugEnabled)
                {
                    this._log.DebugFormat("不允许回滚:{0}", reason = string.Format("上一节点“{0}”是其他节点的子节点,不支持回滚", previous.ActivityName));
                }
                return(false);
            }
            #endregion

            #region  一个节点是人工节点才允许回滚
            var human = previous as HumanActivityInstance;
            if (!human.IsReady(previousActioner))
            {
                if (this._log.IsDebugEnabled)
                {
                    this._log.DebugFormat("不允许回滚:{0}", reason = "传入的上一节点执行人并非实际执行人");
                }
                return(false);
            }
            if (human.Actioners.Length > 1)
            {
                if (this._log.IsDebugEnabled)
                {
                    this._log.DebugFormat("不允许回滚:{0}", reason = string.Format("上一节点“{0}”执行人大于一人,不允许回滚", previous.ActivityName));
                }
                return(false);
            }
            if (_workItemRepository.FindAllByProcess(process).FirstOrDefault(o => o.Status != WorkItemStatus.New) != null)
            {
                if (this._log.IsDebugEnabled)
                {
                    this._log.DebugFormat("不允许回滚:{0}", reason = string.Format("由于流程当前任务已开始被处理,无法回滚"));
                }
                return(false);
            }
            #endregion

            //TODO:目前未考虑子流程节点的情况

            return(true);
        }
Пример #2
0
 //只获取有效状态的任务
 IEnumerable <WorkItem> IWorkItemService.GetWorkItems(Process process)
 {
     return(_repository.FindAllByProcess(process));
 }