/// <summary>
        /// 自动完成结束节点
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="fromActivityInstance"></param>
        /// <param name="activityResource"></param>
        /// <param name="wfLinqDataContext"></param>
        public GatewayExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
            string transitionGUID,
            ActivityInstanceEntity fromActivityInstance,
            ActivityResource activityResource,
            IDbSession session)
        {
            GatewayExecutedResult result = null;
            var toActivityInstance = base.CreateActivityInstanceObject(base.Linker.ToActivity,
                processInstance, activityResource.AppRunner);

            base.ActivityInstanceManager.Insert(toActivityInstance, session);

            base.ActivityInstanceManager.Complete(toActivityInstance.ID,
                activityResource.AppRunner,
                session);

            //写节点转移实例数据
            base.InsertTransitionInstance(processInstance,
                transitionGUID,
                fromActivityInstance,
                toActivityInstance,
                TransitionTypeEnum.Forward,
                TransitionFlyingTypeEnum.NotFlying,
                activityResource.AppRunner,
                session);

            //设置流程完成
            ProcessInstanceManager pim = new ProcessInstanceManager();
            pim.Complete(processInstance.ID, activityResource.AppRunner, session);

            //发送流程结束消息给流程启动人

            return result;
        }
コード例 #2
0
        internal TransitionInstanceEntity CreateTransitionInstanceObject(ProcessInstanceEntity processInstance,
            String transitionGUID,
            ActivityInstanceEntity fromActivityInstance,
            ActivityInstanceEntity toActivityInstance,
            TransitionTypeEnum transitionType,
            TransitionFlyingTypeEnum flyingType,
            WfAppRunner runner,
            byte conditionParseResult)
        {
            var entity = new TransitionInstanceEntity();
            entity.AppName = processInstance.AppName;
            entity.AppInstanceID = processInstance.AppInstanceID;
            entity.ProcessGUID = processInstance.ProcessGUID;
            entity.ProcessInstanceID = processInstance.ID;
            entity.TransitionGUID = transitionGUID;
            entity.TransitionType = (byte)transitionType;
            entity.FlyingType = (byte)flyingType;

            //构造活动节点数据
            entity.FromActivityGUID = fromActivityInstance.ActivityGUID;
            entity.FromActivityInstanceID = fromActivityInstance.ID;
            entity.FromActivityType = fromActivityInstance.ActivityType;
            entity.FromActivityName = fromActivityInstance.ActivityName;
            entity.ToActivityGUID = toActivityInstance.ActivityGUID;
            entity.ToActivityInstanceID = toActivityInstance.ID;
            entity.ToActivityType = toActivityInstance.ActivityType;
            entity.ToActivityName = toActivityInstance.ActivityName;

            entity.ConditionParseResult = conditionParseResult;
            entity.CreatedByUserID = runner.UserID;
            entity.CreatedByUserName = runner.UserName;
            entity.CreatedDateTime = System.DateTime.Now;

            return entity;
        }
        /// <summary>
        /// 创建多实例节点之间回滚时的活动实例,任务数据
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="originalBackwardToActivityInstance"></param>
        /// <param name="backwardType"></param>
        /// <param name="backSrcActivityInstanceID"></param>
        /// <param name="activityResource"></param>
        /// <param name="session"></param>
        internal void CreateBackwardActivityTaskOfInnerMultipleInstance(ProcessInstanceEntity processInstance,
            ActivityInstanceEntity originalBackwardToActivityInstance,
            BackwardTypeEnum backwardType,
            int backSrcActivityInstanceID,
            ActivityResource activityResource,
            IDbSession session)
        {
            //创建回滚到的节点信息
            var rollbackPreviousActivityInstance = base.CreateBackwardToActivityInstanceObject(processInstance,
                backwardType,
                backSrcActivityInstanceID,
                activityResource.AppRunner);

            rollbackPreviousActivityInstance.ActivityState = (short)ActivityStateEnum.Ready;
            rollbackPreviousActivityInstance.MIHostActivityInstanceID = originalBackwardToActivityInstance.MIHostActivityInstanceID;
            rollbackPreviousActivityInstance.CompleteOrder = originalBackwardToActivityInstance.CompleteOrder;
            rollbackPreviousActivityInstance.ComplexType = originalBackwardToActivityInstance.ComplexType;
            rollbackPreviousActivityInstance.SignForwardType = originalBackwardToActivityInstance.SignForwardType;
            rollbackPreviousActivityInstance.AssignedToUserIDs = originalBackwardToActivityInstance.AssignedToUserIDs;      //多实例节点为单一用户任务
            rollbackPreviousActivityInstance.AssignedToUserNames = originalBackwardToActivityInstance.AssignedToUserNames;

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

            //创建新任务数据
            base.CreateNewTask(rollbackPreviousActivityInstance, activityResource, session);
        }
