Appendix A. Sample Implementation of a User-Defined Function

Following are the pre-requisites and the steps to implement a user-defined function:

Prerequisites

To implement a user-defined framework:

  1. Open Visual Studio and create a new Class Library project.

  2. In the Class Library project, delete the default file Class1.cs.

  3. Right-click References and then click Add Reference…

    The Add Reference dialog box appears.

  4. Click Assemblies and then click Framework on the left panel.

  5. Select the System.ComponentModel.Composition option from the right column.

  6. Add reference to the Unisys.CPF.DataExchange.Common.dll file for the project.

    Note: The Unisys.CPF.DataExchange.Common.dll file is located in the root directory where DDW is installed. By default the location is “C:\Program Files\Unisys\Data Exchange\Development Workbench”.

  7. Right-click the project name in the Solution Explorer in Visual Studio and click Add.

  8. Click Class and enter a name for the class in the Name box.

  9. Click Add.

  10. Add the following “using” statements in the new class:

    using System.ComponentModel.Composition;
    using Unisys.CPF.DataExchange.Common;
    using Unisys.CPF.DataExchange.Common.Expression;
  11. Add the following attribute for the new class:

    [Export(typeof(Function))]
  12. Inherit the new class from the following Function class:

    public class StringConcatFunction : Function
  13. Create a constructor and initialize Properties of the function:

    public StringConcatFunction()
    {
    	this.Name = "StringConcat";			
    	this.Body = "StringConcat(<string1>,<string2>)";
    	this.ReturnTypeName = "string";
    	this.Description = "StringConcat is created for sample use.";
    }

    All the properties, except Description must be provided.

    Note: The name of the user-defined function should be same as the name of the function in the function body. If the names are not the same, the function will not be listed under the user-defined functions in DDW.

  14. Override the Execute method to implement the function logic as follows:

    public override EvaluationValue Execute(EvaluationMode mode, EvaluationValue[] args)
    {
    	if(args.Length != 2)			
            {
    	        return new EvaluationValue()
    		{					ErrorType = EvaluationErrorType.ParameterCountIsIncorrect,
    							ErrorMessage = string.Format("Error in {0} function, expected parameter count: {1}.", Name, 2)
    		};
    	}
    			
    	var result = string.Concat(args[0].Value, args[1].Value);
     
    	return new EvaluationValue()
    	{
    		Value = result,
    		DataType = InternalDataType.AsciiString,
    		IsConstant = false,
    		IsSigned = false,
    		StringLength = result.Length
    	};
    }
  15. Click Build in Visual Studio and then click Build Solution (F6)to build the project.

  16. Locate the generated binary file (with the .dll extension).

    It is located in the .bin\Debug or .bin\Release folder of the solution.

    Note: To locate the folder, right-click the Solution node in the Solution Explorer and then click Open in the File Explorer (if you use Visual Studio 2010 or higher).

  17. Copy the binary file to the following paths if you installed Data Exchange with the default settings:

    • C:\Program Files\Unisys\Data Exchange\Development Workbench\Functions\External

    • C:\Program Files\Unisys\Data Exchange\Runtime Service\Functions\External