Tuesday, December 7, 2010

Implementing Asynchronous AgilePart

Here is an example:- an asynchronous AgilePart calls an external web service (or any external service) for some data processing. The action for the data processing might take a few weeks. In this case, the resource for the process instance shall be swapped out from the memory of AgilePoint server for better performance.

i. In AgilePart code, set the Synchronous property to false (This is set to true by defalt).
public class MyAgilePartDescriptor : WFAgilePartDescriptor
{
public MyAgilePartDescriptor()
{
base.Synchronous = false;
}
}
ii. Pass the automatic work item ID when calling external service.
public void Method1(
WFProcessInstance pi,
WFAutomaticWorkItem w,
IWFAPI api,
NameValue[] parameters)
{
try
{
CallExternalService(w.WorkItemID);

if (w.Synchronous) MarkSuccess(api, pi, w, parameters);
}
catch (Exception ex)
{
HandleException(api, pi, w, parameters, ex);
}
}

iii. Once the AgilePart activity is exited, the status of the Automatic work item is set to “Waiting”. The process does not promote to the next activity.
iv. The external service that works with the asynchronous AgilePart shall call the CompleteProcedure function passing in the automatic work item ID (see example below) to notify AgilePoint server that the processing is completed, and AgilePoint Server set the status of this Automatic Work Item to “Completed” and promote the process instance to the next activity.

public void CallExternalService(string autoWorkItemID)
{
//....some processing codes here


IWFWorkflowService api = GetWorkflowService(); // refer tohttp://kb.ascentn.com/KB/KnowledgebaseArticle10020.aspx for details on getting workflow service object
api.CompleteProcedure(autoWorkItemID);

return;
}

No comments:

Post a Comment