コード例 #4
0
        public GatewayExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
            string transitionGUID,
            ActivityInstanceEntity fromActivityInstance,
            ActivityResource activityResource,
            IDbSession session)
        {
            var gatewayActivityInstance = base.CreateActivityInstanceObject(base.GatewayActivity, processInstance, activityResource.AppRunner);
            gatewayActivityInstance.GatewayDirectionTypeID = (short)GatewayDirectionEnum.OrSplit;

            base.InsertActivityInstance(gatewayActivityInstance,
                session);

            base.CompleteActivityInstance(gatewayActivityInstance.ID,
                activityResource,
                session);

            gatewayActivityInstance.ActivityState = (short)ActivityStateEnum.Completed;
            base.GatewayActivityInstance = gatewayActivityInstance;

            //写节点转移实例数据
            base.InsertTransitionInstance(processInstance,
                transitionGUID,
                fromActivityInstance,
                gatewayActivityInstance,
                TransitionTypeEnum.Forward,
                TransitionFlyingTypeEnum.NotFlying,
                activityResource.AppRunner,
                session);

            GatewayExecutedResult result = GatewayExecutedResult.CreateGatewayExecutedResult(GatewayExecutedStatus.Successed);
            return result;
        }
        public GatewayExecutedResult CompleteAutomaticlly(ProcessInstanceEntity processInstance,
            string transitionGUID,
            ActivityInstanceEntity fromActivityInstance,
            ActivityResource activityResource,
            IDbSession session)
        {
            //检查是否有运行中的合并节点实例
            ActivityInstanceEntity joinNode = base.ActivityInstanceManager.GetActivityRunning(
                processInstance.ID,
                base.GatewayActivity.ActivityGUID,
                session);

            if (joinNode == null)
            {
                var joinActivityInstance = base.CreateActivityInstanceObject(base.GatewayActivity,
                    processInstance, activityResource.AppRunner);

                //计算总需要的Token数目
                joinActivityInstance.TokensRequired = GetTokensRequired();
                joinActivityInstance.TokensHad = 1;

                //进入运行状态
                joinActivityInstance.ActivityState = (short)ActivityStateEnum.Running;
                joinActivityInstance.GatewayDirectionTypeID = (short)GatewayDirectionEnum.AndJoin;

                base.InsertActivityInstance(joinActivityInstance,
                    session);
            }
            else
            {
                //更新节点的活动实例属性
                base.GatewayActivityInstance = joinNode;
                int tokensRequired = base.GatewayActivityInstance.TokensRequired;
                int tokensHad = base.GatewayActivityInstance.TokensHad;

                //更新Token数目
                base.ActivityInstanceManager.IncreaseTokensHad(base.GatewayActivityInstance.ID,
                    activityResource.AppRunner,
                    session);

                if ((tokensHad + 1) == tokensRequired)
                {
                    //如果达到完成节点的Token数,则设置该节点状态为完成
                    base.CompleteActivityInstance(base.GatewayActivityInstance.ID,
                        activityResource,
                        session);
                    base.GatewayActivityInstance.ActivityState = (short)ActivityStateEnum.Completed;
                }
            }

            GatewayExecutedResult result = GatewayExecutedResult.CreateGatewayExecutedResult(
                GatewayExecutedStatus.Successed);
            return result;
        }
        /// <summary>
        /// 创建实例方法
        /// </summary>
        /// <param name="isMine"></param>
        /// <param name="previousActivityInstance"></param>
        /// <param name="nextActivityTree"></param>
        /// <returns></returns>
        public static CurrentRunningNodeMap Instance(ActivityInstanceEntity runningNode,
            bool isMine,
            ActivityInstanceEntity previousActivityInstance,
            IList<NodeView> nextActivityTree)
        {
            var nodeMap = new CurrentRunningNodeMap();
            nodeMap.RunningNode = runningNode;
            nodeMap.IsMine = isMine;
            nodeMap.PreviousActivityInstance = previousActivityInstance;
            nodeMap.NextActivityTree = nextActivityTree;

            return nodeMap;
        }
コード例 #7
0
        /// <summary>
        /// 创建退回时的流转节点对象、任务和转移数据
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="fromActivityInstance"></param>
        /// <param name="backMostPreviouslyActivityInstanceID"></param>
        /// <param name="transitionGUID"></param>
        /// <param name="transitionType"></param>
        /// <param name="flyingType"></param>
        /// <param name="activityResource"></param>
        /// <param name="session"></param>
        internal void CreateBackwardActivityTaskTransitionInstance(ProcessInstanceEntity processInstance,
            ActivityInstanceEntity fromActivityInstance,
            BackwardTypeEnum backwardType,
            int backMostPreviouslyActivityInstanceID,
            string transitionGUID,
            TransitionTypeEnum transitionType,
            TransitionFlyingTypeEnum flyingType,
            ActivityResource activityResource,
            IDbSession session)
        {
            //实例化Activity
            var toActivityInstance = base.CreateBackwardToActivityInstanceObject(processInstance,
                backwardType,
                backMostPreviouslyActivityInstanceID,
                activityResource.AppRunner);

            //进入运行状态
            toActivityInstance.ActivityState = (short)ActivityStateEnum.Ready;
            toActivityInstance.AssignedToUsers = base.GenerateActivityAssignedUsers(
                activityResource.NextActivityPerformers[base.BackwardContext.BackwardToTaskActivity.ActivityGUID]);

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

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

            //插入转移数据
            base.InsertTransitionInstance(processInstance,
                transitionGUID,
                fromActivityInstance,
                toActivityInstance,
                transitionType,
                flyingType,
                activityResource.AppRunner,
                session);
        }
コード例 #8
0
 /// <summary>
 /// 判断是否是某个用户的办理任务
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="userID"></param>
 /// <returns></returns>
 internal bool IsMineTask(ActivityInstanceEntity entity, 
     string userID)
 {
     bool isMine = entity.AssignedToUsers.Contains(userID.ToString());
     return isMine;
 }
コード例 #9
0
        internal int Insert(ActivityInstanceEntity entity,
            IDbSession session)
        {
            int newID = Repository.Insert(session.Connection, entity, session.Transaction);
            entity.ID = newID;

            return newID;
        }
