We know that while creating process definitions, the information about all workflow entities is defined in XPDL file. But sometimes, users are interested to add more information about these workflow entities and it is done using Extended Attributes.
Extended attributes are defined in XPDL as XML based tags in Key/Value pair fashion. Extended attributes should not be confused with Data Fields or Variables. The values of data fields can be updated at runtime but the values of extended attributes cannot be altered once defined in XPDL. From programming point of view, you can say that extended attributes act as Constants while data fields behave like variables.
[XPDL View of Extended Attributes]
<ExtendedAttributes>
<ExtendedAttribute Name="ParticipantID" Value="InvoiceCreator"/>
<ExtendedAttribute Name="XOffset" Value="250"/>
<ExtendedAttribute Name="YOffset" Value="60"/>
</ExtendedAttributes>
According to WFMC, extended attributes can be added to almost all workflow entities defined in the XPDL file but Aspose.Workflow currently supports only accessing the extended attributes of a Workflow Package, Process or an Activity. In this topic, we will discuss three ways to access the extended attributes of these workflow entities.
Accessing Extended Attributes of a Package
Developers can define the extended attributes for a workflow package containing any kind of information and then access this information in extended attributes at runtime using Aspose.Workflow.
Once you are logged on to Aspose.Workflow engine, please follow the steps below to access the extended attributes of a workflow 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, use ExtendedAttributes property of the IPackage instance to receive a list of all extended attributes defined for that package in the form of an IDictionary object
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);
//Obtain extended attributes of the specified package as an IDictionary object
IDictionary attributes=package.ExtendedAttributes;
[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)
'Obtain extended attributes of the specified package as an IDictionary object
Dim attributes As IDictionary = package.ExtendedAttributes
Accessing Extended Attributes of a Process
Similar to package, developers can also define extended attributes to any workflow process and then access these attributes at runtime using Aspose.Workflow API. The approach to do so is same as that of accessing extended attributes of a workflow package. But we have to access extended attributes of a process so, we 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. Use ExtendedAttributes property of the IProcess instance to receive a list of all extended attributes defined for that process in the form of an IDictionary object.
Please check out the code snippet given below for the better understanding.
Example:
[C#]
//Getting the instance of a specified process in the package
IProcess process=package.GetProcess("DemoProcess");
//Obtain extended attributes of the specified process as an IDictionary object
IDictionary attributes=process.ExtendedAttributes;
[VB.NET]
'Getting the instance of a specified process in the package
Dim process As IProcess = package.GetProcess("DemoProcess")
'Obtain extended attributes of the specified process as an IDictionary object
Dim attributes As IDictionary = process.ExtendedAttributes
Accessing Extended Attributes of an Activity
To access the extended attributes of a workflow activity, it is first required to access the activities of a workflow process then we can access their extended attributes. So, use Activities property of the IProcess instance. Activities property will return an array of all activities present in that workflow process. Now, developers can iterate through all activities and then use ExtendedAttributes property of each activity (represented by IActivity interface) to receive a list of all extended attributes defined for that activity in the form of an IDictionary object. The example code given below demonstrates this feature.
Example:
[C#]
//Getting the instance of a specified process in the package
IProcess process=package.GetProcess("DemoProcess");
//Iterating through all workflow activities in the process
foreach(IActivity activity in process.Activities)
{
//Obtain extended attributes of the workflow activity as an IDictionary object
IDictionary attributes=activity.ExtendedAttributes;
}
[VB.NET]
'Getting the instance of a specified process in the package
Dim process As IProcess = package.GetProcess("DemoProcess")
'Iterating through all workflow activities in the process
Dim activity As IActivity
For Each activity In process.Activities
'Obtain extended attributes of the workflow activity as an IDictionary object
Dim attributes As IDictionary = activity.ExtendedAttributes
Next