WinFX_Workflow学习笔记-关于WF引擎架构

本来想翻译以下的,可是太多了,翻译下来这一天就不用干别的了,呵呵。这里主要是介绍了WF引擎的架构。分析了不同Layer的关系、功能和实现。摘自《Presenting Windows Workflow Foundation, Beta Edition》。
Windows Workflow Foundation Engine Architecture
Given the breadth of scenarios requiring workflow and the key goal of providing a singular technology layer to support all these scenarios, the workflow technology is a well-factored framework with numerous pluggable interfaces and extensibility as a core design principle. The architecture for Windows Workflow Foundation is depicted in Figure 1.1.


Figure 1.1. Windows Workflow Foundation engine architecture.
1.JPG


At the bottom of Figure 1.1 is the host process. Windows Workflow Foundation has no inherent execution process. Instead, Windows Workflow Foundation is an in-process engine that runs inside a host process. The host process is responsible for providing a set of services to Windows Workflow Foundation. A wide variety of host processes are available on the Windows platform including console applications, WinForms applications, web applications, web services applications, SharePoint Server, and NT Service applications. Effectively, any executable process can host the Windows Workflow Foundation runtime engine.

This also presents some interesting challenges because the capabilities of each host are often different to another host. SharePoint is a dramatically different environment than a console application. For this reason the Windows Workflow Foundation architecture hosting layer provides a set of pluggable interfaces from Windows Workflow Foundation to the host.

Sitting on top of the hosting layer in the Windows Workflow Foundation architecture is the runtime layer. The runtime layer is the core of the engine providing both workflow execution and workflow lifecycle management capabilities.

Finally, the workflow model layer is where most developers will interact with Windows Workflow Foundation. The workflow model layer includes the various workflow models, APIs, and the activities. The following sections provide more details on the hosting, runtime, and workflow model layers.

Hosting Layer
The hosting layer provides interfaces between Windows Workflow Foundation and a particular host for the following key services: Communication, Persistence, Tracking, Timer, Threading, and Transaction. The implementations of the former three services that ship with Windows Workflow Foundation are durable while the latter two services are stateless. However, none of the services are necessarily durable if you write your own. By abstracting each of these services Windows Workflow Foundation can take advantage of specific capabilities available in specific hosts. The following sections describe the functions performed by each of these services:

Persistence:xs Although some workflows may execute for a short period of time, workflow is inherently asynchronous and a particular workflow, such as the Ph.D. thesis approval process, may take many days or months. A workflow engine that retained its state in memory for that period would not scale as each instance of the workflow would consume memory for the duration and eventually the system memory would be exhausted. Instead, a persistent architecture is used where workflow is executed in memory, and should it be required, the workflow state will persist to a store while it waits for a response that might take some time such as the "Ph.D. approved" step in the workflow. Each host application has a specific set of persistence requirements. For example, to persist state, ASP.NET uses a set of Session State objects that has state client providers for in-memory persistence and SQL Server persistence. In contrast, SharePoint persists state in a SharePoint-specific set of tables in SQL Server and your console application may choose to persist state to the file system as XML. With such a large variety of host-specific persistence capabilities, it would not be sensible for a broadly applicable technology such as Windows Workflow Foundation to specify a single persistence provider. The Windows Workflow Foundation hosting layer persistence interface enables Windows Workflow Foundation to work across the full gamut of host persistence architectures.

Timer: Workflows often need to wait for an event to continue. The timer is the supplied clock that is used to manage these delays. For example, an approval workflow may delay and unload from memory until a particular approver completes the necessary approval. The timer implementation in this case might be a durable timer that survives a potential system restart while waiting for approval.

Tracking: A key reason to implement workflow is because the workflow model provides a greater degree of system transparency at runtime than amorphous code. Indeed, all workflows are automatically instrumented without any programming. The tracking instrumentation is consistent across both the event content and the tracking interface. Depending on the host, the target tracking infrastructure is often different. For example, a LOB application often persists workflow tracking information within the LOB database whereas a console application may persist tracking information to an XML file. The tracking interface receives tracking events from the Windows Workflow Foundation runtime and passes them on to the host application.

