官术网_书友最值得收藏!

Building Workflow Solutions

We've all been involved with software projects that try to improve a business process. The process might have involved pizza orders, or financial transactions, or health care. Invariably, the word workflow will arise as we talk about these projects. While the workflow might sound simple, we know the devil is always in the details. We'll need database tables and data access classes to manage the workflow state. We'll need components to send emails and components to wait for messages to arrive in a queue. We will also need to express the workflow itself for the computer to execute. Let's look at a theoretical implementation of a workflow:

// The workflow for a newly submitted Purchase Order
class PurchaseOrderWorkflow
{
public void Execute(PurchaseOrder order)
{
WaitForManagerApproval(order);
NotifyPurchaseManager(order);
WaitForGoods(order);
}
…
}

Assuming we have definitions for the three methods inside of Execute, can a workflow really look this simple? The answer is no. We'll have to add code for exception handling, logging, and diagnostics. We'll need to raise events and provide hooks to track and cancel a running workflow. Also, this workflow will be idle and waiting for an external event to occur, like the arrival of the purchased goods, for the majority of the time. We can't expect to block a running application thread for days or weeks while waiting for a delivery. We'll need to provide a mechanism to save the workflow's state of execution to a persistent data store and remove the running workflow instance from memory. When a significant event occurs, we'll need to restore the workflow state and resume execution.

Unfortunately, we will have so much code in and around the workflow that we will lose sight of the workflow itself. All the supporting code will hide the process we are trying to model. A non-technical businessperson will never be able to look at the code and see the workflow. A developer will need to dig through the code to find the workflow inside.

An improved workflow design will try to separate the definition of a workflow from the engine and supporting code that executes the workflow. This type of approach allows a developer, or even a businessperson, to express what the workflow should be, while the workflow engine takes care of how to execute the workflow. These days, many workflow solutions define workflows inside the loving embrace of angled brackets. Let's look at some theoretical XML for a workflow definition:

<Workflow Name="PurchaseOrderWorkflow">
<Steps>
<WaitForTask Event="ManagerApproval"/>
<NotifyTask Target="PurchaseManager"/>
<WaitForTask Event="Delivery"/>
</Steps>
<Parameters>
<Parameter Type="PurchaseOrder" Name="order"/>
</Parameters>
</Workflow>

Let's ask the question again — can a workflow really look this simple? The answer is yes; what we will need is a workflow engine that understands this XML, and can transform the XML into instructions for the computer. The engine will include all the required features like exception handling, tracking, and enabling cancellations.

Note

The C# code we saw earlier is an example of imperative programming. With imperative programming, we describe how to perform a task by providing a series of instructions to execute. The XML markup above is an example of declarative programming. With declarative programming, we describe what the task looks like, and let other software determine the steps required to complete the task. Most of the commercial workflow solutions on the market allow a declarative definition of workflow, because the declarative approach doesn't become cluttered with exception handling, event raising, and other lower-level details.

One of the benefits to using XML is the large number of tools with the ability to read, modify, create, and transform XML. XML is tool-able. Compared to parsing C# code, it would be relatively easy to parse the XML and generate a visualization of the workflow using blocks and arrows. Conversely, we could let a business user connect blocks together in a visual designer, and generate XML from a diagram.

Let's think about what we want in a workflow solution. We want to specify workflows in a declarative manner, perhaps with the aid of a visual designer. We want to feed workflow definitions into a workflow engine. The engine will manage errors, events, tracking, activation, and de-activation.

Enter Windows Workflow Foundation.

主站蜘蛛池模板: 邯郸县| 黎城县| 郯城县| 奉贤区| 浑源县| 青龙| 石嘴山市| 铁力市| 嘉黎县| 周至县| 汾阳市| 雅江县| 安溪县| 吉木萨尔县| 汶川县| 聊城市| 通榆县| 石景山区| 镇安县| 云浮市| 古田县| 会泽县| 古田县| 徐州市| 吉水县| 英德市| 阳曲县| 贺州市| 高陵县| 丁青县| 潢川县| 浠水县| 湘西| 莒南县| 乃东县| 丹寨县| 日喀则市| 正阳县| 思南县| 青海省| 仲巴县|