Aspose.Workflow allows its users to access all activities present in a workflow process with the help of its easy to use application programming interface. All workflow processes contain some activities defined in XPDL files. In this topic, we will describe that how can developers retrieve the activities of a workflow process using Aspose.Workflow.
Please follow the steps below to access the activities of a workflow process but before that be sure that you have logged on to Aspose.Workflow engine:
- Create a reference of IPackageAdmin interface using PackageAdmin property of IEngine object
- Pass the ID of any desired workflow package to the GetPackage method of the IPackageAdmin object to obtain the reference of that specified package. GetPackage creates the reference of IPackage interface
- Use GetProcess method of the IPackage object and pass the ID of the desired process to GetProcess method as a parameter. Then an instance of IProcess interface containing the process definitions of that specific process, is returned by GetProcess method
- Once the object of desired process (IProcess) is obtained then use Activities property of the IProcess object. Activities property will return all activities (in the form of an array of IActivity interface, which represents an activity in Aspose.Workflow) present in that workflow process.
Now, developers can iterate through all activities and retrieve their information. Each activity in the array is represented by an instance of IActivity interface. Once an object of IActivity is obtained, you can easily use the properties offered by the IActivity to retrieve all information associated to that activity. For example, you can use the following properties of IActivity:
- Id , provides the ID of the specific activity
- Name , provides the name of the specific activity
- PackageId , provides the package ID of the specific activity
- Performer , provides the performer ID of the specific activity. This property can also return a null to indicate that the specific activity has no performer associated to it
- ActivityBlock , provides the activity block in which the activity is contained. A null is returned if activity is not contained in any activity block
- Subflow , provides the subflow in which the activity is contained. A null is returned if activity is not contained in any subflow
The implementation of above steps is shown below in an example.
Example:
[C#]
//Instantiate an object of EngineManager
EngineManager manager = EngineManager.Instance;
//Configure the EngineManager object
manager.Configure();
//Create an object of IEngine interface
IEngine engine = manager.Engine;
//Login to the Aspose.Workflow engine
engine.Login("aspose","aspose");
//Create an instance of IPackageAdmin interface
IPackageAdmin packageAdmin = engine.PackageAdmin;
//Storing the package ID
string packageID="ContractPackage";
//Getting the reference of the package using its ID
IPackage package = packageAdmin.GetPackage(packageID);
//Getting the instance of a specified process in the package
IProcess process=package.GetProcess("DemoProcess");
//Accessing all activities of the specified process as an array of IActivity
IActivity[] activities= process.Activities;
//Iterating through all activities
foreach(IActivity activity in activities)
{
//Accessing the activity ID
string activityId=activity.Id;
//Accessing the activity name
string activityName=activity.Name;
//Accessing the package ID
string packageId=activity.PackageId;
//Accessing the ID of the performer of the activity
string performerId=activity.Performer;
//Accessing the activity block in which the activity is contained
IActivityBlock activityBlock=activity.ActivityBlock;
//Accessing the subflow in which the activity is contained
ISubflow subflow=activity.Subflow;
}
[VB.NET]
'Instantiate an object of EngineManager
Dim manager As EngineManager = EngineManager.Instance
'Configure the EngineManager object
manager.Configure()
'Create an object of IEngine interface
Dim engine As IEngine = manager.Engine
'Login to the Aspose.Workflow engine
engine.Login("aspose","aspose")
'Create an instance of IPackageAdmin interface
Dim packageAdmin As IPackageAdmin = engine.PackageAdmin
'Storing the package ID
Dim packageID As String = "ContractPackage"
'Getting the reference of the package using its ID
Dim package As IPackage = packageAdmin.GetPackage(packageID)
'Getting the instance of a specified process in the package
Dim process As IProcess = package.GetProcess("DemoProcess")
'Accessing all activities of the specified process as an array of IActivity
Dim activities() As IActivity = process.Activities
'Iterating through all activities
Dim activity As IActivity
For Each activity In activities
'Accessing the activity ID
Dim activityId As String = activity.Id
'Accessing the activity name
Dim activityName As String = activity.Name
'Accessing the package ID
Dim packageId As String = activity.PackageId
'Accessing the ID of the performer of the activity
Dim performerId As String = activity.Performer
'Accessing the activity block in which the activity is contained
Dim activityBlock As IActivityBlock = activity.ActivityBlock
'Accessing the subflow in which the activity is contained
Dim subflow As ISubflow = activity.Subflow
Next
Accessing an Activity by its ID
Developers can access an instance of a particular activity of a workflow process by calling GetActivityById method of IProcess interface. This method takes the ID of a workflow activity and returns an instance of IActivity representing the specified activity. Developers can use the properties offered by IActivity to retrieve all information about the activity as shown below in the code snippet.
Example:
[C#]
//Getting the instance of a specified process in the package
IProcess process=package.GetProcess("DemoProcess");
//Accessing an activity of the specified process by using its activity ID
IActivity activity= process.GetActivityById("8_4_TestInstance_TestInstance_Wor1");
//Accessing the activity name
string activityName=activity.Name;
//Accessing the package ID
string packageId=activity.PackageId;
//Accessing the ID of the performer of the activity
string performerId=activity.Performer;
//Accessing the activity block in which the activity is contained
IActivityBlock activityBlock=activity.ActivityBlock;
//Accessing the subflow in which the activity is contained
ISubflow subflow=activity.Subflow;
[VB.NET]
'Getting the instance of a specified process in the package
Dim process As IProcess = package.GetProcess("DemoProcess")
'Accessing an activity of the specified process by using its activity ID
Dim activity As IActivity = process.GetActivityById("8_4_TestInstance_TestInstance_Wor1")
'Accessing the activity name
Dim activityName As String = activity.Name
'Accessing the package ID
Dim packageId As String = activity.PackageId
'Accessing the ID of the performer of the activity
Dim performerId As String = activity.Performer
'Accessing the activity block in which the activity is contained
Dim activityBlock As IActivityBlock = activity.ActivityBlock
'Accessing the subflow in which the activity is contained
Dim subflow As ISubflow = activity.Subflow
Accessing an Activity by its Name
Developers can also access an instance of a particular activity of a workflow process by calling GetActivityByName method of IProcess interface. This method takes the name of a workflow activity and returns an instance of IActivity representing the specified activity. Developers can use the properties offered by IActivity to retrieve all information about the activity as shown below in the code snippet.
Example:
[C#]
//Getting the instance of a specified process in the package
IProcess process=package.GetProcess("DemoProcess");
//Accessing an activity of the specified process by using its activity name
IActivity activity= process.GetActivityByName("Normal Activity 1");
//Accessing the activity ID
string activityId=activity.Id;
//Accessing the package ID
string packageId=activity.PackageId;
//Accessing the ID of the performer of the activity
string performerId=activity.Performer;
//Accessing the activity block in which the activity is contained
IActivityBlock activityBlock=activity.ActivityBlock;
//Accessing the subflow in which the activity is contained
ISubflow subflow=activity.Subflow;
[VB.NET]
'Getting the instance of a specified process in the package
Dim process As IProcess = package.GetProcess("DemoProcess")
'Accessing an activity of the specified process by using its activity name
Dim activity As IActivity = process.GetActivityByName("Normal Activity 1")
'Accessing the activity ID
Dim activityId As String = activity.Id
'Accessing the package ID
Dim packageId As String = activity.PackageId
'Accessing the ID of the performer of the activity
Dim performerId As String = activity.Performer
'Accessing the activity block in which the activity is contained
Dim activityBlock As IActivityBlock = activity.ActivityBlock
'Accessing the subflow in which the activity is contained
Dim subflow As ISubflow = activity.Subflow