Communications: Workflows send and receive events or messages from their host. These events trigger workflows, and move the workflow to the next step in the overall flow. There are a wide variety of communications infrastructures available on the Windows platform including web services, .NET calls, loosely coupled messaging, and so on. For this reason, Windows Workflow Foundation does not provide its own proprietary communications layer. Instead, Windows Workflow Foundation provides pluggable interfaces that can be implemented for any communications layer. Of course, there are easy-to-use, prebuilt communication interfaces to and from common targets such as web services and for passing data objects in and out of a workflow—perhaps from a form.

The physical job of development of these interfaces for specific hosts is relatively challenging compared to other aspects of workflow development described shortly. For this reason, ISVs will typically build host layer providers into their host applications so that end-user developers can simply reuse these services. In addition, Windows Workflow Foundation ships prebuilt support for ASP.NET 2.0 and the interfaces shown in Table 1.1.

Table 1.1. Prebuilt Host Layer Service Implementations
___________________________________________________________________
Host Layer Service Implementation

Persistence SQL Server state persistence

Timer Both an in-memory and SQL Server–based timer

Threading .NET thread pool/ASP.NET thread pool

Tracking SQL Server Tracking Persistence and Event Log recording for termination
Communications .NET components and web services
___________________________________________________________________




Sitting on top of the hosting layer is the runtime layer.

Runtime Layer
The runtime layer is core to Windows Workflow Foundation. In direct comparison to the other layers in the architecture, the runtime layer is not pluggable as it contains the mission-critical services required for workflow. These services include the following:

Execution: The execution service schedules activities and supports common behaviors such as event handling, exceptions, tracking, and transactions.

Tracking: The tracking service creates the tracking events that are serialized through the tracking interface.

State management: The state management service manages states that may be persisted through the persistence interface.

Scheduler: The scheduler service schedules execution of activities.

Rules: The rules service provides policy execution functionality and CodeDOM condition evaluation.

Workflow Model Layer
The workflow model layer is where most application developers will spend the majority of their time writing code for Windows Workflow Foundation. This layer includes support for multiple workflow model types, activities, and the main programming APIs use by most developers.

Windows Workflow Foundation supports two models out of the box:

Sequential workflow model: This model is primarily a structured workflow where a step in the workflow leads to another step in a manner that may be determined often at design-time and can be represented in a flow diagram such as that shown in Figure 1.2.

Figure 1.2. Sequential workflow.
2.JPG

Sequential workflows are most often used to represent structured workflows such as system-to-system workflow. These transformational workflows are self-driven once they are initiated, have a highly predictable path through the events, and are often literally sequential in nature.

State machine workflow model: This model uses the paradigm of states and transitions between states to represent the workflow. There is no deterministic path between the steps from a design perspective because the workflow does not execute in a sequential nature. Rather, the workflow is a set of events that are handled in a highly variable order with one event completing and triggering a state that another event may itself trigger from. The state machine model can literally jump from any stage in the workflow to any other stages, and often will do so multiple times before reaching a completed state. The order workflow is a state machine where various messages are received and trigger the workflow to progress to a particular state. Each iteration of this workflow may result in a different path through the model as depicted in Figure 1.3.


Figure 1.3. State machine workflow model.
3.JPG


State Machine Workflows are an effective way of representing highly people-centric workflows where the workflow thread of execution is not easily represented in a flow. This workflow model is also very useful for scenarios where a high priority event must be processed even though work is already in process or when a large number of events may occur at a particular stage in the workflow. A perfect example is a stage in the order workflow where an "order cancelled," "order updated," and "order completed" event that may be received at any time and should immediately cancel the entire process.

Although Windows Workflow includes these two models, customers can inherit from them to create their own specific models or create new models.

Regardless of model and sequencing behavior the basic element of execution and reuse is called an activity. An example of an activity is "send goods" in the previous sequential workflow example.

