This commit is contained in:
@@ -95,6 +95,8 @@ namespace AyaNova.Util
|
||||
|
||||
|
||||
apiServerState.SetOpsOnly("Seeding database");
|
||||
ServerBootConfig.SEEDING = true;
|
||||
|
||||
//Erase all the data except for the license, schema and the SuperUser
|
||||
await DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log);
|
||||
//Event log erase and seeding
|
||||
@@ -198,7 +200,7 @@ namespace AyaNova.Util
|
||||
|
||||
//Seed special test data for integration testing
|
||||
//log.LogInformation("Seeding known users");
|
||||
await SeedKnownUsersAsync(log);
|
||||
await SeedKnownObjectsAsync(log);
|
||||
|
||||
//log.LogInformation("Seeding all other data");
|
||||
switch (slevel)
|
||||
@@ -282,7 +284,7 @@ namespace AyaNova.Util
|
||||
|
||||
|
||||
//WIDGETS
|
||||
await SeedWidgetAsync(log, 500);
|
||||
await SeedWidgetAsync(log, 100);
|
||||
|
||||
//CUSTOMERS
|
||||
await SeedCustomerAsync(log, 500);
|
||||
@@ -359,7 +361,7 @@ namespace AyaNova.Util
|
||||
|
||||
|
||||
//WIDGETS
|
||||
await SeedWidgetAsync(log, 5000);
|
||||
await SeedWidgetAsync(log, 100);
|
||||
|
||||
//CUSTOMERS
|
||||
await SeedCustomerAsync(log, 5000);
|
||||
@@ -436,7 +438,7 @@ namespace AyaNova.Util
|
||||
|
||||
|
||||
//WIDGETS
|
||||
await SeedWidgetAsync(log, 20000);
|
||||
await SeedWidgetAsync(log, 100);
|
||||
|
||||
//CUSTOMERS
|
||||
await SeedCustomerAsync(log, 20000);
|
||||
@@ -494,8 +496,8 @@ namespace AyaNova.Util
|
||||
}
|
||||
finally
|
||||
{
|
||||
//TODO: fully async: watch the job and don't turn the state back until the job is done?
|
||||
|
||||
//No matter what seeding is done
|
||||
ServerBootConfig.SEEDING = false;
|
||||
log.LogInformation($"Seeder: setting server state back to {wasServerState.ToString()}");
|
||||
apiServerState.SetState(wasServerState, wasReason);
|
||||
}
|
||||
@@ -517,6 +519,9 @@ namespace AyaNova.Util
|
||||
return s + " " + (++RUNNING_COUNT).ToString();
|
||||
}
|
||||
|
||||
public HashSet<string> HashUserNames = new HashSet<string>();
|
||||
public HashSet<string> HashCompanyNames = new HashSet<string>();
|
||||
|
||||
|
||||
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" };
|
||||
|
||||
@@ -530,7 +535,7 @@ namespace AyaNova.Util
|
||||
//////////////////////////////////////////////////////
|
||||
//Seed test data for integration tests
|
||||
//
|
||||
public async Task SeedKnownUsersAsync(ILogger log)
|
||||
public async Task SeedKnownObjectsAsync(ILogger log)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -569,6 +574,9 @@ namespace AyaNova.Util
|
||||
await SeedUserAsync(log, 1, AuthorizationRoles.All, UserType.NotService, true, "es", "es", await TranslationBiz.TranslationNameToIdStaticAsync("es"), KnownUserTags);
|
||||
await SeedUserAsync(log, 1, AuthorizationRoles.All, UserType.NotService, true, "fr", "fr", await TranslationBiz.TranslationNameToIdStaticAsync("fr"), KnownUserTags);
|
||||
|
||||
//CUSTOMER / HO Users
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch
|
||||
@@ -614,9 +622,12 @@ namespace AyaNova.Util
|
||||
User u = new User();
|
||||
u.Active = active;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
u.Name = Fake.Name.FullName();
|
||||
} while (!HashUserNames.Add(u.Name));
|
||||
|
||||
|
||||
u.Name = Uniquify(Fake.Name.FullName());
|
||||
var bogusEmail = u.Name.ToLowerInvariant().Replace(" ", "_") + "@example.net";
|
||||
if (login != null)
|
||||
{
|
||||
@@ -660,14 +671,12 @@ namespace AyaNova.Util
|
||||
//this seems wrong to get a new context inside a loop but in testing is actually faster!?
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
UserBiz Biz = UserBiz.GetBiz(ct);
|
||||
//allow creation of not entirely ready users (missing client id or subcontractor vendor id etc)
|
||||
Biz.SeedOrImportRelaxedRulesMode = true;
|
||||
var NewObject = await Biz.CreateAsync(u);
|
||||
UserBiz biz = UserBiz.GetBiz(ct);
|
||||
var NewObject = await biz.CreateAsync(u);
|
||||
if (NewObject == null)
|
||||
{
|
||||
log.LogError($"Seeder::SeedUser error creating {u.Name}\r\n" + Biz.GetErrorsAsString());
|
||||
throw new System.Exception("Seeder::SeedUser error creating user\r\n" + Biz.GetErrorsAsString());
|
||||
log.LogError($"Seeder::SeedUser error creating {u.Name}\r\n" + biz.GetErrorsAsString());
|
||||
throw new System.Exception("Seeder::SeedUser error creating user\r\n" + biz.GetErrorsAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -675,6 +684,7 @@ namespace AyaNova.Util
|
||||
SeededUserCount += count;
|
||||
}
|
||||
|
||||
#region WIDGET
|
||||
//////////////////////////////////////////////////////
|
||||
//Seed widget for testing
|
||||
//
|
||||
@@ -717,7 +727,7 @@ namespace AyaNova.Util
|
||||
//This seems wrong to do in a loop but is 4 times faster this way ?!?
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
WidgetBiz biz = WidgetBiz.GetBiz(ct);
|
||||
WidgetBiz biz = WidgetBiz.GetBiz(ct);
|
||||
var NewObject = await biz.CreateAsync(o);
|
||||
if (NewObject == null)
|
||||
{
|
||||
@@ -728,7 +738,7 @@ namespace AyaNova.Util
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -738,12 +748,16 @@ namespace AyaNova.Util
|
||||
public async Task SeedCustomerAsync(ILogger log, int count, long? headOfficeId = null)
|
||||
{
|
||||
|
||||
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());
|
||||
|
||||
do
|
||||
{
|
||||
o.Name = Fake.Name.FullName();
|
||||
} while (!HashCompanyNames.Add(o.Name));
|
||||
|
||||
|
||||
o.Active = true;
|
||||
o.Notes = Fake.Company.CatchPhrase();
|
||||
o.Tags = RandomTags();
|
||||
@@ -784,8 +798,6 @@ namespace AyaNova.Util
|
||||
}
|
||||
//Customer contacts
|
||||
await SeedUserAsync(log, 1, AuthorizationRoles.CustomerFull, UserType.Customer, true, null, null, 0, null, null, NewObject.Id, null);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -797,12 +809,16 @@ namespace AyaNova.Util
|
||||
public async Task SeedHeadOfficeAsync(ILogger log, int count)
|
||||
{
|
||||
|
||||
DateTime seedStartWindow = DateTime.Now.AddYears(-1);
|
||||
DateTime seedEndWindow = DateTime.Now.AddYears(1);
|
||||
for (int x = 0; x < count; x++)
|
||||
{
|
||||
HeadOffice o = new HeadOffice();
|
||||
o.Name = Uniquify(Fake.Company.CompanyName());
|
||||
|
||||
do
|
||||
{
|
||||
o.Name = Fake.Name.FullName();
|
||||
} while (!HashCompanyNames.Add(o.Name));
|
||||
|
||||
|
||||
o.Active = true;
|
||||
o.Notes = Fake.Company.CatchPhrase();
|
||||
o.Tags = RandomTags();
|
||||
@@ -852,18 +868,19 @@ namespace AyaNova.Util
|
||||
public async Task SeedVendorAsync(ILogger log, int count)
|
||||
{
|
||||
|
||||
DateTime seedStartWindow = DateTime.Now.AddYears(-1);
|
||||
DateTime seedEndWindow = DateTime.Now.AddYears(1);
|
||||
for (int x = 0; x < count; x++)
|
||||
{
|
||||
Vendor o = new Vendor();
|
||||
do
|
||||
{
|
||||
o.Name = Fake.Name.FullName();
|
||||
} while (!HashCompanyNames.Add(o.Name));
|
||||
|
||||
|
||||
o.Name = Uniquify(Fake.Company.CompanyName());
|
||||
o.Active = true;
|
||||
o.Notes = Fake.Company.CatchPhrase();
|
||||
o.Tags = RandomTags();
|
||||
|
||||
|
||||
o.Contact = Fake.Name.FullName();
|
||||
o.ContactNotes = Fake.Name.FullName();
|
||||
o.AccountNumber = Fake.Finance.Account();
|
||||
@@ -880,8 +897,6 @@ namespace AyaNova.Util
|
||||
o.WebAddress = Fake.Internet.Url();
|
||||
o.EmailAddress = Fake.Internet.ExampleEmail();
|
||||
|
||||
|
||||
|
||||
//This seems wrong to do in a loop but is 4 times faster this way ?!?
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
@@ -894,10 +909,6 @@ namespace AyaNova.Util
|
||||
log.LogError(err);
|
||||
throw new System.Exception(err);
|
||||
}
|
||||
//HeadOffice contacts
|
||||
// await SeedUserAsync(log, 1, AuthorizationRoles.CustomerFull, UserType.HeadOffice, true, null, null, 0, null, null, null, NewObject.Id);
|
||||
//HeadOffice Customer
|
||||
// await SeedCustomerAsync(log, 2, NewObject.Id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,13 @@ namespace AyaNova.Util
|
||||
//STATIC HARD CODED DEFAULTS NOT SET THROUGH CONFIG
|
||||
internal const int FAILED_AUTH_DELAY = 3000;//ms
|
||||
internal const int REPORT_RENDERING_OPERATION_TIMEOUT = 20000;//ms
|
||||
//############################################################################################################
|
||||
//############################################################################################################
|
||||
|
||||
//############################
|
||||
//SEEDING FLAG INTERNAL ONLY
|
||||
//used to speed up seeding with bypasses to normal validation etc
|
||||
internal static bool SEEDING { get; set; }
|
||||
//############################
|
||||
|
||||
//Diagnostic static values used during development, may not be related to config at all, this is just a convenient class to put them in
|
||||
#if (DEBUG)
|
||||
|
||||
Reference in New Issue
Block a user