Crossfire Functions

Crossfire function are useful for adding specific functionality to your mappings.

These can be anything from manipulating data, or lookup of values, or executing code to generate a file.

To create a function see the steps below:

Functions are located under Config > Functions

Click the new button to create a new function.

Name: The name of the function.

Category: The category of the function. Choose between Date, String, Number or Action

Type: The type determines the code used for the functions. There are 3 types, BuiltIn, SQL and CSharp. BuiltIn functions are for internal use within Crossfire. SQL and CSharp functions are specified so that you could choose how you want to write the function.

External Connection: This is only used with SQL connections. If left empty it will use the default middle-ware connection to execute the function against.

Code: This is where the actual code is written to be executed.

Paramters Tab:

The parameters tab is used to manage a collection of parameters that can be used within the function. These parameters are populated in the mapping process by mapping element to it, or using variables.

Assembly References Tab (CSharp functions only):

The Assembly references tan is used to manage a collection of references that the function might use. This is to allow the use of external libraries. These can only be used on CSharp functions.

To add new assembly references follow the steps below:

Go to Advanced > Assembly References to list the current references.

Click the new button to add a new Assembly Reference.

The DLL reference field must contain the full path and the DLL name.

The Using Directive field is used to add any directive to the function. This is optional as most functions in an assembly can be accessed using the fully qualified name. Adding the Using Directive wil help minimising this a bit.

Example Functions


Calling an HTTP Endpoint

The example below requires two assembly references to be added. The first is required for the HTTP call. The second is required for converting the JSON to XML.

  1. C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Net.dll

  2. D:\Engine\Newtonsoft.Json.dll

string url = "https://api.endpoint.com/samplendpoint";

HttpWebRequest myRequest = (HttpWebRequest)System.Net.WebRequest.Create(url);


myRequest.Accept = "application/json";

myRequest.ContentType = "application/json";

myRequest.Headers["MyAPIKey"] = "55aa82eb0cf642bc97897f3472309db7";

myRequest.Method = "GET";


WebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();

Stream dataStream = myResponse.GetResponseStream();

StreamReader readStream = new StreamReader(dataStream, Encoding.UTF8);


string inputMessage = readStream.ReadToEnd();

XmlDocument doc = JsonConvert.DeserializeXmlNode("{\"Row\":" + inputMessage + "}", "root");


XmlNode xnode = doc.SelectSingleNode("root/Invoices[1]/HeaderFields[FieldName='Invoice Number']/FieldValue");


if(xnode == null)

{

return "";

}

else

{

return xnode.InnerText;

}