This commit is contained in:
2020-11-11 17:31:48 +00:00
parent a8e097ba51
commit af125f93b0

View File

@@ -208,26 +208,26 @@ namespace AyaNova.Util
#region GenSmall
//This is for a busy but one man shop with a single office person handling stuff back at the shop
//PERF
await LogStatusAsync(JobId, LogJob, log, $"Seeding SMALL number of user(s)....");
await LogStatusAsync(JobId, LogJob, log, $"Seeding SMALL sample data....");
var watch = new Stopwatch();
watch.Start();
//USERS
//Generate owner and lead tech
await GenSeedUserAsync(log, 1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.OpsAdminFull, UserType.Service);
//Generate one office person / secretary
await GenSeedUserAsync(log, 1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.AccountingFull, UserType.NotService);
//PERF
watch.Stop();
await LogStatusAsync(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
//100 widgets
watch = new Stopwatch();
watch.Start();
//WIDGET
await GenSeedWidgetAsync(log, 100);
//CUSTOMERS
await GenSeedCustomerAsync(log, 100);
//PERF
watch.Stop();
await LogStatusAsync(JobId, LogJob, log, $"100 Widgets seeded in {watch.ElapsedMilliseconds} ms");
await LogStatusAsync(JobId, LogJob, log, $"Small level sample data seeded in {watch.ElapsedMilliseconds} ms");
#endregion gensmall
}
@@ -238,9 +238,11 @@ namespace AyaNova.Util
//This is for a typical AyaNova medium busy shop
//has one location, many techs and full staff for each department
//PERF
await LogStatusAsync(JobId, LogJob, log, $"Seeding MEDIUM number of user(s)....");
await LogStatusAsync(JobId, LogJob, log, $"Seeding MEDIUM sample data....");
var watch = new Stopwatch();
watch.Start();
//USERS
//One IT administrator, can change ops but nothing else
await GenSeedUserAsync(log, 1, AuthorizationRoles.OpsAdminFull, UserType.NotService);
@@ -276,20 +278,16 @@ namespace AyaNova.Util
//10 limited customer users
await GenSeedUserAsync(log, 10, AuthorizationRoles.CustomerLimited, UserType.Customer);
//PERF
watch.Stop();
await LogStatusAsync(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
//500 widgets
await LogStatusAsync(JobId, LogJob, log, $"Seeding 500 Widgets....");
watch = new Stopwatch();
watch.Start();
//await GenSeedWidgetAsync(log, 500);
//WIDGETS
await GenSeedWidgetAsync(log, 500);
//CUSTOMERS
await GenSeedCustomerAsync(log, 500);
//PERF
watch.Stop();
await LogStatusAsync(JobId, LogJob, log, $"500 Widgets seeded in {watch.ElapsedMilliseconds} ms");
await LogStatusAsync(JobId, LogJob, log, $"MEDIUM level sample data seeded in {watch.ElapsedMilliseconds} ms");
#endregion genmedium
}
@@ -301,10 +299,12 @@ namespace AyaNova.Util
//Each location has a full staff and corporate head office has an overarching staff member in charge of each location
//PERF
await LogStatusAsync(JobId, LogJob, log, $"Seeding LARGE number of user(s)....");
await LogStatusAsync(JobId, LogJob, log, $"Seeding LARGE sample data....");
var watch = new Stopwatch();
watch.Start();
//USERS
//IT administrator, can change ops but nothing else
await GenSeedUserAsync(log, 2, AuthorizationRoles.OpsAdminFull, UserType.NotService);
@@ -353,20 +353,16 @@ namespace AyaNova.Util
//100 limited customer users
await GenSeedUserAsync(log, 20, AuthorizationRoles.CustomerLimited, UserType.Customer);
//PERF
watch.Stop();
await LogStatusAsync(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
//5000 widgets
await LogStatusAsync(JobId, LogJob, log, $"Seeding 5,000 Widgets....");
watch = new Stopwatch();
watch.Start();
//await GenSeedWidgetAsync(log, 5000);
//WIDGETS
await GenSeedWidgetAsync(log, 5000);
//CUSTOMERS
await GenSeedCustomerAsync(log, 5000);
//PERF
watch.Stop();
await LogStatusAsync(JobId, LogJob, log, $"5k Widgets seeded in {watch.ElapsedMilliseconds} ms");
await LogStatusAsync(JobId, LogJob, log, $"LARGE level sample data seeded in {watch.ElapsedMilliseconds} ms");
#endregion genlarge
}
break;
@@ -377,11 +373,13 @@ namespace AyaNova.Util
//this is the HUGE dataset for load and other testing
//It is acceptable for this seeding to take many hours as it would normally be used rarely
//PERF
await LogStatusAsync(JobId, LogJob, log, $"Seeding HUGE number of user(s)....");
//PERF
await LogStatusAsync(JobId, LogJob, log, $"Seeding HUGE sample data....");
var watch = new Stopwatch();
watch.Start();
//USERS
//IT administrator, can change ops but nothing else
await GenSeedUserAsync(log, 10, AuthorizationRoles.OpsAdminFull, UserType.NotService);
@@ -430,18 +428,16 @@ namespace AyaNova.Util
//limited customer users
await GenSeedUserAsync(log, 50, AuthorizationRoles.CustomerLimited, UserType.Customer);
//WIDGETS
await GenSeedWidgetAsync(log, 20000);
//CUSTOMERS
await GenSeedCustomerAsync(log, 20000);
//PERF
watch.Stop();
await LogStatusAsync(JobId, LogJob, log, $"{SeededUserCount} Users seeded in {watch.ElapsedMilliseconds} ms");
//20000 widgets
await LogStatusAsync(JobId, LogJob, log, $"Seeding 20,000 Widgets....");
watch = new Stopwatch();
watch.Start();
//await GenSeedWidgetAsync(log, 20000);
await GenSeedWidgetAsync(log, 20000);
watch.Stop();
await LogStatusAsync(JobId, LogJob, log, $"20k Widgets seeded in {watch.ElapsedMilliseconds} ms");
await LogStatusAsync(JobId, LogJob, log, $"HUGE level sample data seeded in {watch.ElapsedMilliseconds} ms");
#endregion genhuge
}
break;
@@ -709,6 +705,45 @@ namespace AyaNova.Util
}
}
//////////////////////////////////////////////////////
//CUSTOMER
//
public async Task GenSeedCustomerAsync(ILogger log, int count)
{
DateTime seedStartWindow = DateTime.Now.AddYears(-1);
DateTime seedEndWindow = DateTime.Now.AddYears(1);
for (int x = 0; x < count; x++)
{
Customer o = new Customer();
o.Name = Uniquify(Fake.Company.CompanyName());
o.Active = true;
o.Notes = Fake.Company.CatchPhrase();
o.Tags = RandomTags();
//This seems wrong to do in a loop but is 4 times faster this way ?!?
using (AyContext ct = ServiceProviderProvider.DBContext)
{
CustomerBiz biz = CustomerBiz.GetBiz(ct);
var NewObject = await biz.CreateAsync(o);
if (NewObject == null)
{
var err = $"Seeder::GenSeedCustomer error creating customer {o.Name}\r\n{biz.GetErrorsAsString()}";
log.LogError(err);
throw new System.Exception(err);
}
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
}//eoc