WF from Getting started to mastering (13th chapter): Creating Custom Activities (i)

Source: Internet
Author: User
Tags remote ftp server visual studio

After completing this chapter, you will learn:

1. Learn which components are required to create a full-featured custom workflow activity

2. Create a basic custom workflow activity

3. Apply validation rules in basic custom workflow activities

4. Integrate basic custom workflow activities into the Workflow View Designer and toolbox of Microsoft Visual Studio

WF is not likely to cover every aspect of what you might want to achieve in your workflow. Even though WF is still a very new technology for the development community, there are a number of free custom activities available that can be sure that business-level activities will eventually follow.

In this chapter, you will learn about WF by creating a new workflow activity that retrieves files from a remote FTP server. You'll see what is required to create your own activities and which ones are pretty good. You will also have a deeper understanding of how activities interact with the workflow runtime.

Note: It is not possible to explore each of the details of custom activity development in a single chapter, which simplifies too much detail. The good news, though, is that it's easy to get a full function of the activity without knowing every detail.

More knowledge about activities

In the fourth chapter (Activities and Workflow type introduction), we have a preliminary understanding of the activities and discussed topics like ActivityExecutionContext, ActivityExecutionContext used to accommodate some of the information related to the activities being performed, The workflow runtime needs to access this information from time to times. We'll take a deeper look at WF activities here.

The virtual method of the activity

The first thing you need to know when creating a custom activity is what virtual methods and properties The base class provides you with. Table 13-1 shows some of the methods that are commonly used in an activity that can be overridden. (There is no virtual attribute here.) )

Commonly used overridable virtual methods in table 13-1activity

Method Function
Cancel Called when the workflow is canceled.
Compensate This method does not actually come from the activity base class, which actually needs to be provided by the Icompensatableactivity interface, many of which derive from the interface. Therefore, for whatever purpose and intention, it is regarded as the method of activity. You will implement this method to compensate for the failed transaction.
Execute is used to perform the corresponding work to be done by the activity.
Handlefault Called when an unhandled exception is thrown by the active internal code. Note that once the method is invoked, there is no way to restart the activity.
Initialize Called when the activity is initialized.
Onactivityexecutioncontextload Called after the activity completes its workflow. The current execution context is being moved to another activity. \ execution
Uninitialize Called when the activity is to be deserialized.

When your activity has been loaded into the workflow runtime but before execution, if you need to do some specific processing work, an excellent location is to do these things in the Initializze method. You may also be doing something outside of the uninitialize approach that is similar to what you are doing.

The Onactivityexecutioncontextload and Onactivityexecutioncontextunload methods respectively indicate that the activity is being loaded into the workflow runtime and that the activity is being moved from the workflow runtime. After the onactivityexecutioncontextload is invoked and Onactivityexecutioncontextunload is invoked, the activity is in an unloaded state from the WF's point of view. It may be serialized into a queue, saved in a database, or even waiting to be loaded on a disk. However, before or after these methods (Onactivityexecutioncontextload and Onactivityexecutioncontextunload methods) are invoked, they do not exist in the workflow runtime.

Cancel, Handlefault, and compensate are invoked when the obvious conditions (meaning cancellation, failure, and compensation conditions) are fired. Although compensate is actually used to perform your transaction compensation (see Chapter 15th: Workflows and transactions), the main purpose is to perform some extra work (such as a log) that you want to perform. It is too late to remember that these methods are invoked because when your activity is required to compensate for the failure, you cannot restore the transaction, nor can you undo an unhandled exception or terminate a cancellation (cancle) request. All you can do is to perform some cleanup or other processing requests that, in compensate, actually provide compensation for failed transactions.

Execute is the virtual method of the activity that is most likely to be rewritten, simply because this method requires you to rewrite it to perform the work that the activities should perform.

Active components

While there is no doubt that you need to write custom activity code yourself, the fully developed WF activity comes with additional code for supporting and workflow-independent behavior, but typically provides developers with a richer development experience in the workflow visualization designer. For example, you might want to provide a validator object to check for an improper activity configuration and return an error message, or you might need to provide a toolboxitem or toolboxbitmap to better integrate with the Visual Studio Toolbox. Whether you believe it or not, by using a dedicated designer class to modify the theme of the activity, you can actually adjust the rendering style of your activities to the Workflow View Designer. The examples in this chapter implement all of these things to demonstrate their functionality and effects.

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.