public Statements.WorkflowActivity Parse(string key, string workflowDefinition, IEnumerable <ActivitySetting> activitySettings) { var settings = GetActivitySettings(); var flow = new Statements.WorkflowActivity(); var v1 = new Variable <string>("v1"); flow.Variables.Add(v1); var third = WorkflowBuilder.CreateServer(settings.ElementAt(2), "节点3", "'1'", null, v1, flow.CustomActivityResult, null, null); var second = WorkflowBuilder.CreateSubProcess(settings.ElementAt(1) , "子流程-节点2" , new Dictionary <string, string>() { { "error", this._finishRule } } , null, null , third); SequenceWorkflowParser.Second = second.Action as SubProcess; flow.Body.StartNode = WorkflowBuilder.CreateHuman(settings.ElementAt(0) , "节点1" , new GetUsers(this._actionerRule) , flow.CustomActivityResult , null , second); SequenceWorkflowParser.First = (flow.Body.StartNode as FlowStep).Action as Human; return(flow); }
public Statements.WorkflowActivity Parse(string key, string workflowDefinition, IEnumerable <ActivitySetting> activitySettings) { var settings = GetActivitySettings(); var flow = new Statements.WorkflowActivity(); ParallelWorkflowParser.Human = WorkflowBuilder.CreateHuman(settings.ElementAt(1) , "并行子节点1" , new GetUsers(this._actionerRule) , null); ParallelWorkflowParser.SubProcess = WorkflowBuilder.CreateSubProcess(settings.ElementAt(2) , "并行子节点2" , new Dictionary <string, string>() { { "error", this._finishRule } } , null); flow.Body.StartNode = WorkflowBuilder.CreateParallel(settings.ElementAt(0) , "并行节点" , this._completion , null , ParallelWorkflowParser.Human , ParallelWorkflowParser.SubProcess); Parallel = (flow.Body.StartNode as FlowStep).Action as Parallel; return(flow); }
//通过Flowchart节点和自定义活动列表解析NTFE-BPM活动树 private Taobao.Workflow.Activities.Statements.WorkflowActivity ParseWorkflowActivity(XElement root , IList <ActivitySetting> activitySettings , bool isCacheMetaData) { var activity = new WorkflowActivity(); var variableElements = root.Descendants("Variable").ToList(); //设置变量集合 this.SetVariablesForActivity(variableElements, activity); var nodeDataElements = root.Descendants("NodeData") .Where(o => o.Attribute("Category").Value != "Comment") .ToList(); var linkDataElements = root.Descendants("LinkData").ToList(); var flowNodes = new Dictionary <string, FlowNodeInfo>(); //定义点集合 var temp = new List <string>(); foreach (var nodeDataElement in nodeDataElements) { var category = nodeDataElement.Attribute("Category").Value; if (category == "HumanPar" || category == "ServerPar" || category == "ChildPar" || category == "Start") { continue; } var activityName = nodeDataElement.Attribute("Text").Value; var key = nodeDataElement.Attribute("Key").Value; if (temp.Contains(activityName)) { throw new InvalidOperationException("流程中包括重复名称的节点,请检查!"); } temp.Add(activityName); var activitySetting = activitySettings.FirstOrDefault(o => o.ActivityName == activityName); if (activitySetting == null) { throw new Exception(string.Format(@"解析出错,找不到名称为“{0}”的ActivitySetting", activityName)); } Taobao.Activities.Statements.FlowStep flowStep = null; if (activitySetting is HumanSetting) { var humanSetting = activitySetting as HumanSetting; //创建人工节点 flowStep = WorkflowBuilder.CreateHuman(activitySetting , activitySetting.ActivityName , new GetUsers(humanSetting.ActionerRule.Scripts) , activity.CustomActivityResult , new Dictionary <string, Taobao.Activities.Statements.FlowNode>() , null); } else if (activitySetting is ServerSetting) { var customSetting = activitySetting as CustomSetting; var serverSetting = activitySetting as ServerSetting; var resultTo = activity.Variables.ToList().FirstOrDefault(o => o.Name == serverSetting.ResultTo); //创建人工节点 flowStep = WorkflowBuilder.CreateServer(activitySetting , activitySetting.ActivityName , serverSetting.Script , customSetting.FinishRule.Scripts , resultTo != null ? (Variable <string>)resultTo : null , activity.CustomActivityResult , new Dictionary <string, Taobao.Activities.Statements.FlowNode>() , null); } else if (activitySetting is SubProcessSetting) { var customSetting = activitySetting as CustomSetting; var subProcessSetting = activitySetting as SubProcessSetting; //创建子流程节点 flowStep = WorkflowBuilder.CreateSubProcess(activitySetting , activitySetting.ActivityName , customSetting.FinishRule.Scripts , activity.CustomActivityResult , new Dictionary <string, Taobao.Activities.Statements.FlowNode>() , null); } else if (activitySetting is ParallelSetting) { IList <Custom> customs = new List <Custom>(); //遍历customs var customParElements = nodeDataElements.Where(o => o.Attribute("SubGraphKey") != null && o.Attribute("SubGraphKey").Value == key).ToList(); foreach (var customParElement in customParElements) { var customeCategory = customParElement.Attribute("Category").Value; var customeActivityName = customParElement.Attribute("Text").Value; if (temp.Contains(customeActivityName)) { throw new InvalidOperationException("流程中包括重复名称的节点,请检查!"); } temp.Add(customeActivityName); var customActivitySetting = activitySettings.FirstOrDefault(o => o.ActivityName == customeActivityName); if (customActivitySetting == null) { throw new Exception(string.Format(@"解析出错,找不到名称为“{0}”的ActivitySetting", customeActivityName)); } if (customActivitySetting is HumanSetting) { var humanSetting = customActivitySetting as HumanSetting; //创建并行容器中人工节点 var human = WorkflowBuilder.CreateHuman(customActivitySetting , customActivitySetting.ActivityName , new GetUsers(humanSetting.ActionerRule.Scripts) , activity.CustomActivityResult); customs.Add(human); } else if (customActivitySetting is ServerSetting) { var customSetting = customActivitySetting as CustomSetting; var serverSetting = customActivitySetting as ServerSetting; var resultTo = activity.Variables.ToList().FirstOrDefault(o => o.Name == serverSetting.ResultTo); //创建并行容器中自动节点 var server = WorkflowBuilder.CreateServer(customActivitySetting , customActivitySetting.ActivityName , serverSetting.Script , customSetting.FinishRule.Scripts , resultTo != null ? (Variable <string>)resultTo : null , activity.CustomActivityResult); customs.Add(server); } else if (customActivitySetting is SubProcessSetting) { var customSetting = customActivitySetting as CustomSetting; var subProcessSetting = customActivitySetting as SubProcessSetting; //创建并行容器中子流程节点 var subprocess = WorkflowBuilder.CreateSubProcess(customActivitySetting , customActivitySetting.ActivityName , customSetting.FinishRule.Scripts , activity.CustomActivityResult); customs.Add(subprocess); } } //创建并行容器节点 flowStep = WorkflowBuilder.CreateParallel(activitySetting , activitySetting.ActivityName , (activitySetting as ParallelSetting).CompletionCondition , null , customs.ToArray()); } flowNodes.Add(key, new FlowNodeInfo() { FlowStep = flowStep }); } if (nodeDataElements.Count(o => o.Attribute("Category").Value == "Start") != 1) { throw new InvalidOperationException("不包括Start开始节点"); } //创建流程节点 this.BuildFlowNode(flowNodes, linkDataElements); var startLinkElement = linkDataElements.FirstOrDefault(o => o.Attribute("From").Value == "Start"); if (startLinkElement == null) { throw new InvalidOperationException("不包含Start到初始点连线"); } activity.Body.StartNode = flowNodes[startLinkElement.Attribute("To").Value].FlowStep; //初始化Flowchart节点的元素 if (isCacheMetaData) { CacheMetadata(activity.Body); } return(activity); }
public WorkflowActivity Parse(string key, string workflowDefinition, IEnumerable <ActivitySetting> activitySettings) { //本测试工程的大部分测试均基于此工作流定义,需谨慎变更 禁止修改 var flow = new Statements.WorkflowActivity(); IEnumerable <ActivitySetting> settings; if (key.IndexOf("SubProcess") >= 0) { //0 节点1 同意|否决 //1 节点2 完成 //2 节点3 完成 settings = GetSubProcessActivitySettings(); var third = WorkflowBuilder.CreateServer(settings.ElementAt(2) , "节点3" , "'1'" , null , null , flow.CustomActivityResult , null , null); var second = WorkflowBuilder.CreateHuman(settings.ElementAt(1) , "节点2" , new GetUsers("originator") , flow.CustomActivityResult , new Dictionary <string, FlowNode>() { { "同意", third } } , null); flow.Body.StartNode = WorkflowBuilder.CreateHuman(settings.ElementAt(0) , "节点1" , new GetUsers("originator") , flow.CustomActivityResult , new Dictionary <string, FlowNode>() { { "同意", second } } , null); } else if (key.IndexOf("ParentProcess") >= 0) { //0 节点1 同意|否决 //1 节点2 完成 //2 节点3 完成 //3 节点4 完成 settings = GetParentProcessActivitySettings(); var forth = WorkflowBuilder.CreateServer(settings.ElementAt(3) , "节点4" , "'1'" , null , null , flow.CustomActivityResult , null , null); var third = WorkflowBuilder.CreateHuman(settings.ElementAt(2) , "节点3" , new GetUsers("originator") , flow.CustomActivityResult , new Dictionary <string, FlowNode>() { { "同意", forth } } , null); var second = WorkflowBuilder.CreateSubProcess(settings.ElementAt(1) , "节点2" , null , flow.CustomActivityResult , null , third); flow.Body.StartNode = WorkflowBuilder.CreateHuman(settings.ElementAt(0) , "节点1" , new GetUsers("originator") , flow.CustomActivityResult , new Dictionary <string, FlowNode>() { { "同意", second } } , null); } else { settings = GetTemplateProcessActivitySettings(); var forth = WorkflowBuilder.CreateServer(settings.ElementAt(3) , "节点4" , "'1'" , null , null , flow.CustomActivityResult , null , null); var third = WorkflowBuilder.CreateHuman(settings.ElementAt(2) , "节点3" , new GetUsers("originator") , flow.CustomActivityResult , new Dictionary <string, FlowNode>() { { "同意", forth } } , null); var second = WorkflowBuilder.CreateHuman(settings.ElementAt(1) , "节点2" , new GetUsers("originator") , flow.CustomActivityResult , new Dictionary <string, FlowNode>() { { "同意", third } } , null); flow.Body.StartNode = WorkflowBuilder.CreateHuman(settings.ElementAt(0) , "节点1" , new GetUsers("originator") , flow.CustomActivityResult , new Dictionary <string, FlowNode>() { { "同意", second } } , null); } return(flow); }
public virtual Statements.WorkflowActivity Parse(string key, string workflowDefinition, IEnumerable <ActivitySetting> activitySettings) { //是否是子流程测试模式 var isSubMode = key.Contains(BaseTest.SubFlag); var settings = isSubMode ? GetSubProcessActivitySettings() : GetActivitySettings(); var flow = new Statements.WorkflowActivity(); var v1 = new Variable <string>("v1"); flow.Variables.Add(v1); //0 节点1 同意|否决 //2 节点2 完成 startRule 10s //4 节点3 完成 OneAtOnce slot=2 发起人->主管->username1 //6 节点4 Server //8 并行节点 子节点1完成则完成 //8 并行子节点1 发起人 startRule 无限期延迟 需要提前唤醒 //8 并行子节点2 主管 //9 节点6 完成 AllAtOnce slot=2 发起人 同意|否决 //11 节点7 完成 AllAtOnce slot=1 发起人|主管 同意|否决 //根据参数追加一个子流程节点 //13 节点8 子流程节点 var eighth = isSubMode ? WorkflowBuilder.CreateSubProcess(settings.ElementAt(9), BaseTest.SubProcessNode, null, null, null, null) : null; var seventh = WorkflowBuilder.CreateHuman(settings.ElementAt(8) , "节点7" , new GetUsers("originator", "getSuperior()") , flow.CustomActivityResult , null , isSubMode ? eighth : null); var sixth = WorkflowBuilder.CreateHuman(settings.ElementAt(7) , "节点6" , new GetUsers("originator") , flow.CustomActivityResult , null , seventh); var parallel_1 = WorkflowBuilder.CreateHuman(settings.ElementAt(5), "并行子节点1", new GetUsers("originator"), null); var parallel_2 = WorkflowBuilder.CreateHuman(settings.ElementAt(6), "并行子节点2", new GetUsers("getSuperior()"), null); //true var parallel = WorkflowBuilder.CreateParallel(settings.ElementAt(4), "并行节点", "true", sixth, parallel_1, parallel_2); var forth = WorkflowBuilder.CreateServer(settings.ElementAt(3) , "节点4", "'1'", null, v1, flow.CustomActivityResult, null, parallel); var third = WorkflowBuilder.CreateHuman(settings.ElementAt(2) , "节点3" , new GetUsers("originator", "getSuperior()", BaseTest.VariableUser) , flow.CustomActivityResult , null , forth); var second = WorkflowBuilder.CreateHuman(settings.ElementAt(1) , "节点2" , new GetUsers("originator") , flow.CustomActivityResult , null , third); flow.Body.StartNode = WorkflowBuilder.CreateHuman(settings.ElementAt(0) , "节点1" , new GetUsers("originator") , flow.CustomActivityResult , new Dictionary <string, FlowNode>() { { "同意", second } } , null); //有需要可在此初始化元数据 //Taobao.Activities.ActivityUtilities.InitializeActivity(flow); return(flow); }