コード例 #10
0
        internal override void CreateActivityTaskTransitionInstance(ActivityEntity toActivity,
           ProcessInstanceEntity processInstance,
           ActivityInstanceEntity fromActivityInstance,
           string transitionGUID,
           TransitionTypeEnum transitionType,
           TransitionFlyingTypeEnum flyingType,
           ActivityResource activityResource,
           IDbSession session)
        {
            if (toActivity.ActivityTypeDetail.ComplexType == ComplexTypeEnum.SignTogether)
            {
                CreateMultipleInstance(toActivity, processInstance, fromActivityInstance,
                    transitionGUID, transitionType, flyingType, activityResource, session);
            }
            else
            {
                //实例化Activity
                var toActivityInstance = 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);

                //启动子流程
                WfExecutedResult startedResult = null;
                var subProcessNode = (SubProcessNode)toActivity.Node;
                subProcessNode.ActivityInstance = toActivityInstance;
                WfAppRunner subRunner = CopyActivityForwardRunner(activityResource.AppRunner,
                    new Performer(activityResource.AppRunner.UserID,
                        activityResource.AppRunner.UserName),
                    subProcessNode);
                var runtimeInstance = WfRuntimeManagerFactory.CreateRuntimeInstanceStartup(subRunner,
                    processInstance,
                    subProcessNode,
                    ref startedResult);
                runtimeInstance.Execute(Session);
            }
        }
        /// <summary>
        /// 创建加签节点记录
        /// </summary>
        /// <param name="activityResource"></param>
        private void CreateSignForwardTasks(ActivityResource activityResource)
        {
            SignForwardTypeEnum signForwardType = (SignForwardTypeEnum)Enum.Parse(typeof(SignForwardTypeEnum),
                base.ActivityForwardContext.ActivityResource.DynamicVariables["SignForwardType"]);

            //根据当前活动实例的记录为加签发起人创建一条新的记录,并修改CompleteOrder
            var newActivityInstance = base.ActivityInstanceManager.CreateActivityInstanceObject(base.ActivityForwardContext.FromActivityInstance);
            newActivityInstance.AssignedToUserIDs = activityResource.AppRunner.UserID;
            newActivityInstance.AssignedToUserNames = activityResource.AppRunner.UserName;
            newActivityInstance.MIHostActivityInstanceID = base.ActivityForwardContext.FromActivityInstance.ID;
            newActivityInstance.SignForwardType = (short)signForwardType;

            if (signForwardType == SignForwardTypeEnum.SignForwardParallel)
            {
                if (base.ActivityForwardContext.ActivityResource.DynamicVariables.ContainsKey("SignForwardCompleteOrder"))
                    newActivityInstance.CompleteOrder = float.Parse(base.ActivityForwardContext.ActivityResource.DynamicVariables["SignForwardCompleteOrder"]);
                else
                    newActivityInstance.CompleteOrder = 1;
            }
            newActivityInstance.ComplexType = (short)ComplexTypeEnum.SignForward;

            //获取加签人集合
            var plist = activityResource.NextActivityPerformers[base.ActivityForwardContext.Activity.ActivityGUID];

            //前加签是别人先审核,然后自己再审核
            if (signForwardType == SignForwardTypeEnum.SignForwardBefore)
            {
                newActivityInstance.CompleteOrder = plist.Count + 1;
                newActivityInstance.ActivityState = (short)ActivityStateEnum.Suspended;
            }
            else if (signForwardType == SignForwardTypeEnum.SignForwardBehind)
            {
                //后加签是自己审批后,其他接收人再加签
                newActivityInstance.CompleteOrder = 1;
            }

            //主节点挂起后,插入当前人的加签记录信息, 并插入任务记录
            base.ActivityInstanceManager.Insert(newActivityInstance, base.Session);
            var signer = new Performer(base.ActivityForwardContext.ActivityResource.AppRunner.UserID,
                base.ActivityForwardContext.ActivityResource.AppRunner.UserName);
            base.TaskManager.Insert(newActivityInstance, signer, base.ActivityForwardContext.ActivityResource.AppRunner, base.Session);

            //创建新加签节点记录
            var signforwardActivityInstance = new ActivityInstanceEntity();
            for (var i = 0; i < plist.Count; i++)
            {
                signforwardActivityInstance = base.ActivityInstanceManager.CreateActivityInstanceObject(base.ActivityForwardContext.FromActivityInstance);
                signforwardActivityInstance.ComplexType = (short)ComplexTypeEnum.SignForward;
                signforwardActivityInstance.AssignedToUserIDs = plist[i].UserID;
                signforwardActivityInstance.AssignedToUserNames = plist[i].UserName;
                signforwardActivityInstance.MIHostActivityInstanceID = base.ActivityForwardContext.FromActivityInstance.ID;

                if (signForwardType == SignForwardTypeEnum.SignForwardBefore)
                {
                    signforwardActivityInstance.CompleteOrder = (short)(i + 1);
                    if (i > 0)
                    {
                        //加签是串行加签,逐次完成
                        signforwardActivityInstance.ActivityState = (short)ActivityStateEnum.Suspended;
                    }
                }
                else if (signForwardType == SignForwardTypeEnum.SignForwardBehind)
                {
                    signforwardActivityInstance.CompleteOrder = (short)(i + 2);
                    signforwardActivityInstance.ActivityState = (short)ActivityStateEnum.Suspended;
                }

                signforwardActivityInstance.SignForwardType = (short)signForwardType;

                base.ActivityInstanceManager.Insert(signforwardActivityInstance, base.Session);
                base.TaskManager.Insert(signforwardActivityInstance, plist[i], activityResource.AppRunner, base.Session);
            }
        }
        /// <summary>
        /// 插入连线实例的方法
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="fromToTransition"></param>
        /// <param name="fromActivityInstance"></param>
        /// <param name="toActivityInstance"></param>
        /// <param name="conditionParseResult"></param>
        /// <param name="wfLinqDataContext"></param>
        /// <returns></returns>
        internal virtual void InsertTransitionInstance(ProcessInstanceEntity processInstance,
            string transitionGUID,
            ActivityInstanceEntity fromActivityInstance,
            ActivityInstanceEntity toActivityInstance,
            TransitionTypeEnum transitionType,
            TransitionFlyingTypeEnum flyingType,
            WfAppRunner runner,
            IDbSession session)
        {
            var tim = new TransitionInstanceManager();
            var transitionInstanceObject = tim.CreateTransitionInstanceObject(processInstance,
                transitionGUID,
                fromActivityInstance,
                toActivityInstance,
                transitionType,
                flyingType,
                runner,
                (byte)ConditionParseResultEnum.Passed);

            tim.Insert(session.Connection, transitionInstanceObject, session.Transaction);
        }