There are two types of activities—the simple activity and the composite activities. What makes Windows Workflow Foundation very different from traditional workflow engines is that the engine has no fixed underlying language or grammar. Instead the engine chains a set of activities that are supplied by Microsoft and created by you the developer. Microsoft-supplied constructs include "If," "Code" blocks, activities for web services, and many more. In addition, you can create your own control flow activities such as "do until" but more likely you will be creating higher level activities such as the "Receive Order" activity described previously. By using an activity execution methodology rather than a language, Windows Workflow Foundation is able to support a broad range of scenarios and you can reuse your activities across multiple workflows. Indeed the flow and the state workflow models share a majority of activities with some specific inclusions and exclusions to each model. Activities become the unit of encapsulation in much the same way that ActiveX controls were for Visual Basic 6 applications. It is expected that customers and partners will share activities in the community and generate business from activity creation.

The set of flow control activities that ship with Windows Workflow Foundation include the following:

Control flow activities: Sequence, Parallel, While, IfElse, Listen, EventDriven, ConditionedActivityGroup, Replicator, Delay

Transaction and exception activities: ExceptionHandler, Throw, Compensate, Suspend, and Terminate

Data/form-centric activities: UpdateData, SelectData, WaitForData, WaitForQuery

Communication activities: InvokeWebService, WebServiceReceive, WebServiceResponse, InvokeMethod, and EventSink

The code activity: Code

There are three additional activities that are specific for the state machine workflow model: StateInitalization, State, and SetState.

Each activity is derived from the Activity base class and includes the code that will execute when the activity and a set of design-time properties for use in the designer is called. Later chapters in this book will go into detail on each of these activities; however, a few activities are worth mentioning here. The data- and form-centric activities enable you to bind data from forms and easily surface that information into a workflow; the web services activities give you the capability to consume and expose web services; more advanced activities such as the conditioned activity group enable policy- or rules-based condition evaluation.

Over time, many activities will become available through the broader activity ecosystem through blogs and shared source as well as through Microsoft partners.

Now that we have addressed activities in detail it is important to point out that the model itself is nothing more than a "root" level activity in the Windows Workflow Foundation infrastructure.

One of the significant features of Windows Workflow Foundation is that it offers you the ability to dynamically create workflow at runtime and dynamically update an existing workflow. This is discussed in more detail later in this book.

Now that you have completed your tour of the Windows Workflow Foundation architecture, it's time to examine the coding and design-time support for you to interact with the engine.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于计算机专业的学生而言,参加各类比赛能够带来多方面的益处,具体包括但不限于以下几点: 技能提升: 参与比赛促使学生深入学习和掌握计算机领域的专业知识与技能,如编程语言、算法设计、软件工程、网络安全等。 比赛通常涉及实际问题的解决,有助于将理论知识应用于实践中,增强问题解决能力。 实践经验: 大多数比赛都要求参赛者设计并实现解决方案,这提供了宝贵的动手操作机会,有助于积累项目经验。 实践经验对于计算机专业的学生尤为重要,因为雇主往往更青睐有实际项目背景的候选人。 团队合作: 许多比赛鼓励团队协作,这有助于培养学生的团队精神、沟通技巧和领导能力。 团队合作还能促进学生之间的知识共享和思维碰撞,有助于形成更全面的解决方案。 职业发展: 获奖经历可以显著增强简历的吸引力,为求职或继续深造提供有力支持。 某些比赛可能直接与企业合作,提供实习、工作机会或奖学金,为学生的职业生涯打开更多门路。 网络拓展: 比赛是结识同行业人才的好机会,可以帮助学生建立行业联系,这对于未来的职业发展非常重要。 奖金与荣誉: 许多比赛提供奖金或奖品,这不仅能给予学生经济上的奖励,还能增强其成就感和自信心。 荣誉证书或奖状可以证明学生的成就,对个人品牌建设有积极作用。 创新与研究: 参加比赛可以激发学生的创新思维,推动科研项目的开展,有时甚至能促成学术论文的发表。 个人成长: 在准备和参加比赛的过程中,学生将面临压力与挑战,这有助于培养良好的心理素质和抗压能力。 自我挑战和克服困难的经历对个人成长有着深远的影响。 综上所述,参加计算机领域的比赛对于学生来说是一个全面发展的平台,不仅可以提升专业技能,还能增强团队协作、沟通、解决问题的能力,并为未来的职业生涯奠定坚实的基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值