WF4.0 BASICS (26) Interop calls the Activity of WF3.X

Source: Internet
Author: User

This section describes the activities in which Interop calls WF3.X.

 

Download this example:

Http://files.cnblogs.com/foundation/InteropSample.rar

Examples

 

Interop calls the Activity of WF3.X

Class Name

System. Activities. Statements. Interop

File

System. Workflow. Runtime. dll

Structure Description

Inherit NativeActivity, ICustomTypeDescriptor

Is a sealed class

Override [CacheMetadata method] and [Cancel method] and [Execute method]

Override [CanInduceIdle attribute]

[ActivityMetaProperties] The property type is [IDictionary <string, object>]

[ActivityProperties] The property type is [IDictionary <string, object>]

[ActivityType] the attribute Type is [Type]

Function Description

[ActivityType attribute] specifies the type of the WF3.5 Activity to be called.

When the Activity type of WF3.5 is specified, two parameters [attribute name] and [attribute name Out] are automatically generated for the Activity binding of WF3.5 In the designer.

 

 

 

Instructions for use

The default WF4.0 project is [. NET Framework 4 Client Profile]. To use Interop, change the project to [. NET Framework 4].

 

Interop is not displayed in the toolbar by default. You need to add

 

 

[ActivityType attribute] specifies the type of the WF3.5 Activity to be called.

 

 

When the Activity type of WF3.5 is specified, two parameters [attribute name] and [attribute name Out] are automatically generated for the Activity binding of WF3.5 In the designer.

 

Example 1: Call the Activity of WF3.X

Note:

1. Create a WF3.X Activity with a binding attribute [printText]

The Activity prints the value of [printText] in the [Execute] method and assigns a new value to [printText ].

 

2. Create a WF4 workflow, use [Interop] to call the Activity of WF3.X, input a value for [printText], and print the return value through [printText ].

 

WF3.X Activity


Public
Partial
Class
MyActivity: Activity

{


Public myActivity ()

{

InitializeComponent ();

}

 

[System. Diagnostics. DebuggerNonUserCode]

[System. CodeDom. Compiler. GeneratedCode ("", "")]


Private
Void InitializeComponent ()

{


This. Name = "myActivity ";

}

 


Public
Static
Readonly
DependencyProperty printTextProperty = DependencyProperty. Register ("printText", typeof (string), typeof (myActivity ));

 


Public
String printText

{


Get

{


Return (string) base. GetValue (printTextProperty );

}


Set

{


Base. SetValue (printTextProperty, value );

}

}

 


Protected
Override
ActivityExecutionStatus Execute (ActivityExecutionContext context)

{


Console. WriteLine (this. printText );


This. printText = printText + ": wxd ";


Return
ActivityExecutionStatus. Closed;

}

}

WF4 Workflow

Host


Static
Void test1 ()

{


WorkflowInvoker. Invoke (new
TestWorkflow ());

 

}

Result

 

 

Example 2: Code operation


Static
Void test2 ()

{

 


Variable <string> myVariable = new
Variable <string> () {Default = "wxwinter "};


Sequence root = new
Sequence ()

{

Variables = {myVariable },

Activities =

{

 


New
Interop ()

{

ActivityType = typeof (myActivity ),

ActivityProperties =

{

 

{"PrintText", new
InArgument <string> (myVariable )}

,

{"PrintTextOut", new
OutArgument <string> (myVariable )}

 

},

ActivityMetaProperties =

{


// Provide a value for the Name meta-property of the WriteLine

{"Name", "myActivity "}

}

}

,


New
WriteLine {Text = myVariable}

}

};

 


WorkflowInvoker. Invoke (root );

}

 

 

 

 

 

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.