Windows 工作流 - IfElse 分支
我正在尝试使用 Windows 工作流并拥有一个与以下链接中的图像类似的模型:
在每个发送活动之后 (GetSomthing
, GetSomthingElse
、GetSomeMoreStuff
)正在调用相同的自定义活动 (LogSomthingBadHappened
)。
虽然在我的真实模型中这张图片中它看起来可能不是那么糟糕,但自定义活动是一个 SequenceActivty,有相当多的节点,当它重复 3 次时开始使工作流程看起来非常难看。
我想做像这样的东西:
IfElse
分支可以这样合并吗?
我应该使用状态机工作流程(还没有弄清楚这些)吗?
I am trying to use Windows Workflow and have a model that looks similar to the image in the link below:
After each of the Send Activities (GetSomthing
, GetSomthingElse
, GetSomeMoreStuff
) the same custom activity is being called (LogSomthingBadHappened
).
While it might not look so bad in this picture in my real model the custom activity is a SequenceActivty, has quite a few nodes, and when its repeated 3 times starts to make the workflow look very ugly.
I would like to do something like this:
Can the IfElse
branches be merged like this?
Should I be using a State Machine work flow instead (haven't figured these out yet)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在顺序工作流程中,所有步骤必须以特定顺序出现,并且执行路径仅由控制结构(IF、WHILE)进行调节。
按照您描述的方式更改执行路径就像在命令式代码中使用 GOTO 语句一样,我们知道这会导致不必要的复杂性。
如果您需要在工作流程的不同阶段执行的 SequenceActivity 中包含的活动完全相同,您可以将它们嵌入自定义活动中。 这样,管理它们就更容易了,因为它们包含在单个逻辑单元中。
在命令式代码中,这就像将一部分重复代码重构到一个方法中,然后在多个位置调用该方法。
In sequential workflows all steps must appear in a specific order, and the execution path is regulated exclusively by control structures (IF, WHILE).
Altering the execution path in the way you describe would be like using a GOTO statement in imperative code, which we know leads to unnecessary complexity.
If the activities contained in the SequenceActivity that you need to execute at different stages of your workflow are exacty the same, you could embed them in a custom activity. This way it is easier to manage them since they are contained in a single logical unit.
In imperative code, this would be like refactoring out a portion of duplicated code into a method, which is then invoked multiple places.
另一种可能有效的替代方法是将您的 LogSomthingBadHappened 活动放入自定义工作流程中并多次包含该活动。 需要注意的几件事: 子工作流异步执行< /a>,如果 LogSomthingBadHappened 活动需要来自主工作流程的状态信息,则将其复制到子工作流程可能会很困难。
我还没有尝试过这个,所以它可能不起作用。
Another alternative that might work is to put your LogSomthingBadHappened activity into a custom workflow and include that several time. Several things to watch out for: Subworkflow are executed asynchronously, if the LogSomthingBadHappened activity needs state information from the main workflow, copying it to the sub workflow might be hard.
I have not tried this, so it might not even work.
我认为 gbanfill 的答案指出了正确的方向。
概括而言,我将问题定义为:
是否有一种方法可以定义将在工作流的多个位置执行的一组活动?
进一步的要求是:
也许执行此操作的方法是定义子工作流并构建一个自定义活动,该活动将实例化子工作流并等待其完成然后再继续。
此自定义活动应至少有两个参数:子工作流 ID 和输入参数。
I think the answer by gbanfill points to the right direction.
To generalize, I define the problem as:
Is there a way to define a group of activities that will be executed in several places of a workflow?
Further requirements are:
Maybe the way to do it is define sub-workflows and build a custom activity that would instantiate the sub-workflow and wait for it to complete before continuing.
This custom activity should have at least two parameters: the sub-workflow id and input parameters.
在工作流上使用FaultHandler 并抛出处理程序将捕获的特定异常类型。 不是最优雅的,但我认为它应该有效。
Use a FaultHandler on the workflow and throw a specific exception type that the handler will catch. Not the most graceful, but I think it should work.