コード例 #13
0
        /// <summary>
        /// 创建活动实例的对象
        /// </summary>
        /// <param name="activity"></param>
        /// <param name="processInstance"></param>
        /// <returns></returns>
        internal ActivityInstanceEntity CreateActivityInstanceObject(string appName,
            string appInstanceID,
            int processInstanceID,
            ActivityEntity activity,
            WfAppRunner runner)
        {
            ActivityInstanceEntity instance = new ActivityInstanceEntity();
            instance.ActivityGUID = activity.ActivityGUID;
            instance.ActivityName = activity.ActivityName;
            instance.ActivityType = (short)activity.ActivityType;
            instance.GatewayDirectionTypeID = (short)activity.GatewayDirectionType;
            instance.ProcessGUID = activity.ProcessGUID;
            instance.AppName = appName;
            instance.AppInstanceID = appInstanceID;
            instance.ProcessInstanceID = processInstanceID;
            instance.TokensRequired = 1;
            instance.TokensHad = 1;
            instance.CreatedByUserID = runner.UserID;
            instance.CreatedByUserName = runner.UserName;
            instance.CreatedDateTime = System.DateTime.Now;
            instance.ActivityState = (short)ActivityStateEnum.Ready;
            instance.CanRenewInstance = 0;

            return instance;
        }
        /// <summary>
        /// 创建活动任务转移实例数据
        /// </summary>
        /// <param name="toActivity"></param>
        /// <param name="processInstance"></param>
        /// <param name="fromActivityInstance"></param>
        /// <param name="transitionGUID"></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)
        {
            //判断是否是会签节点,如果是创建会签节点
            if (toActivity.ActivityTypeDetail != null
                && toActivity.ActivityTypeDetail.ComplexType == ComplexTypeEnum.SignTogether)
            {
                //创建会签节点的主节点,以及会签主节点下的实例子节点记录
                CreateMultipleInstance(toActivity, processInstance, fromActivityInstance,
                    transitionGUID, transitionType, flyingType, activityResource, session);
            }
            else
            {
                //实例化Activity
                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);
            }
        }
        /// <summary>
        /// 退回是会签情况下的处理:
        /// 要退回的节点是会签节点
        /// 1) 全部实例化会签节点下的多实例节点
        /// 2) 只取得办理完成的节点,而且保证CompleteOrder的唯一性
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="originalBackwardToActivityInstance"></param>
        /// <param name="backwardType"></param>
        /// <param name="backSrcActivityInstanceID"></param>
        /// <param name="activityResource"></param>
        /// <param name="session"></param>
        internal void CreateBackwardActivityTaskRepeatedSignTogetherMultipleInstance(ProcessInstanceEntity processInstance,
            ActivityEntity backwardToTaskActvity,
            ActivityInstanceEntity fromActivityInstance,
            BackwardTypeEnum backwardType,
            ActivityInstanceEntity previousMainInstance,
            string transitionGUID,
            TransitionTypeEnum transitionType,
            TransitionFlyingTypeEnum flyingType,
            ActivityResource activityResource,
            IDbSession session)
        {
            //上一步节点是会签节点的退回处理
            //需要重新实例化会签节点上的所有办理人的任务
            //重新封装任务办理人为AssignedToUsers, AssignedToUsernames
            var performerList = AntiGenerateActivityPerformerList(previousMainInstance);

            activityResource.NextActivityPerformers.Clear();
            activityResource.NextActivityPerformers = new Dictionary<string, PerformerList>();
            activityResource.NextActivityPerformers.Add(backwardToTaskActvity.ActivityGUID, performerList);

            //重新生成会签节点的多实例数据
            CreateMultipleInstance(backwardToTaskActvity, processInstance, fromActivityInstance,
                transitionGUID, transitionType, flyingType, activityResource, session);
        }
        /// <summary>
        /// 退回是加签情况下的处理:
        /// 要退回的节点是加签节点
        /// 只实例化当初的加签主节点
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="backwardToTaskActvity"></param>
        /// <param name="fromActivityInstance"></param>
        /// <param name="backwardType"></param>
        /// <param name="previousMainInstance"></param>
        /// <param name="transitionGUID"></param>
        /// <param name="transitionType"></param>
        /// <param name="flyingType"></param>
        /// <param name="activityResource"></param>
        /// <param name="session"></param>
        internal void CreateBackwardActivityTaskRepateSignForwardMainNodeOnly(ProcessInstanceEntity processInstance,
            ActivityEntity backwardToTaskActvity,
            ActivityInstanceEntity fromActivityInstance,
            BackwardTypeEnum backwardType,
            ActivityInstanceEntity previousMainInstance,
            string transitionGUID,
            TransitionTypeEnum transitionType,
            TransitionFlyingTypeEnum flyingType,
            ActivityResource activityResource,
            IDbSession session)
        {
            // 退回是加签情况下的处理:
            // 要退回的节点是加签节点
            // 只实例化当初的加签主节点
            //重新封装任务办理人为AssignedToUsers, AssignedToUsernames
            var performerList = AntiGenerateActivityPerformerList(previousMainInstance);

            activityResource.NextActivityPerformers.Clear();
            activityResource.NextActivityPerformers = new Dictionary<string, PerformerList>();
            activityResource.NextActivityPerformers.Add(backwardToTaskActvity.ActivityGUID, performerList);

            //实例化Activity
            var toActivityInstance = base.CreateBackwardToActivityInstanceObject(processInstance,
                backwardType,
                previousMainInstance.ID,
                activityResource.AppRunner);

            //进入准备运行状态
            toActivityInstance.ActivityState = (short)ActivityStateEnum.Ready;
            toActivityInstance.AssignedToUserIDs = previousMainInstance.AssignedToUserIDs;
            toActivityInstance.AssignedToUserNames = previousMainInstance.AssignedToUserNames;
            toActivityInstance.ComplexType = previousMainInstance.ComplexType;
            toActivityInstance.CompleteOrder = previousMainInstance.CompleteOrder;
            toActivityInstance.SignForwardType = previousMainInstance.SignForwardType;

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

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

            //插入转移数据
            base.InsertTransitionInstance(processInstance,
                transitionGUID,
                fromActivityInstance,
                toActivityInstance,
                transitionType,
                flyingType,
                activityResource.AppRunner,
                session);
        }
