• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
WF Training
 

WF Training

on

  • 2,341 views

http://www.intertech.com/Courses/Course.aspx?CourseID=99332

http://www.intertech.com/Courses/Course.aspx?CourseID=99332

This slide deck on WF was part of Intertech's DevBlitz event

Statistics

Views

Total Views
2,341
Views on SlideShare
2,340
Embed Views
1

Actions

Likes
1
Downloads
0
Comments
0

1 Embed 1

http://www.lmodules.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    WF Training WF Training Document Transcript

    • Brian Myers, Author of “Foundations of WF: An Introduction to Windows Workflow Foundation” • Software Engineer and Database Administrator • Over 8 years of experience as software developer, DBA, and Project Manager • MCP, MCAD for .NET, MCSD for .NET • Author of “Foundations of WF: An Introduction to Windows Workflow Foundation” published by Apress • Also author of “Beginning Object-Oriented ASP.NET 2.0 with VB.NET” published by Apress • Author of several articles for ASPToday.com Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 2
    • • Introduction to Workflow • Requirements for creating WF applications • WF Architecture • First workflow project • Out of the Box Activities • Code Activity and Passing Parameters • Conditional Activities • Flow Activities • Rules-base workflow • Custom Activities • Workflow as a web service Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 3 • How do you define workflow? Any experience with workflow apps? • My definition of workflow: How an item is moved from one person to another through a process • Vacation request workflow example • Employee provides some information • Employee passes information to supervisor • Supervisor determines if time available • Supervisor approves and sends to HR • HR verifies polices have been followed • Accounting performs payroll adjustment at appropriate time Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 4
    • • State-Based workflow • Each step in the flow has criteria that must be met before the flow can continue • Waits for external entity to perform some action • Vacation request example is state based because an external entity (employee, supervisor, etc.) must change the state of the workflow • Sequential workflow • Workflow with steps performed one right after the other with no external entity interaction (except to start the flow) • Sequential refers more to continuous operation instead of the order in which actions are performed • Updating a sales order as complete and sending an email to the customer when a sales order has shipped is an example. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 5 • The traditional concept of sequential in programming is without branching. For example, sequentially reading a file reads one line at a time. • Within a workflow branching is when a decision needs to be made. For example, supervisor must decide if an employee has vacation time to use • For each branch in a workflow there must be at least two alternatives, you can not have a workflow stop at a decision point Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 6
    • • Sequential workflow within WF follows the traditional thinking of workflow, the workflow is in control. • As long as a process is simple and rarely goes out of bounds a sequential workflow will work well • State based workflow deals with different states. If a process has many different iterations it’s a candidate for a state based workflow • For example, a help desk system which allows the user submitting the ticket to verify the fix and decide the ticket is not closed is a good candidate for state based. As a ticket moved thru the system it may have many different “states” or statuses. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 7 • Creating a workflow creates a model of the real world • Most applications that facilitate a business process have a model associated with them, might be use cases or UML diagrams or a simple flow chart • With WF the model and the workflow are the same thing • Previously you could create UML diagrams or flow charts but still needed to take that physical representation and create code to facilitate the process • WF gives you the ability to model the process and only need to add a minor amount of code to tie everything together Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 8
    • • A software developer technology • It's the programming model, engine and tools for building workflow-enabled software on Windows • It gives software developers a model driven tool which is higher level but still integrated with .NET code • It's seriously extensible to enable a wide range of software development projects that require process execution or business logic execution From Paul Andrew’s Blog (http://blogs.msdn/pandrew/) dated 1/16/2007 Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 9 • A software product • It doesn't have a server process that you can directly run in a data center, you have to build this or integrate with IIS • It doesn't have administrative tools, reporting tools, management tools or monitoring tools. • The workflow designer is best suited to developers, not business analysts. Though I have heard of some projects using our designer with a business analyst buddying with a software developer and our designer is freely redistributable. • It doesn't have tools that IT Pros need or end users need. It's focused only on what software developers need From Paul Andrew’s Blog (http://blogs.msdn/pandrew/) dated 1/16/2007 Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 10
    • To review WF is a great technology for building software that has process, workflow or business logic requirements. Software products can benefit from this by using a common low level engine and focus on implementing business value for their users. But don't think WF is a product you can directly deploy for an end customer. From Paul Andrew’s Blog (http://blogs.msdn/pandrew/) dated 1/16/2007 Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 11 • Must have Microsoft .Net Framework 3.0 • To create workflow applications within Visual Studio must have Visual Studio 2005 Extensions for .NET Framework 2.0 (Windows Workflow Foundation) • To create workflow as a web services (as will be demonstrated) must have IIS installed • Does not require Vista • OS: Longhorn, Windows Server 2003 Services Pack 1, Windows Vista, Windows XP Service Pack 2 • If you already have .NET Framework 2.0 installed .NET Framework 3.0 installs only the new Windows Vista components. Does not require migration of .NET Framework 2.0 applications Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 12
    • • The first component of WF is the programming model • Programming model is made up of exposed APIs that other programming languages can use to interact with the workflow engine • APIs encapsulated within the System.Workflow namespace of the .NET Framework • Visual Studio includes new extensions that allow you to create workflow applications using a new Workflow Designer. Allows you to create workflow using drag and drop Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 13 • Second component of WF is actual workflow • Workflow within WF is made up of a group of activities • Activities facilitate a business process or part of a business process. • A single workflow is made up of one or more activities • WF includes a base activity library of “out-of-the-box” activities that provide general functionality Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 14
    • • WF runtime engine executes workflow, made up of activities, and created with the Workflow Designer • Also provides services such as scheduling, state management, and rules • Scheduling service allows activities within a workflow to be scheduled • State management services allows the state of the workflow to persist • Rules allow workflow to be created based on business rules and activities can be executed or not executed based on those rules Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 15 • WF does not have an executable environment • Another process must host the runtime engine and workflows • Can be a windows application or ASP.Net application or others • During development VS 2005 is the host process Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 16
    • • Code Time! • Lab 1 Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 17 • As you have seen, by viewing the Toolbox within VS, WF provides many out of the box activities to accomplish common workflow actions. • These out of the box activities can be placed within a workflow via drag and drop Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 18
    • • The code activity allows you to add your own VB or C# code to the workflow. This is a very simple form of the custom activity. • The actual code will reside in a “code beside” file and gets compiled with the workflow. • Any code entered here executes synchronously, so the workflow must wait for it to complete. • This activity should not be used for tasks that may stall such as those that rely on an external source for data. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 19 • This is an exception handling activity and can only be added to an exception handler activity. • This activity is used to undo actions already performed by workflow after an error has occurred. • This is the equivalent of rolling back a transaction. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 20
    • • Executes other activities based on a condition that applies to the conditional activity group or to the activity that is linked to the conditional activity group. • Use this grouping of activities to execute a set of activities based on criteria specified for each activity in the group until some condition is met for the group as a whole. • This would allow a group of activities to be executed in parallel since they each have their own criteria for defining when the activity is complete. • You can use a WhenCondition on an activity within the group and an UntilCondition on the group as a whole. • All activities continue to execute, if a WhenCondition is provided for the activities, unless the UntilCondition on the group is met. At the time the UntilCondition on the group is satisfied the entire group will stop executing. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 21 • This is a flow activity. Allows you to build in interval based pauses into your workflow. With this activity you can set a duration that the workflow will pause before continuing to execute. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 22
    • • This is a flow activity. This activity contains other activities that are to be executed when an event occurs. The event is subscribed to by child activities such as the DelayActivity which wait for external events to happen. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 23 • This is an error handling activity. The Fault Handler activity performs very much like the Catch block in code. • A workflow can have many of these activities to handle the various types of exceptions that could occur within the workflow. • The Fault Handler activity can contain other activities that are fired when an exception is encountered. This could include a Compensate activity. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 24
    • • This is a conditional activity. Use the IfElse activity to execute a branch of activities based on a condition. • The first branch must have a condition but the last branch does not require a condition (this is the else part of the activity). • The execution is the same as an If Else statement, the first successful branch execution ends the execution of the activity. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 25 • This workflow affects the life of a workflow. This activity is used to execute one workflow from another. • When executed, this activity completes and then launches the second workflow. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 26
    • • This workflow affects the life of a workflow. This activity invokes a web service using a proxy class and can pass and receive parameters. • When invoking a web service with this activity you specify a method of the web service to invoke. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 27 • This activity is a composite activity (made up of a minimum of two activities). Each activity that makes up the listen activity must be an EventDriven activity. • The first event raised by an EventDriven activity will be executed and the other EventDriven activity or activities within the Listen activity will not be executed. • A Listen activity can not be used in a state machine workflow. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 28
    • • This activity is a composite activity, it is made up of two ore more Sequence activities. The Parallel activity allows the execution of more than one activity at the same time. • The activity is not complete until all Sequence activities that make up the Parallel activity have completed. • You need to be careful with the parallel activity as more than one sequence activity within the parallel activity may attempt to access the same data and could cause conflicts. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 29 • The Policy activity can be used to represent a collection of rules. A rule has a condition and action or actions that should be taken when that condition is met. • The policy allows you to setup rules based workflow that can have many conditions instead of using a series of IfElse activities. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 30
    • • The Replicator activity is conditional activity and similar to the For Each statement. • The Replicator creates a number of instances of a single activity while running. • All instances must complete before the Replicator activity can complete. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 31 • This is a flow activity and a composite activity. This activity provides an easy way to link activities, to be executed in sequence, together. • All activities in the sequence are executed before the sequence is complete. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 32
    • • This activity is a flow activity. This activity is used to specify a transition to a new state within a state machine workflow. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 33 • This is a flow activity. This activity represents a state, which is the main component of a state machine workflow, within a state machine workflow. • The state activity makes up the build block of the state machine workflow. • When an event is handled within a state machine workflow a different state activity is entered to handle that state. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 34
    • • This activity is a flow activity and a composite activity. This activity is part of a State activity and is made up of other activities that are to be executed when the State activity is first entered. • This activity does not need to respond to events. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 35 • This is a flow activity. The Suspend activity pauses the operation of a workflow to allow intervention to occur if an error condition requiring special attention is encountered. • When this activity is executed an error is logged. A workflow that has been paused can still receive messages, but those messages are queued. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 36
    • • This is a flow activity. This activity immediately ends a workflow’s operation if an error condition is met. • Unlike the Suspend activity, which only pauses the workflow when a serious error occurs this activity stops the workflow. This activity also logs an error. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 37 • This is an error handling activity. Use this activity to throw an exception from within a workflow or another activity. • The action of this activity is the same as the Throw statement within a Catch block in code. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 38
    • • This is a flow activity. This activity provides transaction support and exception and event handling. • All activities that make up a transaction are placed within this activity. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 39 • This is a conditional activity. This activity executes another activity until a condition is met. • The condition that needs to be met can be a rule condition (see Policy Activity) or a code condition. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 40
    • • Allows you to setup branching within a workflow. Branching within a workflow performs some action (in this case an activity) based on a condition. • You define and evaluate the condition within an IfElseBranch activity within the IfElse activity • When the workflow encounters an IfElse activity the leftmost IfElseBranch activity is evaluated first. If that branch returns True it’s executed, otherwise the next branch is executed. • You do not need to set a condition on the second branch-it’s considered the Else Portion. • You can use the IfElse activity with only one branch the same as an If…EndIf statement. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 41 • IfElse • While Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 42
    • • Allows you to perform another activity multiple times, as long as a condition is evaluated to True. • The While activity can only have one activity within it, so you might need to use composite activities to perform multiple tasks. • The process of the While activity is: • Evaluate the condition • If the condition is True the activity within the While activity is executed otherwise the While activity completes Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 43 • State Related Activities • Delay • Suspend • Terminate Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 44
    • • Allows you to control the timing of the workflow by building delays into the workflow • The delays can be in hours or days • The workflow pauses a period of time when the Delay activity is executed Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 45 • Suspends the workflow operation and logs an error. • Use this to intervene when an error condition is met • You can also specify a message that gets logged with the error • When a Suspend activity is encountered, the workflow pauses as with the Delay activity but the Suspend activity waits for the workflow to be started by some external action Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 46
    • • Immediately stops the workflow • Use this in the event of some fatal error or other unusual situation. • You can provide a message for why the workflow terminated Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 47 • Rules-Based workflow is a workflow made up of activities that have rules associated with them. • These rules are essentially If-Else statements with a condition and action • A rules-based workflow is a good way to model actual business processes, as business processes have business rules associated with them. • You can use rules to define criteria that must be met for an activity to take place • WF provides two ways to use rules, a condition on an activity or using the Policy activity • WF has four activities to which conditions can be applied: IFElse, While, Replicator, and Conditional Activity Group Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 48
    • • WF has four activities to which conditions can be applied: IFElse, While, Replicator, and Conditional Activity Group • Conditions within one of these activities determine if the activity executes or not • Instead of using Code Condition as a Condition property you can use Declarative Rule Condition • Declarative Rule Condition points to a RuleCondition that is defined in a .rules file associated with the workflow Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 49 • Contains the definition and execution of a RuleSet, which is a collection of rules with a set of execution steps. • When you create a RuleSet for a Policy activity the same types of actions occur as when you create a rule for an activity condition. • A rules file is created for the workflow, and all rules are captured in this file. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 50
    • • WF has provided extensibility so you can expand the set of activities available from which to build workflows, so you can create activities specific to your problem domain • You can derive a custom activity from either an out-of-the-box activity or another custom activity • You can add your custom activities to the VS2005 WF Toolbox so they are available to other projects Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 51 • You can inherit from an existing activity and add functionality to the custom activity by using related classes called activity components • Validator: provide custom validation logic • Designer: provides custom behavior within VS environment • Toolbox Item: Provides custom behavior within the Toolbox • Serializer: Provides any custom serialization required • Code Generator: Allows compile-time code generation • You can inherit these activity components into new classes, and you only need to change what you want to change, the remaining functionality will stay the same. Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 52
    • • WF provides an activity to work with web services, as well as several activities that allow your workflow to become a web service. • InvokeWebService activity allows you to call to a web service from within the workflow • WebServiceInput accepts input into the workflow when the workflow is a web service • WebServiceOutput returns an output from the workflow when the workflow is a web service • WebServiceFault – used for exception handling within a workflow as a web service Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 53 • Code Time! • Lab 2 Copyright © Intertech, Inc. 2007 • www.Intertech.com • 800-866-9884 • Slide 54