This commit is contained in:
@@ -14,6 +14,14 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
public class Seeder
|
public class Seeder
|
||||||
{
|
{
|
||||||
|
public int SeededUserCount = 0;
|
||||||
|
public Faker Fake;
|
||||||
|
|
||||||
|
public Seeder()
|
||||||
|
{
|
||||||
|
Fake = new Faker();
|
||||||
|
}
|
||||||
|
|
||||||
public static class Level
|
public static class Level
|
||||||
{
|
{
|
||||||
public enum SeedLevel { NotValid, SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet, HugeForLoadTest };
|
public enum SeedLevel { NotValid, SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet, HugeForLoadTest };
|
||||||
@@ -39,8 +47,6 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int SeededUserCount = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
@@ -467,10 +473,10 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
private string[] TagSet = new[] { "red", "orange", "yellow", "green", "blue", "indigo", "violet", "brown", "black", "white", "silver", "gold", "fuchsia", "jade", "mauve", "purple", "quince", "xanthic", "zebra", "zone0", "zone1", "zone2", "zone3", "zone4", "zone5", "zone6", "zone7", "zone8", "zone9" };
|
private string[] TagSet = new[] { "red", "orange", "yellow", "green", "blue", "indigo", "violet", "brown", "black", "white", "silver", "gold", "fuchsia", "jade", "mauve", "purple", "quince", "xanthic", "zebra", "zone0", "zone1", "zone2", "zone3", "zone4", "zone5", "zone6", "zone7", "zone8", "zone9" };
|
||||||
|
|
||||||
private List<string> RandomTags(Faker f)
|
private List<string> RandomTags()
|
||||||
{
|
{
|
||||||
|
|
||||||
var t = f.PickRandom(TagSet, f.Random.Int(1, 5));//pick up to 5 tags to apply
|
var t = Fake.PickRandom(TagSet, Fake.Random.Int(1, 5));//pick up to 5 tags to apply
|
||||||
return new List<string>(t);
|
return new List<string>(t);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -552,7 +558,7 @@ namespace AyaNova.Util
|
|||||||
if (translationId == 0)
|
if (translationId == 0)
|
||||||
translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
|
translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
|
||||||
|
|
||||||
Faker Fake = new Faker();
|
|
||||||
|
|
||||||
for (int x = 0; x < count; x++)
|
for (int x = 0; x < count; x++)
|
||||||
{
|
{
|
||||||
@@ -581,7 +587,7 @@ namespace AyaNova.Util
|
|||||||
//TODO: After have USER and HEADOFFICE and VENDOR, if usertype is subcontractor or client or headoffice it needs to set a corresponding user's parent org record id to go with it
|
//TODO: After have USER and HEADOFFICE and VENDOR, if usertype is subcontractor or client or headoffice it needs to set a corresponding user's parent org record id to go with it
|
||||||
//use provided tags or generate them
|
//use provided tags or generate them
|
||||||
if (tags == null)
|
if (tags == null)
|
||||||
u.Tags = RandomTags(Fake);
|
u.Tags = RandomTags();
|
||||||
else
|
else
|
||||||
u.Tags = tags;
|
u.Tags = tags;
|
||||||
//Children and relations
|
//Children and relations
|
||||||
@@ -741,10 +747,7 @@ namespace AyaNova.Util
|
|||||||
{
|
{
|
||||||
//this is 4 times slower than doing it inside the loop below
|
//this is 4 times slower than doing it inside the loop below
|
||||||
//seems counterintuitive but maybe it's to do with the db context not being refreshed?
|
//seems counterintuitive but maybe it's to do with the db context not being refreshed?
|
||||||
|
|
||||||
var f = new Bogus.Faker();//todo: this *can't* be right, I'm seeding 20k widgets in some cases
|
|
||||||
|
|
||||||
|
|
||||||
//RANDOM ROLES
|
//RANDOM ROLES
|
||||||
Array values = Enum.GetValues(typeof(UserType));
|
Array values = Enum.GetValues(typeof(UserType));
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
@@ -754,26 +757,26 @@ namespace AyaNova.Util
|
|||||||
for (int x = 0; x < count; x++)
|
for (int x = 0; x < count; x++)
|
||||||
{
|
{
|
||||||
Widget o = new Widget();
|
Widget o = new Widget();
|
||||||
o.Name = Uniquify(f.Commerce.ProductName());
|
o.Name = Uniquify(Fake.Commerce.ProductName());
|
||||||
o.Active = true;
|
o.Active = true;
|
||||||
DateTime dtSeed = f.Date.Between(seedStartWindow, seedEndWindow).ToUniversalTime();
|
DateTime dtSeed = Fake.Date.Between(seedStartWindow, seedEndWindow).ToUniversalTime();
|
||||||
o.StartDate = dtSeed;
|
o.StartDate = dtSeed;
|
||||||
o.EndDate = dtSeed.AddMinutes(60).ToUniversalTime();
|
o.EndDate = dtSeed.AddMinutes(60).ToUniversalTime();
|
||||||
o.DollarAmount = Convert.ToDecimal(f.Commerce.Price());
|
o.DollarAmount = Convert.ToDecimal(Fake.Commerce.Price());
|
||||||
|
|
||||||
//Random but valid enum
|
//Random but valid enum
|
||||||
UserType randomUserType = (UserType)values.GetValue(random.Next(values.Length));
|
UserType randomUserType = (UserType)values.GetValue(random.Next(values.Length));
|
||||||
o.UserType = randomUserType;
|
o.UserType = randomUserType;
|
||||||
o.Notes = f.Lorem.Sentence(null, 5);
|
o.Notes = Fake.Lorem.Sentence(null, 5);
|
||||||
o.Tags = RandomTags(f);
|
o.Tags = RandomTags();
|
||||||
o.UserId = f.Random.Int(1, SeededUserCount);
|
o.UserId = Fake.Random.Int(1, SeededUserCount);
|
||||||
|
|
||||||
//RANDOM CUSTOM FIELD DATA
|
//RANDOM CUSTOM FIELD DATA
|
||||||
var c1 = DateUtil.UniversalISO8661Format(f.Date.Between(DateTime.Now.AddYears(-1), DateTime.Now.AddYears(1)));
|
var c1 = DateUtil.UniversalISO8661Format(Fake.Date.Between(DateTime.Now.AddYears(-1), DateTime.Now.AddYears(1)));
|
||||||
var c2 = f.Lorem.Sentence(null, 5);
|
var c2 = Fake.Lorem.Sentence(null, 5);
|
||||||
var c3 = f.Random.Int(1, 99999999);
|
var c3 = Fake.Random.Int(1, 99999999);
|
||||||
var c4 = f.Random.Bool().ToString().ToLowerInvariant();
|
var c4 = Fake.Random.Bool().ToString().ToLowerInvariant();
|
||||||
var c5 = f.Random.Decimal();
|
var c5 = Fake.Random.Decimal();
|
||||||
o.CustomFields = $@"{{c1:""{c1}"",c2:""{c2}"",c3:{c3},c4:{c4},c5:{c5}}}";
|
o.CustomFields = $@"{{c1:""{c1}"",c2:""{c2}"",c3:{c3},c4:{c4},c5:{c5}}}";
|
||||||
|
|
||||||
//This seems wrong to do in a loop but is 4 times faster this way ?!?
|
//This seems wrong to do in a loop but is 4 times faster this way ?!?
|
||||||
|
|||||||
Reference in New Issue
Block a user