递归调用 Windows 工作流

发布于 2024-08-14 06:41:11 字数 622 浏览 7 评论 0原文

我有一个工作流程,在某个时刻需要递归触发。

我似乎不知道该怎么做。

我尝试了以下代码,但上下文最终为空?

private void codeTriggerChildren_ExecuteCode(object sender, EventArgs e)
{
    ActivityExecutionContext context = sender as ActivityExecutionContext;
    //context is null here?!

    IStartWorkflow aWorkflow = context.GetService(typeof(ApprovalFlow)) as IStartWorkflow;

    Dictionary<string, object> parameters = new Dictionary<string, object>();
    parameters.Add("Parm1", "foo");
    parameters.Add("Parm2", "bar");

    Guid guid = aWorkflow.StartWorkflow(typeof(ApprovalFlow), parameters);
}

I have a workflow, that at a certain point, needs to be triggered recursively.

I can't seem to figure out how to do this.

I tried the following code but context ends up being null??

private void codeTriggerChildren_ExecuteCode(object sender, EventArgs e)
{
    ActivityExecutionContext context = sender as ActivityExecutionContext;
    //context is null here?!

    IStartWorkflow aWorkflow = context.GetService(typeof(ApprovalFlow)) as IStartWorkflow;

    Dictionary<string, object> parameters = new Dictionary<string, object>();
    parameters.Add("Parm1", "foo");
    parameters.Add("Parm2", "bar");

    Guid guid = aWorkflow.StartWorkflow(typeof(ApprovalFlow), parameters);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

╄→承喏 2024-08-21 06:41:11

这里的主要问题是,本例中的发送者是 CodeActivity,而不是 ActivityExecutionContext。所以这段代码在第一个障碍处就失败了。

下面是一个自定义活动的示例,可以执行您想要的操作:-

public class RecurseApproval : Activity
{
    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        IStartWorkflow aWorkflow = executionContext.GetService(typeof(IStartWorkflow)) as IStartWorkflow;

        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("Param1", "Foo");
        parameters.Add("Param2", "bar");

        Guid guid = aWorkflow.StartWorkflow(typeof(ApprovalWorkflow), parameters);

        return ActivityExecutionStatus.Closed;

    }
}

请注意,GetService 获取 IStartWorkflow 类型。

Primarily the problem here is that the sender in this case is a CodeActivity not an ActivityExecutionContext. So this code fails at the first hurdle.

Here is an example of custom activity that can do what you are after:-

public class RecurseApproval : Activity
{
    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        IStartWorkflow aWorkflow = executionContext.GetService(typeof(IStartWorkflow)) as IStartWorkflow;

        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("Param1", "Foo");
        parameters.Add("Param2", "bar");

        Guid guid = aWorkflow.StartWorkflow(typeof(ApprovalWorkflow), parameters);

        return ActivityExecutionStatus.Closed;

    }
}

Note that the GetService gets type of IStartWorkflow.

等风来 2024-08-21 06:41:11

您的发送者的类型为 CodeActivity 而不是 ActivityExecutionContext。您需要创建一个自定义活动并重写 Execute 方法,该方法将向您传递 ActivityExecutionContext。

Your sender is of type CodeActivity not ActivityExecutionContext. You need to create a custom activity and override the Execute method which will pass you a ActivityExecutionContext.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文