예제 #1
0
        /// <summary>
        /// 继续执行主流程
        /// </summary>
        /// <param name="processInstance">子流程实例</param>
        /// <param name="session">数据库会话</param>
        private void ContinueMainProcessRunning(ProcessInstanceEntity processInstance,
                                                IDbSession session)
        {
            //读取流程下一步办理人员列表信息
            var runner = FillNextActivityPerformersByRoleList(processInstance.InvokedActivityInstanceID,
                                                              processInstance.InvokedActivityGUID,
                                                              session);

            //开始执行下一步
            var runAppResult    = WfExecutedResult.Default();
            var runtimeInstance = WfRuntimeManagerFactory.CreateRuntimeInstanceAppRunning(runner, session, ref runAppResult);

            if (runAppResult.Status == WfExecutedStatus.Exception)
            {
                throw new WfRuntimeException(LocalizeHelper.GetEngineMessage("nodemediatorend.ContinueMainProcessRunning.warn", runAppResult.Message));
            }

            //注册事件并运行
            WfRuntimeManagerFactory.RegisterEvent(runtimeInstance,
                                                  runtimeInstance_OnWfProcessRunning,
                                                  runtimeInstance_OnWfProcessContinued);
            bool isRun = runtimeInstance.Execute(session);

            void runtimeInstance_OnWfProcessRunning(object sender, WfEventArgs args)
            {
                Delegate.DelegateExecutor.InvokeExternalDelegate(session,
                                                                 Delegate.EventFireTypeEnum.OnProcessRunning,
                                                                 runner.DelegateEventList,
                                                                 runtimeInstance.ProcessInstanceID);
            }

            void runtimeInstance_OnWfProcessContinued(object sender, WfEventArgs args)
            {
                runAppResult = args.WfExecutedResult;
                if (runAppResult.Status == WfExecutedStatus.Success)
                {
                    Delegate.DelegateExecutor.InvokeExternalDelegate(session,
                                                                     Delegate.EventFireTypeEnum.OnProcessContinued,
                                                                     runner.DelegateEventList,
                                                                     runtimeInstance.ProcessInstanceID);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 消息消费函数
        /// </summary>
        /// <param name="entity">消息实体对象</param>
        /// <returns>消费结果</returns>
        public MessageConsumedResult ConsumeMessage(MessageEntity entity)
        {
            var msgResult     = MessageConsumedResult.Default();
            var topic         = entity.Topic;
            var msgRunnerView = JsonConvert.DeserializeObject <MessageRunnerView>(entity.Line);

            if (!string.IsNullOrEmpty(topic))
            {
                try
                {
                    IWorkflowService wfService = new WorkflowService();
                    WfExecutedResult wfResult  = WfExecutedResult.Default();
                    var catchActivity          = msgRunnerView.ActivityEntity;
                    if (catchActivity.ActivityType == ActivityTypeEnum.StartNode)
                    {
                        if (catchActivity.ActivityTypeDetail.TriggerType == TriggerTypeEnum.Message &&
                            catchActivity.ActivityTypeDetail.MessageDirection == MessageDirectionEnum.Catch)
                        {
                            var startRunner = GetRunnerFromMessagExchange(msgRunnerView);
                            wfResult = wfService.StartProcess(startRunner);
                            if (wfResult.Status == WfExecutedStatus.Success)
                            {
                                msgResult.Status = MessageConsumedStatus.Success;
                            }
                            else
                            {
                                msgResult.Status  = MessageConsumedStatus.Exception;
                                msgResult.Message = wfResult.Message;
                            }
                        }
                        else
                        {
                            msgResult.Status  = MessageConsumedStatus.Exception;
                            msgResult.Message = string.Format("Unknown activity type detail:{0}, message direction:{1}",
                                                              catchActivity.ActivityTypeDetail.TriggerType.ToString(),
                                                              catchActivity.ActivityTypeDetail.MessageDirection.ToString());
                        }
                    }
                    else
                    {
                        if (catchActivity.ActivityTypeDetail.TriggerType == TriggerTypeEnum.Message &&
                            catchActivity.ActivityTypeDetail.MessageDirection == MessageDirectionEnum.Catch)
                        {
                            var runner = GetRunnerFromMessagExchange(msgRunnerView);
                            wfResult = wfService.RunProcess(runner);
                            if (wfResult.Status == WfExecutedStatus.Success)
                            {
                                msgResult.Status = MessageConsumedStatus.Success;
                            }
                            else
                            {
                                msgResult.Status  = MessageConsumedStatus.Exception;
                                msgResult.Message = wfResult.Message;
                            }
                        }
                        else
                        {
                            msgResult.Status  = MessageConsumedStatus.Exception;
                            msgResult.Message = string.Format("Unknown activity type detail:{0}, message direction:{1}",
                                                              catchActivity.ActivityTypeDetail.TriggerType.ToString(),
                                                              catchActivity.ActivityTypeDetail.MessageDirection.ToString());
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    msgResult.Status  = MessageConsumedStatus.Failed;
                    msgResult.Message = ex.Message;
                }
            }

            if (msgResult.Status == MessageConsumedStatus.Exception ||
                msgResult.Status == MessageConsumedStatus.Failed)
            {
                throw new WfMessageDelegationException(msgResult.Message);
            }
            return(msgResult);
        }
예제 #3
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 new 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 = GenerateActivityAssignedUserInfo(toActivityInstance, activityResource);

            //插入主节点实例数据
            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();
                var        subProcessNode = (SubProcessNode)toActivity.Node;
                subProcessNode.ActivityInstance = entity;   //在流程实例表中记录激活子流程的活动节点ID
                WfAppRunner subRunner = CopyActivityForwardRunner(activityResource.AppRunner,
                                                                  plist[i],
                                                                  subProcessNode);

                WfExecutedResult startedResult = WfExecutedResult.Default();
                var runtimeInstance            = WfRuntimeManagerFactory.CreateRuntimeInstanceStartupSub(subRunner,
                                                                                                         processInstance,
                                                                                                         subProcessNode,
                                                                                                         plist,
                                                                                                         session,
                                                                                                         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))
                {
                    base.ProcessInstanceManager.Suspend(startedResult.ProcessInstanceIDStarted, subRunner, subSession);
                }
            }
        }
예제 #4
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="performer">执行者</param>
        /// <param name="session">会话</param>
        private void CreateSubProcessNode(ActivityEntity toActivity,
                                          ProcessInstanceEntity processInstance,
                                          ActivityInstanceEntity fromActivityInstance,
                                          string transitionGUID,
                                          TransitionTypeEnum transitionType,
                                          TransitionFlyingTypeEnum flyingType,
                                          ActivityResource activityResource,
                                          Performer performer,
                                          IDbSession session)
        {
            WfExecutedResult startedResult = WfExecutedResult.Default();

            //实例化Activity
            var toActivityInstance = CreateActivityInstanceObject(toActivity, processInstance, activityResource.AppRunner);

            //进入运行状态
            toActivityInstance.ActivityState = (short)ActivityStateEnum.Ready;
            if (performer != null)
            {
                //并行容器中的子流程节点,每个人发起一个子流程
                toActivityInstance.AssignedToUserIDs   = performer.UserID;
                toActivityInstance.AssignedToUserNames = performer.UserName;
                //插入活动实例数据
                base.ActivityInstanceManager.Insert(toActivityInstance, session);
                //插入任务数据
                this.TaskManager.Insert(toActivityInstance, performer, activityResource.AppRunner, session);
            }
            else
            {
                toActivityInstance = GenerateActivityAssignedUserInfo(toActivityInstance, activityResource);
                //插入活动实例数据
                base.ActivityInstanceManager.Insert(toActivityInstance, session);
                //插入任务数据
                base.CreateNewTask(toActivityInstance, activityResource, session);
            }

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

            //启动子流程
            var subProcessNode = (SubProcessNode)toActivity.Node;

            subProcessNode.ActivityInstance = toActivityInstance;

            WfAppRunner subRunner     = null;
            var         performerList = new PerformerList();

            if (performer != null)
            {
                subRunner = CopyActivityForwardRunner(activityResource.AppRunner,
                                                      new Performer(performer.UserID,
                                                                    performer.UserName),
                                                      subProcessNode);
                performerList.Add(performer);
            }
            else
            {
                subRunner = CopyActivityForwardRunner(activityResource.AppRunner,
                                                      new Performer(activityResource.AppRunner.UserID,
                                                                    activityResource.AppRunner.UserName),
                                                      subProcessNode);
                performerList = activityResource.NextActivityPerformers[toActivity.ActivityGUID];
            }

            var runtimeInstance = WfRuntimeManagerFactory.CreateRuntimeInstanceStartupSub(subRunner,
                                                                                          processInstance,
                                                                                          subProcessNode,
                                                                                          performerList,
                                                                                          session,
                                                                                          ref startedResult);

            runtimeInstance.OnWfProcessExecuted += runtimeInstance_OnWfProcessStarted;
            runtimeInstance.Execute(session);

            void runtimeInstance_OnWfProcessStarted(object sender, WfEventArgs args)
            {
                startedResult = args.WfExecutedResult;
            }
        }