/// <summary>
        /// 把XML节点转换为ActivityEntity实体对象
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        internal ActivityEntity ConvertXmlActivityNodeToActivityEntity(XmlNode node)
        {
            ActivityEntity entity = new ActivityEntity();

            entity.ActivityName = XMLHelper.GetXmlAttribute(node, "name");
            entity.ActivityCode = XMLHelper.GetXmlAttribute(node, "code");
            entity.ActivityGUID = XMLHelper.GetXmlAttribute(node, "id");
            entity.ProcessGUID  = ProcessEntity.ProcessGUID;

            //节点类型信息
            XmlNode typeNode = node.SelectSingleNode("ActivityType");

            entity.ActivityType       = (ActivityTypeEnum)Enum.Parse(typeof(ActivityTypeEnum), XMLHelper.GetXmlAttribute(typeNode, "type"));
            entity.ActivityTypeDetail = ConvertXmlNodeToActivityTypeDetail(typeNode);

            if (entity.ActivityType == ActivityTypeEnum.SubProcessNode)
            {
                //子流程节点
                var subProcessNode = new SubProcessNode(entity);
                subProcessNode.SubProcessGUID = XMLHelper.GetXmlAttribute(typeNode, "subid");
                entity.Node = subProcessNode;
            }

            //任务完成类型信息
            XmlNode implementNode = node.SelectSingleNode("Implement");

            if (implementNode != null)
            {
                entity.TaskImplementDetail = new TaskImplementDetail();
                entity.TaskImplementDetail.ImplementationType = (ImplementationTypeEnum)Enum.Parse(typeof(ImplementationTypeEnum), XMLHelper.GetXmlAttribute(implementNode, "type"));

                //完成类型的详细信息
                XmlNode contentNode = implementNode.SelectSingleNode("Content");
                if (contentNode != null)
                {
                    entity.TaskImplementDetail.Assembly  = XMLHelper.GetXmlAttribute(contentNode, "assembly");
                    entity.TaskImplementDetail.Interface = XMLHelper.GetXmlAttribute(contentNode, "interface");
                    entity.TaskImplementDetail.Method    = XMLHelper.GetXmlAttribute(contentNode, "method");
                    entity.TaskImplementDetail.Content   = contentNode.InnerText;
                }
            }

            //节点的Split Join 类型
            string gatewaySplitJoinType = XMLHelper.GetXmlAttribute(typeNode, "gatewaySplitJoinType");

            if (!string.IsNullOrEmpty(gatewaySplitJoinType))
            {
                entity.GatewaySplitJoinType = (GatewaySplitJoinTypeEnum)Enum.Parse(typeof(GatewaySplitJoinTypeEnum), gatewaySplitJoinType);
            }

            string gatewayDirection = XMLHelper.GetXmlAttribute(typeNode, "gatewayDirection");

            //节点的路由信息
            if (!string.IsNullOrEmpty(gatewayDirection))
            {
                entity.GatewayDirectionType = (GatewayDirectionEnum)Enum.Parse(typeof(GatewayDirectionEnum), gatewayDirection);
            }

            return(entity);
        }
Exemplo n.º 2
0
        private SubProcessNode CreateSubProcessNode(XmlNode element)
        {
            SubProcessNode subProcessNode = new SubProcessNode();

            FillNode(subProcessNode, element);
            return(subProcessNode);
        }
Exemplo n.º 3
0
        public static WfRuntimeManager CreateRuntimeInstanceStartup(WfAppRunner runner,
                                                                    ProcessInstanceEntity parentProcessInstance,
                                                                    SubProcessNode subProcessNode,
                                                                    ref WfExecutedResult result)
        {
            //检查流程是否可以被启动
            var rmins = new WfRuntimeManagerStartup();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            var pim = new ProcessInstanceManager();
            ProcessInstanceEntity processInstance = null;

            if (subProcessNode == null)
            {
                //正常流程启动
                processInstance = pim.GetProcessInstanceLatest(runner.AppName,
                                                               runner.AppInstanceID,
                                                               runner.ProcessGUID);
            }
            else
            {
                //子流程启动
                processInstance = pim.GetProcessInstanceLatest(runner.AppName,
                                                               runner.AppInstanceID,
                                                               subProcessNode.SubProcessGUID);
            }

            //不能同时启动多个主流程
            if (processInstance != null &&
                processInstance.ParentProcessInstanceID == null &&
                processInstance.ProcessState == (short)ProcessStateEnum.Running)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Started_IsRunningAlready;
                result.Message       = "流程已经处于运行状态,如果要重新启动,请先终止当前流程实例!";
                return(rmins);
            }

            //processInstance 为空,此时继续执行启动操作
            rmins.AppRunner             = runner;
            rmins.ParentProcessInstance = parentProcessInstance;
            rmins.InvokedSubProcessNode = subProcessNode;

            //获取流程第一个可办理节点
            rmins.ProcessModel = ProcessModelFactory.Create(runner.ProcessGUID);
            var firstActivity = rmins.ProcessModel.GetFirstActivity();

            rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(firstActivity.ActivityGUID,
                                                                                                   runner.UserID,
                                                                                                   runner.UserName);

            rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers);

            return(rmins);
        }
