0% found this document useful (0 votes)
205 views

Workflow Engine Guide

WorkflowEngine.NET is a .NET component that allows adding workflow capabilities to applications. It supports designing workflow schemes in a web browser, high performance, and integrating workflow quickly. The core allows creating processes, defining states, executing commands, and changing states. It uses XML schemes that can be modified manually or with a designer. Commands and next states are available based on the current activity and transition rules. The runtime provides methods for creating instances, getting available commands, executing commands, and setting states to control workflow in applications.

Uploaded by

Noel Koutlis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
205 views

Workflow Engine Guide

WorkflowEngine.NET is a .NET component that allows adding workflow capabilities to applications. It supports designing workflow schemes in a web browser, high performance, and integrating workflow quickly. The core allows creating processes, defining states, executing commands, and changing states. It uses XML schemes that can be modified manually or with a designer. Commands and next states are available based on the current activity and transition rules. The runtime provides methods for creating instances, getting available commands, executing commands, and setting states to control workflow in applications.

Uploaded by

Noel Koutlis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

WorkflowEngine.NET 1.

workflowenginenet.com

Guide
Workflow Engine .NET

[email protected]

2015 OptimaJet

WorkflowEngine.NET 1.4

workflowenginenet.com

ontent
1. Intro

2. Core

2.1. How to connect

2.2. WorkflowRuntime

2.3. Scheme

2.4. DB Interfaces

10

2.5. Life cycle

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

1. HOW TO SET A PROCESS STATUS?

22

2. HOW TO CREATE A DOCUMENT HISTORY FOR STATUS CHANGES?

22

3. HOW TO OBTAIN PROCESS LISTS FOR INBOX/OUTBOX FOLDERS?

23

4. HOW TO CREATE PARALLEL APPROVAL WITHIN A SINGLE STAGE?

24

[email protected]

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

[email protected]

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.

2.1. How to connect


Steps for connection the engine to your project:
[email protected]

2015 OptimaJet

WorkflowEngine.NET 1.4

workflowenginenet.com

Implementation of interface: IWorkflowRuleProvider, IWorkflowActionProvider


Create WorkflowBuilder
Create WorkflowRuntime
Implementation of interface: IWorkflowRuleProvider, IWorkflowActionProvider
IWorkflowRuleProvider - Interface of provider for Rules
public interface IWorkflowRuleProvider
{
List<string> GetRules();
bool Check(Guid processId, string identityId, string ruleName, string parameter);
IEnumerable<string> GetIdentities(Guid processId, string ruleName, string parameter);
}

IWorkflowActionProvider - Interface of provider for Actions


public interface IWorkflowActionProvider
{
void ExecuteAction(string name, ProcessInstance processInstance, string actionParameter);
bool ExecuteCondition(string name, ProcessInstance processInstance, string actionParameter);
List<string> GetActions();
}

Create IWorkflowBuilder
IWorkflowBuilder builder = new WorkflowBuilder<XElement>(
new DbXmlWorkflowGenerator(connectionString),
new XmlWorkflowParser(),
new DbSchemePersistenceProvider(connectionString)
).WithDefaultCache();

,where connectionString - connection string for database-provider

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

[email protected]

2015 OptimaJet

WorkflowEngine.NET 1.4

workflowenginenet.com

Create the instance


Function: WorkflowRuntime.CreateInstance
Purpose: Create instance of process.
public void CreateInstance(
string schemeCode,
Guid processId,
string identityId,
string impersonatedIdentityId,
IDictionary<string, object> parameters)

Parameters:
#

Parameter name

Type

Description

schemeCode

Code of the scheme

1 processId

Guid

The process id for which it is necessary to


obtain a list of commands

2 identityId

string

The user id who create the instance

3 impersonatedIdentityId

string

The user id for whom the instance is create

4 parameters

IDictionary<string,
object>

The parameters for creating scheme of


process.

Getting the list of available commands


Function: WorkflowRuntime.GetAvailableCommands
Purpose: Returns the list of available commands for current state of the process and known user
Id.
public IEnumerable<WorkflowCommand> GetAvailableCommands(
Guid processId,
IEnumerable<string> identityIds,
string commandNameFilter = null,
Guid? mainIdentityId = null)

Parameters:
#

Parameter name

Type

Description

1 processId

Guid

The process id for which it is necessary to


obtain a list of commands

2 identityIds

