Table of Contents

Getting started

The following guide helps you set up DCR.Workflow for integration in a larger project in the most common way.

This guide assumes that:

Setup

Here are the steps:

  1. Add the DCR.Workflow nuget package to your project.
  2. Add Runtime as a service. E.g., in a razor application in Program.cs:
Warning

It looks like the sample you are looking for does not exist.

Initialization

When a case is created, it is often necessary to run initially pending robots before any user interaction takes place. To facilitate this, you can use the Initialize method provided by the Runtime class.

    DCR.Workflow.Runtime middleware = ...
    Model model = await ...                         // Load "model" from persistent storage.
    var context = new Dictionary<string, string> {  // Provide contextual information for
      { "CaseId":   /* caseid */,                     //   ativity exection
        "UserId": /* id of current user */
      }
    }; 
    await middleware.Initialize(model, context);
    ...                                             // Persist to storage with a preferred method

Executing events

Use one of the Runtime.Execute methods to advance model state, executing effects in the process.

Applications commonly proceed as follows:

    DCR.Workflow.Runtime middleware = ...        // Acquire Runtime via DI
    Model model = await ...                         // Load "model" from persistent storage.
    var context = new Dictionary<string, string> {  // Provide contextual information for
      { "CaseId":   /* caseid */,                     //   ativity exection
        "UserId": /* id of current user */
      }
    }; 
    await middleware.Execute(model, activity);      // Update state of model by executing "activity". 
                                                    // "Execute" runs side-effects and executes
                                                    // additional activities as required by "model".
    await ... (model.ToXDocument())                 // Write back "model" to persistent storage
Caution

The DCR.Workflow.Model.Execute(DCR.Workflow.Activity,DCR.Core.Data.value) method on the Model class does not execute effects. Use as described above if you execute effects.