WF 4.0 Beta1 Activities Overview (1): Procedural

Source: Internet
Author: User
Tags foreach error handling exception handling finally block instance method visual studio visual studio 2010

We can use these activities to author workflows or create custom activities, compared to WF 3.5,WF 4.0 Beta1 provides a large number of out-of-the-box activities. This article will make a quick and easy overview of these activities and describe their key features.

An activity is a unit of work for a workflow program. In WF 4.0, the activity consists of a signature and body. A signature is a terminological definition of the active public parameters that define the input and output data streams for the activity. The text refers to the execution logic of the activity, which can be expressed declaratively by other activities, or by code.

Below is a brief introduction to these built-in activities in accordance with the assortment of WF 4.0 Beta1 in the Visual Studio 2010 toolbar.

Procedural

Procedural activities provide a mechanism for simulating sequential flow control, and we are already familiar with this flow control in the process of using standard programming languages such as C # and VB. Procedural activities contain basic building blocks that can be used to represent sequential behavior, covering aspects including flow control, method calls to CLR objects, collection maintenance, and error handling. It also involves some high-end scenarios, such as parallel activities, transaction management, compensation, cancellation, and persistence. The following table contains all the activities in the procedural taxonomy. The bold characters in the description represent the most important parameters.

Activities Describe Designer appearance
Collection Management
Addtocollection<t> Add Item to collection.  
Removefromcollection<t> Remove item from collection.
Clearcollection<t> Clears the collection and removes all of the child items that are stored in it.
Existsincollection Verify if the item exists in collection. If a subkey exists, the active result parameter is assigned to TRUE.
Flow control
If An If activity executes a child activity based on a Boolean expression.

If the Boolean expression-condition evaluates to True (and the then activity is configured), the execution of the then activity is scheduled. If the expression evaluates to False (and the else activity is set), the else activity is evaluated.
Dowhile Repeatedly executes its body until Condition evaluates to True. The body is executed at least once.  
Foreach/foreach<t> A foreach activity contains a list of values and a body. At run time, the list is cycled, and the body is executed once for each value in the list.
Pick The pick activity provides an event-based flow control model in WF. Pick the only valid child activity is pickbranches.

When pick begins execution, all trigger activities of its branches are scheduled to execute. When the first trigger completes the corresponding action activity it plans to perform, all other trigger activities will be canceled.
Pickbranch Pickbranch represents a branch of the pick activity. It is made up of trigger and action. Pickbranch can only be added to the pick activity.
Sequence The sequence activity allows one or more activities to be executed in order.
Switch<t> The switch activity is similar to the C # switch statement. It contains a expression and a set of cases (each case has a key and an activity). When the expression is evaluated, the switch activity looks for the case that matches the result of the expression and, if found, executes the activity associated with the event.
While When the Boolean type condition evaluates to True, the while activity executes its body.
Parallel execution
Parallel The parallel activity allows its child activities to execute in parallel. It schedules the execution of each workflowelement in its branches collection at the start of execution. When all branches are complete or their Completioncondition property evaluates to True, it completes execution.  
Parallelforeach/parallelforeach<t> The Parallelforeach activity traverses its set of values and merges it into each element of the collection by performing a activities that resemble foreach. The main difference is that the embedded statements are executed in parallel mode.

Like parallel activities, Parallelforeach also has a completioncondition, so the Parallelforeach activity can be completed ahead of time, provided that Completioncondition returns True. The completioncondition is calculated after each iteration completes.
Error handling
TryCatch The TryCatch activity is similar to a try in C #. Catch structure: All activities in a try block are executed, and if an exception occurs, the most matching catch block is scheduled to be executed (if no matching catch is found, the workflow is interrupted). All catch blocks are located in a collection named catches.

The Trycatch activity also has a finally block that will be executed after the try (and the catch that may be executed).

Tips on exceptions that are not handled:

TryCatch provides an exception handling mechanism at the workflow level. When an unhandled exception is thrown, the workflow is interrupted so that the finally block is not executed. This behavior is also the same as try in C #. The catch structure remains consistent.
Catch<t> Represents a catch in the trycatch activity. If an exception is thrown in the try element, Trycatch attempts to find a matching Catch element based on the type that throws the exception.

Catch<t> can only be used in trycatch activities.
Throw The Throw activity throws an exception in the workflow. The Throw activity contains a exception property that contains an exception that will be thrown at execution time.
Practical Tools
Assign The Assign activity assigns the value of its values parameter to its to parameter.

The types of the two parameters must be compatible. This compatibility is validated during run time.
Delay The delay activity, as the name suggests, blocks the execution of the current workflow for a period of time that is specified by the user through its duration parameter. After the delay expires, the workflow continues to execute. The delay delay should be set to a TimeSpan value.
Invokemethod/invokemethod<t> InvokeMethod is an activity that allows us to invoke an existing CLR method and a static method. To invoke a method, all we need to do is provide owner information for the method (static method is TargetType, instance method is TargetObject), MethodName, and parameters of the method.

InvokeMethod supports the following methods to invoke the scene:

Common instance methods and static methods

Parameters passed by value or reference

Support for parameter arrays

Support for generic parameters

Asynchronous method call
WriteLine Outputs the text to the configured output console.

Output to the back of the System.Console:

WriteLine has a TextWriter parameter that can be configured for different outputs. For example, we can configure the TextWriter property to send text to a asp.net page. If TextWriter is not set, its default value-system Console is selected.
Advanced (cancellation, compensation, transactions, and persistence)
Cancellationscope The Cancellationscope activity consists of two main sections, body and Cancelhandler. The body includes activities that are normally performed. If the activity is canceled, the Cancelhandler is executed.
Compensatableactivity Compensableactivity is used to define a potentially long-running activity, along with compensation and confirmation logic.

Compensation allows the user to specify activities that perform corrective actions that will be executed after the body completes successfully.
Compensate Compensate is used to explicitly invoke the Compensableactivity compensation handler.
Confirm Confirm is used to explicitly invoke a compensableactivity acknowledgment handler.
Persist Persisting workflow instances. The persistence of the workflow is accomplished based on the configuration of the workflowinstancethe in execution (this activity does not contain any parameters).
TransactionScopeActivity TransactionScopeActivity provides a complete operation to initialize a new transaction, build a transactional environment (a workflow execution property), and invoke the transaction after the body of the TransactionScope activity completes.

TransactionScopeActivity supports the "requirement" semantics. If an environment transaction is already in use, a new transaction is created.

Nested transaction scope

TransactionScopeActivity can be nested in another transactionscopeactivity. A transactionscopeactivity that is nested in another transactionscopeactivity will use an existing transaction.

This article comes to a temporary pause, and the next article is followed by an overview of the other types of activities provided by WF 4.0 BETA1: Flowchart, messaging, PowerShell, and migration.

This article is translated from: http://blogs.msdn.com/endpoint/archive/2009/05/29/a-tour-on-the-wf4-activity-palette.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.