Ejemplo n.º 1
0
        /// <summary>
        /// 流程返签,先检查约束条件,然后调用wfruntimeinstance执行
        /// </summary>
        /// <param name="appName"></param>
        /// <param name="appInstanceID"></param>
        /// <param name="processGUID"></param>
        /// <param name="userID"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static WfRuntimeManager CreateRuntimeInstanceReverse(WfAppRunner runner,
                                                                    ref WfExecutedResult result)
        {
            var rmins = new WfRuntimeManagerReverse();

            rmins.WfExecutedResult = result = new WfExecutedResult();
            var pim             = new ProcessInstanceManager();
            var processInstance = pim.GetProcessInstanceLatest(runner.AppName, runner.AppInstanceID, runner.ProcessGUID);

            if (processInstance == null || processInstance.ProcessState != (short)ProcessStateEnum.Completed)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Reverse_NotInCompleted;
                result.Message       = string.Format("当前应用:{0},实例ID:{1}, 没有完成的流程实例,无法让流程重新运行!",
                                                     runner.AppName, runner.AppInstanceID);
                return(rmins);
            }

            var tim = new TransitionInstanceManager();
            var endTransitionInstance = tim.GetEndTransition(runner.AppName, runner.AppInstanceID, runner.ProcessGUID);

            var processModel = new ProcessModel(runner.ProcessGUID);
            var endActivity  = processModel.GetActivity(endTransitionInstance.ToActivityGUID);

            var aim = new ActivityInstanceManager();
            var endActivityInstance = aim.GetById(endTransitionInstance.ToActivityInstanceID);

            bool hasGatewayNode           = false;
            var  lastTaskActivityInstance = tim.GetPreviousActivityInstance(endActivityInstance, false,
                                                                            out hasGatewayNode).ToList()[0];
            var lastTaskActivity = processModel.GetActivity(lastTaskActivityInstance.ActivityGUID);

            //封装返签结束点之前办理节点的任务接收人
            rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(lastTaskActivityInstance.ActivityGUID,
                                                                                                   lastTaskActivityInstance.EndedByUserID,
                                                                                                   lastTaskActivityInstance.EndedByUserName);

            rmins.ActivityResource        = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers);
            rmins.AppRunner.AppName       = runner.AppName;
            rmins.AppRunner.AppInstanceID = runner.AppInstanceID;
            rmins.AppRunner.ProcessGUID   = runner.ProcessGUID;
            rmins.AppRunner.UserID        = runner.UserID;
            rmins.AppRunner.UserName      = runner.UserName;

            rmins.BackwardContext.ProcessInstance                = processInstance;
            rmins.BackwardContext.BackwardToTaskActivity         = lastTaskActivity;
            rmins.BackwardContext.BackwardToTaskActivityInstance = lastTaskActivityInstance;
            rmins.BackwardContext.BackwardToTargetTransitionGUID =
                hasGatewayNode == false ? endTransitionInstance.TransitionGUID : String.Empty;
            rmins.BackwardContext.BackwardFromActivity         = endActivity;
            rmins.BackwardContext.BackwardFromActivityInstance = endActivityInstance;
            rmins.BackwardContext.BackwardTaskReciever         = WfBackwardTaskReciever.Instance(lastTaskActivityInstance.ActivityName,
                                                                                                 lastTaskActivityInstance.EndedByUserID,
                                                                                                 lastTaskActivityInstance.EndedByUserName);

            return(rmins);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 流程返签,先检查约束条件,然后调用wfruntimeinstance执行
        /// </summary>
        /// <param name="appName"></param>
        /// <param name="appInstanceID"></param>
        /// <param name="processGUID"></param>
        /// <param name="userID"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public WfRuntimeManager GetRuntimeInstanceReverse(string appName,
                                                          int appInstanceID,
                                                          Guid processGUID,
                                                          int userID,
                                                          string userName)
        {
            var pim             = new ProcessInstanceManager();
            var processInstance = pim.GetCompletedProcess(appName, appInstanceID, processGUID);

            if (processInstance == null)
            {
                throw new WfRuntimeException(string.Format("当前应用:{0},实例ID:{0}, 没有办结的流程实例,无法让流程重新运行!",
                                                           appName, appInstanceID));
            }

            var processModel            = new ProcessModel(processGUID);
            var endTransitionInstance   = (new TransitionInstanceManager()).GetEndTransition(appName, appInstanceID, processGUID);
            var lastTaskActivity        = processModel.GetActivity(endTransitionInstance.FromActivityGUID);
            var lastTaskActivityInstace = (new ActivityInstanceManager()).GetById(endTransitionInstance.FromActivityInstanceGUID);
            var lastToEndTransition     = processModel.GetForwardTransition(lastTaskActivity.ActivityGUID);

            if (!lastTaskActivityInstace.EndedByUserID.HasValue)
            {
                throw new WfRuntimeException("流程最后一步的办理人员为空,不正常的流程数据,无法使结束的流程回退!");
            }

            var endActivity         = processModel.GetActivity(endTransitionInstance.ToActivityGUID);
            var endActivityInstance = (new ActivityInstanceManager()).GetById(endTransitionInstance.ToActivityInstanceGUID);

            this.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(endTransitionInstance.FromActivityGUID,
                                                                                                  lastTaskActivityInstace.EndedByUserID.Value,
                                                                                                  lastTaskActivityInstace.EndedByUserName);

            this.ActivityResource        = new ActivityResource(userID, userName, this.AppRunner.NextActivityPerformers);
            this.AppRunner.AppName       = appName;
            this.AppRunner.AppInstanceID = appInstanceID;
            this.AppRunner.ProcessGUID   = processGUID;
            this.AppRunner.UserID        = userID;
            this.AppRunner.UserName      = userName;

            this.BackwardContext.ProcessInstance                = processInstance;
            this.BackwardContext.BackwardToTaskActivity         = lastTaskActivity;
            this.BackwardContext.BackwardToTaskActivityInstance = lastTaskActivityInstace;
            this.BackwardContext.BackwardToTargetTransition     = lastToEndTransition;
            this.BackwardContext.FromActivity         = endActivity;
            this.BackwardContext.FromActivityInstance = endActivityInstance;
            return(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 任务执行的上下文对象
        /// </summary>
        /// <param name="task"></param>
        /// <param name="processModel"></param>
        /// <param name="activityResource"></param>
        private ActivityForwardContext(TaskViewEntity task,
                                       ProcessModel processModel,
                                       ActivityResource activityResource)
        {
            this.TaskView = task;

            //check task condition has load activity instance
            this.FromActivityInstance = (new ActivityInstanceManager()).GetById(task.ActivityInstanceID);
            this.ProcessInstance      = (new ProcessInstanceManager()).GetById(task.ProcessInstanceID);
            this.Activity             = processModel.GetActivity(task.ActivityGUID);
            this.ProcessModel         = processModel;
            this.ActivityResource     = activityResource;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 获取活动的定义数据
 /// </summary>
 /// <param name="processGUID"></param>
 /// <param name="activityGuid"></param>
 /// <returns></returns>
 public static ActivityEntity GetActivity(Guid processGUID,
                                          Guid activityGuid)
 {
     try
     {
         var processModel = new ProcessModel(processGUID);
         return(processModel.GetActivity(activityGuid));
     }
     catch (System.Exception)
     {
         //throw new WfDataException(string.Format("获取流程节点信息失败,详细信息:{0}", ex.Message), ex);
         throw;
     }
 }
Ejemplo n.º 5
0
        public static NextActivityMatchedResult GetNextActivityList(Guid processGUID,
                                                                    Guid processInstanceGUID,
                                                                    Guid activityGUID,
                                                                    ConditionKeyValuePair conditionKeyValuePair)
        {
            try
            {
                //var pm = new ProcessManager();
                //var
                var processModel = new ProcessModel(processGUID);
                var activity     = processModel.GetActivity(activityGUID);

                return(processModel.GetNextActivityList(processInstanceGUID, activity, conditionKeyValuePair));
            }
            catch (System.Exception)
            {
                //throw new WfDataException(string.Format("获取当前节点的下一节点信息失败,详细信息:{0}", ex.Message), ex);
                throw;
            }
        }
Ejemplo n.º 6
0
        public static NextActivityMatchedResult GetNextActivityList(Guid processGUID,
                                                                    Guid processInstanceGUID,
                                                                    Guid activityGUID,
                                                                    ConditionKeyValuePair conditionKeyValuePair,
                                                                    ActivityResource activityResource,
                                                                    Expression <Func <ActivityResource, ActivityEntity, bool> > expression)
        {
            try
            {
                var processModel = new ProcessModel(processGUID);
                var activity     = processModel.GetActivity(activityGUID);

                return(processModel.GetNextActivityList(processInstanceGUID, activity, conditionKeyValuePair, activityResource, expression));
            }
            catch (System.Exception)
            {
                //throw new WfDataException(string.Format("获取当前节点的下一节点信息失败,详细信息:{0}", ex.Message), ex);
                throw;
            }
        }
        /// <summary>
        /// 退回操作的处理逻辑
        /// </summary>
        /// <param name="session">会话</param>
        internal override void ExecuteInstanceImp(IDbSession session)
        {
            try
            {
                var runningExecutionContext = ActivityForwardContext.CreateRunningContext(base.TaskView,
                                                                                          base.ProcessModel,
                                                                                          base.ActivityResource,
                                                                                          true,
                                                                                          session);

                //执行节点
                NodeMediator mediator = NodeMediatorFactory.CreateNodeMediator(runningExecutionContext, session);
                mediator.Linker.FromActivityInstance = RunningActivityInstance;
                var toActivityGUID = runningExecutionContext.ActivityResource.NextActivityPerformers.First().Key;
                mediator.Linker.ToActivity = ProcessModel.GetActivity(toActivityGUID);
                mediator.ExecuteWorkItem();

                //构造回调函数需要的数据
                var result = base.WfExecutedResult;
                result.Status  = WfExecutedStatus.Success;
                result.Message = mediator.GetNodeMediatedMessage();
            }
            catch (WfRuntimeException rx)
            {
                var result = base.WfExecutedResult;
                result.Status        = WfExecutedStatus.Failed;
                result.ExceptionType = WfExceptionType.RunApp_RuntimeError;
                result.Message       = rx.Message;
                throw rx;
            }
            catch (System.Exception ex)
            {
                var result = base.WfExecutedResult;
                result.Status        = WfExecutedStatus.Failed;
                result.ExceptionType = WfExceptionType.RunApp_RuntimeError;
                result.Message       = ex.Message;
                throw ex;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取当前活动实体
        /// </summary>
        /// <param name="processGUID"></param>
        /// <param name="activityGUID"></param>
        /// <returns></returns>
        public ActivityEntity GetActivityEntity(string processGUID, string version, string activityGUID)
        {
            var processModel = new ProcessModel(processGUID, version);

            return(processModel.GetActivity(activityGUID));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 创建活动任务转移实例数据
        /// </summary>
        /// <param name="toActivity">活动</param>
        /// <param name="processInstance">流程实例</param>
        /// <param name="fromActivityInstance">开始活动实例</param>
        /// <param name="transitionGUID">转移GUID</param>
        /// <param name="transitionType">转移类型</param>
        /// <param name="flyingType">跳跃类型</param>
        /// <param name="activityResource">活动资源</param>
        /// <param name="session">会话</param>
        internal override void CreateActivityTaskTransitionInstance(ActivityEntity toActivity,
                                                                    ProcessInstanceEntity processInstance,
                                                                    ActivityInstanceEntity fromActivityInstance,
                                                                    string transitionGUID,
                                                                    TransitionTypeEnum transitionType,
                                                                    TransitionFlyingTypeEnum flyingType,
                                                                    ActivityResource activityResource,
                                                                    IDbSession session)
        {
            Boolean isParallel = false;

            if (fromActivityInstance.ActivityType == (short)ActivityTypeEnum.GatewayNode)
            {
                //并发多实例分支判断(AndSplit Multiple)
                var processModel = new ProcessModel(processInstance.ProcessGUID, processInstance.Version);
                var activityNode = processModel.GetActivity(fromActivityInstance.ActivityGUID);
                if (activityNode.GatewaySplitJoinType == GatewaySplitJoinTypeEnum.Split &&
                    activityNode.GatewayDirectionType == GatewayDirectionEnum.AndSplitMI)
                {
                    isParallel = true;
                }
            }


            if (isParallel)
            {
                //并行多实例
                var entity = new ActivityInstanceEntity();
                var plist  = activityResource.NextActivityPerformers[toActivity.ActivityGUID];
                for (var i = 0; i < plist.Count; i++)
                {
                    entity = base.CreateActivityInstanceObject(toActivity, processInstance, activityResource.AppRunner);
                    entity.AssignedToUserIDs   = plist[i].UserID;
                    entity.AssignedToUserNames = plist[i].UserName;
                    entity.ActivityState       = (short)ActivityStateEnum.Ready;
                    //插入活动实例数据
                    entity.ID = base.ActivityInstanceManager.Insert(entity, session);
                    //插入任务
                    base.TaskManager.Insert(entity, plist[i], activityResource.AppRunner, session);
                    //插入转移数据
                    InsertTransitionInstance(processInstance,
                                             transitionGUID,
                                             fromActivityInstance,
                                             entity,
                                             transitionType,
                                             flyingType,
                                             activityResource.AppRunner,
                                             session);
                }
            }
            else
            {
                //普通任务节点
                var toActivityInstance = base.CreateActivityInstanceObject(toActivity, processInstance, activityResource.AppRunner);

                //进入运行状态
                toActivityInstance.ActivityState     = (short)ActivityStateEnum.Ready;
                toActivityInstance.AssignedToUserIDs = GenerateActivityAssignedUserIDs(
                    activityResource.NextActivityPerformers[toActivity.ActivityGUID]);
                toActivityInstance.AssignedToUserNames = GenerateActivityAssignedUserNames(
                    activityResource.NextActivityPerformers[toActivity.ActivityGUID]);

                //插入活动实例数据
                base.ActivityInstanceManager.Insert(toActivityInstance, session);

                //插入任务数据
                base.CreateNewTask(toActivityInstance, activityResource, session);

                //插入转移数据
                InsertTransitionInstance(processInstance,
                                         transitionGUID,
                                         fromActivityInstance,
                                         toActivityInstance,
                                         transitionType,
                                         flyingType,
                                         activityResource.AppRunner,
                                         session);
            }
        }