如何加载运行实例与实例存储乘工作流定义时,服务器重启实例、工作流、重启、加载

2023-09-03 22:02:01 作者:我男神叫權志龍

我评估工作流基础4或4.5,并且想知道如何加载运行实例从实例存储在服务器重新启动?

I'm evaluating Workflow Foundation 4 or 4.5, and want to know how to load runnable instances with multiply workflow definitions from instance store when server restart?

这是同样的问题在论坛主题:http://social.msdn.microsoft.com/Forums/en-US/wf$p$prelease/thread/b8d5ed34-054a-4e55-88e1-cd430ac42110?prof=required

It's same question as the forum topic: http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/b8d5ed34-054a-4e55-88e1-cd430ac42110?prof=required

当使用InstanceStore.WaitForEvents,所述HasRunnableWorkflowEvent事件引发如果任何实例准备,而且,调用WorkflowApplication.LoadRunnableInstance(),我们需要创建一个新WorkflowApplication,并且它要求权利的工作流定义,它是具有当只有1的工作流程的实现。但是,如果有倍数类型和同样InstanceStore相关联的工作流,并且由于HasRunnableWorkflowEvent不具有在现成实例的任何其它信息将由LoadRunnableInstance()被加载,就可以容易知道是什么类型的实例,我们必须创造新的WorkflowApplication。

"When using the InstanceStore.WaitForEvents, the HasRunnableWorkflowEvent event is raised if any instance is ready. And, to call the WorkflowApplication.LoadRunnableInstance (), we need to create a new WorkflowApplication, and it require the right workflow definition. It's easy when having only 1 workflow implementation. But, if there are multiples types of workflows associated with the same InstanceStore, and because the HasRunnableWorkflowEvent doesn't have any other informations on the ready instance that will be loaded by the LoadRunnableInstance (), we can't know what type of instance we must create for the new WorkflowApplication."

但答案提示:

的唯一方法是用WorkflowApplication托管时,有一个单独的实例存储为每个工作流定义。

The only way is to have a separate instance store for each workflow definition when hosting with WorkflowApplication.

我错过了什么?

推荐答案

您可以有多种类型的在单店的工作流定义,但你需要跟踪哪些工作流定义的用于启动工作流。这是你的问题。在我目前的项目中,我们解决了这个使用以下。

You can have multiple kind of workflow definitions in a single store but you need to keep track of which workflow definition you used to start the workflow. Which is your problem. In my current project we solved this using the following.

我们使用周围的WorkflowApplication类包装类,并用它来启动工作流。在这种包装,才真正开始工作流,我们写在我们店很快将要运行的eorkflow定义的数据库表中的一个WorkflowInstance记录。除了其他一些信息,我们还为'坚持-ID',这是由WorkflowApplication对象所生成的ID的列。我们不知道这个ID,当我们启动工作流,所以我们离开此列空。当运行的工作流实例持久化(你可以的通知通过处理WorkflowApplication对象上的事件),则可以检索由WorkflowApplication对象生成的ID。与坚持-ID更新您的WorkflowInstance,并在工作流后重新启动服务器重新加载,可以我们的ID检索workflowdefinition。

We use a wrapper class around the WorkflowApplication class, and use this to start the workflow. In this wrapper, before we actually start the workflow we write a WorkflowInstance record in a table in a database where we store the definition of the soon-to-be-running eorkflow. Aside from some other info, we also have a column for the 'persisted-id', which is the id generated by the WorkflowApplication object. We do not know this id when we start the workflow, so we leave this column empty. When the running workflow instance is persisted (which you can be notified of by handling an event on the WorkflowApplication object), you CAN retrieve the id generated by the WorkflowApplication object. Update your WorkflowInstance with the persisted-id, and when the workflow is to be reloaded upon a server restart, you can us the id to retrieve the workflowdefinition.

希望这有助于。工程就像这里的魅力。

Hope this helps. Works like a charm here.