Beruflich Dokumente
Kultur Dokumente
Windows® Workflow
Foundation
Module 4: Creating and Configuring Custom
Activities
• Creating Custom Activities
• Raising Events
[ToolboxBitmap(typeof(SendEmailActivity), "EmailMessage.png")]
public partial class SendEmailActivity : Activity
{
…
}
Defining Instance Properties and Meta Properties
Instance properties:
• Can be set at design time or can be bound to instance data
• Can be modified directly during workflow execution
Meta properties:
• Must be set to a literal value at design time
• Cannot be modified during workflow execution
[Browsable(true)]
public string ToAddress
{
get { return toAddress; }
set { toAddress = value; }
}
Defining Dependency Properties
What are dependency properties?
• A centralized repository of the state of a workflow
• Can be bound to other values on the workflow
[ActivityValidator(typeof(SendEmailValidator))]
public partial class SendEmailActivity : Activity
{
…
}
Demonstration: Creating Custom Activities
In this demonstration, you will see how to:
• Create a custom activity
[ToolboxBitmap(typeof(MyCompositeActivity), "MyBitmap.png")]
public class MyCompositeActivity : CompositeActivity
{
// Properties
…
}
Adding Child Activities to a Custom Composite
Activity
To add child activities to a custom composite activity:
• Implement InitializeComponent, to add child activities
• Override Execute, to handle the execution of child activities
[ToolboxBitmap(typeof(MyCompositeActivity), "MyBitmap.png")]
public class MyCompositeActivity : CompositeActivity
{
private void InitializeComponent()
{ … }
[ToolboxBitmap(typeof(MessageBoxActivity), "MessageBoxBitmap.png")]
public class MessageBoxActivity : SequenceActivity
{
// Properties
…
}
Adding Child Activities to a Sequential Custom
Composite Activity
To add child activities to a sequential custom composite
activity:
• Drag activities from the Toolbox and drop them onto the Designer
surface
• Custom Serialization
Provides basic
WorkflowMarkupSerializer
serialization services
ActivityMarkupSerializer CompositeActivityMarkupSerializer
To deserialize a workflow:
• Create an XmlReader object to read the serialized workflow file
• Create a WorkflowRuntime object
• Invoke the CreateWorkflow method on the WorkflowRuntime
Demonstration: Serializing and Deserializing
Workflows
In this demonstration, you will see how to:
• Serialize a workflow to XAML
However, there
• TODO: Show anare specific
example of ascenarios where
deployment the file?
manifest default
serialization might be inadequate for a custom activity
• In this case, you must define a custom serializer class for the
custom activity class
• You must associate the custom serializer class with the custom
activity class
Defining a Custom Serializer
To define a custom serializer:
• Define a class that inherits from WorkflowMarkupSerializer
• Override serialization and deserialization methods
[DesignerSerializer(typeof(MyMarkupSerializer,
typeof(WorkflowMarkupSerializer))]
public class MyActivity : Activity
{
…
}
Lesson: Defining Custom Activity Layout
• Default Designers
ActivityDesigner
CompositeActivityDesigner
FreeformActivityDesigner StructuredCompositeActivityDesigner
ParallelActivityDesigner SequentialActivityDesigner
Defining a Custom Designer for a Custom Activity
To create a custom designer for a custom activity:
• Define a class that inherits from an existing designer class
• Override members from the base designer class
• Associate a theme class with the designer class, if appropriate
[ActivityDesignerTheme(typeof(MyTheme))]
public class MyActivityDesigner : ActivityDesigner
{
protected override Rectangle ImageRectangle
{ … }
[Designer(typeof(MyActivityDesigner))]
public class MyActivity : Activity
{
…
}
Specifying the Designer for a Custom Composite
Activity
To specify the designer for a custom composite activity:
• Set the Designer attribute to SequentialActivityDesigner or
ParallelActivityDesigner
[Designer(typeof(SequentialActivityDesigner))]
public class CompositeActivity1 : CompositeActivity …
{
…
}
[Designer(typeof(ParallelActivityDesigner))]
public class CompositeActivity2 : CompositeActivity
{
…
}
Lab: Creating and Configuring Custom Activities
• Exercise 1: Creating a Custom Activity
Logon information
Password Pa$$w0rd
• Best Practices