IEnumerable<string>

The users ids for which it is necessary to


obtain a list of commands

3 commandNameFilter

string

The name of the command which should


be checked. If the field is not specified,
function checks access to all commands

4 mainIdentityId

string?

The main user id

[email protected]

2015 OptimaJet

WorkflowEngine.NET 1.4

workflowenginenet.com

Execution of the command


Function: WorkflowRuntime.ExecuteCommand
Purpose: The call will execute the command.
public void ExecuteCommand(
Guid processId,
string identityId,
string impersonatedIdentityId,
WorkflowCommand command)

Parameters:
#

Parameter name

Type

Description

1 processId

Guid

The process id

2 identityId

string

The user id who executes the command

3 impersonatedIdentityId string

The user id for whom the command is


executed

4 command

WorkflowCommand to execute

WorkflowCommand

Getting the list of available states to set


Function: WorkflowRuntime.GetAvailableStateToSet
Purpose: Returns the list of available states, that can be set through the SetState function.
public IEnumerable<WorkflowState> GetAvailableStateToSet (
Guid processId,
CultureInfo culture)

Parameters:
#

Parameter name

Type

Description

1 processId

Guid

The process id for which it is necessary to


obtain a list of states

2 identityIds

CultureInfo

Culture for the name of the state


localization

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

The user id who executes the command

3 impersonatedIdentityId string

The user id for whom the command is


executed

4 state

string

state to execute

5 parameters

IDictionary<string,
object>

The parameters for set state of process.

A more complete list of the methods listed in the table below:

[email protected]

2015 OptimaJet

WorkflowEngine.NET 1.4

workflowenginenet.com

Method

Description

1 CreateInstance

Create instance of process

2 ExecuteCommand

Executing of the command

3 GetAllActorsForAllCommandTransitions
Getting Actors
GetAllActorsForDirectAndUndefinedCommandTransitions
GetAllActorsForDirectCommandTransitions
GetAllActorsForReverseCommandTransitions
4 GetAvailableCommands

Getting the list of available commands

5 GetAvailableStateToSet
6 GetCurrentActivityName
7 GetCurrentStateName
8 GetInitialCommands
9 GetInitialState
10 GetLocalizedCommandName
GetLocalizedCommandNameBySchemeId
GetLocalizedStateName
GetLocalizedStateNameByProcessName
GetLocalizedStateNameBySchemeId
11 GetProcessInstanceAndFillProcessParameters
12 GetProcessScheme

Getting ProcessScheme

13 GetProcessStatus

Getting status of process

14 IsProcessExists

Check whether a process exists

15 PreExecute
PreExecuteFromCurrentActivity
PreExecuteFromInitialActivity

Start preexecution mode

16 SetSchemeIsObsolete

Set flag IsObsolete for schema of process

17 SetState

Forcing set state

18 UpdateSchemeIfObsolete

Updating obsolete schemes

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

The schema are stored in table: WorkflowScheme.


The schema of processes are stored in table: WorkflowProcessScheme. The schema of process
updates when setting the flag IsObsolete.

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

Contains snapshot of process scheme, taken at the


moment of creating new process. Used for versioning of
schemes.

2 WorkflowProcessInstance

Contains main parameters of the process, such as


current state, previous state etc.

3 WorkflowProcessInstancePersistence

Contains user defined parameters of the process marked


as "Persisted".

4 WorkflowProcessInstanceStatus

Contains information about process execution status


(running or idled).

5 WorkflowProcessTransitionHistory

Contains history of the process transitions.

6 WorkflowProcessTimer

Contains active timer of process.

7 WorkflowRuntime

Will be presented in future versions.

8 WorkflowScheme

Contains master schemes for creating new processes

9 spWorkflowProcessResetRunningStatus

All processes will be marked as idled after execution of


this stored procedure.

10 DropWorkflowProcess

Deletes all information about the process.

11 DropWorkflowProcesses

Deletes all information about the processes.

[email protected]

10

2015 OptimaJet

WorkflowEngine.NET 1.4

workflowenginenet.com

2.5. Life cycle


#

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

To initialize the mode, call PreExecute (PreExecuteFromCurrentActivity/


PreExecuteFromInitialActivity).
The process status remains unchanged.
A mode to execute either a transition upon command, or a timed or automatic
transition.

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.

[email protected]

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

An automatic update of the process scheme is only possible in Activity marked


