This commit is contained in:
2020-12-04 20:49:05 +00:00
parent 55433a8ace
commit cd016efbfb
12 changed files with 89 additions and 58 deletions

4
.vscode/launch.json vendored
View File

@@ -53,8 +53,8 @@
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
"AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles", "AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles",
"AYANOVA_SERVER_TEST_MODE": "false", "AYANOVA_SERVER_TEST_MODE": "true",
"AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "huge",
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7",
"AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\" "AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\"
}, },

View File

@@ -37,6 +37,7 @@ namespace AyaNova
_hostingEnvironment = hostingEnvironment; _hostingEnvironment = hostingEnvironment;
AyaNova.Util.ApplicationLogging.LoggerProvider = nlogLoggerProvider; AyaNova.Util.ApplicationLogging.LoggerProvider = nlogLoggerProvider;
ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH = hostingEnvironment.ContentRootPath; ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH = hostingEnvironment.ContentRootPath;
ServerBootConfig.SEEDING=false;
} }
private readonly ILogger _newLog; private readonly ILogger _newLog;

View File

@@ -210,6 +210,8 @@ namespace AyaNova.Biz
private async Task ValidateAsync(Customer proposedObj, Customer currentObj) private async Task ValidateAsync(Customer proposedObj, Customer currentObj)
{ {
//skip validation if seeding
if (ServerBootConfig.SEEDING) return;
bool isNew = currentObj == null; bool isNew = currentObj == null;

View File

@@ -205,6 +205,8 @@ namespace AyaNova.Biz
private async Task ValidateAsync(HeadOffice proposedObj, HeadOffice currentObj) private async Task ValidateAsync(HeadOffice proposedObj, HeadOffice currentObj)
{ {
//skip validation if seeding
if (ServerBootConfig.SEEDING) return;
bool isNew = currentObj == null; bool isNew = currentObj == null;

View File

@@ -136,6 +136,7 @@ namespace AyaNova.Biz
//will iterate the subscriptions and see if any apply here //will iterate the subscriptions and see if any apply here
internal static async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel newObject, ICoreBizObjectModel originalObject = null) internal static async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel newObject, ICoreBizObjectModel originalObject = null)
{ {
if (ServerBootConfig.SEEDING) return;
log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{newObject.AyaType}, AyaEvent:{ayaEvent}]"); log.LogDebug($"HandlePotentialNotificationEvent processing: [AyaType:{newObject.AyaType}, AyaEvent:{ayaEvent}]");
//set to true if any changes are made to the context (NotifyEvent added) //set to true if any changes are made to the context (NotifyEvent added)
bool SaveContext = false; bool SaveContext = false;
@@ -144,7 +145,7 @@ namespace AyaNova.Biz
using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext) using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext)
{ {
//short circuit if there are no subscriptions which would be typical of a v8 migrate scenario or fresh import or just not using notification //short circuit if there are no subscriptions which would be typical of a v8 migrate scenario or fresh import or just not using notification
if(!await ct.NotifySubscription.AnyAsync()) if (!await ct.NotifySubscription.AnyAsync())
return; return;
//switch through AyaEvent then individual Ayatypes as required for event types //switch through AyaEvent then individual Ayatypes as required for event types

View File

@@ -12,7 +12,7 @@ namespace AyaNova.Biz
internal class TranslationBiz : BizObject internal class TranslationBiz : BizObject
{ {
public bool SeedOrImportRelaxedRulesMode { get; set; }
internal TranslationBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles) internal TranslationBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles)
{ {
@@ -21,7 +21,6 @@ namespace AyaNova.Biz
UserTranslationId = userTranslationId; UserTranslationId = userTranslationId;
CurrentUserRoles = userRoles; CurrentUserRoles = userRoles;
BizType = AyaType.Translation; BizType = AyaType.Translation;
SeedOrImportRelaxedRulesMode = false;//default
} }
internal static TranslationBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null) internal static TranslationBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)

View File

@@ -17,7 +17,7 @@ namespace AyaNova.Biz
internal class UserBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject internal class UserBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject
{ {
public bool SeedOrImportRelaxedRulesMode { get; set; }
internal UserBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles) internal UserBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles userRoles)
{ {
@@ -26,7 +26,6 @@ namespace AyaNova.Biz
UserTranslationId = userTranslationId; UserTranslationId = userTranslationId;
CurrentUserRoles = userRoles; CurrentUserRoles = userRoles;
BizType = AyaType.User; BizType = AyaType.User;
SeedOrImportRelaxedRulesMode = false;//default
} }
//This is where active tech license consumers are accounted for //This is where active tech license consumers are accounted for
@@ -448,6 +447,9 @@ namespace AyaNova.Biz
//Can save or update? //Can save or update?
private async Task ValidateAsync(User proposedObj, User currentObj) private async Task ValidateAsync(User proposedObj, User currentObj)
{ {
//skip validation if seeding
if(ServerBootConfig.SEEDING) return;
//run validation and biz rules //run validation and biz rules
bool isNew = currentObj == null; bool isNew = currentObj == null;
@@ -535,7 +537,7 @@ namespace AyaNova.Biz
} }
//Validate customer type user //Validate customer type user
if (!SeedOrImportRelaxedRulesMode && proposedObj.UserType == UserType.Customer) if (proposedObj.UserType == UserType.Customer)
{ {
if (proposedObj.CustomerId == null || proposedObj.CustomerId == 0) if (proposedObj.CustomerId == null || proposedObj.CustomerId == 0)
{ {
@@ -550,7 +552,7 @@ namespace AyaNova.Biz
} }
//Validate headoffice type user //Validate headoffice type user
if (!SeedOrImportRelaxedRulesMode && proposedObj.UserType == UserType.HeadOffice) if (proposedObj.UserType == UserType.HeadOffice)
{ {
if (proposedObj.HeadOfficeId == null || proposedObj.HeadOfficeId == 0) if (proposedObj.HeadOfficeId == null || proposedObj.HeadOfficeId == 0)
{ {
@@ -565,7 +567,7 @@ namespace AyaNova.Biz
} }
//Validate subcontractor type user //Validate subcontractor type user
if (!SeedOrImportRelaxedRulesMode && proposedObj.UserType == UserType.ServiceContractor) if (proposedObj.UserType == UserType.ServiceContractor)
{ {
if (proposedObj.VendorId == null || proposedObj.VendorId == 0) if (proposedObj.VendorId == null || proposedObj.VendorId == 0)
{ {

View File

@@ -54,6 +54,7 @@ namespace AyaNova.Biz
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
await SearchIndexAsync(newObject, true); await SearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null); await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await NotifyEventProcessor.HandlePotentialNotificationEvent(AyaEvent.Created, newObject); await NotifyEventProcessor.HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject; return newObject;
} }
@@ -202,6 +203,9 @@ namespace AyaNova.Biz
private async Task ValidateAsync(Vendor proposedObj, Vendor currentObj) private async Task ValidateAsync(Vendor proposedObj, Vendor currentObj)
{ {
//skip validation if seeding
if (ServerBootConfig.SEEDING) return;
bool isNew = currentObj == null; bool isNew = currentObj == null;
//Name required //Name required

View File

@@ -226,6 +226,9 @@ namespace AyaNova.Biz
// //
private async Task ValidateAsync(Widget proposedObj) private async Task ValidateAsync(Widget proposedObj)
{ {
//skip validation if seeding
if(ServerBootConfig.SEEDING) return;
//NOTE: In DB schema only name and serial are not nullable //NOTE: In DB schema only name and serial are not nullable
//run validation and biz rules //run validation and biz rules

View File

@@ -95,6 +95,8 @@ namespace AyaNova.Util
apiServerState.SetOpsOnly("Seeding database"); apiServerState.SetOpsOnly("Seeding database");
ServerBootConfig.SEEDING = true;
//Erase all the data except for the license, schema and the SuperUser //Erase all the data except for the license, schema and the SuperUser
await DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log); await DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log);
//Event log erase and seeding //Event log erase and seeding
@@ -198,7 +200,7 @@ namespace AyaNova.Util
//Seed special test data for integration testing //Seed special test data for integration testing
//log.LogInformation("Seeding known users"); //log.LogInformation("Seeding known users");
await SeedKnownUsersAsync(log); await SeedKnownObjectsAsync(log);
//log.LogInformation("Seeding all other data"); //log.LogInformation("Seeding all other data");
switch (slevel) switch (slevel)
@@ -282,7 +284,7 @@ namespace AyaNova.Util
//WIDGETS //WIDGETS
await SeedWidgetAsync(log, 500); await SeedWidgetAsync(log, 100);
//CUSTOMERS //CUSTOMERS
await SeedCustomerAsync(log, 500); await SeedCustomerAsync(log, 500);
@@ -359,7 +361,7 @@ namespace AyaNova.Util
//WIDGETS //WIDGETS
await SeedWidgetAsync(log, 5000); await SeedWidgetAsync(log, 100);
//CUSTOMERS //CUSTOMERS
await SeedCustomerAsync(log, 5000); await SeedCustomerAsync(log, 5000);
@@ -436,7 +438,7 @@ namespace AyaNova.Util
//WIDGETS //WIDGETS
await SeedWidgetAsync(log, 20000); await SeedWidgetAsync(log, 100);
//CUSTOMERS //CUSTOMERS
await SeedCustomerAsync(log, 20000); await SeedCustomerAsync(log, 20000);
@@ -494,8 +496,8 @@ namespace AyaNova.Util
} }
finally 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()}"); log.LogInformation($"Seeder: setting server state back to {wasServerState.ToString()}");
apiServerState.SetState(wasServerState, wasReason); apiServerState.SetState(wasServerState, wasReason);
} }
@@ -517,6 +519,9 @@ namespace AyaNova.Util
return s + " " + (++RUNNING_COUNT).ToString(); 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" }; 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 //Seed test data for integration tests
// //
public async Task SeedKnownUsersAsync(ILogger log) public async Task SeedKnownObjectsAsync(ILogger log)
{ {
try 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, "es", "es", await TranslationBiz.TranslationNameToIdStaticAsync("es"), KnownUserTags);
await SeedUserAsync(log, 1, AuthorizationRoles.All, UserType.NotService, true, "fr", "fr", await TranslationBiz.TranslationNameToIdStaticAsync("fr"), KnownUserTags); await SeedUserAsync(log, 1, AuthorizationRoles.All, UserType.NotService, true, "fr", "fr", await TranslationBiz.TranslationNameToIdStaticAsync("fr"), KnownUserTags);
//CUSTOMER / HO Users
} }
catch catch
@@ -614,9 +622,12 @@ namespace AyaNova.Util
User u = new User(); User u = new User();
u.Active = active; 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"; var bogusEmail = u.Name.ToLowerInvariant().Replace(" ", "_") + "@example.net";
if (login != null) 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!? //this seems wrong to get a new context inside a loop but in testing is actually faster!?
using (AyContext ct = ServiceProviderProvider.DBContext) using (AyContext ct = ServiceProviderProvider.DBContext)
{ {
UserBiz Biz = UserBiz.GetBiz(ct); UserBiz biz = UserBiz.GetBiz(ct);
//allow creation of not entirely ready users (missing client id or subcontractor vendor id etc) var NewObject = await biz.CreateAsync(u);
Biz.SeedOrImportRelaxedRulesMode = true;
var NewObject = await Biz.CreateAsync(u);
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());
throw new System.Exception("Seeder::SeedUser error creating user\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; SeededUserCount += count;
} }
#region WIDGET
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
//Seed widget for testing //Seed widget for testing
// //
@@ -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) 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++) for (int x = 0; x < count; x++)
{ {
Customer o = new Customer(); 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.Active = true;
o.Notes = Fake.Company.CatchPhrase(); o.Notes = Fake.Company.CatchPhrase();
o.Tags = RandomTags(); o.Tags = RandomTags();
@@ -784,8 +798,6 @@ namespace AyaNova.Util
} }
//Customer contacts //Customer contacts
await SeedUserAsync(log, 1, AuthorizationRoles.CustomerFull, UserType.Customer, true, null, null, 0, null, null, NewObject.Id, null); 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) 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++) for (int x = 0; x < count; x++)
{ {
HeadOffice o = new HeadOffice(); 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.Active = true;
o.Notes = Fake.Company.CatchPhrase(); o.Notes = Fake.Company.CatchPhrase();
o.Tags = RandomTags(); o.Tags = RandomTags();
@@ -852,18 +868,19 @@ namespace AyaNova.Util
public async Task SeedVendorAsync(ILogger log, int count) 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++) for (int x = 0; x < count; x++)
{ {
Vendor o = new Vendor(); 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.Active = true;
o.Notes = Fake.Company.CatchPhrase(); o.Notes = Fake.Company.CatchPhrase();
o.Tags = RandomTags(); o.Tags = RandomTags();
o.Contact = Fake.Name.FullName(); o.Contact = Fake.Name.FullName();
o.ContactNotes = Fake.Name.FullName(); o.ContactNotes = Fake.Name.FullName();
o.AccountNumber = Fake.Finance.Account(); o.AccountNumber = Fake.Finance.Account();
@@ -880,8 +897,6 @@ namespace AyaNova.Util
o.WebAddress = Fake.Internet.Url(); o.WebAddress = Fake.Internet.Url();
o.EmailAddress = Fake.Internet.ExampleEmail(); o.EmailAddress = Fake.Internet.ExampleEmail();
//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)
{ {
@@ -894,10 +909,6 @@ namespace AyaNova.Util
log.LogError(err); log.LogError(err);
throw new System.Exception(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);
} }
} }

View File

@@ -17,6 +17,12 @@ namespace AyaNova.Util
internal const int REPORT_RENDERING_OPERATION_TIMEOUT = 20000;//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 //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) #if (DEBUG)
internal static List<string> TranslationKeysRequested { get; set; } internal static List<string> TranslationKeysRequested { get; set; }