dotConnect for PostgreSQL Documentation
In This Topic
    Workflow Instance Store
    In This Topic

    As of version 7.2, dotConnect for PostgreSQL implements PostgreSQL Workflow Instance Store. To use PostgreSQL Workflow Instance Store you need PostgreSQL server 8 or higher.

    Before using PostgreSQL Workflow Instance Store, you need to create a database that is used to persist workflow instances. dotConnect for PostgreSQL provides the scripts for creating this database. They are placed to the WF Services subfolder of the dotConnect for PostgreSQL installation folder. By default it is %ProgramFiles%\Devart\dotConnect\PostgreSQL\WF Services\. Note that there are two versions of scripts - for .NET Framework 4.5, and for previous versions of .NET Framework.

    If you target .NET Framework 4.5, execute the PgSqlInstanceStoreSchema45.sql script first and then execute PgSqlInstanceStoreLogic45.sql. If you target .NET Framework 3.0, 3.5, or 4.0, execute the PgSqlInstanceStoreSchema.sql script first and then execute PgSqlInstanceStoreLogic.sql. You may use these scripts to clean up the persistence database to have a fresh database in the same way, just execute them in the same order.

    Configuring InstanceStore for Self-Hosted Workflows that use WorkflowApplication

    To enable persistence for self-hosted workflows that use WorkflowApplication, perform the following steps:

    1. Add the reference to Devart.Data.PostgreSql.WorkflowFoundation.dll in your project.
    2. Specify the using directive:

      using Devart.Data.PostgreSql.DurableInstancing;
      Imports Devart.Data.PostgreSql.DurableInstancing
      
    3. Create PgSqlInstanceStore and assign the following code to the InstanceStore property of WorkflowApplication:

      PgSqlInstanceStore store = new PgSqlInstanceStore(your_connection_string);
      WorkflowApplication wfApp = new WorkflowApplication(new Workflow1());
      wfApp.InstanceStore = store;
      Dim store As New PgSqlInstanceStore(your_connection_string)
      Dim wfApp As New WorkflowApplication(New Workflow1())
      wfApp.InstanceStore = store
      
    4. Call the Persist() method on the WorkflowApplication to persist a workflow.

    Configuring InstanceStore with PgSqlInstanceStoreBehavior Class

    To enable persistence using the PgSqlInstanceStoreBehavior class, perform the following steps:

    1. Add a reference to the Devart.Data.PostgreSql.Activities.Description.dll
    2. Add the following statement at the top of the source file after the existing "using" statements.

      using Devart.Data.PostgreSql.Activities.Description;
      Imports Devart.Data.PostgreSql.Activities.Description
      
    3. Create an instance of the WorkflowServiceHost and add endpoints for the workflow service.

      WorkflowServiceHost host = new WorkflowServiceHost(new CountingWorkflow(), new Uri(hostBaseAddress));
      host.AddServiceEndpoint("ICountingWorkflow", new BasicHttpBinding(), "");
      Dim host As New WorkflowServiceHost(New CountingWorkflow(), New Uri(hostBaseAddress))
      host.AddServiceEndpoint("ICountingWorkflow", New BasicHttpBinding(), "")
      
    4. Construct an PgSqlInstanceStoreBehavior object and to set properties of the behavior object.

      PgSqlInstanceStoreBehavior instanceStoreBehavior = new PgSqlInstanceStoreBehavior(connectionString);
      instanceStoreBehavior.HostLockRenewalPeriod = new TimeSpan(0, 0, 5);
      instanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll;
      instanceStoreBehavior.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry;
      instanceStoreBehavior.InstanceEncodingOption = InstanceEncodingOption.GZip;
      instanceStoreBehavior.RunnableInstancesDetectionPeriod = new TimeSpan("00:00:02");
      host.Description.Behaviors.Add(instanceStoreBehavior);
      Dim instanceStoreBehavior As New PgSqlInstanceStoreBehavior(connectionString)
      instanceStoreBehavior.HostLockRenewalPeriod = New TimeSpan(0, 0, 5)
      instanceStoreBehavior.InstanceCompletionAction = InstanceCompletionAction.DeleteAll
      instanceStoreBehavior.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry
      instanceStoreBehavior.InstanceEncodingOption = InstanceEncodingOption.GZip
      instanceStoreBehavior.RunnableInstancesDetectionPeriod = New TimeSpan("00:00:02")
      host.Description.Behaviors.Add(instanceStoreBehavior)
      
    5. Open the workflow service host.

      host.Open();
      host.Open()
      

    Configuring InstanceStore with Config File

    To configure PostgreSQL Instance Store by using the postgresqlInstanceStore behavior element in a configuration file, perform the following steps:

    1. Add the following behavior extension element to the Machine.config file so that you can use the <postgresqlInstanceStore> service behavior element in the configuration files of your applications to configure persistence for your services:

      <configuration>
          <system.serviceModel>
              <extensions>
                  <behaviorExtensions>
                      <add name="postgresqlInstanceStore" type="Devart.Data.PostgreSql.Activities.Configuration.PgSqlInstanceStoreElement, Devart.Data.PostgreSql.WorkflowFoundation, Version=7.1.26.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
                  </behaviorExtensions>
              </extensions>
          </system.serviceModel>
      </configuration>

      Note: Replace 7.1.26.0 in the code with your actual version.

    2. Configure PostgreSQL Instance Store by using the postgresqlInstanceStore behavior element in a configuration file of your application:

      <configuration>
          <system.serviceModel>
            <behaviors>  
              <serviceBehaviors>
          	    <behavior name="">
                      <postgresqlInstanceStore 
                          connectionString="host=server;database=test;user id=postgres;"
                          instanceEncodingOption="GZip | None"
                          instanceCompletionAction="DeleteAll | DeleteNothing"
                          instanceLockedExceptionAction="NoRetry | BasicRetry |AggressiveRetry"
                          hostLockRenewalPeriod="00:00:30" 
                          runnableInstancesDetectionPeriod="00:00:05" />
          	    </behavior>
              </serviceBehaviors>
            </behaviors>  
          </system.serviceModel>
      </configuration>

    See Also

    Workflow Tracking Support  | Development Tools and Features