Implement Interface to Get Action and Workflow Status Change Information from Engine
- Last UpdatedJun 10, 2024
- 2 minute read
In scenarios where custom logic has to be implemented on the basis of the changes in the status of Workflows or Actions, we can make use of the IWorkflowInformation interface to get the Workflow events from the AVEVA Work Tasks engine.
We can only get the status and cannot change it using this interface. The class implementing the Workflow.NET.Interfaces.IWorkflowInformation can be used the get alerts from engine on changes in status.
Note: This interface cannot be used to get Workflow Execution Pending status. In the sample code, we will create a dll which logs custom message on to the logger based on the change in the workflow status.
PROCEDURE
Dll REFERENCE
System
Workflow.NET.NET2
NAMESPACE USED
System
Workflow.NET
Workflow.NET.Interfaces
Skelta.Core
A sample implementation code is shown below.
using System;
using Workflow.NET;
using Workflow.NET.Interfaces;
public class ExecutionInfo:IWorkflowInformation, ISkeltaAddInProvider
{
Log logger = new Log();
public ExecutionInfo()
{
logger.MachineName="";
logger.ModuleName="WFExecutionInfo";
logger.Source="";
logger.FileName="";
}
public void OnActionExecutedWithErrors(int ExecutionId, int ExecutionDetailsID, string
ActionName, Exception ObjException)
{
// TODO: Add ExecutionInfo.OnActionExecutedWithErrors implementation
logger.LogInformation("Testing: Action executed with errors for ExecutionId:"+ ExecutionId
+", ExecutionDetailsID:"+ ExecutionDetailsID +", ActionName:"+ ActionName +", Exception:"+ObjException.Message);
}
public void OnWorkflowCompletedSuccessfully(int ExecutionId)
{
// TODO: Add ExecutionInfo.OnWorkflowCompletedSuccessfully implementation
logger.LogInformation("Testing: Workflow completed successfully for ExecutionId:"+
ExecutionId);
}
public string ApplicationName
{
get
{
// TODO: Add ExecutionInfo.ApplicationName getter implementation
return null;
}
set
{
logger.LogInformation("Testing: Application Name:"+ value);
}
}
public void OnActionStatusUpdate(int ExecutionId, int ExecutionDetailsID, string ActionName,
string Status)
{
// TODO: Add ExecutionInfo.OnActionStatusUpdate implementation
logger.LogInformation("Testing: Action status updated for ExecutionId:"+ ExecutionId
+", ExecutionDetailsID:"+ ExecutionDetailsID +", ActionName:"+ ActionName +", Status:"+Status);
}
public void OnWorkflowCompletedWithErrors(int ExecutionId)
{
// TODO: Add ExecutionInfo.OnWorkflowCompletedWithErrors implementation
logger.LogInformation("Testing: Workflow completed with errors for ExecutionId:"+
ExecutionId);
}
public void OnWorkflowStatusUpdate(int ExecutionId, string Status)
{
// TODO: Add ExecutionInfo.OnWorkflowStatusUpdate implementation
logger.LogInformation("Testing: Workflow status updated for ExecutionId:"+ ExecutionId
+", Status:"+ Status);
}
public void OnWorkflowStarted(int ExecutionId)
{
// TODO: Add ExecutionInfo.OnWorkflowStarted implementation
logger.LogInformation("Testing: Workflow started for Application:"+ ApplicationName
+", ExecutionId:"+ ExecutionId );
}
#region ISkeltaAddInProvider Members
Guid _Id = Guid.Empty;
public Guid Id
{
get { return _Id; }
}
public void InitializeProvider(string settings, Guid id)
{
_Settings = settings;
_Id = id;
}
string _Settings = "";
public string Settings
{
get { return _Settings; }
}
#endregion
}
Compile the class and add the dll in to the AVEVA Work Tasks\bin folder. Now make an entry in the SKAddInProviders table in the Repository database.
Run the following SQL Command, after providing the specific values for ClassName and Assembly on the repository database.
INSERT INTO SKAddInProviders (Type,[Name],ClassName,[Assembly],Settings,IsGacAssembly) VALUES('WorkflowInformation','WorkflowInformation','ClassName','bin\<DLLName>.dll','',1)
Note: Ensure the Name column of the table is unique. The Type and [Name] must be 'WorkflowInformation'.
To test the working of the implementation, test run a workflow from the specific repository with the logger kept open. You can see that the custom message getting displayed in the Logger Console.