コード例 #17
0
        /// <summary>
        /// 会签类型的主节点, 多实例节点处理
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="fromToTransition"></param>
        /// <param name="fromActivityInstance"></param>
        /// <param name="activityResource"></param>
        /// <param name="session"></param>
        internal void CreateMultipleInstance(ActivityEntity toActivity,
            ProcessInstanceEntity processInstance,
            ActivityInstanceEntity fromActivityInstance,
            String transitionGUID,
            TransitionTypeEnum transitionType,
            TransitionFlyingTypeEnum flyingType,
            ActivityResource activityResource,
            IDbSession session)
        {
            //实例化主节点Activity
            var toActivityInstance = CreateActivityInstanceObject(toActivity,
                processInstance, activityResource.AppRunner);

            //主节点实例数据
            toActivityInstance.ActivityState = (short)ActivityStateEnum.Suspended;
            toActivityInstance.ComplexType = (short)ComplexTypeEnum.SignTogether;
            if (toActivity.ActivityTypeDetail.MergeType == MergeTypeEnum.Parallel)
            {
                toActivityInstance.CompleteOrder = toActivity.ActivityTypeDetail.CompleteOrder;
            }
            toActivityInstance.AssignedToUserIDs = GenerateActivityAssignedUserIDs(
                activityResource.NextActivityPerformers[toActivity.ActivityGUID]);

            //插入主节点实例数据
            base.ActivityInstanceManager.Insert(toActivityInstance, session);

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

            //插入会签子节点实例数据
            var plist = activityResource.NextActivityPerformers[toActivity.ActivityGUID];
            ActivityInstanceEntity entity = new ActivityInstanceEntity();
            for (short i = 0; i < plist.Count; i++)
            {
                entity = base.ActivityInstanceManager.CreateActivityInstanceObject(toActivityInstance);
                entity.AssignedToUserIDs = plist[i].UserID;
                entity.AssignedToUserNames = plist[i].UserName;
                entity.MIHostActivityInstanceID = toActivityInstance.ID;
                entity.CompleteOrder = (short)(i + 1);

                //只有第一个节点处于运行状态,其它节点挂起
                if ((i > 0) && (toActivity.ActivityTypeDetail.MergeType == MergeTypeEnum.Sequence))
                {
                    entity.ActivityState = (short)ActivityStateEnum.Suspended;
                }

                //插入活动实例数据,并返回活动实例ID
                entity.ID = base.ActivityInstanceManager.Insert(entity, session);

                //插入任务数据
                base.TaskManager.Insert(entity, plist[i], activityResource.AppRunner, session);

                //启动子流程
                IDbSession subSession = SessionFactory.CreateSession();
                WfExecutedResult startedResult = null;
                var subProcessNode = (SubProcessNode)toActivity.Node;
                subProcessNode.ActivityInstance = entity;   //在流程实例表中记录激活子流程的活动节点ID
                WfAppRunner subRunner = CopyActivityForwardRunner(activityResource.AppRunner,
                    plist[i],
                    subProcessNode);
                var runtimeInstance = WfRuntimeManagerFactory.CreateRuntimeInstanceStartup(subRunner,
                    processInstance,
                    subProcessNode,
                    ref startedResult);

                if (runtimeInstance.WfExecutedResult.Status == WfExecutedStatus.Exception)
                {
                    throw new WfRuntimeException(runtimeInstance.WfExecutedResult.Message);
                }
                runtimeInstance.Execute(subSession);

                //如果是串行会签,只有第一个子流程可以运行,其它子流程处于挂起状态
                if ((i > 0) && (toActivity.ActivityTypeDetail.MergeType == MergeTypeEnum.Sequence))
                {
                    var startResult = (WfExecutedResult)runtimeInstance.WfExecutedResult;
                    base.ProcessInstanceManager.Suspend(startedResult.ProcessInstanceIDStarted, subRunner, subSession);
                }
            }
        }
