How can I integrate the wf4.0 workflow designer with lightswitch? (Reference)

Source: Internet
Author: User
(OK) process designer for wf4.0 (for wxd. WF, BPM. Foundation, wxwinter. WF upgrade) http://www.cnblogs.com/foundation/archive/2010/02/05/1664402.html (OK) visualworkflowtracking aka workflowsimulator

Http://blogs.msdn.com/ B /kushals/archive/2009/12/22/visualworkflowtracking-aka-workflowsimulator.aspx

----------------------------------------------------------------------------

Http://www.evget.com/zh-CN/Info/catalog/14027.html

Code: http://files.cnblogs.com/zengxinle/WorkflowDesigner_4Code.zip

In wf3.0, You can host the workflow designer in your own application. However, in addition to some basic operations, it is very difficult to do some complex operations.
In wf4.0, application portability is better. With only 200 lines of code, you can create a fully functional and useful workflow designer.

Workflowdesigner

Workflowdesigner is the main class for running the workflow designer. It provides the actual design interface through the view attribute. Properties are provided through the propertyinspectorview attribute. If the host is in WPF, these two attributes are ready for use by the WPF uielement, it is easy to add them to the form. It is also very easy to load and save a workflow. The load () and save () functions are required. They need to use a XAML file for parameters. Some code is as follows:

Code

_ Workflowdesigner = new workflowdesigner ();

_ Workflowdesigner. Load (_ filename );
VaR view = _ workflowdesigner. view;

Grid. setcolumn (view, 1 );

Grid. setrow (view, 1 );

Layoutgrid. Children. Add (View );

VaR propinspector = _ workflowdesigner. propertyinspectorview;

Grid. setcolumn (propinspector, 2 );

Grid. setrow (propinspector, 1 );

Layoutgrid. Children. Add (propinspector );

Designermetadata:
Another thing that needs to be done is to register the metadata of the Process activity design. It is just a simple call, but if you discard it, it means that all activities are just a small image, it is also impossible to expand.

New designermetadata (). Register ();

Display activity on the toolbar

The toolbar on the left uses another standard WPF control: toolboxcontrol. It is also very easy to add to the WPF form. Add toolboxitemwrapper to the activity type. In this way, you can drag and drop the activity directly to the design interface without doing any other work. The following code only scans several sets to get all activity types. If it is a valid activity, we add it to the toolbar.

Code


VaR toolbox = new toolboxcontrol ();

VaR cat = new toolboxcategory ("standard activities ");

VaR assemblies = new list <Assembly> ();

Assemblies. Add (typeof (send). Assembly );

Assemblies. Add (typeof (Delay). Assembly );

Assemblies. Add (typeof (receiveandsendreplyfactory). Assembly );

VaR query = from ASM in assemblies

From type in ASM. gettypes ()

Where type. ispublic &&

! Type. isnested &&

! Type. isabstract &&

! Type. containsgenericparameters &&

(Typeof (activity). isassignablefrom (type) |

Typeof (iactivitytemplatefactory). isassignablefrom (type ))

Orderby type. Name

Select New toolboxitemwrapper (type );

Query. tolist (). foreach (Ti => CAT. Add (Ti ));

Toolbox. categories. Add (CAT );

Grid. setcolumn (toolbox, 0 );

Grid. setrow (toolbox, 1 );

Layoutgrid. Children. Add (Toolbox );

Current selection
At the top of the form, I show the selected activity and its parent activity. Workflowdesigner has a collection of projects with a set of useful objects. One of them is the selection object. We can periodically check this selection, use the subscribe () function and pass it in a handler. This will be triggered when the selection changes, this may be easier to implement.

_ Workflowdesigner. Context. Items. subscribe <selection> (selectionchanged );

Handler is not complicated:

Code

Private void selectionchanged (selection)

{

VaR modelitem = selection. primaryselection;

VaR sb = new stringbuilder ();

 

While (modelitem! = NULL)

{

VaR displayname = modelitem. properties ["displayname"];

 

If (displayname! = NULL)

{

If (sb. length> 0)

SB. insert (0 ,"-");

SB. insert (0, displayname. computedvalue );

}

 

Modelitem = modelitem. parent;

}

 

Currentactivityname. Text = sb. tostring ();

}

Verify Workflow
It is perfect to let users know whether the designed workflow is effective. This is also very simple. Add an ivalidationerrorservice in workflowdesigner services. In this example, I add a ListBox to the form. Let ivalidationerrorservice add each error to The ListBox item. You do not need to call any function. Once the workflow changes, the ivalidationerrorservice is automatically called.

VaR validationerrorservice = new validationerrorservice (workflowerrors. items );

_ Workflowdesigner. Context. Services. Publish <ivalidationerrorservice> (validationerrorservice );

Ivalidationerrorservice is composed of a simple function. Write errors in a parameter list.

Code

Public class validationerrorservice: ivalidationerrorservice

{

Private ilist _ errorlist;

Public validationerrorservice (ilist errorlist)

{

_ Errorlist = errorlist;

}

 

Public void showvalidationerrors (ilist <validationerrorinfo> errors)

{

_ Errorlist. Clear ();

Foreach (VAR error in errors)

{

_ Errorlist. Add (error. Message );

}

}

}

Run workflow:

To run the workflow, I add some code and use workflowapplication to run the workflow. Loading is also very easy. activityxamlservices. Load () needs to pass a file for calling. It returns a dynamicactivity.

Code

VaR writer = new stringwriter ();

VaR workflow = activityxamlservices. Load (_ filename );

VaR WA = new workflowapplication (workflow );

Wa. Extensions. Add (writer );

Wa. Completed = workflowcompleted;

Wa. onunhandledexception = workflowunhandledexception;

Wa. Run ();

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.