Workflow Engine Guide
Workflow Engine Guide
workflowenginenet.com
Guide
Workflow Engine .NET
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
ontent
1. Intro
2. Core
2.2. WorkflowRuntime
2.3. Scheme
2.4. DB Interfaces
10
11
3. Designer
13
3.1.Server-side
13
3.2.Client-side
13
3.3.Toolbar
15
3.4.Activities
15
3.5.Transitions
17
3.6.Actors
18
3.7.Commands
19
3.8.Parameters
19
3.9.Timers
19
3.10.Creating a scheme
21
4. F.A.Q.
22
22
22
23
24
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
1. Intro
WorkflowEngine.NET - component that adds workflow in your application. It can be fully integrated
into your application, or be in the form of a specific service (such as a web service).
The benefits of using WorkflowEngine.NET:
Designer of process scheme in web-browser (HTML5)
High performance
Quick adding to your project workflow
Autogenerate incoming list
Change the scheme process in real-time
Database providers: MS SQL Server, MongoDB, RavenDB.
WorkflowEngine.NET is perfect for:
Adding workflow in your application with minimal changes to your code
The process of challenging and \ or frequently changing
Some modules or some applications need to change the status of the documents
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
2. Core
The core supports the following basic workflow functions:
Creating processes
Defining the current state
Receiving commands accessible to the user
Executing commands
Forcing set state
Impersonation
Schema versioning
Localization
A document scheme is presented as an XML that can be modified manually or via a designer.
The engine uses two-stage scheme processing: a basic schema and a schema of process.
The schema is used as a basic processing method. The schema are stored in the
WorkflowScheme table.
The schema of process is generated based on the workflow group scheme processes with the help
of IWorkflowGenerator. The group of processes can be differentiated by the scheme code and the
set of parameters for generation. The schema of processes are stored in the
WorkflowProcessScheme table.
For impersonation (i.e. to execute commands on behalf of another person), use an additional
parameter: impersonatedIdentityId.
The route is specified by a set of Activities and Transitions. In Activity, indicate the document
status, a set of methods that must be executed when a document reaches a specific Activity. In
Transition, indicate possible transitions between Activities, transition limitations, and events that
cause a transition.
The rules for changing Activities:
1. To execute a route, begin with an Activity marked as Initial. The system changes the status of
the process to this Activity.
2. To set the status in Activity, the system consistently calls all Actions from Implementation
block (Pre-ExecutionImplementation in Pre-Execution mode).
3. Each outgoing Transition requires a check for an automatic change. For this, the system uses
the Conditions block to look for Transitions with an Auto type. If such a transition is possible,
the system automatically moves the document into a linked Activity. If a transition is not
possible, the document remains in the same Activity.
4. If an Activity is marked as Final or an Activity has no outgoing Transitions, then the process
changes its status to Finalized. Otherwise the process becomes Idle.
5. At each stage, the available commands are defined on the basis of the current Activity and
conditions for Restrictions in linked Transitions.
6. When executing a command (or by using a trigger), the system checks the possibility for a
specified user to make a transition based on the data from Conditions block. If a transition is
possible, the document moves into the next Activity.
7. In the event of process errors, the document changes its status to Terminated.
8. You can change the Finalized or Terminated processes by calling the SetState method.
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
Create IWorkflowBuilder
IWorkflowBuilder builder = new WorkflowBuilder<XElement>(
new DbXmlWorkflowGenerator(connectionString),
new XmlWorkflowParser(),
new DbSchemePersistenceProvider(connectionString)
).WithDefaultCache();
Create WorkflowRuntime
WorkflowRuntime runtime = new WorkflowRuntime(new Guid("{8D38DB8F-F3D5-4F26-A989-4FDD40F32D9D}"))
.WithBuilder(builder)
.WithActionProvider(new WorkflowActions())
.WithRuleProvider(new WorkflowRule())
.WithPersistenceProvider(new DbPersistenceProvider(connectionString))
.WithTimerManager(new TimerManager())
.WithBus(new NullBus())
.SwitchAutoUpdateSchemeBeforeGetAvailableCommandsOn()
.Start();
2.2. WorkflowRuntime
The basic operations:
Create the instance
Getting the list of available commands
Execution of the command
Getting the list of available states to set
Set State
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
Parameters:
#
Parameter name
Type
Description
schemeCode
1 processId
Guid
2 identityId
string
3 impersonatedIdentityId
string
4 parameters
IDictionary<string,
object>
Parameters:
#
Parameter name
Type
Description
1 processId
Guid
2 identityIds
IEnumerable<string>
3 commandNameFilter
string
4 mainIdentityId
string?
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
Parameters:
#
Parameter name
Type
Description
1 processId
Guid
The process id
2 identityId
string
3 impersonatedIdentityId string
4 command
WorkflowCommand to execute
WorkflowCommand
Parameters:
#
Parameter name
Type
Description
1 processId
Guid
2 identityIds
CultureInfo
Set state
Function: WorkflowRuntime.SetState
Purpose: The call will set state for the process.
public void SetState(
Guid processId,
string identityId,
string impersonatedIdentityId,
WorkflowCommand command)
Parameters:
[email protected]
2015 OptimaJet
WorkflowEngine.NET 1.4
Parameter name
workflowenginenet.com
Type
Description
1 processId
Guid
The process id
2 identityId
string
3 impersonatedIdentityId string
4 state
string
state to execute
5 parameters
IDictionary<string,
object>
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
Method
Description
1 CreateInstance
2 ExecuteCommand
3 GetAllActorsForAllCommandTransitions
Getting Actors
GetAllActorsForDirectAndUndefinedCommandTransitions
GetAllActorsForDirectCommandTransitions
GetAllActorsForReverseCommandTransitions
4 GetAvailableCommands
5 GetAvailableStateToSet
6 GetCurrentActivityName
7 GetCurrentStateName
8 GetInitialCommands
9 GetInitialState
10 GetLocalizedCommandName
GetLocalizedCommandNameBySchemeId
GetLocalizedStateName
GetLocalizedStateNameByProcessName
GetLocalizedStateNameBySchemeId
11 GetProcessInstanceAndFillProcessParameters
12 GetProcessScheme
Getting ProcessScheme
13 GetProcessStatus
14 IsProcessExists
15 PreExecute
PreExecuteFromCurrentActivity
PreExecuteFromInitialActivity
16 SetSchemeIsObsolete
17 SetState
18 UpdateSchemeIfObsolete
2.3. Scheme
Workflow process scheme represented as XML.
Workflow scheme described by the following sections:
Activities
Transitions
Actors
Commands
Times
Parameters
Localization
[email protected]
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
2.4. DB Interfaces
Available providers of databases:
MS SQL Server / AsureSQL
MongoDB
RavenDB
If you are using a different database, you need to implement interfaces:
IPersistenceProvider
ISchemePersistenceProvider
IRuntimePersistence
IWorkflowGenerator
Typical db objects:
#
DB Objects
Description
1 WorkflowProcessScheme
2 WorkflowProcessInstance
3 WorkflowProcessInstancePersistence
4 WorkflowProcessInstanceStatus
5 WorkflowProcessTransitionHistory
6 WorkflowProcessTimer
7 WorkflowRuntime
8 WorkflowScheme
9 spWorkflowProcessResetRunningStatus
10 DropWorkflowProcess
11 DropWorkflowProcesses
10
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
Stage
Desctiption
1. Creating a process starts by calling CreateInstance and specifying the code
of scheme and generation parameters.
The engine then looks for an existing schema with specified parameters. If
there is a similar but obsolete scheme, or if the scheme does not exist, the core
then creates a new process scheme with the help of IWorkflowGenerator.
1 Create
Once the scheme is created, the following records are added to the tables:
WorkflowProcessInstance - main parameters of the process, such as
current state, previous state etc.
WorkflowProcessInstancePersistence - user defined parameters of the
process marked as "Persisted".
WorkflowProcessInstanceStatus - information about process execution
status.
2. The process status is marked as Initialized.
3. Actions from the Implementation section are executed consistently.
4. The process status is marked as Idle.
2 Idle
Wait state.
A special mode to ensure a consistent transition through all document statuses,
while executing Actions from the Pre-Execute Implemetation block. The mode
is used to create the next stages of document.
3 Pre-Execution
4 Execute
6 Set state
Continuity:
1. Check for user access to the operation.
2. Check for the state of the document (execution continues if the status is
Idle).
3. Transition into the next Activity, updating process parameters in
WorkflowProcessInstance and creating a record in
WorkflowProcessTransitionHistory.
4. Consistent execution of all Actions from the Implementation block.
5. Setting the status to Idle.
Setting the state is only available in the Activities marked as Set state. To call,
use SetState.
The process status remains unchanged.
11
2015 OptimaJet
WorkflowEngine.NET 1.4
Stage
workflowenginenet.com
Desctiption
The document moves to this stage if its scheme is marked as IsObsolete. In
this case, the system updates the scheme of process.
7 Updating scheme
8 Terminated
9 Finalized
In WorkflowProcessInstanceStatus, the document receives the status
Finalized.
12
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
3. Designer
The product provides a completely web-based designer that can be used to visually model
your business processes. Designer supports HTML5. You can use any compatible browser.
3.1.Server-side
To process server operations must be routing out in the method of requests:
WorkflowInit.Runtime.DesignerAPI.
Example for ASP.NET MVC:
public ActionResult API()
{
Stream filestream = null;
if (Request.Files.Count > 0)
filestream = Request.Files[0].InputStream;
var pars = new NameValueCollection();
pars.Add(Request.Params);
if(Request.HttpMethod.Equals("POST", StringComparison.InvariantCultureIgnoreCase))
{
var parsKeys = pars.AllKeys;
foreach (var key in Request.Form.AllKeys)
{
if (!parsKeys.Contains(key))
{
pars.Add(Request.Form);
}
}
}
var res = WorkflowInit.Runtime.DesignerAPI(pars, filestream, true);
if (pars["operation"].ToLower() == "downloadscheme")
return File(UTF8Encoding.UTF8.GetBytes(res), "text/xml", "scheme.xml");
return Content(res);
}
3.2.Client-side
Required:
JQuery v 1.11
JQuery.treeTable
KineticJS v 5
Using begins with the creation of the object: WorkflowDesigner:
var wfdesigner = new WorkflowDesigner({
name: 'simpledesigner',
apiurl: '/Designer/API',
renderTo: 'wfdesigner',
imagefolder: '/images/',
[email protected]
13
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
graphwidth: 1200,
graphheight: 800
});
Parameter
Description
1 name
Name
2 apiurl
Url API
3 renderTo
DIV
4 graphwidth
Width
5 graphheight
Height
Parameters:
schemecode
processid
schemeid
Show custom data:
wfdesigner.data = data;
wfdesigner.render();
Save:
wfdesigner.schemecode = schemecode;
wfdesigner.save(function () {
alert('The scheme is saved!');
});
Validation:
wfdesigner.validate();
14
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
3.3.Toolbar
Button
Comment
Create activity
Create an activity
Copy selected
Delete
Move
Move
Zoom In
Zoom in
Zoom Out
Zoom out
Zoom and position default set Zoom and position default set
Auto arrangement
Auto arrangement
Actors
Commands
Parameters
Localization
Timers
Additional Parameters
3.4.Activities
In Activity, indicate the document status, a set of methods that must be executed when a document
reaches a specific Activity.
The item is displayed as a rectangle.
15
2015 OptimaJet
WorkflowEngine.NET 1.4
Item
workflowenginenet.com
Description
1 Name
2 State
3 Delete
4 Create activity and transition Create new Activity and Transition (From: current activity; To: new
activity)
5 Create transition
Attribute name
Description
1 Name
Name
2 State
State name
3 Initial
4 Final
7 Implementation
8 PreExecution Implementation
16
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
3.5.Transitions
In Transition, indicate possible transitions between Activities, transition limitations, and events that
cause a transition.
#
1 Touch points
2 Active point
Indicates the type of transition. When you double-client opens a form of editing.
3 Delete button
Delete.
Type of Transition:
Name
Description
AA
Auto Always
AC
Auto Condition
AO
Auto Otherwise
CA
Command Always
CC
Command Condition
CO
Command Otherwise
TA
Timer Always
TC
Timer Condition
TO
Timer Otherwise
17
2015 OptimaJet
WorkflowEngine.NET 1.4
Attribute name
workflowenginenet.com
Description
1 Name
Name
2 From activity
3 To activity
4 Classifier
5 Restrictions
6 Triggers
7 Conditions
3.6.Actors
Used to define the Actors. Used in Transition-Restrictions.
18
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
Attribute name
Description
1 Name
Name
2 Rule
3 Value
3.7.Commands
Used to define the commands.
#
Parameter
Description
1 Name
Name
2 Input Parameters
Parameters
3.8.Parameters
Used to define the parameters.
#
Parameter
Description
1 Name
Name
2 Type
.NET-type
3 Purpose
Available values:
1. Temporary - parameter retains its value during the execution of command and is not
stored in the database (persistence store)
2. Persistence - parameter always retains its value and stored in the database
(persistence store);
3. System - parameter is the part of workflow engine
3.9.Timers
Used to define the Timers.
19
2015 OptimaJet
WorkflowEngine.NET 1.4
Attribute name
workflowenginenet.com
Description
1 Name
Name
2 Type
Types of timer:
1. Interval
2. Time
3. Date
4. DateAndTime
3 Value
Do not reset the timer, if the previous Activity was with the same
timer.
20
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
3.10.Creating a scheme
We recommend adhering to the following order when creating a process scheme:
1. Create Actors, Command, and Timers.
2. Create the first Activity marked as Initial.
3. Create Activities, in which the document can move from the current Activity. Link the current
and new Activities with the help of Transitions.
4. For each new Activity indicate:
4.1.
In the State fieldthe name of a documents status.
4.2.
If the status can be forcefully moved into a particular state, then check the box For set
state.
4.3.
If a scheme may be updated in this Activity, then check the box Auto scheme update.
4.4.
Fill in the Action calls in the boxes Implementation and Pre-ExecutionImplementation.
Methods from the Implementation box will be called, when the document moves to a
respective Activity (in Pre-Execute mode, methods from the Pre-Execution
Implementation box will be called). If you use the constructor functionality to build a
concordance history, then you need to add the appropriate methods in the data blocks (in
our example, these are UpdateTransitionHistory and WriteTransitionHistory, respectively).
5. For each new Transition:
5.1.
Indicate the value of the Classifier. Use Direct or Reverse for direct or reverse
Transitions, respectively.
5.2.
In the Restrictions block, indicate Actors with access rights for this Transition. When
several Conditions are indicated, they are grouped by AND. This function is available for
Trigger type equal Command.
5.3.
In the Triggers block, indicate the type of operation (as per p. 3.5) that initiates a
Transition.
5.4.
In the Condition block, indicate the type of Condition (as per p. 3.5) that helps define the
possibility of a Transition and choose an appropriate Transition Type.
6. If each new Activity contains possible Transitions, repeat pp. 36 for each Activity. If these
Activities are final, mark them as Final.
7. Create Parameters and indicate them in the appropriate Commands.
8. Create Localization.
9. The workflow is ready!
21
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
4. F.A.Q.
1. HOW TO SET A PROCESS STATUS?
Subscribe to ProcessStatusChanged event in WorkflowRuntime.
This event is called when the process status is changed.
To get the name of the status use:
e.ProcessInstance.CurrentState
To get the name of the status in your locale use GetLocalizedStateName method:
var nextState = WorkflowInit.Runtime.GetLocalizedStateName(e.ProcessId, e.ProcessInstance.CurrentState);
22
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
DestinationState = nextState,
DocumentId = processInstance.ProcessId,
InitialState = currentstate,
Command = command
};
context.DocumentTransitionHistories.InsertOnSubmit(historyItem);
context.SubmitChanges();
}
}
23
2015 OptimaJet
WorkflowEngine.NET 1.4
workflowenginenet.com
For Outbox:
A list of documents agreed upon by the user (or his assistant) can be obtained by filtering
WorkflowProcessTransitionHistory table by ExecutorIdentityId and ActorIdentityId fields.
To create a stage with simultaneous concordance among several users, do the following:
1. In IWorkflowRuleProvider, register a rule to check the user access rights to concordance. The
access should be defined by taking into account concordances previously executed at this
stage. Executed concordances are recorded in WorkflowProcessTransitionHistory table.
2. Add a record into the Actors block with a rule from p. 1.
3. Add a cyclical Transition to the current Activity with the following parameters: Trigger Type:
Command, Restrictions: Actor from p. 2.
4. In IWorkflowActionProvider, register an Action that will check whether or not the stage has been
fully concurred. Executed concordances are recorded in WorkflowProcessTransitionHistory
table.
5. Add an outgoing Transition to a current Activity with the following parameters: Trigger Type:
Auto, Condition Action: Action from p. 4.
24
2015 OptimaJet