This commit is contained in:
@@ -17,6 +17,37 @@ namespace AyaNova.Util
|
||||
public enum SeedLevel { SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet, HugeForLoadTest };
|
||||
public static int SeededUserCount = 0;
|
||||
|
||||
#region CACHED OBJECTS
|
||||
|
||||
//DB CONTEXT
|
||||
private static AyContext _context = null;
|
||||
internal static AyContext Cached_Context
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_context == null)
|
||||
{
|
||||
_context = ServiceProviderProvider.DBContext;
|
||||
}
|
||||
return _context;
|
||||
}
|
||||
}
|
||||
|
||||
//WIDGETBIZ
|
||||
private static WidgetBiz _widgetBiz = null;
|
||||
internal static WidgetBiz Cached_WidgetBiz
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_widgetBiz == null)
|
||||
{
|
||||
_widgetBiz = WidgetBiz.GetBizInternal(Cached_Context);
|
||||
}
|
||||
return _widgetBiz;
|
||||
}
|
||||
}
|
||||
#endregion cached objects
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
//Seed database for trial and testing purposes
|
||||
//
|
||||
@@ -68,12 +99,13 @@ namespace AyaNova.Util
|
||||
//Erase all the data except for the license, schema and the manager user
|
||||
DbUtil.EmptyBizDataFromDatabaseForSeedingOrImporting(log);
|
||||
|
||||
|
||||
|
||||
//Set the time zone of the manager account
|
||||
{
|
||||
var ct = ServiceProviderProvider.DBContext;
|
||||
var mgr = ct.UserOptions.FirstAsync(m => m.Id == 1).Result;
|
||||
var mgr = Cached_Context.UserOptions.FirstAsync(m => m.Id == 1).Result;
|
||||
mgr.TimeZoneOffset = timeZoneOffset;
|
||||
ct.SaveChanges();
|
||||
Cached_Context.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +159,7 @@ namespace AyaNova.Util
|
||||
};
|
||||
|
||||
//Create and save to db
|
||||
var res = FormCustomBiz.GetBizInternal(ServiceProviderProvider.DBContext).CreateAsync(fc).Result;
|
||||
var res = FormCustomBiz.GetBizInternal(Cached_Context).CreateAsync(fc).Result;
|
||||
}
|
||||
|
||||
//Seed special test data for integration testing
|
||||
@@ -158,7 +190,7 @@ namespace AyaNova.Util
|
||||
//100 widgets
|
||||
watch = new Stopwatch();
|
||||
watch.Start();
|
||||
GenSeedWidget(log, 100);
|
||||
GenSeedWidgetAsync(log, 100);
|
||||
//PERF
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"100 Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
@@ -219,7 +251,7 @@ namespace AyaNova.Util
|
||||
watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
GenSeedWidget(log, 500);
|
||||
GenSeedWidgetAsync(log, 500);
|
||||
//PERF
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"500 Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
@@ -294,7 +326,7 @@ namespace AyaNova.Util
|
||||
LogStatus(JobId, LogJob, log, $"Seeding 5,000 Widgets....");
|
||||
watch = new Stopwatch();
|
||||
watch.Start();
|
||||
GenSeedWidget(log, 5000);
|
||||
GenSeedWidgetAsync(log, 5000);
|
||||
|
||||
//PERF
|
||||
watch.Stop();
|
||||
@@ -370,7 +402,7 @@ namespace AyaNova.Util
|
||||
LogStatus(JobId, LogJob, log, $"Seeding 20,000 Widgets....");
|
||||
watch = new Stopwatch();
|
||||
watch.Start();
|
||||
GenSeedWidget(log, 20000);
|
||||
GenSeedWidgetAsync(log, 20000);
|
||||
watch.Stop();
|
||||
LogStatus(JobId, LogJob, log, $"20k Widgets seeded in {watch.ElapsedMilliseconds} ms");
|
||||
#endregion genhuge
|
||||
@@ -391,6 +423,8 @@ namespace AyaNova.Util
|
||||
{
|
||||
log.LogInformation($"Seeder: setting server state back to {wasServerState.ToString()}");
|
||||
apiServerState.SetState(wasServerState, wasReason);
|
||||
_context = null;
|
||||
_widgetBiz = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,7 +534,7 @@ namespace AyaNova.Util
|
||||
public static void GenSeedUser(ILogger log, int count, AuthorizationRoles roles, UserType userType, decimal timeZoneOffset, bool active = true, string login = null, string password = null, long localeId = 0)
|
||||
{
|
||||
|
||||
UserBiz Biz = UserBiz.GetBizInternal(ServiceProviderProvider.DBContext);
|
||||
UserBiz Biz = UserBiz.GetBizInternal(Cached_Context);
|
||||
|
||||
//allow creation of not entirely ready users (missing client id or subcontractor vendor id etc)
|
||||
Biz.SeedOrImportRelaxedRulesMode = true;
|
||||
@@ -538,7 +572,7 @@ namespace AyaNova.Util
|
||||
u.UserOptions.EmailAddress = p.Email.Replace("gmail.com", "helloayanova.com").Replace("hotmail.com", "helloayanova.com").Replace("yahoo.com", "helloayanova.com");
|
||||
u.UserOptions.TimeZoneOffset = timeZoneOffset;
|
||||
|
||||
var NewObject = Biz.Create(ServiceProviderProvider.DBContext, u);
|
||||
var NewObject = Biz.Create(Cached_Context, u);
|
||||
if (NewObject == null)
|
||||
{
|
||||
log.LogError($"Seeder::GenSeedUser error creating user {u.Name}\r\n" + Biz.GetErrorsAsString());
|
||||
@@ -552,9 +586,9 @@ namespace AyaNova.Util
|
||||
//////////////////////////////////////////////////////
|
||||
//Seed widget for testing
|
||||
//
|
||||
public static void GenSeedWidget(ILogger log, int count)
|
||||
public static async void GenSeedWidgetAsync(ILogger log, int count)
|
||||
{
|
||||
WidgetBiz Biz = WidgetBiz.GetBizInternal(ServiceProviderProvider.DBContext);
|
||||
|
||||
var f = new Bogus.Faker();
|
||||
|
||||
//RANDOM ROLES
|
||||
@@ -590,11 +624,11 @@ namespace AyaNova.Util
|
||||
o.CustomFields = $@"{{c1:""{c1}"",c2:""{c2}"",c3:{c3},c4:{c4},c5:{c5}}}";
|
||||
|
||||
|
||||
var NewObject = Biz.Create(ServiceProviderProvider.DBContext, o);
|
||||
var NewObject = await Cached_WidgetBiz.CreateAsync(o);
|
||||
if (NewObject == null)
|
||||
{
|
||||
log.LogError($"Seeder::GenSeedWidget error creating widget {o.Name}\r\n" + Biz.GetErrorsAsString());
|
||||
throw new System.Exception("Seeder::GenSeedWidget error creating widget\r\n" + Biz.GetErrorsAsString());
|
||||
log.LogError($"Seeder::GenSeedWidget error creating widget {o.Name}\r\n" + Cached_WidgetBiz.GetErrorsAsString());
|
||||
throw new System.Exception("Seeder::GenSeedWidget error creating widget\r\n" + Cached_WidgetBiz.GetErrorsAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user