コード例 #18
0
 internal void Update(ActivityInstanceEntity entity,
     IDbSession session)
 {
     Repository.Update(session.Connection, entity, session.Transaction);
 }
コード例 #19
0
 private bool IsAssignedUserInActivityInstance(ActivityInstanceEntity entity,
     int userID)
 {
     var assignedToUsers = entity.AssignedToUsers;
     var userList = assignedToUsers.Split(',');
     var single = userList.FirstOrDefault<string>(a=>a == userID.ToString());
     if (!string.IsNullOrEmpty(single))
         return true;
     else
         return false;
 }
コード例 #20
0
ファイル: TaskManager.cs プロジェクト: zengcheng/Slickflow
 /// <summary>
 /// 插入任务数据
 /// </summary>
 /// <param name="activityInstance"></param>
 /// <param name="performers"></param>
 /// <param name="wfLinqDataContext"></param>
 internal void Insert(ActivityInstanceEntity activityInstance,
     PerformerList performers, 
     WfAppRunner runner,
     IDbSession session)
 {
     foreach (Performer performer in performers)
     {
         Insert(activityInstance, performer, runner, session);
     }
 }
 /// <summary>
 /// 判断是否是我的任务
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="userID"></param>
 /// <returns></returns>
 public bool IsMineTask(ActivityInstanceEntity entity, string userID)
 {
     var aim = new ActivityInstanceManager();
     bool isMine = aim.IsMineTask(entity, userID);
     return isMine;
 }
コード例 #22
0
ファイル: TaskManager.cs プロジェクト: zengcheng/Slickflow
 /// <summary>
 /// 插入任务数据
 /// </summary>
 /// <param name="activityInstance"></param>
 /// <param name="performer"></param>
 /// <param name="runner"></param>
 /// <param name="session"></param>
 internal void Insert(ActivityInstanceEntity activityInstance,
     Performer performer,
     WfAppRunner runner,
     IDbSession session)
 {
     Insert(activityInstance, performer.UserID, performer.UserName,
         runner.UserID, runner.UserName, session);
 }
 /// <summary>
 /// 插入实例数据
 /// </summary>
 /// <param name="activityInstance"></param>
 /// <param name="wfLinqDataContext"></param>
 internal virtual void InsertActivityInstance(ActivityInstanceEntity activityInstance,
     IDbSession session)
 {
     ActivityInstanceManager.Insert(activityInstance, session);
 }
コード例 #24
0
ファイル: TaskManager.cs プロジェクト: zengcheng/Slickflow
 /// <summary>
 /// 插入任务数据(创建任务)
 /// </summary>
 /// <param name="activityInstance"></param>
 /// <param name="performerID"></param>
 /// <param name="performerName"></param>
 /// <param name="runnerID"></param>
 /// <param name="runnerName"></param>
 /// <param name="session"></param>
 private void Insert(ActivityInstanceEntity activityInstance,
     string performerID,
     string performerName,
     string runnerID,
     string runnerName,
     IDbSession session)
 {
     TaskEntity entity = new TaskEntity();
     entity.AppName = activityInstance.AppName;
     entity.AppInstanceID = activityInstance.AppInstanceID;
     entity.ActivityInstanceID = activityInstance.ID;
     entity.ProcessInstanceID = activityInstance.ProcessInstanceID;
     entity.ActivityGUID = activityInstance.ActivityGUID;
     entity.ActivityName = activityInstance.ActivityName;
     entity.ProcessGUID = activityInstance.ProcessGUID;
     entity.TaskType = (short)TaskTypeEnum.Manual;
     entity.AssignedToUserID = performerID;
     entity.AssignedToUserName = performerName;
     entity.TaskState = 1; //1-待办状态
     entity.CreatedByUserID = runnerID;
     entity.CreatedByUserName = runnerName;
     entity.CreatedDateTime = System.DateTime.Now;
     entity.RecordStatusInvalid = 0;
     //插入任务数据
     Insert(entity, session);
 }
        /// <summary>
        /// 升级当前节点为加签主节点
        /// </summary>
        /// <param name="currentActivityInstance"></param>
        private void UpgradeToMainSignForwardNode(ActivityInstanceEntity currentActivityInstance)
        {
            currentActivityInstance.ComplexType = (short)ComplexTypeEnum.SignForward;
            currentActivityInstance.ActivityState = (short)ActivityStateEnum.Suspended;

            base.ActivityInstanceManager.Update(currentActivityInstance, base.Session);
        }
