Workflow Application: Assembly: Use an assembly method with a workflow context parameter for more flexibility

Presentation

As of version 5.6.2, WorkflowGen features an Assembly workflow application, which lets you declare a .NET class method as a workflow application.

As of version 5.6.3, your assembly method can be configured to receive and to return a workflow context.

By using a workflow context (instead of standard method parameters), you can use the same assembly method to manage multiple scenarios in terms of action parameters.

Simple example

This example shows how to create a simple class library with a method using a single workflow context parameter.

  1. In Visual Studio, create a new Class library Solution “WorkflowAppSample”.

    • .NET framework: WorkflowGen version 5.x.x supports .NET 2.0 and .NET 3.5; WorkflowGen versions 6.x.x and 7.x.x support .NET 4 and .NET 4.5.
  2. Add a reference to WorkflowGen.My.dll v2.3.4 or above (only required when you need to exchange files). This library is found in \wfgen\bin.

    Method requirements:

    • The workflow context parameter must be named WFGEN_CONTEXT and the datatype must be string or System.Xml.Linq.XElement.

    • The method can be a void or a function. If the method is a function the return value must be a string that contains the updated workflow context.

  3. Code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using WorkflowGen.My.Data;
    
    namespace WorkflowApp
    {
     
        public class Test
        {
    
            public string Convert(string WFGEN_CONTEXT)
            {
    
                //System.IO.File.WriteAllText(@"c:\temp\wcf_debug_xml.xml", WFGEN_CONTEXT);
    
                double exchangeRate = 1.45;
             
                double amountEuro = 0;
                string WFGEN_CONTEXT_UPDATED = null;
    
                // Create a new object of ContextParameters and Load the Context
                ContextParameters myWorkflowContextParameters;
                myWorkflowContextParameters = new WorkflowGen.My.Data.ContextParameters(WFGEN_CONTEXT);
    
                // If the context is empty then generate an error
                if (myWorkflowContextParameters.Count == 0)
                {
                    // If context is empty generate an error
                    throw new Exception("XML Context is empty");
                }
    
                // Check whether parameter exists  
                if (myWorkflowContextParameters.Contains("AMOUNT_EURO"))
                {
                    // Get the value of 'AMOUNT_EURO' if not null
                    if (myWorkflowContextParameters["AMOUNT_EURO"].Value != null)
                    {
                        // Get the value of 'AMOUNT_EURO'
                        amountEuro = (double)myWorkflowContextParameters["AMOUNT_EURO"].Value;
                    }
                    else
                    {
                        // If Euro amount is null generate an error
                        throw new Exception("Error: 'AMOUNT_EURO' parameter must not be null");
                    }
                }
                // If no Euro amount then generate an error
                else
                {
                    throw new Exception("Error: 'AMOUNT_EURO' parameter is required");
                }
    
                // Check whether parameter exists  
                if (myWorkflowContextParameters.Contains("AMOUNT_DOLLARS"))
                {
                    // Convert
                    myWorkflowContextParameters["AMOUNT_DOLLARS"].Value = amountEuro * exchangeRate;
    
                }
                // If no Dollars amount then generate an error
                else
                {
                    throw new Exception("Error: 'AMOUNT_DOLLARS' parameter is required");
                }
    
                // Updating the context parameters
                myWorkflowContextParameters.Update();
    
                WFGEN_CONTEXT_UPDATED = myWorkflowContextParameters.GetXml();
                
                //System.IO.File.AppendAllText(@"c:\temp\wcf_debug_xml.xml", WFGEN_CONTEXT_UPDATED);
    
                return WFGEN_CONTEXT_UPDATED;
            }
    }
    
  4. Compile the solution.

  5. Copy the generated WorkflowAppSample.Dll assembly into the ..\wfgen\bin folder.

    Note: If you use Remote Approval, the Web Services API, or the WorkflowGen Engine service to complete workflow actions, you must also copy the DLL into the ..\wfgen\ws\bin and DRIVE:\Program Files\Advantys\WorkflowGen\Services\bin folders. (For more information, see Workflow Application: Assembly: The assembly system action started but did not complete successfully.)

    Important: You must stop the WorkflowGen Engine service before copying your assembly DLL into the service bin folder.

  6. On the Applications screen in the WorkflowGen Administration Module, click New Application.

    • Name: SAMPLE_CONVERT

    • Description: Convert sample

    • Type: Assembly

    • Assembly full name or path: WorkflowAppSample

  7. Click Save.

    • Class full name: Select WorkflowApp.Test

    • Method: Select Convert

You can now use this workflow application in your processes.

For actions using this workflow application, you have to add one IN parameter, AMOUNT_EURO (numeric), and one OUT parameter, AMOUNT_DOLLARS (numeric).

You can customize the assembly code to manage other parameters which can be optional according to your needs (e.g., in this example, you can add a optional EXCHANGE_RATE parameter).