as Auto scheme update.
The process status remains unchanged.
The document moves to this stage in the event there are process errors.

8 Terminated

In WorkflowProcessInstanceStatus the document receives the status


Terminated.
The document moves to this stage, only after it reached the Activity marked as
Final or Activity without any outgoing Transitions.

9 Finalized
In WorkflowProcessInstanceStatus, the document receives the status
Finalized.

[email protected]

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);
}

Type of server operations is defined in the parameter operation:


load
save
uploadscheme
downloadscheme

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

Load data from server:


wfdesigner.load({ schemecode: <SampleWF> });

Parameters:
schemecode
processid
schemeid
Show custom data:
wfdesigner.data = data;
wfdesigner.render();

Create a new scheme:


wfdesigner.create();

Save:
wfdesigner.schemecode = schemecode;
wfdesigner.save(function () {
alert('The scheme is saved!');
});

Validation:
wfdesigner.validate();

For localization of use WorkflowDesignerConstants.

[email protected]

14

2015 OptimaJet

WorkflowEngine.NET 1.4

workflowenginenet.com

3.3.Toolbar
Button

Comment

Create activity

Create an activity

Copy selected

Coping selected items

Delete

Deleting selected items

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

Opening window Actors.

Commands

Opening window Commands.

Parameters

Opening window Parameters.

Localization

Opening window Localization. Used to define the localized


names of: state, command, parameter.

Timers

Opening window Timers. Used to define the timers.

Additional Parameters

Opening window Additional Parameters (IsObsolete, Defining


parameters, Process 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.

[email protected]

15

2015 OptimaJet

WorkflowEngine.NET 1.4

Item

workflowenginenet.com

Description

1 Name

Name of current activity

2 State

State of current activity

3 Delete

Deleting this activity

4 Create activity and transition Create new Activity and Transition (From: current activity; To: new
activity)
5 Create transition

Create new Transition (From: current activity)

When you double-click on the rectangle opens editing form.

Attribute name

Description

1 Name

Name

2 State

State name

3 Initial

The flag that specifies the initial status

4 Final

The flag that specifies the final status

5 For set state

Determines possibility to set this state through the function "Set


State"

6 Auto scheme update

Determines that if process scheme obsolete Workflow Runtime will try


upgrade it automatically

7 Implementation

Describes a set of Action*, which will be executed in case of the


execution of Activity

8 PreExecution Implementation

Activities which running when PreExecute method in


WorkflowRuntime is called

* List of action gets through the IWorkflowActionProvider.

[email protected]

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

Pulling these elements can be associated with other selected Activity.

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

Automatic transition, executed at all times.

AC

Auto Condition

Automatic transition, executed if a chosen Action returns a True


response.

AO

Auto Otherwise

Automatic transition, executed if other transitions not execute.

CA

Command Always

Transition upon command, executed at all times.

CC

Command Condition

Transition upon command, executed if a chosen Action returns


a True response.

CO

Command Otherwise

Transition upon command, executed if other transitions not


execute.

TA

Timer Always

Timer Transition, executed at all times.

TC

Timer Condition

Timer Transition, executed if a chosen Action returns a True


response.

TO

Timer Otherwise

Timer Transition, executed if other transitions not execute.

[email protected]

17

2015 OptimaJet

WorkflowEngine.NET 1.4

Attribute name

workflowenginenet.com

Description

1 Name

Name

2 From activity

Source Activity name

3 To activity

Destination Activity name

4 Classifier

Classifier to determine the direction of the document's movement. For


example, in case of denial.
Available values:
1. NotSpecified
2. Direct
3. Reverse

5 Restrictions

It's used to authorize current user for execute command

6 Triggers

Impacts, leading to the execution of the transition.


Type of impact:
1. Auto
2. Command
3. Timer

7 Conditions

Conditions that must be true, for execution of the transition.


Type of condition.
1. Always
2. Action*
3. Otherwise

* List of action gets through the IWorkflowActionProvider.

3.6.Actors
Used to define the Actors. Used in Transition-Restrictions.

[email protected]

18

2015 OptimaJet

WorkflowEngine.NET 1.4

workflowenginenet.com

Attribute name

Description

1 Name

Name

2 Rule

List of action gets through the IWorkflowRuleProvider

3 Value

Parameter for IWorkflowRuleProvider

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

4 DefaultValue Default value

3.9.Timers
Used to define the Timers.

[email protected]

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

Use UTC format:


12/16/2014 12:50:00
12/17/2014
12:51:00
For type Interval: integer value in milliseconds.
For custom culture use: WorkflowRuntime.SchemeParsingCulture.

4 Do not override timer if exists

[email protected]

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!

[email protected]

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);

