Starting a workflow

To write Flower client application you need the Flower client API to be installed. You can install it by running MSBuild in the Flower package directory:

msbuild /t:Client /p:InstallDir=c:\Your\Flower\Installation\Path

Normally, client applications access Flower via Flower.Client.IFlowerClient interface from Flower.Client.dll. The API provides an implementation of this interface Flower.Client.FlowerClient and the WCF directory proxy Flower.Client.DirectoryClient which is implementation of IDirectory service interface. FlowerClient constructor accepts an instance of IDirectory and an instance of Flower.Client.FlowerClientSettings which is a set of properties - one for each client setting.

You should always use not more than one instance of FlowerClient per application domain.

In most of cases you will need to setup WCF client endpoint of the directory service in the application configuration file and then, in runtime, create a singleton instance of FlowerClient provided with directory service proxy instance and settings. If you use Spring.NET, your Flower client configuration may look like this:

<objects xmlns=""
  <object id="flowerClient" type="Flower.Client.FlowerClient, Flower.Client">
    <constructor-arg name="directory">
      <object type="Flower.Client.DirectoryClient, Flower.Client">
        <constructor-arg name="endpointConfigurationName" value="Directory" />
    <constructor-arg name="settings">
      <object type="Flower.Client.FlowerClientSettings, Flower.Client">
        <property name="ApplicationContextLoadersCount" value="10" />
        <property name="ApplicationContextExpirationCheckInterval" value="00:00:15" />
        <property name="TransactionTimeout" value="00:01:00" />

The settings constructor argument is optional; each particular setting has default value, so any of them may be omitted.

To start a workflow, you need to call IFlowerClient.StartProcess method providing a workflow path, an input argument and a logger.

For the StartProcess method a workflow can be identified by either local or global path. A global path starts with '/'; a local path is considered relative to '/Workflows' folder.

The argument passed to StartProcess will be passed to Initialize method of the workflow.

To obtain a logger, an application needs to reference Flower.Logging.dll. To create a logger, call Flower.Logging.LogManager.CreateLog. You can use a single global logger instance for each logging source just like in log4net or NLog. The logger passed to the StartProcess method is available in the initializer of a workflow via context.Log. To learn more about logging, see "Flower logging".

The IFlowerClient.StartProcess method loads workflow information from the directory, instantiates the process definition type via reflection using the default constructor, calls Initialize method of the created instance and saves the first process state. The client creates an ambient transaction around Initialize call and the process state saving, so that, if the initialization changes the state of a transactional resource, this change and the process state saving will be a single atomic operation. The isolation level of the transaction is ReadCommitted.

It is important to note that the FlowerClient class in the constructor attaches a handler to AssemblyResolve of the current application domain. This handler resolves assemblies from the directory, so that it is not required to install the assemblies containing workflows locally on the host of an application starting workflows. The handler is detached as the FlowerClient instance is disposed. If, by some reason, you don't want the assemblies in your application to be resolved from the directory, you need to wrap IFlowerClient.StartProcess calls in a service running in a separate application domain.

The IFlowerClient.StartProcess method returns as the first process state is saved and the transaction is committed. It returns the result of the Initialize call and the process id (pid) using which an application can communicate with the process. To learn more, see "Sets and inter-process communication in Flower".

Last edited Jan 30, 2014 at 6:42 PM by dbratus, version 3


No comments yet.