Skip to main content

Workflow Activities

  • 4 minutes to read

Activities are the basic building blocks of workflows. Generally, you create a workflow by combining activities via the workflow designer. By default, the designer exposes a number of standard built-in activities that ship with WF, such as If, ForEach, or Delay. In addition to these, XAF comes with additional CRUD activities simplifying business object manipulation. This topic provides a general overview of how activities work on the inside, and describes XAF CRUD workflow activity specifics.

Overview

An activity is a reusable component that performs a single operation. On the inside, an activity is a descendant of the System.Workflow.ComponentModel.Activity class. Being a regular class, each activity can have a set of properties and events along with logic defining the activity functionality. An activity that performs a single function and derives from the Activity class, is called simple. An activity derived from the System.Workflow.ComponentModel.CompositeActivity class that can host other activities is called composite. Each activity has a signature formed by its set of arguments (see Variables and Arguments). Input arguments specify the data needed by an activity to function properly. Output arguments specify results of activity execution.

WF ships with a number of standard built-in activities. To learn about them, refer to the NET Framework 4 Built-In Activity Library MSDN article.

XAF CRUD Activities

Along with the activities provided by WF, the Workflow module ships with basic XAF-specific activities simplifying business object manipulation.

  • Workflow_Activity_NoPersistScopeNoPersistScope

    An activity that prevents a containing workflow instance from being persisted to the database and unloaded from memory when the workflow server stops or a long running workflow instance becomes inactive. An example of such a situation is a long running workflow instance, which has a Delay activity encapsulated into a While activity to perform routine tasks each day. After daily tasks are executed, the workflow server will start unloading the workflow instance state into the database. The server will attempt to persist all variables including those that reference business objects. Since these objects are not serializable, an exception will occur. Thus, all activities manipulating business objects should be encapsulated into the NoPersistScope activity or into its descendant - the ObjectSpaceTransactionScope activity. If you need to use a Delay activity, put it outside of the NoPersistScope activity scope. In case you need to have a delay between two operations with business objects, these operations should reside in two separate NoPersistScopes - one before a Delay activity and one after it. More details on persisting and unloading are available in Persistence Best Practices and NoPersistHandle Class MSDN topics.

  • Workflow_Activity_ObjectSpaceTransactionScopeObjectSpaceTransactionScope

    An activity derived from the NoPersistScope activity. Creates and maintains an Object Space. By default, the Object Space is automatically committed at the end of the ObjectSpaceTransactionScope activity. Use this activity to manipulate business objects.

  • Workflow_Activity_TransactionalGetObjectSpaceTransactionalGetObjectSpace

    Use this activity to retrieve the Object Space used by the containing ObjectSpaceTransactionScope. You can assign the retrieved Object Space to a variable via the Assign activity or you can call the Object Space’s methods via the InvokeMethod activity. The TransactionalGetObjectSpace activity can only be used inside an ObjectSpaceTransactionScope.

  • Workflow_Activity_CreateObjectSpaceCreateObjectSpace

    Use this activity when you need more than a single Object Space provided by the ObjectSpaceTransactionScope activity. The CreateObjectSpace activity can only be used inside one ObjectSpaceTransactionScope activity.

Object Space Activities

There are also several XAF-specific activities that invoke Object Space methods, and thus require an IObjectSpace instance. You cannot use these activities outside a NoPersistScope or an ObjectSpaceTransactionScope.

Activity Description Corresponding IObjectSpace method
Workflow_Activity_CommitChanges CommitChanges Saves all changes made to persistent objects to the database. IObjectSpace.CommitChanges
Workflow_Activity_CreateObject CreateObject<T> Creates an object of the specified type. IObjectSpace.CreateObject<ObjectType>
Workflow_Activity_DeleteObject DeleteObject<T> Deletes a persistent object and its aggregated objects. IObjectSpace.Delete
Workflow_Activity_FindObjectByCriteria FindObjectByCriteria<T> Searches for the first object of the specified type, matching a particular string criteria, e.g.:"[AssignedTo.Oid] = " + targetObjectId.ToString() IObjectSpace.FindObject<ObjectType>
Workflow_Activity_GetObjectKey GetObjectKey Returns the key property value of a particular object. IObjectSpace.GetObjectKey
Workflow_Activity_GetObjectsByCriteria GetObjectsByCriteria<T> Returns a collection of objects of the specified type, matching a particular criteria. IObjectSpace.GetObjects<T>
Workflow_Activity_GetObjectByKey GetObjectByKey<T> Returns a persistent object of the specified type with a particular key property value. IObjectSpace.GetObjectByKey<ObjectType>
Workflow_Activity_Rollback Rollback Cancels changes made to persistent objects. IObjectSpace.Rollback

Tip

You can also use custom activities.

See Also