XAF Workflow persistence storage

XAF Team Blog
24 August 2011

The .NET Framework 4 ships with the SQL Workflow Instance Store which allows workflows to persist state information about workflow instances in a SQL Server 2005 or SQL Server 2008 database. However its implementation is based on stored procedures which can be a bit scary if you are not familiar with them. In addition our customers may follow different standards (Oracle, Firebird, VistaDB, MySQL, PostgreSQL etc.) and it’s unrealistic to hire more people to support SQL Server infrastructure.

Usually when dealing with these issues the first thing we do is to carry out a Google search for storage solutions. Surprisingly there is no such solution out there! Moreover there is very little useful code or samples available. Luckily XAF provides us with an easier route!

XAF is the perfect workflow modeling environment. It provides a ready made solution for creating and deploying a server that will execute workflows as described here.  In order to start modeling workflows we can use VS design time along with our re-hosted runtime Workflow designer and custom WF4 activities. XAF also gives us increased control over our workflows for example through the ability to manually start workflows. Finally since XAF uses XPO to access data we can easily support 16 different database systems simply by providing a connection string!

XPO Data Store Adapter XPO Data Store Adapter's Assembly Name Database Provider Assembly
AccessConnectionProvider DevExpress.Xpo.vXXX System.Data.dll
AdvantageConnectionProvider DevExpress.Xpo.vXXX.Providers Advantage.Data.Provider.dll 9.10.2.0
AsaConnectionProvider DevExpress.Xpo.vXXX.Providers iAnywhere.Data.SQLAnywhere.dll 11.0.0.12642
AseConnectionProvider DevExpress.Xpo.vXXX.Providers Sybase.Data.AseClient.dll 1.15.50.0
DB2ConnectionProvider DevExpress.Xpo.vXXX.Providers IBM.Data.DB2.dll 9.5.2.2
FirebirdConnectionProvider DevExpress.Xpo.vXXX.Providers FirebirdSql.Data.Firebird.dll 1.7.1.0
FirebirdSql.Data.FirebirdClient.dll 2.5.1.0
MSSqlConnectionProvider DevExpress.Xpo.vXXX System.Data.dll
MSSqlCEConnectionProvider DevExpress.Xpo.vXXX.Providers System.Data.SqlServerCe.dll 3.5.0
System.Data.SqlServerCe.dll 4.0.8482.1
MySqlConnectionProvider DevExpress.Xpo.vXXX.Providers MySql.Data.dll 5.2.5.0
OracleConnectionProvider DevExpress.Xpo.vXXX.Providers System.Data.OracleClient.dll 2.0.0.0
Oracle.DataAccess.dll 9.2.0.700
ODPConnectionProvider DevExpress.Xpo.vXXX.Providers Oracle.DataAccess.dll 10.1.0.200
PervasiveSqlConnectionProvider DevExpress.Xpo.vXXX.Providers Pervasive.Data.SqlClient.dll 2.10.0.15
PostgreSqlConnectionProvider DevExpress.Xpo.vXXX.Providers Npgsql.dll 2.0.11.0
SQLiteConnectionProvider DevExpress.Xpo.vXXX.Providers System.Data.SQLite.dll 1.0.61.0
VistaDBConnectionProvider DevExpress.Xpo.vXXX.Providers VistaDB.4.dll 4.0.0.0

More info @ Database Systems Supported by XPO

This is only one example of what XAF can do for us. XAF provides a comprehensive set of solutions that allow you to outsource all of the mundane programming tasks leaving you to focus purely on your business needs. For more info consult our docs, blogs, code central and support center.

DevExpress Workflow Instance Store

In version 11.1.7 our team now provides workflow instance support outside XAF borders! With a few lines of code, it is now possible to store our workflows in any of the 14 database systems described.

Durability is a key benefit of the Workflow Foundation and it is based on the ability to store a running workflow instance on the fly at almost any time.
To this end Microsoft workflow team implemented the SqlWokflowInstanceStore class. Using this class and a few lines is possible to store workflow instances in SQL Server as shown,

// Define SqlWorkflowInstanceStoreBehavior:

// Set interval to renew instance lock to 5 seconds.

// Set interval to check for runnable instances to 2 seconds.

