WF4.0 Beta1 flow Designer and Activity Designer

Source: Internet
Author: User

WF4.0 Beta1 flow Designer and Activity Designer

Data

Public class myData

{

Public string result

{Set; get ;}

 

Public string description

{Set; get ;}

}

 

 

Custom Activity

Public sealed class node <T>: NativeActivity <myData>

{

Public node ()

: Base ()

{

This. DisplayName = "";

 

}

 

String _ n = "mywait ";

Public string node name

{

Get {return _ n ;}

Set {_ n = value ;}

}

 

String _ s = "Enter content ";

Public string content

{

Get {return _ s ;}

Set {_ s = value ;}

}

 

Protected override void Execute (ActivityExecutionContext context)

{

System. Console. WriteLine ("content: {0}", content );

Context. CreateNamedBookmark (node name, new BookmarkCallback (bookmarkCallback ));

}

 

Void bookmarkCallback (ActivityExecutionContext context, Bookmark bookmark, object obj)

{

MyData r = obj as myData;

 

If (r. Result = "")

{

System. Console. WriteLine ("{0}, please handle the following issues:", r. Description );

}

This. Result. Set (context, r );

}

}

 

Custom Designer

<Sad: WorkflowElementDesigner x: Class = "WpfApplication1.myDesigner"

Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"

Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"

Xmlns: sad = "clr-namespace: System. Activities. Design; assembly = System. Activities. Design"

Xmlns: sadv = "clr-namespace: System. Activities. Design. View; assembly = System. Activities. Design">

 

<Sad: WorkflowElementDesigner. Resources>

 

<DataTemplate x: Key = "d1">

<StackPanel>

<TextBlock Margin = "," Text = "content:"/>

<TextBox Height = "50" AcceptsReturn = "True" Text = "{Binding Path = ModelItem. Content}"/>

</StackPanel>

 

</DataTemplate>

 

</Sad: WorkflowElementDesigner. Resources>

 

<Grid>

<ContentPresenter ContentTemplate = "{DynamicResource d1}" Content = "{Binding}"/>

</Grid>

</Sad: WorkflowElementDesigner>

 

Process designer

<Window x: Class = "WpfApplication1.Window1"

Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"

Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"

Title = "Window1">

<StackPanel>

<StackPanel Orientation = "Horizontal">

<Button Content = "Startup Process" Width = "80" Height = "30" Click = "Button_Click"/>

<TextBlock Margin = "20, 0, 0, 0" Text = ""/>

 

<Button Name = "yes" Content = "agree" Width = "80" Height = "30" Click = "yes_Click"/>

<Button Name = "nextUser" Content = "Submit to the specified person for another discussion" Width = "80" Height = "30" Click = "nextUser_Click"/>

<TextBox Name = "tb" Width = "200"/>

</StackPanel>

 

<StackPanel Orientation = "Horizontal" Loaded = "StackPanel_Loaded">

 

<StackPanel xmlns: sad = "clr-namespace: System. Activities. Design; assembly = System. Activities. Design">

<StackPanel Name = "propertyPanel"/>

<Sad: ToolboxControl Width = "250" Height = "400" Name = "toolbox"/>

</StackPanel>

<ContentControl Height = "800" Width = "800" Name = "desienerPanel"/>

</StackPanel>

</StackPanel>

</Window>

Public partial class Window1: Window

{

Public Window1 ()

{

InitializeComponent ();

}

WorkflowDesigner designer;

Private void StackPanel_Loaded (object sender, RoutedEventArgs e)

{

ToolboxCategoryItemsCollection toolList = new ToolboxCategoryItemsCollection ("basic tools ");

Toolbox. Categories. Add (toolList );

ToolList. Add (new ToolboxItemWrapper (typeof (node <myData>), "Node "));

ToolList. Add (new ToolboxItemWrapper (typeof (System. Activities. Statements. FlowSwitch), "branch "));

ToolList. Add (new ToolboxItemWrapper (typeof (System. Activities. Statements. WriteLine), "output "));

// ======

 

DesignerMetadata dm = new DesignerMetadata ();

Dm. Register ();

//-

 

AttributeTableBuilder builder = new AttributeTableBuilder ();

Builder. AddCustomAttributes (typeof (node <myData>), new DesignerAttribute (typeof (myDesigner )));

MetadataStore. AddAttributeTable (builder. CreateTable ());

 

// ==============

 

Designer = new WorkflowDesigner ();

 

Var root = new System. Activities. Statements. Flowchart ();

 

Var v = new System. Activities. Variable <myData> ();

V. Name = "content ";

V. Default = new myData ();

Root. Variables. Add (v );

Designer. Load (root );

 

DesienerPanel. Content = designer. View;

PropertyPanel. Children. Add (designer. PropertyInspectorView );

}

 

WorkflowInstance myInstance;

Public WorkflowInstance createInstanceFromXamlString (string xaml)

{

System. Text. UTF8Encoding utf8 = new System. Text. UTF8Encoding ();

Byte [] bs = utf8.GetBytes (xaml );

System. IO. MemoryStream memoryStream = new System. IO. MemoryStream (bs );

WorkflowElement activity = WorkflowXamlServices. Load (memoryStream );

WorkflowInstance myInstance = new WorkflowInstance (activity );

Return myInstance;

}

 

 

 

Private void Button_Click (object sender, RoutedEventArgs e)

{

System. Console. Clear ();

MyInstance = createInstanceFromXamlString (designer. Text );

MyInstance. OnCompleted = delegate (WorkflowCompletedEventArgs ee) {System. Console. WriteLine ("end ");};

MyInstance. Run ();

}

 

 

Private void yes_Click (object sender, RoutedEventArgs e)

{

MyData date = new myData ();

Date. Result = "";

Date. Description = tb. Text;

 

MyInstance. ResumeBookmark ("mywait", date );

}

 

Private void nextUser_Click (object sender, RoutedEventArgs e)

{

MyData date = new myData ();

Date. Result = "B ";

Date. Description = tb. Text;

MyInstance. ResumeBookmark ("mywait", date );

}

}

 

 

Design Process

Design the following process:

 

 

 

 

 

 

 

 

 

Running instructions

 

 

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.