Exemplo n.º 4
0
        public static WfRuntimeManager CreateRuntimeInstanceStartup(WfAppRunner runner, IServiceProvider serviceProvider,
                                                                    WfProcessInstance parentProcessInstance,
                                                                    SubProcessNode subProcessNode,
                                                                    ref WfExecutedResult result)
        {
            //检查流程是否可以被启动
            var rmins = new WfRuntimeManagerStartup(serviceProvider);

            rmins.WfExecutedResult = result = new WfExecutedResult();
            var pim = new ProcessInstanceManager(serviceProvider);
            WfProcessInstance processInstance = null;

            if (subProcessNode == null)
            {
                //正常流程启动
                processInstance = pim.GetProcessInstanceLatest(
                    runner.ProcessUid,
                    runner.BillUid);
            }
            else
            {
                //子流程启动
                processInstance = pim.GetProcessInstanceLatest(
                    subProcessNode.SubProcessId, runner.BillUid);
            }

            //不能同时启动多个主流程
            if (processInstance != null &&
                processInstance.ParentProcessInsUid == null &&
                processInstance.ProcessState == WfProcessInstanceState.Running)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Started_IsRunningAlready;
                result.Message       = "流程已经处于运行状态,不要重复提交!";
            }
            else
            {
                //processInstance 为空,此时继续执行启动操作
                rmins.AppRunner             = runner;
                rmins.ParentProcessInstance = parentProcessInstance;
                rmins.InvokedSubProcessNode = subProcessNode;

                //获取流程第一个可办理节点
                rmins.ProcessModel = new ProcessModel(serviceProvider, runner.ProcessUid, runner.BillUid);
            }

            //var firstActivity = rmins.ProcessModel.GetFirstActivity();

            //rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(firstActivity.ActivityID,
            //    runner.UserId,
            //    runner.UserName);


            return(rmins);
        }
        /// <summary>
        /// 创建子流程时,重新生成runner信息
        /// </summary>
        /// <param name="runner">运行者</param>
        /// <param name="performer">下一步执行者</param>
        /// <param name="subProcessNode">子流程节点</param>
        /// <param name="session">会话</param>
        /// <returns></returns>
        private WfAppRunner CreateSubProcessRunner(WfAppRunner runner,
                                                   Performer performer,
                                                   SubProcessNode subProcessNode,
                                                   IDbSession session)
        {
            WfAppRunner subRunner = new WfAppRunner();

            subRunner.AppInstanceCode = runner.AppInstanceCode;
            subRunner.AppInstanceID   = runner.AppInstanceID;
            subRunner.AppName         = runner.AppName;
            subRunner.UserID          = performer.UserID;
            subRunner.UserName        = performer.UserName;

            //如果是动态调用子流程,则需要获取具体子流程实体对象
            var isSubProcessNotExisted = false;

            if (subProcessNode.SubProcessType == SubProcessTypeEnum.Dynamic)
            {
                var subProcessId = runner.DynamicVariables[subProcessNode.SubVarName];
                if (!string.IsNullOrEmpty(subProcessId))
                {
                    int processID = 0;
                    int.TryParse(subProcessId, out processID);
                    if (processID > 0)
                    {
                        var pm      = new ProcessManager();
                        var process = pm.GetByID(session.Connection, processID, session.Transaction);
                        if (process != null)
                        {
                            subProcessNode.SubProcessGUID = process.ProcessGUID;
                        }
                        else
                        {
                            isSubProcessNotExisted = true;
                        }
                    }
                    else
                    {
                        isSubProcessNotExisted = true;
                    }
                }
                else
                {
                    isSubProcessNotExisted = true;
                }
            }

            if (isSubProcessNotExisted == true)
            {
                throw new WfRuntimeException(LocalizeHelper.GetEngineMessage("nodemediatorsubprocess.CreateSubProcessRunner.nonevariableparamsvalue.warn"));
            }
            subRunner.ProcessGUID = subProcessNode.SubProcessGUID;

            return(subRunner);
        }
        /// <summary>
        /// 创建子流程时,重新生成runner信息
        /// </summary>
        /// <param name="runner"></param>
        /// <param name="subProcessNode"></param>
        /// <returns></returns>
        private WfAppRunner CopyActivityForwardRunner(WfAppRunner runner,
                                                      Performer performer,
                                                      SubProcessNode subProcessNode)
        {
            WfAppRunner subRunner = new WfAppRunner();

            subRunner.AppInstanceCode = runner.AppInstanceCode;
            subRunner.AppInstanceID   = runner.AppInstanceID;
            subRunner.AppName         = runner.AppName;
            subRunner.UserID          = performer.UserID;
            subRunner.UserName        = performer.UserName;
            subRunner.ProcessGUID     = subProcessNode.SubProcessGUID;
            return(subRunner);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Parse ao filho de nodeList, subProcess
        /// </summary>
        /// <param name="element"></param>
        private void ParseSubProcessNodeElement(XmlNode element)
        {
            SubProcessNode subProcessNode = CreateSubProcessNode(element);

            foreach (XmlNode child in element.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element)
                {
                    ParseInnerNodes(subProcessNode, child);
                }
            }
            AddNode(subProcessNode);
            ResolveUnresolved();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 创建子流程时,重新生成runner信息
        /// </summary>
        /// <param name="runner">运行者</param>
        /// <param name="performer">下一步执行者</param>
        /// <param name="subProcessNode">子流程节点</param>
        /// <returns></returns>
        private WfAppRunner CopyActivityForwardRunner(WfAppRunner runner,
                                                      Performer performer,
                                                      SubProcessNode subProcessNode)
        {
            WfAppRunner subRunner = new WfAppRunner();

            subRunner.BillData   = runner.BillData;
            subRunner.BillUid    = runner.BillUid;
            subRunner.AppName    = runner.AppName;
            subRunner.UserId     = performer.UserId;
            subRunner.UserName   = performer.UserName;
            subRunner.ProcessUid = subProcessNode.SubProcessId;

            return(subRunner);
        }
        /// <summary>
        /// 子流程启动
        /// </summary>
        /// <param name="runner">运行者</param>
        /// <param name="parentProcessInstance">父流程</param>
        /// <param name="subProcessNode">子流程节点</param>
        /// <param name="performerList">执行者列表</param>
        /// <param name="session">数据库会话</param>
        /// <param name="result">运行结果</param>
        /// <returns>运行时管理器</returns>
        public static WfRuntimeManager CreateRuntimeInstanceStartupSub(WfAppRunner runner,
                                                                       ProcessInstanceEntity parentProcessInstance,
                                                                       SubProcessNode subProcessNode,
                                                                       PerformerList performerList,
                                                                       IDbSession session,
                                                                       ref WfExecutedResult result)
        {
            //检查流程是否可以被启动
            var rmins = new WfRuntimeManagerStartupSub();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            var pim = new ProcessInstanceManager();
            ProcessInstanceEntity processInstance = pim.GetProcessInstanceCurrent(session.Connection,
                                                                                  runner.AppInstanceID,
                                                                                  subProcessNode.SubProcessGUID,
                                                                                  session.Transaction);

            //不能同时启动多个主流程
            if (processInstance != null &&
                processInstance.ParentProcessInstanceID == null &&
                processInstance.ProcessState == (short)ProcessStateEnum.Running)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Started_IsRunningAlready;
                result.Message       = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceStartup.error");
                return(rmins);
            }

            //processInstance 为空,此时继续执行启动操作
            rmins.AppRunner             = runner;
            rmins.ParentProcessInstance = parentProcessInstance;
            rmins.InvokedSubProcessNode = subProcessNode;

            //获取流程第一个可办理节点
            rmins.ProcessModel = ProcessModelFactory.Create(runner.ProcessGUID, runner.Version);
            var startActivity = rmins.ProcessModel.GetStartActivity();
            var firstActivity = rmins.ProcessModel.GetFirstActivity();

            //子流程自动获取第一个办理节点上的人员列表
            rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(firstActivity.ActivityGUID,
                                                                                                   performerList);
            rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers);

            return(rmins);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Convert XmlNode to Activity Entity
        /// </summary>
        /// <param name="node">Xml Node</param>
        /// <param name="processGUID">ProcessGUID</param>
        /// <returns>Activity Entity</returns>
        public static ActivityEntity ConvertXmlActivityNodeToActivityEntity(XmlNode node, string processGUID)
        {
            ActivityEntity entity = new ActivityEntity();

            entity.ActivityGUID = XMLHelper.GetXmlAttribute(node, "id");
            entity.ActivityName = XMLHelper.GetXmlAttribute(node, "name");
            entity.ActivityCode = XMLHelper.GetXmlAttribute(node, "code");
            entity.ActivityUrl  = XMLHelper.GetXmlAttribute(node, "url");
            entity.ProcessGUID  = processGUID;

            //描述信息
            XmlNode descNode = node.SelectSingleNode("Description");

            entity.Description = (descNode != null) ? descNode.InnerText : string.Empty;

            //节点类型信息
            XmlNode typeNode = node.SelectSingleNode("ActivityType");

            entity.ActivityType       = (ActivityTypeEnum)Enum.Parse(typeof(ActivityTypeEnum), XMLHelper.GetXmlAttribute(typeNode, "type"));
            entity.ActivityTypeDetail = ConvertXmlNodeToActivityTypeDetail(typeNode);
            entity.WorkItemType       = XPDLHelper.GetWorkItemType(entity.ActivityType);

            if (entity.ActivityType == ActivityTypeEnum.SubProcessNode)             //sub process node
            {
                //子流程节点
                var subProcessNode = new SubProcessNode(entity);
                var strSubType     = XMLHelper.GetXmlAttribute(typeNode, "subType");
                if (!string.IsNullOrEmpty(strSubType))
                {
                    subProcessNode.SubProcessType = (SubProcessTypeEnum)Enum.Parse(typeof(SubProcessTypeEnum), strSubType);
                    subProcessNode.SubVarName     = XMLHelper.GetXmlAttribute(typeNode, "subVar");
                }
                else
                {
                    subProcessNode.SubProcessType = SubProcessTypeEnum.Fixed;
                }
                subProcessNode.SubProcessGUID = XMLHelper.GetXmlAttribute(typeNode, "subId");
                entity.Node = subProcessNode;
            }
            else if (entity.ActivityType == ActivityTypeEnum.MultipleInstanceNode)      //multiple instance node
            {
                var multipleInstanceNode = new MultipleInstanceNode(entity);
                entity.Node = multipleInstanceNode;
            }

            //获取节点的操作列表
            XmlNode actionsNode = node.SelectSingleNode("Actions");

            if (actionsNode != null)
            {
                XmlNodeList         xmlActionList = actionsNode.ChildNodes;
                List <ActionEntity> actionList    = new List <ActionEntity>();
                foreach (XmlNode element in xmlActionList)
                {
                    actionList.Add(ConvertXmlActionNodeToActionEntity(element));
                }
                entity.ActionList = actionList;
            }

            //获取节点的服务列表
            XmlNode servicesNode = node.SelectSingleNode("Services");

            if (servicesNode != null)
            {
                XmlNodeList          xmlServiceList = servicesNode.ChildNodes;
                List <ServiceEntity> serviceList    = new List <ServiceEntity>();
                foreach (XmlNode element in xmlServiceList)
                {
                    serviceList.Add(ConvertXmlServiceNodeToServiceEntity(element));
                }
                entity.ServiceList = serviceList;
            }

            //获取节点边界列表
            XmlNode boundariesNode = node.SelectSingleNode("Boundaries");

            if (boundariesNode != null)
            {
                XmlNodeList           xmlBoundaryList = boundariesNode.ChildNodes;
                List <BoundaryEntity> boundaryList    = new List <BoundaryEntity>();
                foreach (XmlNode element in xmlBoundaryList)
                {
                    boundaryList.Add(ConvertXmlBoundaryNodeToBoundaryEntity(element));
                }
                entity.BoundaryList = boundaryList;
            }

            //获取节点自定义章节信息
            XmlNode sectionsNode = node.SelectSingleNode("Sections");

            if (sectionsNode != null)
            {
                XmlNodeList          xmlSectionList = sectionsNode.ChildNodes;
                List <SectionEntity> sectionList    = new List <SectionEntity>();
                foreach (XmlNode element in xmlSectionList)
                {
                    sectionList.Add(ConvertXmlSectionNodeToSectionEntity(element));
                }
                entity.SectionList = sectionList;
            }


            //节点的Split Join 类型
            string gatewaySplitJoinType = XMLHelper.GetXmlAttribute(typeNode, "gatewaySplitJoinType");

            if (!string.IsNullOrEmpty(gatewaySplitJoinType))
            {
                entity.GatewaySplitJoinType = (GatewaySplitJoinTypeEnum)Enum.Parse(typeof(GatewaySplitJoinTypeEnum), gatewaySplitJoinType);
            }

            string gatewayDirection = XMLHelper.GetXmlAttribute(typeNode, "gatewayDirection");

            //节点的路由信息
            if (!string.IsNullOrEmpty(gatewayDirection))
            {
                entity.GatewayDirectionType = (GatewayDirectionEnum)Enum.Parse(typeof(GatewayDirectionEnum), gatewayDirection);
            }

            string gatewayJoinPass = XMLHelper.GetXmlAttribute(typeNode, "gatewayJoinPass");

            if (!string.IsNullOrEmpty(gatewayJoinPass))
            {
                entity.GatewayJoinPassType = EnumHelper.TryParseEnum <GatewayJoinPassEnum>(gatewayJoinPass);
            }

            return(entity);
        }
Exemplo n.º 11
0
 private SubProcessNode CreateSubProcessNode(XmlNode element)
 {
     SubProcessNode subProcessNode = new SubProcessNode();
     FillNode(subProcessNode, element);
     return subProcessNode;
 }