Пример #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 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);
        }