Custom generators

BizDataX Designer offers full support for creating custom data generators which can be implemented in case none of the existing generators provide just the right data.

For the purpose of this walkthrough we'll use an interesting use case as our example for creating niche custom generators.

Example

A company stores external e-mail addresses for the company employees in the database and they need to be masked. E-mail addresses should be replaced with new e-mail usernames that consist of three separate parts:

  1. Employee's first name
  2. Delimiter
  3. Random number

During the masking of the database all e-mail addresses must be replaced by randomly generated username that fits these requirements:

  1. Generated employee's first name should be different than the original
  2. Delimiter should be consistent - all usernames must have the same delimiter
  3. Generated random number must be within defined range
  4. Usernames should not contain e-mail domain name, nor '@' sign

Example: Some usernames that fit described format are Julia#1234, Nero_56, Cleopatra!789

Preconditions

Implementation

  1. In the Solution Explorer right-click on the package name and select Add -> Class...
  2. In the Add New Item pop-up window set class name to UsernameGenerator.cs and press Add
  3. Import the IGenerator<t> interface by adding using Ekobit.BizDataX.DataMasking.DataGenerators; to the top of the file
  4. Set the class to public and add : IGenerator<string> to class declaration
using Ekobit.BizDataX.DataMasking.DataGenerators;

namespace BizDataXPackage_TestProject
{
    public class UsernameGenerator: IGenerator<string>
    {
    }
}
  1. Declare internal merge generator as private IGenerator<string> _mergeGenerator; that will merge all parts of the username together

  2. For generator to work as intended we'll make two constructors that'll take following parameters:

    1. Number generator - any generator that produces integers that will produce the last part of the username
    2. String delimiter - string that will stand between the first and last part of the username
    3. Optional country code - it will allow for more control over which names should be considered when generating first part of the username
public UsernameGenerator(IGenerator<int> numberGenerator, string delimiter, string countryCode){}

public UsernameGenerator(IGenerator<int> numberGenerator, string delimiter) : this(numberGenerator, delimiter, null){}
  1. Import PickLists by adding using Ekobit.BizDataX.LookupData; to the top of the file. Picklists contain data such as domain names and business suffixes that can be used in custom generators
  2. Implement constructors as follows:
public UsernameGenerator(IGenerator<int> numberGenerator, string delimiter, string countryCode)
{
    IGenerator<string> firstNameGenerator;
    IGenerator<string> generatorWithConversion;

    if (countryCode == null)
    {
        firstNameGenerator = new ItemsInRandomOrderGenerator<string>(
            PickLists.WorldFirstNames.OnlyFirstNames());
    }
    else
    {
        firstNameGenerator = new ItemsInRandomOrderGenerator<string>(
            PickLists.WorldFirstNames.OnlyCountry(countryCode).OnlyFirstNames());
    }

    generatorWithConversion = new GeneratorWithConversion<int, string="">(numberGenerator, _ => _.ToString());
    _mergeGenerator = new MergeGenerator(delimiter, firstNameGenerator, generatorWithConversion);
}
  1. Implement interface member IGenerator<string>.GetNext()
public string GetNext()
{
    return _mergeGenerator.GetNext();
}

Usage

  1. From the Solution Explorer open the Package.xaml file
  2. Delete the workflow created by default
  3. Drag the Sequence activity from the Toolbox into the opened Package.xaml
  4. Drag the Customer_Activity from the Toolbox into the Sequence activity. A Masking engine with Customer iterator, Customer handler and Masking block is created inside the sequence
  5. Drag the Generate value masking activity from the Toolbox into the created Masking block
  6. In the Select Types pop-up window choose string
  7. In the Generate value masking activity, select Email as the "Property"
  8. Set "Value generator" field to:
new UsernameGenerator(new RandomNumberGenerator(100, 999), "_", "US")
  1. Build solution by pressing Build -> Build Solution
  2. Start the masking process by pressing Start

Example: Relevant data before and after masking

Before masking After masking
claudia.mclaughlin@gmail.com Annika_746
kent.carey@gmail.com Frances_969
jayme.petty@gmail.com Clare_487
amanda.hartman@gmail.com Eugene_564

Note: Any generator that produces integers can be used in place RandomNumberGenerator</int,>