When workflow process instances are created using Aspose.Workflow then developers may also need to access these process instances at runtime to control or monitor them. So, Aspose.Workflow provides a variety of ways to access these workflow process instances. Developers may need to access these workflow process instances for many reasons, some of which are listed below:
- Removing all or particular workflow process instances
- Abort workflow process instances
- Retrieve information about workflow process instances etc.
There can be many other reasons, which depend upon the requirements of users. In this topic, we will discuss all those ways through which users can access these workflow process instances for any reason.
To access workflow process instances, users need to create an instance of IInstanceAdmin interface, which can be created using the InstanceAdmin property of IEngine interface. For more information about IEngine interface and its usage to create the objects of other interfaces, please Click here.
Accessing Only Running Instances
Whenever users create a process instance, it starts running and gets closed finishing its job. If developers need to access all process instances that are currently running in Aspose.Workflow engine then they need to call GetProcessInstanceList method of IInstanceAdmin interface. To get the list of all running process instances, developers would pass three parameters to this method as follows:
- Package ID, which contains the process definitions
- Process ID, whose instance is to be accessed
- true, a boolean value to retrieve Only Running process instances
When developers call GetProcessInstanceList method, they receive an array of IProcessInstance interface. Developers can iterate through this array of all process instances. Each process instance in the array is represented by an object of IProcessInstance interface. Once an object of IProcessInstance is obtained, you can easily use the properties offered by the IProcessInstance to retrieve all information associated to that process instance. For example, you can use the following properties of IProcessInstance:
- Id , provides the ID of the specific process instance
- ProcessId , provides the process ID of the specific process instance
- PackageId , provides the package ID of the specific process instance
- StartTime , provides the start time of the specific process instance
- StartUserName , provides the name of the user who started the specific process instance
- EndTime , provides the end time of the specific process instance
Please review the example below for better understanding about its usage.
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 IInstanceAdmin interface
IInstanceAdmin instanceAdmin = engine.InstanceAdmin;
//Access only running process instances by passing "true"
IProcessInstance[] instances = instanceAdmin.GetProcessInstanceList(
"DemoPackage","DemoProcess",true);
//Iterating through all process instances
foreach(IProcessInstance instance in instances)
{
//Accessing instance ID
string instanceId=instance.Id;
//Accessing the process ID of the specific process instance
string instanceId=instance.ProcessId;
//Accessing the package ID of the specific process instance
string instanceId=instance.PackageId;
//Accessing the start time of the specific process instance
DateTime instanceId=instance.StartTime;
//Accessing the user name who started the specific process instance
string instanceId=instance.StartUserName;
//Accessing the stop time of the specific process instance
DateTime instanceId=instance.StopTime;
}
[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 IInstanceAdmin interface
Dim instanceAdmin As IInstanceAdmin = engine.InstanceAdmin
'Access only running process instances by passing "true"
Dim instances() As IProcessInstance = instanceAdmin.GetProcessInstanceList(
"DemoPackage","DemoProcess",True)
'Iterating through all process instances
Dim instance As IProcessInstance
For Each instance In instances
'Accessing instance ID
Dim instanceId As String = instance.Id
'Accessing the process ID of the specific process instance
Dim instanceId As String = instance.ProcessId
'Accessing the package ID of the specific process instance
Dim instanceId As String = instance.PackageId
'Accessing the start time of the specific process instance
Dim instanceId As DateTime = instance.StartTime
'Accessing the user name who started the specific process instance
Dim instanceId As String = instance.StartUserName
'Accessing the stop time of the specific process instance
Dim instanceId As DateTime = instance.StopTime
Next
Accessing All Instances
If developers need to access all process instances in Aspose.Workflow engine including the Running and Closed ones then they again need to call GetProcessInstanceList method of IInstanceAdmin interface. To get the list of all process instances, developers would pass three parameters to this method as follows:
- Package ID, which contains the process definitions
- Process ID, whose instance is to be accessed
- false, a boolean value to retrieve All process instances
As we explained above, when developers call GetProcessInstanceList method, they receive an array of IProcessInstance interface. Developers can iterate through this array of all process instances and retrieve every kind of information associated to each process instance.
Please review the example below for better understanding about its usage.
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 IInstanceAdmin interface
IInstanceAdmin instanceAdmin = engine.InstanceAdmin;
//Access all process instances by passing "false"
IProcessInstance[] instances = instanceAdmin.GetProcessInstanceList(
"DemoPackage","DemoProcess",false);
//Iterating through all process instances
foreach(IProcessInstance instance in instances)
{
//Accessing instance ID
string instanceId=instance.Id;
//Accessing the process ID of the specific process instance
string instanceId=instance.ProcessId;
//Accessing the package ID of the specific process instance
string instanceId=instance.PackageId;
//Accessing the start time of the specific process instance
DateTime instanceId=instance.StartTime;
//Accessing the user name who started the specific process instance
string instanceId=instance.StartUserName;
//Accessing the stop time of the specific process instance
DateTime instanceId=instance.StopTime;
}
[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 IInstanceAdmin interface
Dim instanceAdmin As IInstanceAdmin = engine.InstanceAdmin
'Access all process instances by passing "false"
Dim instances() As IProcessInstance = instanceAdmin.GetProcessInstanceList(
"DemoPackage","DemoProcess",False)
'Iterating through all process instances
Dim instance As IProcessInstance
For Each instance In instances
'Accessing instance ID
Dim instanceId As String = instance.Id
'Accessing the process ID of the specific process instance
Dim instanceId As String = instance.ProcessId
'Accessing the package ID of the specific process instance
Dim instanceId As String = instance.PackageId
'Accessing the start time of the specific process instance
Dim instanceId As DateTime = instance.StartTime
'Accessing the user name who started the specific process instance
Dim instanceId As String = instance.StartUserName
'Accessing the stop time of the specific process instance
Dim instanceId As DateTime = instance.StopTime
Next
Accessing a Specific Instance
Aspose.Workflow also provides control to developers to access any specified process instance instead of having a list of process instances. For doing so, users would have to call GetProcessInstance method of IInstanceAdmin interface. This method would only require the ID of that process instance, which needs to be accessed and return an object of IProcessInstance interface. After the object of IProcessInstance is created then you can use the properties of IProcessInstance to access all information about that specific process instance.
An example is given below to demonstrate the use of this feature.
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 IInstanceAdmin interface
IInstanceAdmin instanceAdmin = engine.InstanceAdmin;
//Access a specific process instance by passing its instance ID
IProcessInstance instance = instanceAdmin.GetProcessInstance(
"1_TestInstance_TestInstance_Wor1");
//Accessing the process ID of the specific process instance
string instanceId=instance.ProcessId;
//Accessing the package ID of the specific process instance
string instanceId=instance.PackageId;
//Accessing the start time of the specific process instance
DateTime instanceId=instance.StartTime;
//Accessing the user name who started the specific process instance
string instanceId=instance.StartUserName;
//Accessing the stop time of the specific process instance
DateTime instanceId=instance.StopTime;
[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 IInstanceAdmin interface
Dim instanceAdmin As IInstanceAdmin = engine.InstanceAdmin
'Access a specific process instance by passing its instance ID
Dim instance As IProcessInstance = instanceAdmin.GetProcessInstance(
"1_TestInstance_TestInstance_Wor1")
'Accessing the process ID of the specific process instance
Dim instanceId As String = instance.ProcessId
'Accessing the package ID of the specific process instance
Dim instanceId As String = instance.PackageId
'Accessing the start time of the specific process instance
Dim instanceId As DateTime = instance.StartTime
'Accessing the user name who started the specific process instance
Dim instanceId As String = instance.StartUserName
'Accessing the stop time of the specific process instance
Dim instanceId As DateTime = instance.StopTimeDescribes how to start using Aspose.Workflow engine.12/28/2005 6:20:26 AM - -210.56.19.84