在 StateMachine 中使用 CallExternalMethodActivity/HandleExternalEventActivity

发布于 2024-08-03 02:35:32 字数 2233 浏览 7 评论 0原文

我试图让 StateMachine 在状态之间执行一些数据库操作。

因此,我有一个“启动”状态,它使用 CallExternalMethodActivity 在用ExternalDataExchangeAttribute 装饰的类上调用“BeginExecuteNonQuery”函数。之后,它使用 SetStateActivity 更改为“结束”状态。

“结束”状态使用 HandleExternalEventActivity 来侦听“EndExecuteNonQuery”事件。

我可以单步执行本地服务,进入“BeginExecuteNonQuery”函数。

问题是“EndExecuteNonQuery”为空。

public class FailoverWorkflowController : IFailoverWorkflowController
{
    private readonly WorkflowRuntime workflowRuntime;

    private readonly FailoverWorkflowControlService failoverWorkflowControlService;
    private readonly DatabaseControlService databaseControlService;

    public FailoverWorkflowController()
    {
        workflowRuntime = new WorkflowRuntime();
        workflowRuntime.WorkflowCompleted += workflowRuntime_WorkflowCompleted;
        workflowRuntime.WorkflowTerminated += workflowRuntime_WorkflowTerminated;

        ExternalDataExchangeService dataExchangeService = new ExternalDataExchangeService();
        workflowRuntime.AddService(dataExchangeService);

        databaseControlService = new DatabaseControlService();
        workflowRuntime.AddService(databaseControlService);

        workflowRuntime.StartRuntime();
    }

    ...
}

...

public void BeginExecuteNonQuery(string command)
{
    Guid workflowInstanceID = WorkflowEnvironment.WorkflowInstanceId;

    ThreadPool.QueueUserWorkItem(delegate(object state)
                                     {
                                         try
                                         {
                                             int result = ExecuteNonQuery((string)state);
                                             EndExecuteNonQuery(null, new ExecuteNonQueryResultEventArgs(workflowInstanceID, result));
                                         }
                                         catch (Exception exception)
                                         {
                                             EndExecuteNonQuery(null, new ExecuteNonQueryResultEventArgs(workflowInstanceID, exception));
                                         }
                                     }, command);
}

我的实施做错了什么?

-斯坦

I'm attempting to make a StateMachine execute some database action between states.

So I have a "starting" state that uses CallExternalMethodActivity to call a "BeginExecuteNonQuery" function on an class decorated with ExternalDataExchangeAttribute. After that it uses a SetStateActivity to change to an "ending" state.

The "ending" state uses a HandleExternalEventActivity to listen to a "EndExecuteNonQuery" event.

I can step through the local service, into the "BeginExecuteNonQuery" function.

The problem is that the "EndExecuteNonQuery" is null.

public class FailoverWorkflowController : IFailoverWorkflowController
{
    private readonly WorkflowRuntime workflowRuntime;

    private readonly FailoverWorkflowControlService failoverWorkflowControlService;
    private readonly DatabaseControlService databaseControlService;

    public FailoverWorkflowController()
    {
        workflowRuntime = new WorkflowRuntime();
        workflowRuntime.WorkflowCompleted += workflowRuntime_WorkflowCompleted;
        workflowRuntime.WorkflowTerminated += workflowRuntime_WorkflowTerminated;

        ExternalDataExchangeService dataExchangeService = new ExternalDataExchangeService();
        workflowRuntime.AddService(dataExchangeService);

        databaseControlService = new DatabaseControlService();
        workflowRuntime.AddService(databaseControlService);

        workflowRuntime.StartRuntime();
    }

    ...
}

...

public void BeginExecuteNonQuery(string command)
{
    Guid workflowInstanceID = WorkflowEnvironment.WorkflowInstanceId;

    ThreadPool.QueueUserWorkItem(delegate(object state)
                                     {
                                         try
                                         {
                                             int result = ExecuteNonQuery((string)state);
                                             EndExecuteNonQuery(null, new ExecuteNonQueryResultEventArgs(workflowInstanceID, result));
                                         }
                                         catch (Exception exception)
                                         {
                                             EndExecuteNonQuery(null, new ExecuteNonQueryResultEventArgs(workflowInstanceID, exception));
                                         }
                                     }, command);
}

What am I doing wrong with my implementation?

-Stan

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

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

发布评论

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

评论(2

放飞的风筝 2024-08-10 02:35:32

我无法从代码片段中看出,但请确保您使用ExternalDataExchangeService 来托管您的服务,并且不要将您的服务直接添加到运行时。 ExternalDataExchangeService 负责添加所需的事件处理程序并将事件转换为工作流的排队消息。

I can't tell from the code snippet but make sure you are using the ExternalDataExchangeService to host your service and don't add you service directly to the runtime. The ExternalDataExchangeService is responsible for adding the required eventhandlers and turning the events into queued messages for the workflow.

忘东忘西忘不掉你 2024-08-10 02:35:32

我通过更改配置文件来使用没有代码的ExternalDataExchangeService,如下所示 此处

I'm using ExternalDataExchangeService without code by changing my config file as shown here :

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