コード例 #26
0
        /// <summary>
        /// 读取节点的上一步节点信息
        /// </summary>
        /// <param name="runningNode">当前节点</param>
        /// <param name="hasPassedGatewayNode">是否经由路由节点</param>
        /// <returns></returns>
        internal IList<ActivityInstanceEntity> GetPreviousActivityInstance(ActivityInstanceEntity runningNode,
            bool isSendback,
            out bool hasPassedGatewayNode)
        {
            hasPassedGatewayNode = false;
            var transitionList = GetTransitionInstanceList(runningNode.AppInstanceID,
                runningNode.ProcessGUID,
                runningNode.ProcessInstanceID).ToList();

            var backSrcActivityInstanceId = 0;
            if (isSendback == true && runningNode.BackSrcActivityInstanceID != null)
            {
                //节点时曾经发生退回的节点
                backSrcActivityInstanceId = runningNode.BackSrcActivityInstanceID.Value;
            }
            else
                backSrcActivityInstanceId = runningNode.ID;

            var aim = new ActivityInstanceManager();
            var runningTransitionList = transitionList
                .Where(o => o.ToActivityInstanceID == backSrcActivityInstanceId)
                .ToList();

            IList<ActivityInstanceEntity> previousActivityInstanceList = new List<ActivityInstanceEntity>();
            foreach (var entity in runningTransitionList)
            {
                //如果是逻辑节点,则继续查找
                if (entity.FromActivityType == (short)ActivityTypeEnum.GatewayNode)
                {
                    GetPreviousOfGatewayActivityInstance(transitionList, entity.FromActivityInstanceID, previousActivityInstanceList);
                    hasPassedGatewayNode = true;
                }
                else
                {
                    previousActivityInstanceList.Add(aim.GetById(entity.FromActivityInstanceID));
                }
            }
            return previousActivityInstanceList;
        }
コード例 #27
0
ファイル: NodeMediator.cs プロジェクト: zengcheng/Slickflow
        /// <summary>
        /// 递归执行节点
        /// </summary>
        /// <param name="root"></param>
        /// <param name="fromNode"></param>
        /// <param name="conditionKeyValuePair"></param>
        protected void ContinueForwardCurrentNodeRecurisivly(ActivityEntity fromActivity,
            ActivityInstanceEntity fromActivityInstance,
            NextActivityComponent root,
            IDictionary<string, string> conditionKeyValuePair,
            Boolean isJumpforward)
        {
            foreach (NextActivityComponent comp in root)
            {
                if (comp.HasChildren)
                {
                    //此节点类型为分支或合并节点类型:首先需要实例化当前节点(自动完成)
                    NodeMediatorGateway gatewayNodeMediator = NodeMediatorGatewayFactory.CreateGatewayNodeMediator(comp.Activity,
                        ProcessModel, Session);

                    ICompleteAutomaticlly autoGateway = (ICompleteAutomaticlly)gatewayNodeMediator;
                    GatewayExecutedResult gatewayResult = autoGateway.CompleteAutomaticlly(
                        ActivityForwardContext.ProcessInstance,
                        comp.Transition.TransitionGUID,
                        fromActivityInstance,
                        ActivityForwardContext.ActivityResource,
                        Session);

                    if (gatewayResult.Status == GatewayExecutedStatus.Successed)
                    {
                        //遍历后续子节点
                        ContinueForwardCurrentNodeRecurisivly(fromActivity,
                            gatewayNodeMediator.GatewayActivityInstance,
                            comp,
                            conditionKeyValuePair,
                            isJumpforward);
                    }
                    else
                    {
                        WfRuntimeException e = new WfRuntimeException("第一个满足条件的节点已经被成功执行,此后的节点被阻止在XOrJoin节点!");
                        LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, e);
                    }
                }
                else if (comp.Activity.IsSimpleWorkItem)
                {
                    //此节点类型为任务节点:根据fromActivityInstance的类型判断是否可以创建任务
                    if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed)
                    {
                        //创建新任务节点
                        NodeMediator taskNodeMediator = new NodeMediatorTask(Session);
                        taskNodeMediator.CreateActivityTaskTransitionInstance(comp.Activity,
                            ActivityForwardContext.ProcessInstance,
                            fromActivityInstance,
                            comp.Transition.TransitionGUID,
                            comp.Transition.DirectionType == TransitionDirectionTypeEnum.Loop ?
                                TransitionTypeEnum.Loop : TransitionTypeEnum.Forward, //根据Direction方向确定是否是自身循环
                            isJumpforward == true ?
                                TransitionFlyingTypeEnum.ForwardFlying : TransitionFlyingTypeEnum.NotFlying,
                            ActivityForwardContext.ActivityResource,
                            Session);
                    }
                    else
                    {
                        //下一步的任务节点没有创建,需给出提示信息
                        if ((fromActivity.GatewayDirectionType | GatewayDirectionEnum.AllJoinType)
                            == GatewayDirectionEnum.AllJoinType)
                        {
                            WfRuntimeException e = new WfRuntimeException("等待其它需要合并的分支!");
                            LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, e);
                        }
                    }
                }
                else if (comp.Activity.ActivityType == ActivityTypeEnum.SubProcessNode)
                {
                    //节点类型为subprocessnode
                    if (fromActivityInstance.ActivityState == (short)ActivityStateEnum.Completed)
                    {
                        //实例化subprocess节点数据
                        NodeMediator subNodeMediator = new NodeMediatorSubProcess(Session);
                        subNodeMediator.CreateActivityTaskTransitionInstance(comp.Activity,
                            ActivityForwardContext.ProcessInstance,
                            fromActivityInstance,
                            comp.Transition.TransitionGUID,
                            comp.Transition.DirectionType == TransitionDirectionTypeEnum.Loop ?
                                TransitionTypeEnum.Loop : TransitionTypeEnum.Forward,
                            TransitionFlyingTypeEnum.NotFlying,
                            ActivityForwardContext.ActivityResource,
                            Session);
                    }
                }
                else if (comp.Activity.ActivityType == ActivityTypeEnum.EndNode)
                {
                    //此节点为完成结束节点,结束流程
                    var endMediator = new NodeMediatorEnd(ActivityForwardContext, Session);
                    endMediator.Linker.ToActivity = comp.Activity;
                    endMediator.CompleteAutomaticlly(ActivityForwardContext.ProcessInstance,
                        comp.Transition.TransitionGUID,
                        fromActivityInstance,
                        ActivityForwardContext.ActivityResource,
                        Session);
                }
                else
                {
                    WfRuntimeException e = new WfRuntimeException(string.Format("XML文件定义了未知的节点类型,执行失败,节点类型信息:{0}",
                        comp.Activity.ActivityType.ToString()));
                    LogManager.RecordLog("递归执行节点方法异常", LogEventType.Exception, LogPriority.Normal, null, e);
                }
            }
        }
