Flow Hello World

From FlexRule Wiki
(Redirected from Flow Hello Word)
Jump to: navigation, search

Modeling a Flow

The main container in Flow looks as follows:

  1. <Flow name="FlowName" version="1.0.0.0">
  2.   <Declaration>
  3.     <!-- section to define parameters: Variables or Types -->
  4.   </Declaration>
  5.  
  6.   <Nodes>
  7.     <!-- Nodes and Transitions come in this section -->
  8.   </Nodes>
  9.  
  10. </Flow>

where you can replace your name in the name setting of the model. In the Declaration section you can define the Parameter.

Mandatory Nodes

All Flows must have at least two Nodes:

  1. Start node
  2. End node

And a Transition that connects the Nodes to each other:

  1. <Flow name="FlowName" version="1.0.0.0">
  2.  
  3.   <Nodes>
  4.    <Start name="startNode">
  5.       <Transition name="tr1" to="endNode"/>
  6.    </Start>
  7.  
  8.    <End name="endNode" />
  9.   </Nodes>
  10.  
  11. </Flow>

In this example we simply defined a Flow that has two nodes and one transition that connects the Start node to the End node. Please note that the End Node cannot have any Transitions.

FirstFlow.png

Also, it is important that in a Flow all names must be unique (i.e., Nodes, Transitions, etc.).

Adding an Activity

The simplest way to add an task to be achieved in a Flow is using an Activity node.

  1. <Flow name="Flow1" version="1.0.0.0">
  2.   <Nodes>
  3.     <Start name="nodeStart">
  4.       <Transition name="tr0" to="Activity1" />
  5.     </Start>
  6.  
  7.     <Activity name="Activity1">
  8.       <Transition name="tr1" to="nodeEnd" />
  9.     </Activity>
  10.  
  11.     <End name="nodeEnd" />
  12.   </Nodes>
  13. </Flow>

This becomes a flow, similar to the following:

FirstFlow2.png

An activity in flow can either:

  1. Execute an expression expression parameter of an Activity node
  2. Be linked to other models:
    1. Procedural Activity node
    2. Validation Validator node
    3. Decision Table Decision Table node
    4. Natural Language Natural Language node
    5. Decision Requirement Diagram Drd node
    6. Information Requirement Diagram Ird node
    7. Sub-Flow CallFlow

Adding Hello World Action

In this example, we link the activity to a procedural logic. The simplest way of referencing an action to an Activity Node is referencing the Node to a procedure.

Let's say we have the following procedure saved as HelloWorld.xml

  1. <Procedure name="hello">
  2.   <Declaration>
  3.     <Using path="System.Console"/>
  4.   </Declaration>
  5.  
  6.   <CallMethod method='Console.WriteLine("From Flow: hello world!")'/>
  7. </Procedure>

Then using CallProc, we can reference the procedure to the node. Make sure that the Flow and Procedure models are both located next to each other.

Complete Flow Model

  1. <Flow name="FlowRuleFlow" version="1.0.0.0">
  2.   <Nodes>
  3.     <Start name="nodeStart">
  4.       <Transition name="tr0" to="Activity1" />
  5.     </Start>
  6.  
  7.     <Activity name="Activity1">
  8.       <CallProc contextMode="New" resultCopyMode="None">
  9.         <ProcSource uri="HelloWorld.xml" />
  10.       </CallProc>
  11.       <Transition name="tr1" to="nodeEnd" />
  12.     </Activity>
  13.  
  14.     <End name="nodeEnd" />
  15.   </Nodes>
  16. </Flow>


Executing a Flow

Executing the flow is easy. There are just a couple of steps that need to be followed.

  1. Loading a Runtime engine
  2. Calling run method of engine


  1. private void RunHelloWorld()
  2. {
  3.     //TODO: insert your path to the flow xml model source below, and replace YOUR_PATH_GOES_HERE with your path to your xml model source
  4.     string flowPath=YOUR_PATH_GOES_HERE; 
  5.     var engine = RuntimeEngine.FromXml(File.OpenRead(flowPath));
  6.  
  7.     // execute!
  8.     engine.Run();
  9. }