// Instance Store does not keep instances after it is completed.

// Select exponential back-off algorithm when retrying to load a locked instance.

// Instance state information is compressed using the GZip compressing algorithm.

SqlWorkflowInstanceStoreBehavior instanceStoreBehavior = new SqlWorkflowInstanceStoreBehavior(connectionString);

instanceStoreBehavior.HostLockRenewalPeriod = new TimeSpan(0, 0, 5);

instanceStoreBehavior.RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2);

instanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll;

instanceStoreBehavior.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry;

instanceStoreBehavior.InstanceEncodingOption = InstanceEncodingOption.GZip;

host.Description.Behaviors.Add(instanceStoreBehavior);

The above code was copied from the "BuiltInConfiguration" demo, "InstanceStore1" project. This demo is described at "Built-in Configuration"
(
http://msdn.microsoft.com/en-us/library/ee622978.aspx). You can download full sources of this demo and many others at "WCF and WF Samples for .NET Framework 4"
(
http://www.microsoft.com/download/en/details.aspx?id=21459).

Following the same architecture our team implemented the DX WorkFlow Instance Store. eXpress Persistent Objects (XPO) is used for common objects storage and is fully capable of working transparently with 14 different database systems. For example to provide support for an Oracle database we could write,

//We create or connect to a database by setting the connectionstring

//This code will create 2 tables (XpoWorkflowInstance, XpoInstanceKeyc) in the database

using (var session = new Session()) {

session.ConnectionString = "Data Source=DevExpressInstanceStore;User Id=myUsername;Password=myPassword";

session.UpdateSchema(typeof(XpoWorkflowInstance), typeof(XpoInstanceKey));

session.CreateObjectTypeRecords(typeof(XpoWorkflowInstance), typeof(XpoInstanceKey));

}

// Define WorkflowInstanceStoreBehavior:

var dxInstanceStoreBehavior = new WorkflowInstanceStoreBehavior(

typeof(XpoWorkflowInstance), typeof(XpoInstanceKey), DevExpressConnectionString);

host.Description.Behaviors.Add(dxInstanceStoreBehavior);

dxInstanceStoreBehavior.RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 2);

dxInstanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll;

You can download a modified version of the “BuiltInConfiguration” solution here. The console application starts a long running workflow that implements a counting service. Once the service’s start method is invoked, the service counts from 0 to 59. The counter is incremented every 2 seconds. After each count the workflow persists so you can close the application at any time and when you start it next time it will continue. A new one will be started from '0' value in addition to the loaded instances. The second project “InstanceStore2” in the solution provides the same functionality, however it is configured using the app.config file as shown,

<system.serviceModel>

<extensions>

<behaviorExtensions>

<add name="DevExpressWorkflowInstanceStore" type="DevExpress.Workflow.Store.WorkflowInstanceStoreElement, DevExpress.Workflow.Activities.v11.1"/>

</behaviorExtensions>

</extensions>

<services>

<service name="CountingWorkflow" behaviorConfiguration="">

</service>

</services>

<behaviors>

<serviceBehaviors>

<behavior name="">

<!--<sqlWorkflowInstanceStore

connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=InstanceStore;Integrated Security=True;Asynchronous Processing=True"

hostLockRenewalPeriod="00:00:05" runnableInstancesDetectionPeriod="00:00:02" instanceCompletionAction="DeleteAll"

instanceLockedExceptionAction="AggressiveRetry" instanceEncodingOption="GZip"

/>-->

<DevExpressWorkflowInstanceStore

connectionString="Data Source=DevExpressInstanceStore;User Id=myUsername;Password=myPassword"

runnableInstancesDetectionPeriod="00:00:02" instanceCompletionAction="DeleteAll"/>

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

Note; All we need to do to use these code snippets in our code is to reference 'DevExpress.ExpressApp.v11.1.dll' and 'DevExpress.Workflow.Activities.v11.1.dl assemblies. Even though these assemblies are part of our eXpressApp framework and need a special license they can also be used to support any other type of .NET application!

We are waiting to read your feedback about this. Remember that your questions are the best candidates for future posts.

Related Links
Blog posts
Online documentation
Videos

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.