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.
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:
During the masking of the database all e-mail addresses must be replaced by randomly generated username that fits these requirements:
Example: Some usernames that fit described format are Julia#1234, Nero_56, Cleopatra!789
UsernameGenerator.cs
and press AddIGenerator<t>
interface by adding using Ekobit.BizDataX.DataMasking.DataGenerators;
to the top of the file: IGenerator<string>
to class declarationusing Ekobit.BizDataX.DataMasking.DataGenerators;
namespace BizDataXPackage_TestProject
{
public class UsernameGenerator: IGenerator<string>
{
}
}
Declare internal merge generator as private IGenerator<string> _mergeGenerator;
that will merge all parts of the username together
For generator to work as intended we'll make two constructors that'll take following parameters:
public UsernameGenerator(IGenerator<int> numberGenerator, string delimiter, string countryCode){}
public UsernameGenerator(IGenerator<int> numberGenerator, string delimiter) : this(numberGenerator, delimiter, null){}
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 generatorspublic 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);
}
IGenerator<string>.GetNext()
public string GetNext()
{
return _mergeGenerator.GetNext();
}
Email
as the "Property"new UsernameGenerator(new RandomNumberGenerator(100, 999), "_", "US")
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,>
BizDataX Documentation © Built by Ekobit. All rights reserved.
https://www.ekobit.com/ https://bizdatax.com/ https://bizdatax.com/support/