禁用流程图上的步骤

发布于 2025-01-03 08:55:49 字数 1132 浏览 0 评论 0原文

我想在执行之前禁用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苹果你个爱泡泡 2025-01-10 08:55:49

有两种方法可以做到这一点。

  1. 如果使用 ActivityXamlServices.Load 动态加载 XAML () 您可以在实际加载和执行 XAML 之前更新它。最终 XAML 就是 XML。
  2. 您可以将活动包装在 FlowDecision 活动中并且只在您想要的时候执行。

There are two ways you can do this.

  1. If you dynamically load the XAML using the ActivityXamlServices.Load() you can update the XAML before you actually load and execute it. In the end XAML is just XML.
  2. You can wrap the activities inside of FlowDecision activities and only execute when you want to.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文