Genpact Cora Knowledge Center

Support

Extend Functionality of a Task Activity

Write an extension to add functionality to a Task Execute procedure. Task Execute occurs on the following operations:

  • Submit
  • Fetch
  • Return
  • Assign
  • Others

This example shows how to perform an action during submit, fetch, or return operations.

Activate the Code

  1. Add a class library to your solution. Add the relevant references.
    • PNMsoft.Sequence
    • PNMsoft.Sequence.Forms
    • PNMsoft.Sequence.Security
    • PNMsoft.Sequence.Extension
  2. Strongly sign the project.
  3. Complete the code in the relevant places, and compile the assembly.
  4. Put the assembly in the GAC.
  5. Insert a new record into tblTemplateWorkflowExtensions.
    1. In fldType, type the assembly strong name.
    2. In fldGuid, type the GUID in the class decorator.

NOTE: If your code raises an exception, execution will continue.

//***************************************************
//
// Copyright (C) PNMsoft. All rights reserved.
// 
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//***************************************************
 
using System;
using PNMsoft.Sequence;
using PNMsoft.Sequence.Forms.Activities;
using PNMsoft.Sequence.Forms.Activities.Operations;
 
namespace SequenceEx.Tasks.Samples
{
 [WorkflowElementExtension("Generated Guid", Name = "TaskActivityExtension")]
 public sealed class TaskActivityExtension : WorkflowElementExtension<TaskActivity>
 {
 public TaskActivityExtension()
 {
 }
 
 protected override void OnAttached()
 {
 base.OnAttached();
 
 this.Owner.Executed += new EventHandler<ActivityExecutedEventArgs>(OnActivityExecuted);
 }
 
 protected override void OnDetached()
 {
 base.OnDetached();
 
 this.Owner.Executed -= new EventHandler<ActivityExecutedEventArgs>(OnActivityExecuted);
 }
 
 private void OnActivityExecuted(object sender, ActivityExecutedEventArgs e)
 {
 object inputData = e.Context.InputData;
 
 if (inputData is SubmitTaskOperationContext)
 {
 SubmitTaskOperationContext submitTaskOperationContext = (SubmitTaskOperationContext)inputData;
 
 //Insert your code here.
 }
 else if (inputData is FetchTaskOperationContext)
 {
 FetchTaskOperationContext fetchTaskOperationContext = (FetchTaskOperationContext)inputData;
 
 //Insert your code here.
 }
 else if (inputData is ReturnTaskOperationContext)
 {
 ReturnTaskOperationContext returnTaskOperationContext = (ReturnTaskOperationContext)inputData;
 
 //Insert your code here.
 }
 }
 }
}