电梯工作流程 [英] Elevator workflow

查看:122
本文介绍了电梯工作流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过阅读一些书来学习Windows Workflow Foundation。我想开发一个演示应用程序,使其更实用。我虽然关于模拟电梯的应用程序。

电梯有一些状态(可能还有更多,比如太重,但为了保持简单,我忘了那些)
*移动
*门打开
* Doos关闭
*空闲

每层都有一个按钮面板(上下按钮,顶层和底层除外)。这些按钮用于请求电梯。

在电梯内部有一个面板,每个楼层都有一个按钮。

这些事件(按下外部面板按钮或内部面板按钮)可以随时触发。

首先我必须选择工作流程类型。我正在考虑不同州的电梯,因此状态机是合适的。或者我错了?

然后我想知道如何处理按钮事件。我知道我可以使用HandleExternalEvent活动,但工作流应该显式监听这些事件。如果电梯处于移动事件(从一个楼层到另一个楼层)并且一个人按下电梯内的按钮怎么办?在我看来,如果工作流程不在监听模式下,将忽略此事件。

所以我想在此提供有关如何实施电梯工作流程的反馈。谢谢你给我建议。

I am learning the Windows Workflow Foundation by reading some books. I want to develop a demo application to make it more practical. I though about an application which simulates an elevator.

The elevator has some states (there are maybe even more, like too much weight but to keep it simple I forget those)
* Moving
* Doors open
* Doos closed
* Idle

Each floor has a button panel (up and down button, except for the top and bottom floors). These buttons are to request the elevator.

Inside the elevator there is a panel which has a button for each floor.

These events (pushing outside panel buttons or inside panel buttons) can be triggered at any moment.

First I have to choose the workflow type. I was thinking about an elevator in different states, so a state machine would be appropiate. Or am I wrong?

Then I was wondering how to handle the button events. I know that I can use HandleExternalEvent activities but the workflow should listen explicit to those events. What if the elevator is in a moving event (from one floor to another) and a person pressed a button inside the elevator. Looks to me that this event will be ignored if the workflow is not in a listen mode.

So I would like to here your feedback about how to implement a Elevator workflow. Thanks for giving me advice.

推荐答案

是的,你需要用HandleExternalEvent创建一个StateMachineWorkflow。
然后为Elevator定义一个接口服务(用 ExternalDataExchange 属性)并声明一些事件:
移动,左门打开,门关闭,
空闲

确定。基本上,当你按下一个按钮时,你将调用Moving事件,这将在WF中处理,一段时间后,这将把新状态设置为DoorsOpen。在DoorsOpen事件驱动的活动中,在跳转到DoorsClosed状态之前,您可以拖动延迟活动。
现在,为了解决同步问题(当您按下按钮并且电梯正在移动时),您可以保留命令队列。如果电梯未处于空闲状态,您将在队列中添加新命令。因此,当按下按钮时,您可以测试" CurrentStateName "是"移动" state,如果是,则在队列中添加命令,直到currentstate进入空闲状态。

您可以获得CurrentStateName,如:
StateMachineWorkflowInstance instance = < span style ="color:#0000ff"> new StateMachineWorkflowInstance(wfR
untime,instanceId);
并获取 instance.CurrentStateName

之后,设置一个计时器来调用如果状态为空闲,则来自队列的命令。这将调用所有状态,直到所有电梯命令都被处理完毕。

Calin Tatar
Yes, you need to create a StateMachineWorkflow, with HandleExternalEvent's.
Then define an interface for the Elevator service(decorated with ExternalDataExchange attribute) and declare some events:
Moving,
DoorsOpen,
DoorsClosed,
Idle

OK. basically, when you'll press a button you'll invoke the Moving event, and this will be handled in the WF and after some time this will set the new state as DoorsOpen. In DoorsOpen event driven activity, before jumping to DoorsClosed state, you may drag a Delay activity.
Now, to solve the syncronization issue (when you press a button and the elevator is moving), you may keep a Queue of commands. If the elevator is not in the Idle state, you'll add a new command in the queue. So, when pressing the button, you may test if the "CurrentStateName" is the "Moving" state, if yes, add the command in the queue until the currentstate goes to Idle.

You may get the CurrentStateName like:
StateMachineWorkflowInstance instance = new StateMachineWorkflowInstance(wfRuntime, instanceId);
and get instance.CurrentStateName

After that, set a timer to call the commands from the queue, if the state is Idle. This will call all the states, until all elevator commands were handled.


Calin Tatar


这篇关于电梯工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