Generator.OnGenerateNextValues Method
Generates the next value according to the data generation algorithm.
Namespace: Microsoft.VisualStudio.TeamSystem.Data.DataGenerator
Assembly: Microsoft.VisualStudio.TeamSystem.Data (in microsoft.visualstudio.teamsystem.data.dll)
Syntax
'Declaration
Protected Overridable Sub OnGenerateNextValues
'Usage
Me.OnGenerateNextValues
protected virtual void OnGenerateNextValues ()
protected:
virtual void OnGenerateNextValues ()
protected void OnGenerateNextValues ()
protected function OnGenerateNextValues ()
Remarks
The OnGenerateNextValues method creates the data when a data generation plan runs. You must override this method to provide the logic that generates the data for the output properties of your data generator.
The GenerateNextValues method calls this method. You should override OnGenerateNextValues if you want to override the GenerateNextValues functionality.
Example
This example overrides the OnGenerateNextValues method to generate the random data for a data generator. This code example is part of a larger example provided for the Generator class.
DateTime mRandomDate;
Random mRandom;
Random mRandomRange;
protected override void OnGenerateNextValues()
{
DateTime min;
DateTime max;
//Generate a random date from either range 1 or range 2.
//Randomly select either range 1 or range 2 by randomly
//generating an odd or an even random number.
//------------------------------------------------------------
if (mRandomRange.Next() % 2 == 0) //check for odd or even
{
min = mRange1Min;
max = mRange1Max;
}
else
{
min = mRange2Min;
max = mRange2Max;
}
//The formula for creating a random number in a specific range is:
//start of range + (size of range * random number between 0 and 1)
//size of range
TimeSpan range = max - min;
//(size of range * random number between 0 and 1)
TimeSpan randomNumber = new TimeSpan((long)(range.Ticks * mRandom.NextDouble()));
//start of range + (size of range * random number between 0 and 1)
mRandomDate = min + randomNumber;
}
Dim mRandomDate As Date
Dim mRandom As Random
Dim mRandomRange As Random
Protected Overrides Sub OnGenerateNextValues()
Dim min As Date
Dim max As Date
'Generate a random date from either range 1 or range 2.
'Randomly select either range 1 or range 2 by randomly
'generating an odd or an even random number.
'------------------------------------------------------------
If mRandomRange.Next() Mod 2 = 0 Then 'check for odd or even
min = mRange1Min
max = mRange1Max
Else
min = mRange2Min
max = mRange2Max
End If
'The formula for creating a random number in a specific range is:
'start of range + (size of range * random number between 0 and 1)
'size of range
Dim range As TimeSpan = max - min
'(size of range * random number between 0 and 1)
Dim randomNumber As TimeSpan = New TimeSpan(CLng(range.Ticks * mRandom.NextDouble()))
'start of range + (size of range * random number between 0 and 1)
mRandomDate = min + randomNumber
End Sub
See Also
Tasks
Walkthrough: Creating a Custom Data Generator for a Check Constraint
Reference
Generator Class
Generator Members
Microsoft.VisualStudio.TeamSystem.Data.DataGenerator Namespace
GeneratorAttribute
GeneratorInit
IGenerator
Concepts
An Overview of Data Generator Extensibility
Specifying Details of Data Generation for a Column