Datapolis Process System SDK

Search:

Contents
:
IndexBookmarkPrint
Home > Functions > Creating Function Tutorial

Creating Function Tutorial

 

 

This walkthrough will guide you through creating a custom function. The function takes date as argument and returns hour.

 

Prerequisites


Before creating a custom activity, be sure you have installed all of the necessary components.

Setup Project

  1. Open a new Visual Studio project (File | New | Project)
  2. Create a new class library project.
  3. Name the project appropriately. In this case it might be Datapolis.WorkBox.Sdk.Samples. Set the other project properties (Location, Solution Name etc.)
  4. Sign the assembly.
  5. Add references to Datapolis.WorkBox.Common and Datapolis.WorkBox.Functions - they should be available in GAC.
  6. Add a new class by right clicking on the project node in Solution Explorer and select Add | Class.... Name it WBHour.cs
  7. Change WBHour namespace to Datapolis.WorkBox.Sdk.Samples.Functions
  8. Add the resources file. Right click on the project node in Solution Explorer and select Add | New Items... from the project context menu. Select Resources Files from Templates window. Name the resources file e.g. Datapolis.WorkBox.Sdk.Samples.Functions.resx. Do the same for the another language version e.g. the Polish version resource file name is: Datapolis.WorkBox.Sdk.Samples.Functions.pl-PL.resx
  9. Add two xml files. The first name Datapolis.WorkBox.Sdk.Samples.Functions.xml and the second Datapolis.WorkBox.Sdk.Samples.Functions.Categories.xml.

Modify Post Built Events

  1. Right click on the project node in Solution Explorer and select Properties. Select Build Events tab. Click on Edit Post-build ... button.
  2. Convert *.resx resource file to *.resource format. Use the .NET Framework 4.5 tool by adding the following script to the Post-build Event Command Line window:

    ResGen.exe Datapolis.WorkBox.Sdk.Samples.Functions.resx Datapolis.WorkBox.Sdk.Samples.Functions.resources

    ResGen.exe Datapolis.WorkBox.Sdk.Samples.Functions.pl-PL.resx Datapolis.WorkBox.Sdk.Samples.Functions.pl-PL.resources

  3. Copy the generated *.resource file by adding the following script: xcopy *.resources "%CommonProgramW6432%\microsoft shared\web server extensions\15\WorkBox\Functions\" /y
  4. Add the line: xcopy *.xml "%CommonProgramW6432%\microsoft shared\web server extensions\15\WorkBox\Functions\" /y to automatically copy your xml files to 15\WorkBox\Functions folder

Note: If you encounter errors when building your project please see "Environment Variables" section in Visual Studio Integration. Errors are probably caused by unspecified path to building tools. Also they may be related to problems with find 15th folder - check its path.

 

Prepare xml files


Define the function category. Open Datapolis.WorkBox.Sdk.Samples.Functions.Categories.xml and insert definition of the 'Date' function category.

 
  <FunctionCategory Name="SDK.Date" Title="$Resources:Datapolis.WorkBox.Sdk.Samples.Functions,FunctionCategoryDate;"></FunctionCategory>
 
</FunctionCategories>

 

Define the function. Open Datapolis.WorkBox.Sdk.Samples.Functions.xml and insert the below function definition

 
  <Function Name="Datapolis.WorkBox.Sdk.Samples.Functions.WBHour" Title="$Resources:Datapolis.WorkBox.Sdk.Samples.Functions,WBHour_FunctionTitle;" Description="$Resources:Datapolis.WorkBox.Sdk.Samples.Functions,WBHour_FunctionDescription;" Assembly="Datapolis.WorkBox.Sdk.Samples, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0a68baededa28155" Category="SDK.Date">
    <Parameter Name="Value" Title="$Resources:Datapolis.WorkBox.Sdk.Samples.Functions,WBHour_Value_Title;" Description="$Resources:Datapolis.WorkBox.Sdk.Samples.Functions,WBHour_Value_Description;" Type="String"></Parameter>
  </Function>
 
</Functions>

 

Develop code


When the both function category and function are defined, open WBHour.cs file and insert code implementation of the function:

using System;
using Datapolis.WorkBox.Common;
using Datapolis.WorkBox.Functions;
 
namespace Datapolis.WorkBox.Sdk.Samples.Functions
{
    public class WBHour :IWBFunctionBase
    {
        public DateTime? Value { get; set; }
 
        public object Execute(WBFunctionExecutionContext functionExecutionContext)
        {
            if(this.Value == null)
                return null;
 
            return this.Value.Value.Hour;
        }
    }
}

 

Prepare multilanguage (optional)


Set the activity translation. Right click on the resource file Datapolis.WorkBox.Sdk.Samples.Functions.resx and select Open With... context menu. Pick XML Editor and click OK button. Just before the node: </root> insert the following xml translation

 

<data name="FunctionCategoryDate" xml:space="preserve">
  <value>SDK Date</value>
</data>
 
<data name="WBHour_FunctionDescription" xml:space="preserve">
  <value>Returns the hour of a time value. The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).</value>
</data>
<data name="WBHour_FunctionTitle" xml:space="preserve">
  <value>Hour</value>
</data>
<data name="WBHour_Value_Description" xml:space="preserve">
  <value>Enter the date that contains the hour you want to find.</value>
</data>
<data name="WBHour_Value_Title" xml:space="preserve">
  <value>Date</value>
</data>

 

 

For Polish version use the below translations:

 

<data name="FunctionCategoryDate" xml:space="preserve">
  <value>SDK Funkcje daty</value>
</data>
 
<data name="WBHour_FunctionDescription" xml:space="preserve">
  <value>Zwraca godzinę w postaci numeru seryjnego. Godzina jest określona liczbą całkowitą z zakresu od 0 do 23.</value>
</data>
<data name="WBHour_FunctionTitle" xml:space="preserve">
  <value>Godzina</value>
</data>
<data name="WBHour_Value_Description" xml:space="preserve">
  <value>Określa datę, z której chcesz uzyskać godzinę.</value>
</data>
<data name="WBHour_Value_Title" xml:space="preserve">
  <value>Data</value>
</data>

 

Build project


Finally build your project and check how it works in Workflow Designer.

Remember that if you change some important parts of xml (like assembly, function name, parameter name) you have to remove function form your workflow, reopen designer and add your function again - otherwise it may not work.

 

Next Steps


Optionally, after reading this walkthrough you can see the same function code attached in SDK Samples in Download section.