Slickflow.net Open Source Workflow Engine Basics Introduction (II)

Source: Internet
Author: User

  1. The need for an integrated process engine

    The change of business process is a common phenomenon in the BPM system, the enterprise management needs to optimize the organization structure, transform the business process, inevitably bring the change of business process, the enterprise information system will be faced with the possibility of reconstruction. A direct way is to transform the business code to adapt to changes in the business process, which will face the need to constantly rewrite the code, another way is to use the process engine to control changes in business processes, the rewriting of business code to the process engine, through the process engine to resolve business rules, drive business process flow, This minimizes the likelihood of rewriting business code.

    Obviously, the benefit of the process engine is to better solve the change of business process caused by the risk of restructuring, if the information system is flexible, scalable, dynamic adaptation, then it can maintain the possibility of not being quickly replaced, it will naturally be able to reduce the continuous upgrade or implementation of the costs incurred by the enterprise.

  2. How business processes and process engines interact

    Embedding process engine middleware in a business process is a common and straightforward approach; although some engine components can configure the reflection interface of a business module, we now consider it reasonable that the process engine should not bind the business interface too much, because changes in the business interface are always unavoidable and will always occur, The engine components also need to remain stable.

    Typically in a business module, when the business functions are processed, the service interfaces of the engine components are invoked to drive the flow of business processes. We have been part of the business process to deal with the changes in the service processing, process engine middleware always only deal with parsing rules, driving the flow of responsibility. This avoids the function expansion of the engine components and keeps the engine components nimble.

    A common business process invokes the diagram of the Process Engine service interface:

    Step 1: Calls that are currently executing the function unit initiation

    Step 2: Finished, the next step is already in the waiting function unit

  3. Advantages of the process engine middleware integration approach

    First, the responsibility of the process engine middleware is to parse the business rules and drive the business process. People are constantly encapsulating engine functions as components, which facilitates the invocation of business modules. By handing over the most complex and easily changing parts to the engine middleware, you will be able to focus more on the implementation of business functions. Separating the functionality of the engine components from the business modules reduces the overall complexity of the system and makes the business system easier to maintain.

    Second, the process engine middleware provides dynamic component references, as well as webservice access, to meet the integration requirements of multiple architectural systems. In the prevailing mode of software architecture in Internet Cloud mode, middleware can provide RESTful API interface in WebService way, so that the service of engine can cross system structure, organize boundary to drive business process flow, This distributed mode greatly plays the function of engine middleware.

  4. code example

The following code demonstrates the process of how a business class (production order) integrates the workflow engine and invokes the service interface.

  4.1 Implementing the Iwfserviceregister interface

    <summary>///    Workflow Registration interface///    </summary> public    interface Iwfserviceregister    {        Wfapprunner Wfapprunner {get; set;}        void Registerwfapprunner (Wfapprunner runner);    }

4.2 Interface Implementation code example

    <summary>///    Production order service///    sample code, do not use directly as a production project code. ///    </summary> public    partial class productorderservice:servicebase, Iproductorderservice, Iwfserviceregister    {        #region iworkflowregister members public        Wfapprunner Wfapprunner        {            get;            Set;        }        public void Registerwfapprunner (Wfapprunner runner)        {            wfapprunner = runner;        }        #endregion    }

4.3 Business Invocation Example

1) Wfservice Service Interface Registration

    Iwfserviceregister sr = Productorderservice as Iwfserviceregister;    Sr. Registerwfapprunner (runner);    Wfappresult Appresult = productorderservice.sample (productorder);     The node method of the business class is called here, with the process interaction code inside.    if (appresult.status = = 1)        result = responseresult.success ("Proofing operation succeeded! ");    else        result = Responseresult.error (string. Format ("Proofing operation failed: {0}", appresult.message));

 2) Business class method implementation

    <summary>//Proofing//</summary>//<param name= "entity" ></param> public Wfapp        Result Sample (productorderentity entity) {var appresult = Wfappresult.default ();        var wfas = new Wfappinteropservice ();        var session = Sessionfactory.createsession (); try {session.            BeginTrans (); The process runs var result = Wfas.    Runprocess (Session, Wfapprunner, wfapprunner.conditions); The process interaction class invokes the if (result). Status = = wfexecutedstatus.success) {//write step record table write (Session, Wfapprunner, "proofing", Entity.id. ToString (), entity.                Ordercode, "complete proofing");                Business data Processing section, here is a simple example ...                UpdateStatus (Entity.id, (short) productorderstatusenum.sampled, session);                Session.commit ();            Appresult = Wfappresult.success (); } else {session.                Rollback (); Appresult = Wfappresult.Error (result.            Message); }} catch (System.Exception ex) {session.            Rollback (); Appresult = Wfappresult.error (ex.        Message); } finally {session.        Dispose ();    } return Appresult; }

4.4 Process app Interaction API Encapsulation

    <summary>///Workflow Run///</summary>//<param Name= "session" ></param>//< Param name= "Runner" ></param>///<returns></returns> public wfexecutedresult runprocess (idbsess Ion session, Wfapprunner Runner, idictionary<string, string> conditions = null) {var result = new Wfexecu        Tedresult ();        var wfservice = new WorkflowService (); var nodeviewlist = Wfservice.getnextactivitytree (runner, conditions).        Tolist<nodeview> ();       foreach (var node in nodeviewlist) {var performerlist = wfservice.getperformerlist (node); Read Performer list dictionary<string, performerlist> dict = new dictionary<string, performerlist> () according to the node role definition            ; Dict. ADD (node.            Activityguid, performerlist); Runner.            Nextactivityperformers = Dict; if (node. Isskipto = = true)//judgment processing on a particular node {result = Wfservice.jumpprocess (SessioN.connection, runner, session.            Transaction); } else {result = Wfservice.runprocessapp (session). Connection, runner, session.            Transaction);    }} return result; }

Slickflow.net Open Source Workflow Engine Basics Introduction (b)

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.