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 );
}
|
|