Persistence Provider Initialization
First, it is necessary to determine whether you need an SQL or NoSQL database and download the necessary provider from the downloads page or via NuGet. You will find provider's source code in the downloaded archive or in our GitHub repository.
If you use an RDMS such as MS SQL Server, PostgreSQL, Oracle or MySql you have to run the CreatePersistenceObjects.sql script, that creates the following tables in the database:
WorkflowProcessScheme
— all process schemes are kept here. TheScheme
column contains a serialized XML scheme, theSchemeCode
column has the scheme name (code).DefiningParameters
andDefiningParametersHash
columns contain the parameters passed to the scheme generator (feel free to explore our the Scheme Generation section to learn how to use them).IsObsolete
indicates the scheme's relevance: if it's relevant, new processes will rest on it (read the Schemes Update section). Other columns contain data for creating subprocesses (read about parallel branches in the Parallel Branches section).WorkflowProcessInstance
— contains process data, such as the current activity and state, previous activities, etc. There is also IDs of parent and root processes here.WorkflowProcessInstancePersistence
— this table keeps process parameters. Parameter values are serialized in JSON and shown in theValue
column.WorkflowProcessTransitionHistory
— contains information about successful process transitions. The table is used for process tracking.WorkflowProcessInstanceStatus
— theStatus
field indicates current process status: 0 - Initialized, 1 - Running, 2 - Idled, 3 - Finalized.WorkflowProcessTimer
— contains trigger actuation times for different processes.WorkflowGlobalParameter
— global Code Actions and subprocess trees are stored here.WorkflowScheme
— this table is used by the scheme generator by default. The scheme from designer is saved here; if WorkflowRuntime can't find a relevant scheme in theWorkflowProcessScheme
table, it grabs the scheme from here.WorkflowInbox
— doesn't belong to Workflow Engine but is used in our examples as the inbox folder.WorkflowRuntime
- information about all workflow runtimes connected to this database is kept here.WorkflowSync
- is used in the multi-server mode for timer synchronization.
If you use Oracle, the tables will have different names:
WORKFLOWPROCESSTRANSITIONH
instead ofWorkflowProcessTransitionHistory
;WORKFLOWPROCESSINSTANCEP
instead ofWorkflowProcessInstancePersistence
;WORKFLOWPROCESSINSTANCES
instead ofWorkflowProcessInstanceStatus
;
With MongoDB all data are kept in structurally similar objects. In Redis the data are stored in key-value storage.
Take a look at the example of persistence provider initialization that you will need in the next section. The code for relational databases is quite similar.
for MS SQL:
// Get a DB connection string
var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
// Initiate a provider
var dbProvider = new MSSQLProvider(connectionString);for PostgreSQL:
// Get a DB connection string
var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
// Initiate a provider
var dbProvider = new PostgreSQLProvider(connectionString);for Oracle:
// Get a DB connection string
var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
// Initiate a provider
var dbProvider = new OracleProvider(connectionString);for MySQL:
// Get a DB connection string
var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
// Create a provider
var dbProvider = new MySQLProvider(connectionString);
For NoSQL databases, the code will be different.
for MongoDB:
// Get DB's URL and name from config
var url = ConfigurationManager.AppSettings["Url"];
var databaseName = ConfigurationManager.AppSettings["DatabaseName"];
// Create a MongoDatabase object
var mongoDatabase = new MongoClient(url).GetServer().GetDatabase(databaseName);
// Create a provider
var dbProvider = new MongoDBProvider(mongoDatabase);for Redis:
// Get Redis server URL from config
var url = ConfigurationManager.AppSettings["Url"];
// Create a ConnectionMultiplexer object
var multiplexer = ConnectionMultiplexer.Connect(url);
// Create a provider
var dbProvider = new RedisProvider(multiplexer);
The next section outlines WorkflowRuntime object initialization and creation.