Aspose.Workflow allows developers to access all or a specified process defined in a workflow package. In this topic, we will learn that how can we accomplish these tasks using Aspose.Workflow API.
Accessing All Processes in a Package
Using Aspose.Workflow, developers can upload workflow packages in the form of XPDL files containing process definitions. Once the packages are uploaded to Aspose.Workflow engine then developers can access these process definitions at runtime using Aspose.Workflow API.
After logging on to the Aspose.Workflow engine, please follow the steps below to access all processes in a package:
- 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
- Once the reference of your desired package is created, call GetAllProcesses method of the IPackage instance to receive an array of IProcess to represent all processes defined in that package
Developers can iterate through the array of all processes retrieved from the workflow package. Each process in the array is represented by an instance of IProcess interface. Once an object of IProcess is obtained, you can easily use the properties offered by the IProcess to retrieve all information associated to that process. For example, you can use the following properties of IProcess:
- Id , provides the ID of the specific process
- Name , provides the name of the specific process
- InstanceCount , provides the total number of instances of the specific process
- PackageId , provides the package ID of the specific process
Please review the example given below for the demonstration purposes.
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 an array of all processes in the specified package
IProcess[] processes = package.GetAllProcesses();
//Iterating through all processes
foreach(IProcess process in processes)
{
//Accessing the process ID
string processId=process.Id;
//Accessing the process name
string processName=process.Name;
//Accessing the total number of instances of the current process
int totalProcessInstances=process.InstanceCount;
//Access the package ID to which the current process belongs
string packageId=process.PackageId;
}
[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 an array of all processes in the specified package
Dim processes() As IProcess = package.GetAllProcesses()
'Iterating through all processes
Dim process As IProcess
For Each process In processes
'Accessing the process ID
Dim processId As String = process.Id
'Accessing the process name
Dim processName As String = process.Name
'Accessing the total number of instances of the current process
Dim totalProcessInstances As Integer = process.InstanceCount
'Access the package ID to which the current process belongs
Dim packageId As String = process.PackageId
Next
Accessing a Specific Process
To access a specific process in the workflow package, use GetProcess method of the IPackage object instead of calling its GetAllProcesses method. But, you will have to pass the ID of the desired process to GetProcess method as a parameter and then an instance of IProcess interface containing the process definitions of that specific process, will be returned. After having the instance of IProcess, you can easily access the information about that process using its properties and methods. Please check out the code snippet given below for better understanding.
Example:
[C#]
//Getting a specific process in the package
IProcess process = package.GetProcess("DemoProcess");
//Accessing the process name
string processName=process.Name;
//Accessing the total number of instances of the current process
int totalProcessInstances=process.InstanceCount;
//Access the package ID to which the current process belongs
string packageId=process.PackageId;
[VB.NET]
'Getting a specific process in the package
Dim process As IProcess = package.GetProcess("DemoProcess")
'Accessing the process name
Dim processName As String = process.Name
'Accessing the total number of instances of the current process
Dim totalProcessInstances As Integer = process.InstanceCount
'Access the package ID to which the current process belongs
Dim packageId As String = process.PackageId