This commit is contained in:
@@ -15,7 +15,6 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
public class Seeder
|
public class Seeder
|
||||||
{
|
{
|
||||||
public int SeededUserCount = 0;
|
|
||||||
public Faker Fake;
|
public Faker Fake;
|
||||||
//### FAKER BIG LIST OF ALL SOURCE DATA HERE:
|
//### FAKER BIG LIST OF ALL SOURCE DATA HERE:
|
||||||
//https://github.com/bchavez/Bogus/blob/master/Source/Bogus/data/en.locale.json
|
//https://github.com/bchavez/Bogus/blob/master/Source/Bogus/data/en.locale.json
|
||||||
@@ -66,7 +65,7 @@ namespace AyaNova.Util
|
|||||||
public async Task SeedDatabaseAsync(Level.SeedLevel slevel, Guid JobId, Decimal timeZoneOffset)
|
public async Task SeedDatabaseAsync(Level.SeedLevel slevel, Guid JobId, Decimal timeZoneOffset)
|
||||||
{
|
{
|
||||||
bool LogJob = JobId != Guid.Empty;
|
bool LogJob = JobId != Guid.Empty;
|
||||||
SeededUserCount = 0;
|
// TotalSeededUserCount = 0;
|
||||||
|
|
||||||
ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("Seeder");
|
ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("Seeder");
|
||||||
ApiServerState apiServerState = (ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(ApiServerState));
|
ApiServerState apiServerState = (ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(ApiServerState));
|
||||||
@@ -871,7 +870,7 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
|
|
||||||
public HashSet<string> HashUserNames = new HashSet<string>();
|
public HashSet<string> HashUserNames = new HashSet<string>();
|
||||||
|
private int TotalSeededUserCount = 0;
|
||||||
|
|
||||||
public async Task SeedUserAsync(
|
public async Task SeedUserAsync(
|
||||||
ILogger log, int count, AuthorizationRoles roles, UserType userType,
|
ILogger log, int count, AuthorizationRoles roles, UserType userType,
|
||||||
@@ -911,7 +910,7 @@ namespace AyaNova.Util
|
|||||||
u.Password = u.Login;
|
u.Password = u.Login;
|
||||||
u.Roles = roles;
|
u.Roles = roles;
|
||||||
u.UserType = userType;
|
u.UserType = userType;
|
||||||
u.EmployeeNumber = "A-" + (454 + SeededUserCount + x).ToString() + "-Y";
|
u.EmployeeNumber = "A-" + (454 + TotalSeededUserCount + x).ToString() + "-Y";
|
||||||
u.Notes = Fake.Lorem.Sentence(null, 5);//Fake.Lorem.Paragraph(2);
|
u.Notes = Fake.Lorem.Sentence(null, 5);//Fake.Lorem.Paragraph(2);
|
||||||
//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
|
||||||
@@ -941,6 +940,7 @@ namespace AyaNova.Util
|
|||||||
{
|
{
|
||||||
UserBiz biz = UserBiz.GetBiz(ct);
|
UserBiz biz = UserBiz.GetBiz(ct);
|
||||||
var NewObject = await biz.CreateAsync(u);
|
var NewObject = await biz.CreateAsync(u);
|
||||||
|
TotalSeededUserCount++;
|
||||||
if (NewObject == null)
|
if (NewObject == null)
|
||||||
{
|
{
|
||||||
log.LogError($"Seeder::SeedUser error creating {u.Name}\r\n" + biz.GetErrorsAsString());
|
log.LogError($"Seeder::SeedUser error creating {u.Name}\r\n" + biz.GetErrorsAsString());
|
||||||
@@ -949,7 +949,7 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SeededUserCount += count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region WIDGET
|
#region WIDGET
|
||||||
@@ -982,7 +982,7 @@ namespace AyaNova.Util
|
|||||||
o.UserType = randomUserType;
|
o.UserType = randomUserType;
|
||||||
o.Notes = Fake.Lorem.Sentence(null, 5);
|
o.Notes = Fake.Lorem.Sentence(null, 5);
|
||||||
o.Tags = RandomTags();
|
o.Tags = RandomTags();
|
||||||
o.UserId = Fake.Random.Int(1, SeededUserCount);
|
o.UserId = Fake.Random.Int(1, TotalSeededUserCount);
|
||||||
|
|
||||||
//RANDOM CUSTOM FIELD DATA
|
//RANDOM CUSTOM FIELD DATA
|
||||||
var c1 = DateUtil.UniversalISO8661Format(Fake.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)));
|
||||||
@@ -1010,6 +1010,7 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
public HashSet<string> HashCompanyNames = new HashSet<string>();
|
public HashSet<string> HashCompanyNames = new HashSet<string>();
|
||||||
|
|
||||||
|
private int TotalSeededCustomers=0;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
//CUSTOMER
|
//CUSTOMER
|
||||||
@@ -1059,6 +1060,7 @@ namespace AyaNova.Util
|
|||||||
CustomerBiz biz = CustomerBiz.GetBiz(ct);
|
CustomerBiz biz = CustomerBiz.GetBiz(ct);
|
||||||
var NewObject = await biz.CreateAsync(o);
|
var NewObject = await biz.CreateAsync(o);
|
||||||
|
|
||||||
|
TotalSeededCustomers++;
|
||||||
if (NewObject == null)
|
if (NewObject == null)
|
||||||
{
|
{
|
||||||
var err = $"Seeder::SeedCustomer error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
var err = $"Seeder::SeedCustomer error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
||||||
@@ -1074,6 +1076,7 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int TotalSeededHeadOffices=
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
//HEADOFFICE
|
//HEADOFFICE
|
||||||
//
|
//
|
||||||
@@ -1233,6 +1236,7 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
|
|
||||||
public HashSet<string> HashRateNames = new HashSet<string>();
|
public HashSet<string> HashRateNames = new HashSet<string>();
|
||||||
|
private int TotalSeededServiceRates = 0;
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
//SERVICERATE
|
//SERVICERATE
|
||||||
//
|
//
|
||||||
@@ -1262,7 +1266,7 @@ namespace AyaNova.Util
|
|||||||
{
|
{
|
||||||
ServiceRateBiz biz = ServiceRateBiz.GetBiz(ct);
|
ServiceRateBiz biz = ServiceRateBiz.GetBiz(ct);
|
||||||
var NewObject = await biz.CreateAsync(o);
|
var NewObject = await biz.CreateAsync(o);
|
||||||
|
TotalSeededServiceRates++;
|
||||||
if (NewObject == null)
|
if (NewObject == null)
|
||||||
{
|
{
|
||||||
var err = $"Seeder::SeedServiceRate error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
var err = $"Seeder::SeedServiceRate error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
||||||
@@ -1273,6 +1277,7 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int TotalSeededTravelRates = 0;
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
//TRAVELRATE
|
//TRAVELRATE
|
||||||
//
|
//
|
||||||
@@ -1304,7 +1309,7 @@ namespace AyaNova.Util
|
|||||||
{
|
{
|
||||||
TravelRateBiz biz = TravelRateBiz.GetBiz(ct);
|
TravelRateBiz biz = TravelRateBiz.GetBiz(ct);
|
||||||
var NewObject = await biz.CreateAsync(o);
|
var NewObject = await biz.CreateAsync(o);
|
||||||
|
TotalSeededTravelRates++;
|
||||||
if (NewObject == null)
|
if (NewObject == null)
|
||||||
{
|
{
|
||||||
var err = $"Seeder::SeedTravelRate error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
var err = $"Seeder::SeedTravelRate error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
||||||
@@ -1318,6 +1323,7 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
|
|
||||||
public HashSet<string> HashUnitModelNames = new HashSet<string>();
|
public HashSet<string> HashUnitModelNames = new HashSet<string>();
|
||||||
|
private int TotalSeededUnitModels = 0;
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
//UNITMODEL
|
//UNITMODEL
|
||||||
//
|
//
|
||||||
@@ -1354,6 +1360,60 @@ namespace AyaNova.Util
|
|||||||
o.WarrantyLength = Fake.PickRandom(WarrantyMonths);
|
o.WarrantyLength = Fake.PickRandom(WarrantyMonths);
|
||||||
o.WarrantyTerms = Fake.PickRandom(WarrantyTerms);
|
o.WarrantyTerms = Fake.PickRandom(WarrantyTerms);
|
||||||
|
|
||||||
|
//This seems wrong to do in a loop but is 4 times faster this way ?!?
|
||||||
|
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||||
|
{
|
||||||
|
UnitModelBiz biz = UnitModelBiz.GetBiz(ct);
|
||||||
|
var NewObject = await biz.CreateAsync(o);
|
||||||
|
TotalSeededUnitModels++;
|
||||||
|
if (NewObject == null)
|
||||||
|
{
|
||||||
|
var err = $"Seeder::SeedUnitModel error creating {o.Name}\r\n{biz.GetErrorsAsString()}";
|
||||||
|
log.LogError(err);
|
||||||
|
throw new System.Exception(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public HashSet<string> HashUnitNames = new HashSet<string>();
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//UNIT
|
||||||
|
//
|
||||||
|
public async Task SeedUnitAsync(ILogger log, int count)
|
||||||
|
{
|
||||||
|
DateTime seedStartWindow = DateTime.Now.AddYears(-5);
|
||||||
|
DateTime seedEndWindow = DateTime.Now.AddYears(1);
|
||||||
|
var WarrantyMonths = new[] { 1, 6, 12, 24, 36 };
|
||||||
|
var WarrantyTerms = new[] { "Parts only", "Parts and service", "Service only", "Shipping parts and service", "First month parts and service here; after is depot only" };
|
||||||
|
|
||||||
|
for (int x = 0; x < count; x++)
|
||||||
|
{
|
||||||
|
Unit o = new Unit();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
o.Name = $"{Fake.Vehicle.Model()} {Fake.Commerce.Categories(1)[0]}";
|
||||||
|
} while (!HashUnitModelNames.Add(o.Name));
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
o.Number = Fake.Finance.Account(6);
|
||||||
|
} while (!HashUnitModelNames.Add(o.Number));
|
||||||
|
|
||||||
|
o.Active = true;
|
||||||
|
o.Notes = Fake.Lorem.Sentence();
|
||||||
|
o.Tags = RandomTags();
|
||||||
|
o.VendorId = Fake.Random.Long(1, 10);
|
||||||
|
o.UPC = Fake.Commerce.Ean13();
|
||||||
|
o.LifeTimeWarranty = false;
|
||||||
|
o.IntroducedDate = Fake.Date.Between(seedStartWindow, DateTime.Now).ToUniversalTime();
|
||||||
|
o.Discontinued = false;
|
||||||
|
o.DiscontinuedDate = null;
|
||||||
|
o.WarrantyLength = Fake.PickRandom(WarrantyMonths);
|
||||||
|
o.WarrantyTerms = Fake.PickRandom(WarrantyTerms);
|
||||||
|
|
||||||
//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 ?!?
|
||||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||||
{
|
{
|
||||||
@@ -1371,9 +1431,6 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
|
|||||||
Reference in New Issue
Block a user