Following this, set the status value in your database.

2. HOW TO CREATE A DOCUMENT HISTORY FOR STATUS CHANGES?


1. Register two functions in IWorkflowActionProvider.
1.1.
The first function (WriteTransitionHistory) is for making a list.*
1.2.
The second function (UpdateTransitionHistory) is for adding a current action into the table
of changes history.
2. Add these functions into Implemtation and Pre-Execute Implementation units for each
Activity that defines the document status.
3. Subscribe to ProcessStatusChanged event in WorkflowRuntime. In the command handler, do
the following:
3.1.
Delete empty history fields (if exists).
3.2.
Call PreExecuteFromCurrentActivity method in WorkflowRuntime.
*Use the process Instance.IdentityIds to form a list of potential approvers.

Example of method for PreExcute Implementation:


public static void WriteTransitionHistory(ProcessInstance processInstance, string parameter)
{
if (processInstance.IdentityIds == null)
return;
var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId,
processInstance.CurrentState);
var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId,
processInstance.ExecutedActivityState);
var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId,
processInstance.CurrentCommand);
using (var context = new DataModelDataContext())
{
GetEmployeesString(processInstance.IdentityIds, context);
var historyItem = new DocumentTransitionHistory
{
Id = Guid.NewGuid(),
AllowedToEmployeeNames = GetEmployeesString(processInstance.IdentityIds, context),
[email protected]

22

2015 OptimaJet

WorkflowEngine.NET 1.4

workflowenginenet.com

DestinationState = nextState,
DocumentId = processInstance.ProcessId,
InitialState = currentstate,
Command = command
};
context.DocumentTransitionHistories.InsertOnSubmit(historyItem);
context.SubmitChanges();
}
}

Example of method for Implementation:


public static void UpdateTransitionHistory(ProcessInstance processInstance, string parameter)
{
var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId,
processInstance.CurrentState);
var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId,
processInstance.ExecutedActivityState);
var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId,
processInstance.CurrentCommand);
using (var context = new DataModelDataContext())
{
var historyItem =
context.DocumentTransitionHistories.FirstOrDefault(
h => h.DocumentId == processInstance.ProcessId && !h.TransitionTime.HasValue &&
h.InitialState == currentstate && h.DestinationState == nextState);
if (historyItem == null)
{
historyItem = new DocumentTransitionHistory
{
Id = Guid.NewGuid(),
AllowedToEmployeeNames = string.Empty,
DestinationState = nextState,
DocumentId = processInstance.ProcessId,
InitialState = currentstate
};
context.DocumentTransitionHistories.InsertOnSubmit(historyItem);
}
historyItem.Command = command;
historyItem.TransitionTime = DateTime.Now;
if (string.IsNullOrWhiteSpace(processInstance.IdentityId))
historyItem.EmployeeId = null;
else
historyItem.EmployeeId = new Guid(processInstance.IdentityId);
context.SubmitChanges();
}
}

3. HOW TO OBTAIN PROCESS LISTS FOR INBOX/OUTBOX FOLDERS?


For Inbox:
1. Create a WorkflowInbox table (Id, ProcessId, IdentityId).
[email protected]

23

2015 OptimaJet

WorkflowEngine.NET 1.4

workflowenginenet.com

2. Subscribe to ProcessStatusChanged event in WorkflowRuntime and run the following


algorithm:
2.1.Delete all records from WorkflowInbox table for the current ProcessId.
2.2.Using GetAllActorsForDirectCommandTransitions, get IDs of all users who can execute
periods in the current Activity.
2.3.Add the necessary records to WorkflowInbox table based on data from p. 2.2.
3. To get the list of incoming processes, filter the IdentityId field in the WorkflowInbox table.
4. To calculate the list of incoming documents, clear the WorkflowInbox table and call
GetAllActorsForDirectCommandTransitions for every active process. If there are a lot of active
processes, this operation may take a long time.

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.

5. HOW TO CREATE PARALLEL APPROVAL WITHIN A SINGLE STAGE?

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.

[email protected]

24

2015 OptimaJet

You might also like