コード例 #28
0
        /// <summary>
        /// 会签类型的主节点, 多实例节点处理
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="fromToTransition"></param>
        /// <param name="fromActivityInstance"></param>
        /// <param name="activityResource"></param>
        /// <param name="session"></param>
        internal void CreateMultipleInstance(ActivityEntity toActivity,
            ProcessInstanceEntity processInstance,
            ActivityInstanceEntity fromActivityInstance,
            String transitionGUID,
            TransitionTypeEnum transitionType,
            TransitionFlyingTypeEnum flyingType,
            ActivityResource activityResource,
            IDbSession session)
        {
            //实例化主节点Activity
            var toActivityInstance = base.CreateActivityInstanceObject(toActivity,
                processInstance, activityResource.AppRunner);

            //主节点实例数据
            toActivityInstance.ActivityState = (short)ActivityStateEnum.Suspended;
            toActivityInstance.ComplexType = (short)ComplexTypeEnum.MultipleInstance;
            if (toActivity.ActivityTypeDetail.MergeType == MergeTypeEnum.Parallel)
            {
                toActivityInstance.CompleteOrder = toActivity.ActivityTypeDetail.CompleteOrder;
            }
            toActivityInstance.AssignedToUsers = GenerateActivityAssignedUsers(
                activityResource.NextActivityPerformers[toActivity.ActivityGUID]);

            //插入主节点实例数据
            base.ActivityInstanceManager.Insert(toActivityInstance, session);

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

            //插入会签子节点实例数据
            var plist = activityResource.NextActivityPerformers[toActivity.ActivityGUID];
            ActivityInstanceEntity entity = new ActivityInstanceEntity();
            for (short i = 0; i < plist.Count; i++)
            {
                entity = base.ActivityInstanceManager.CreateActivityInstanceObject(toActivityInstance);
                entity.AssignedToUsers = plist[i].UserID.ToString();
                entity.MIHostActivityInstanceID = toActivityInstance.ID;
                entity.CompleteOrder = (short)(i + 1);

                //如果是串行会签,只有第一个节点处于运行状态,其它节点挂起
                if ((i > 0) && (toActivity.ActivityTypeDetail.MergeType == MergeTypeEnum.Sequence))
                {
                    entity.ActivityState = (short)ActivityStateEnum.Suspended;
                }

                //插入活动实例数据,并返回活动实例ID
                entity.ID = base.ActivityInstanceManager.Insert(entity, session);

                //插入任务数据
                base.TaskManager.Insert(entity, plist[i], activityResource.AppRunner, session);
            }
        }
コード例 #29
0
        /// <summary>
        /// 根据主节点复制子节点
        /// </summary>
        /// <param name="main"></param>
        /// <returns></returns>
        internal ActivityInstanceEntity CreateActivityInstanceObject(ActivityInstanceEntity main)
        {
            ActivityInstanceEntity instance = new ActivityInstanceEntity();
            instance.ActivityGUID = main.ActivityGUID;
            instance.ActivityName = main.ActivityName;
            instance.ActivityType = main.ActivityType;
            instance.GatewayDirectionTypeID = main.GatewayDirectionTypeID;
            instance.ProcessGUID = main.ProcessGUID;
            instance.AppName = main.AppName;
            instance.AppInstanceID = main.AppInstanceID;
            instance.ProcessInstanceID = main.ProcessInstanceID;
            instance.TokensRequired = 1;
            instance.TokensHad = 1;
            instance.CreatedByUserID = main.CreatedByUserID;
            instance.CreatedByUserName = main.CreatedByUserName;
            instance.CreatedDateTime = System.DateTime.Now;
            instance.ActivityState = (short)ActivityStateEnum.Ready;
            instance.CanRenewInstance = 0;

            return instance;
        }
コード例 #30
0
ファイル: NodeMediator.cs プロジェクト: zengcheng/Slickflow
        /// <summary>
        /// 创建任务的虚方法
        /// 1. 对于自动执行的工作项,无需重写该方法
        /// 2. 对于人工执行的工作项,需要重写该方法,插入待办的任务数据
        /// </summary>
        /// <param name="activityResource"></param>
        /// <param name="wfLinqDataContext"></param>
        internal virtual void CreateNewTask(ActivityInstanceEntity toActivityInstance,
            ActivityResource activityResource,
            IDbSession session)
        {
            if (activityResource.NextActivityPerformers == null)
            {
                throw new WorkflowException("无法创建任务,流程流转下一步的办理人员不能为空!");
            }

            TaskManager.Insert(toActivityInstance,
                activityResource.NextActivityPerformers[toActivityInstance.ActivityGUID],
                activityResource.AppRunner,
                session);
        }