禁用流程图上的步骤
我想在执行之前禁用 WF4 流程图上的某些步骤。 我的流程图非常简单,一个起始节点和 3 个序列,每个序列上都有一个 WriteLine 活动:“步骤 1”、“步骤 2”、“步骤 3”。
我想抑制“第 2 步”序列,因此控制台必须编写“第 1 步”\n“第 3 步”,这是我的代码(它适用于顺序工作流程,但不适用于流程图!!)
Activity a = new Activity1();
Activity customActivity = Customize(a);
WorkflowInvoker.Invoke(customActivity);
Console.ReadLine();
static System.Activities.Activity Customize(System.Activities.Activity scheme)
{
var activities = WorkflowInspectionServices.GetActivities(scheme);
var rootActivity = activities.FirstOrDefault();
if (rootActivity is Sequence)
{
var seqActivities = ((Sequence)rootActivity).Activities;
var badActivity = seqActivities.FirstOrDefault(a => a.DisplayName == "Step2");
seqActivities.Remove(badActivity);
}
if (rootActivity is Flowchart)
{
var seqActivities = ((Flowchart)rootActivity).Nodes.Cast<FlowStep>().ToList();
var badActivity = seqActivities.FirstOrDefault(a => a.Action.DisplayName == "Step2");
bool b = ((Flowchart)rootActivity).Nodes.Remove(badActivity);
}
return scheme;
}
谢谢为了您的帮助!
I would like to disable some steps on a WF4 flowchart, before execute it.
My flowchart is very simple, a start node and 3 sequences with a WriteLine activity on each one : "Step 1", "Step 2", "Step 3".
I would like to suppress the "Step 2" sequence, so the Console must write "Step 1" \n "Step 3", here is my code (It works pefectly with a sequential workflow, but not with a flowchart !!)
Activity a = new Activity1();
Activity customActivity = Customize(a);
WorkflowInvoker.Invoke(customActivity);
Console.ReadLine();
static System.Activities.Activity Customize(System.Activities.Activity scheme)
{
var activities = WorkflowInspectionServices.GetActivities(scheme);
var rootActivity = activities.FirstOrDefault();
if (rootActivity is Sequence)
{
var seqActivities = ((Sequence)rootActivity).Activities;
var badActivity = seqActivities.FirstOrDefault(a => a.DisplayName == "Step2");
seqActivities.Remove(badActivity);
}
if (rootActivity is Flowchart)
{
var seqActivities = ((Flowchart)rootActivity).Nodes.Cast<FlowStep>().ToList();
var badActivity = seqActivities.FirstOrDefault(a => a.Action.DisplayName == "Step2");
bool b = ((Flowchart)rootActivity).Nodes.Remove(badActivity);
}
return scheme;
}
Thx for your help !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种方法可以做到这一点。
There are two ways you can do this.