WF framework programming (designer part)

Source: Internet
Author: User
Tags to domain sharpdevelop
Document directory
  • 2.1 activity designer

V. Basic Framework of workflow designer 1. Net designer

. The namespace of the basic framework of the net designer is system. componentmodel. and WF, Asp.net, and win from are all built on. net.

The namespace where the WF designer framework is located is system. workflow. componentmodel. design. The relevant classes are all in this namespace. Before studying the WF designer, let's take a look at the winform designer. The Research on the winform designer is helpful for understanding the WF designer.

1.1 winform designer design:

I have studied for a few daysSharpdevelop,A free and open-source IDE development environment with idea similar to Eclipse plug-ins. There is a complete winform designer implementation in this open-source IDE. Winform

IDE mainly relies on the following interfaces and classes. As long as the related interfaces and abstractions are implemented, the. NET Framework will help us implement the winform designer. Like the template method. The corresponding interfaces and classes are:

Winform designer Structure

Ü desingerhost:

1. Service Management: Service containers and service providers

2. Component Management and transaction management

Ü isite:

Bind components and containers. All services in the designerhost can be obtained through the isite (getservice ).

Ü iserviceprovide

Ü idesinger

Provides customized services. During the design period, you can add menu commands and add components to the context menu of the components for operations.

Association with icompont in initialize method

Toolbox implementation:

Ü itoolboxservice

Toolboxitem Storage

How to fill the toolbox?

To use toolboxitemfilterattribute

Addtoolboxentries: ListBox. Items. Add (New selfhosttoolboxitem (entry)

Categorynames: toolbox category attribute

Addcreator:

I think workflowdesignercontrol is an application in the mediator mode.

Ü select a service

Containers related to assemblies and CCU: typeprovider

You can go downSharpdevelopFor more information, see the source code.

2 WF designer

The implementation idea of the WF designer is mainly the activitydesigner and the Designer surface corresponding to each activity. This also provides us with the idea to implement the web-based WF designer, in comparison with the webform environment, acitivitydesinger remains unchanged and changes the resident environment. I haven't been in touch with WF for a long time. The environment discussed here is winfrom. In the future, I will organize it in a Web environment.


WF designer Structure

2.1 activity designer

The default designerattribute declaration of an activity is designer (typeof (activitydesigner), typeof (idesigner), designer (typeof (activitydesigner), and typeof (irootdesigner)

If we implement a custom acitivity, We can generally inherit from the activity and do not need to write it again. Because activitydesigner is designed as a simple rectangle, the activities we see are like simple rectangles. Of course, we can also modify them very beautifully. Corresponds to a composite activity, inherited from compositeactivitydesigner. There are several desinger, all of which have their own design performance. Among them, parallelactivitydesigner shows that all sub-activities are in parallel; sequencedesigner automatically presents sub-activities in sequence.

If it is a special compound activity, you may need to implement your own desinger. The examples here are based on the WF nature. You can also compare them to see that e-books can be downloaded for free. In this example, to implement a custom prioritizedinterleave, the design performance needs to show the priority relationship on the designer. Because the existing class library lacks support, you need to implement the acitiworkflow designer.

How to Implement custom activitydesigner

In the prioritizedinterleavedesigner example, the design intent is that the point self-activity can set the priority attribute in propertygrid. Based on the priority value, the sub-activity is located in a non-characteristic location.

You can set properties through propertygrid

1. Add a specific iextenderprovider to iextenderlistservice. See the class diagram.

2. Specific iextenderprovider implementation

Associate with propertygrid through providepropertyattribute

Iextenderprovider. canextend is used as the basis for whether to use the attribute. If it is true, the propertygrid control searches for the get <propertyname> and set <propertyname> methods in the extender class to interact with the acivity attribute.

WF is not open-source yet. I guess we use the AOP code to weave and use the template mode.

3. The activity Declaration uses the custom activitydesigner. Designer (typeof (custom activitydesigner), typeof (idesigner)

In this example, prioritizedinterleavedesigner inherits from compositeactivitydesigne, so the declaration of prioritizedinterleave actually declares the entire composite activity.

Compositeactivitydesigner. containeddesigners

Right-click menu to modify attributes

1. Implement the idesignerverbprovider Interface

2. idesignerverbproviderservice. addverbprovider (idesignerverbprovider) during activity initialization );

3. Interface implementation

Use activitydesignerverb. properties to obtain the activity

For this activity, get and modify the set

4. Modify mlayout to make the modification take effect.

Modify designer graphics (both composite and basic activities can be modified)

1. For the override glyphs method of the composite activity, activitydesignerglyphcollection is obtained.

Activitydesignerglyphcollection. Add (designerglyph );

2. Implementation of designerglyph

The override method implements the getbounds and onpaint methods of designerglyph.

3. For simple activities, override implements the onlayoutsize and onpaint methods of activitydesigner.

Onlayoutsize: returned size

Onpaint: implements some necessary drawing functions.

Getbounds: returns the rectangle representing the graphic boundary.

Modify designer Layout

Reload the onlayoutsize and onlayoutposition of acitivity designer.

Onlayoutsize returns the total size of the designer. onlayoutposition calculates the offset of the sub-activity.

Designer topic

1. Implement specific activitydesignertheme

2. activitydesignerthemeattribute Injection

3. You can call theme in activitydesigner. onpaint.

Toolbox

By default, toolboxitemattribute is used to point to activitytoolboxitem.

If you have special requirements, for example, to implement a composite control during the drag operation, you can inherit the activitytoolboxitem and implement it in createcomponentscore.

In this case, toolboxitemattribute points to the custom activitytoolboxitem.

You can use toolboxbitmapattribute to customize a view in the toolbox.

2.2 resident designer

Designer surface: manages the designer host and interacts with users (obtains the view, obtains the host, and asynchronously loads the designer loader)

Responsibilities of designer host

1. Manage the interaction between icomponent and related idesigner;

2. It is a service container that provides functions required by cancellation, clipboard, and other activity designers.

Transaction Management

Component Management: createcomponent, getdesigner, GetType

Designer loading and Management

// Summary:

// Occurs when the designer is activated.

Event eventhandler activated;

//

// Summary:

// Occurs when the designer is disabled.

Event eventhandler deactivated;

//

// Summary:

// This occurs when the designer loads the document.

Event eventhandler loadcomplete;

Responsibilities of designer View

1. Present various activitydesigners and send messages to each activitydesigner

2. Form management, command routing, form scrolling, shelving, scrolling, layout, printing, and print preview

Isite is responsible for binding components and containers. All the services in designerhost can be obtained through the isite (getservice ).

Iservicecontainer is a service container that can form a tree. If the promote parameter is true, the Service addition and deletion operations are submitted to the base container. The Implementation ideas of these interfaces are similar to those of the winfrom designer.

2. Designer serialization

Like vs, the process must be stored persistently. During the next use or modification, we can get the previously designed process through deserialization.

We can serialize the activity tree to XAML or code (default), or even to domain description languages such as (BPEL, DSL. The format of serialization can be specified in the attribute of acitivity.

Typecodedomserializer: serialized as code

Workflowmarkupserializer: serialized as a XAML File


Class library used by the designer for serialization

4. Code Generation

If code activity exists in the process, you also need the designer to dynamically generate code. If typecodedomserializer is specified, dynamic code generation is also required. Finally, the entire WF activity can be compiled into an assembly under. net.

Activity code generation calls C # code compilation before verification. activity code generation actually gives you the opportunity to use codedom to generate code files. Let's talk about code generation next time.

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.