We will use that file to validate our customers. We need to do this in two steps:

First we need to read the file. To do this we will use a “Read / Write to File” component.

Then we need to analyze if the customer ID and PIN are in this file. To do this we need to execute a piece of C# code using a “Launch External Script” component.

Reading the contents of the file

Add a “Read / Write to File” component, dragging it from the toolbox to the designer, into the component “ValidateData” created in the Part 1 of this series. Rename this component to “readXML”, and configure it as follows:

Analyzing the contents of the file

Now that the file has been read, we need to analyze its content. To do this, we’ll use a “Launch External Script”component. Add this component below the readXML component, and rename it to analyzeXML.

It’s time to create the C# file to include in the project. Create a new text file TextFileValidator.cs, and add the following code inside:

Setting the validation result

Now that our C# code has done the job, we just need to assign the validation result to the output property ValidationResult. To do this, we’ll use an Assign a Variable component to set the result to the variable callflow$.ValidationResult using the following expression:

analyzeXML.ReturnValue

The component will look like in the following screenshot:

Performing the validation using a CSV text file

Other possible file format to use is CSV (Comma Separated Values). Let’s suppose that the file has the format “ID,PIN”, for example:

100001,111111

100002,222222

100003,333333

100004,444444

100005,555555

We can extend the previous C# class by adding a method “ValidateCSV”. The code for this new method could be:

public bool ValidateCSV(string fileContent, string id, string pin)

{

foreach (string line in fileContent.Split('\n'))

{

string[] lineParts = line.Trim().Split(',');

if (lineParts.Length == 2)

{

string customerID = lineParts[0];

string customerPIN = lineParts[1];

if (id == customerID && pin == customerPIN)

return true;

}

}

return false;

}

Then we just need to invoke this new method from the Launch External Script component, in the same way we did for XML File.

Conclusion

In this article we explained how to validate the data entered by the customer using an XML file and a CSV text file, using C# code and calling this code from a Launch External Script component. The next article in this series will show how to perform this validation through the following external data sources: