Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Work Tasks

Return Values from Engine to Client

  • Last UpdatedJun 10, 2024
  • 3 minute read

The below code sample attempts to demonstrate the communication between the AVEVA Work Tasks engine and the client. For example, based on the property Applicationuri entered in the Activity Properties of the custom action named "Agent app Navigator" [It is created by using the below code], appropriate messages are displayed in the Logger Console.

PROCEDURE

Dll REFERENCE  

System

Workflow.NET.NET2

NAMESPACE USED

System

System.Collections.Generic

System.Text

Workflow.NET

Steps to Create Custom Activity

Step 1

  1. Define the class for the custom action's handler using the following code; build as a DLL and put this dll in [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\Bin folder.

    using System;

    using System.Collections.Generic;

    using System.Text;

    using Workflow.NET;

     

    namespace AppNavigatorActivity

    {

        public class AppNavigator : Workflow.NET.Engine.Interfaces.IActionRun,Workflow.NET.Engine.Interfaces.IActionEventMessage

        {

            #region IActionRun Members

     

            Workflow.NET.Interfaces.IActivityWebUIHandler 

            Workflow.NET.Engine.Interfaces.IActionRun.GetActivityWebUIHandler()

            {

                throw new Exception("The method or operation is not implemented.");

            }

     Workflow.NET.Engine.Interfaces.ActionResult Workflow.NET.Engine.Interfaces.IActionRun.Run(int    ExecutionID, int ExecutionDetailsID, Workflow.NET.Engine.Context CurrentContext,

    Workflow.NET.Action CurrentAction, string InlinkOutput, bool Retrying, out string Output)

            {

                CurrentContext.log.LogInformation("Inside Action");

    //Setting blocking output value for a workflow

                CurrentContext.BlockingOutput = (string)((Property)CurrentAction.Properties["ApplicationURI"]).Value+","+ExecutionDetailsID;

                Output = "";

                return Workflow.NET.Engine.Interfaces.ActionResult.Sleep;

            }

     

            #endregion

     

     #region IActionEventMessage Members

     

    void Workflow.NET.Engine.Interfaces.IActionEventMessage.HandleEventMessage(int executionID, int executionDetailsID, Workflow.NET.Engine.Context currentContext, Workflow.NET.Action currentAction, object eventMessage, bool retrying, out string output, out Workflow.NET.Engine.Interfaces.ActionResult result, out bool ignoreOutputAndResult)

    {

          output = eventMessage.ToString().ToLower();

          result = Workflow.NET.Engine.Interfaces.ActionResult.Completed;

          ignoreOutputAndResult = false;

    }

     

    #endregion

     

        }

    }

  2.  Define custom action using the following code, this must be added to the Actions.xml. 

    <category name= "BPO Activities" sortorder="8" image="custom.gif">

      <action name="ApplicationNavigator" displayname="Agent App Navigator">

        <description>Dummy action to replace the action types which are not present.</description>

        <image resourcename="dummyaction.png"></image>

        <handler classname="AppNavigatorActivity.AppNavigator" 

         assembly="AppNavigatorActivity.dll"></handler>

        <properties>

          <property name="ApplicationURI" type="string"></property>

        </properties>

              <return>

                <value helpstring="Next">Next</value>

                <value helpstring="Previous">Previous</value>

                <value helpstring="End">End</value>

              </return>

    </action>

    </category>

  3. The custom action will be added to the Process Designer under the category BPO Activities (the category defined for the custom action).

  4. Set the ApplicationURI property for the action.

Step 2

The value from the AVEVA Work Tasks engine can be returned to the client by using the out parameter in the Client.ExecuteBlocking method.

Create a web Application and include this code to check the returned values from the engine.

Workflow.NET.Engine.Client cl = new Workflow.NET.Engine.Client("Application", "workflow");

//Encapsulates the information required for redirecting the client.

Workflow.NET.Engine.SynchronousActionData syncData = new Workflow.NET.Engine.SynchronousActionData(false, this.Context);

string url = "";

//Requests for the execution of the specified version of the workflow and waits till an action in the workflow returns a URL for redirecting the client.

//The client can handle the redirection or leave the redirection to the application.

cl.ExecuteBlocking("activedirectory::bob", "<content></content>", syncData, true, out url);

cl.Close();

ProcessSyncData(syncData);

 

void ProcessSyncData(Workflow.NET.Engine.SynchronousActionData syncData)

{

if (syncData.IsExplicitBlockingOutput)

{

//The output returned from the workflow using BlockingOutput in Context is stored to the variable "message"

string message = syncData.BlockingOutput.ToString().ToLower();

string[] msgs = message.Split(',');

message = msgs[0];

Log logger = new Log();


if (message == "app1")

logger.LogInformation("################### app1");

else if (message == "app2")

logger.LogInformation(" ############## app2");

else if (message == "app3")

logger.LogInformation(" ############## app3");

else

logger.LogInformation(" ############## No matching output");

}

Output:

The value typed in the property ApplicationURI of the custom activity is app1 and a message "app1" is displayed in the Logger Console as shown below:


Related Links
TitleResults for “How to create a CRG?”Also Available in