This commit is contained in:
2018-08-28 22:46:53 +00:00
parent 5cd914767d
commit 78ce79fc5c
4 changed files with 80 additions and 65 deletions

View File

@@ -23,6 +23,8 @@ Overall plan for now: anything standing in the way of making the initial client
- Make sure trial generated data generates log events so that we can properly test with huge dataset - Make sure trial generated data generates log events so that we can properly test with huge dataset
- Test with huge dataset - Test with huge dataset
- Remove CREATED from all objects now that event log tracks it - Remove CREATED from all objects now that event log tracks it
- V7 Import: check for efficiency changes after seeing how seeder needed to be optimized
- Also need to see about event log working with it, should it attempt to keep the v7 created / modifed or start afresh
- Localized text - Localized text
- Search and search text indexing - Search and search text indexing
- Auto visible id number assigning code - Auto visible id number assigning code

View File

@@ -383,7 +383,7 @@ namespace AyaNova
lb.ValidateLocales(); lb.ValidateLocales();
AyaNova.Core.License.Initialize(apiServerState, dbContext, _log); AyaNova.Core.License.Initialize(apiServerState, dbContext, _log);
AyaNova.Core.License.Fetch(apiServerState, dbContext, _log); AyaNova.Core.License.Fetch(apiServerState, dbContext, _log);
Util.Seeder.SeedDatabase(dbContext, Util.Seeder.SeedLevel.MediumLocalServiceCompanyTrialDataSet); Util.Seeder.SeedDatabase(Util.Seeder.SeedLevel.LargeCorporateMultiRegionalTrialDataSet);
#endif #endif

View File

@@ -75,7 +75,7 @@ namespace AyaNova.Biz
//Get the import filename from the jsondata //Get the import filename from the jsondata
JObject jobData = JObject.Parse(job.JobInfo); JObject jobData = JObject.Parse(job.JobInfo);
var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>(); var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>();
Seeder.SeedDatabase(ct, seedLevel); Seeder.SeedDatabase(seedLevel);
JobsBiz.LogJob(job.GId, "Finished.", ct); JobsBiz.LogJob(job.GId, "Finished.", ct);
JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct); JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct);
await Task.CompletedTask; await Task.CompletedTask;

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using AyaNova.Models; using AyaNova.Models;
using AyaNova.Biz; using AyaNova.Biz;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -34,7 +35,7 @@ namespace AyaNova.Util
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
//Seed database for trial and testing purposes //Seed database for trial and testing purposes
// //
public static void SeedDatabase(AyContext ct, SeedLevel slevel) public static void SeedDatabase(SeedLevel slevel)
{ {
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));
@@ -62,7 +63,7 @@ namespace AyaNova.Util
var f = new Faker("en"); var f = new Faker("en");
//Seed special test data for integration testing //Seed special test data for integration testing
SeedTestData(ct); SeedTestData();
switch (slevel) switch (slevel)
@@ -71,13 +72,13 @@ namespace AyaNova.Util
//This is for a busy but one man shop with a single office person handling stuff back at the shop //This is for a busy but one man shop with a single office person handling stuff back at the shop
case SeedLevel.SmallOneManShopTrialDataSet: case SeedLevel.SmallOneManShopTrialDataSet:
//Generate owner and lead tech //Generate owner and lead tech
GenSeedUser(1, ct, AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.OpsAdminFull); GenSeedUser(1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.OpsAdminFull);
//Generate one office person / secretary //Generate one office person / secretary
GenSeedUser(1, ct, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.AccountingFull); GenSeedUser(1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull | AuthorizationRoles.AccountingFull);
//200 widgets //200 widgets
GenSeedWidget(200, ct); GenSeedWidget(200);
break; break;
//This is for a typical AyaNova medium busy shop //This is for a typical AyaNova medium busy shop
@@ -85,90 +86,89 @@ namespace AyaNova.Util
case SeedLevel.MediumLocalServiceCompanyTrialDataSet: case SeedLevel.MediumLocalServiceCompanyTrialDataSet:
//One IT administrator, can change ops but nothing else //One IT administrator, can change ops but nothing else
GenSeedUser(1, ct, AuthorizationRoles.OpsAdminFull); GenSeedUser(1, AuthorizationRoles.OpsAdminFull);
//One business administrator, can view ops issues //One business administrator, can view ops issues
GenSeedUser(1, ct, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited); GenSeedUser(1, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited);
//One owner who doesn't control anything but views stuff //One owner who doesn't control anything but views stuff
GenSeedUser(1, ct, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited); GenSeedUser(1, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited);
//20 techs //20 techs
GenSeedUser(20, ct, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited); GenSeedUser(20, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited);
//2 subcontractors //2 subcontractors
GenSeedUser(2, ct, AuthorizationRoles.SubContractorFull); GenSeedUser(2, AuthorizationRoles.SubContractorFull);
//3 sales / generic office people people //3 sales / generic office people people
GenSeedUser(3, ct, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited); GenSeedUser(3, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited);
//1 dispatch manager //1 dispatch manager
GenSeedUser(1, ct, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited); GenSeedUser(1, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited);
//1 Inventory manager //1 Inventory manager
GenSeedUser(1, ct, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited); GenSeedUser(1, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited);
//1 accountant / bookkeeper //1 accountant / bookkeeper
GenSeedUser(1, ct, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited); GenSeedUser(1, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited);
//10 full on client users //10 full on client users
GenSeedUser(10, ct, AuthorizationRoles.ClientLimited); GenSeedUser(10, AuthorizationRoles.ClientLimited);
//10 limited client users //10 limited client users
GenSeedUser(10, ct, AuthorizationRoles.ClientLimited); GenSeedUser(10, AuthorizationRoles.ClientLimited);
//2000 widgets //2000 widgets
GenSeedWidget(2000, ct); GenSeedWidget(2000);
//GenSeedWidget(100, ct);
break; break;
//this is a large corporation with multiple branches in multiple locations all in the same country //this is a large corporation with multiple branches in multiple locations all in the same country
//Each location has a full staff and corporate head office has an overarching staff member in charge of each location //Each location has a full staff and corporate head office has an overarching staff member in charge of each location
case SeedLevel.LargeCorporateMultiRegionalTrialDataSet: case SeedLevel.LargeCorporateMultiRegionalTrialDataSet:
//IT administrator, can change ops but nothing else //IT administrator, can change ops but nothing else
GenSeedUser(2, ct, AuthorizationRoles.OpsAdminFull); GenSeedUser(2, AuthorizationRoles.OpsAdminFull);
//business administrator, can view ops issues //business administrator, can view ops issues
GenSeedUser(2, ct, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited); GenSeedUser(2, AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminLimited);
//owner / upper management who doesn't control anything but views stuff //owner / upper management who doesn't control anything but views stuff
GenSeedUser(5, ct, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited); GenSeedUser(5, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited);
//techs //techs
GenSeedUser(100, ct, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited); GenSeedUser(100, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited);
//limited techs //limited techs
GenSeedUser(50, ct, AuthorizationRoles.TechLimited | AuthorizationRoles.DispatchLimited); GenSeedUser(50, AuthorizationRoles.TechLimited | AuthorizationRoles.DispatchLimited);
//20 subcontractors //20 subcontractors
GenSeedUser(20, ct, AuthorizationRoles.SubContractorFull); GenSeedUser(20, AuthorizationRoles.SubContractorFull);
//10 limited subcontractors //10 limited subcontractors
GenSeedUser(10, ct, AuthorizationRoles.SubContractorLimited); GenSeedUser(10, AuthorizationRoles.SubContractorLimited);
//30 sales / generic office people people //30 sales / generic office people people
GenSeedUser(30, ct, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited); GenSeedUser(30, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited);
//5 dispatch manager //5 dispatch manager
GenSeedUser(5, ct, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited); GenSeedUser(5, AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryLimited);
//5 Inventory manager //5 Inventory manager
GenSeedUser(5, ct, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited); GenSeedUser(5, AuthorizationRoles.InventoryFull | AuthorizationRoles.DispatchLimited);
//10 Inventory manager assistants //10 Inventory manager assistants
GenSeedUser(5, ct, AuthorizationRoles.InventoryLimited); GenSeedUser(5, AuthorizationRoles.InventoryLimited);
//5 accountant / bookkeeper //5 accountant / bookkeeper
GenSeedUser(5, ct, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited); GenSeedUser(5, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited);
//100 full on client users //100 full on client users
GenSeedUser(100, ct, AuthorizationRoles.ClientFull); GenSeedUser(100, AuthorizationRoles.ClientFull);
//100 limited client users //100 limited client users
GenSeedUser(100, ct, AuthorizationRoles.ClientLimited); GenSeedUser(100, AuthorizationRoles.ClientLimited);
//20000 widgets //20000 widgets
GenSeedWidget(20000, ct); GenSeedWidget(20000);
break; break;
} }
@@ -192,28 +192,29 @@ namespace AyaNova.Util
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
//Seed test data for integration tests //Seed test data for integration tests
// //
public static void SeedTestData(AyContext ct) public static void SeedTestData()
{ {
//TEST USERS //TEST USERS
//one of each role type //one of each role type
GenSeedUser(1, ct, AuthorizationRoles.BizAdminLimited, "BizAdminLimited", "BizAdminLimited"); GenSeedUser(1, AuthorizationRoles.BizAdminLimited, "BizAdminLimited", "BizAdminLimited");
GenSeedUser(1, ct, AuthorizationRoles.BizAdminFull, "BizAdminFull", "BizAdminFull"); GenSeedUser(1, AuthorizationRoles.BizAdminFull, "BizAdminFull", "BizAdminFull");
GenSeedUser(1, ct, AuthorizationRoles.DispatchLimited, "DispatchLimited", "DispatchLimited"); GenSeedUser(1, AuthorizationRoles.DispatchLimited, "DispatchLimited", "DispatchLimited");
GenSeedUser(1, ct, AuthorizationRoles.DispatchFull, "DispatchFull", "DispatchFull"); GenSeedUser(1, AuthorizationRoles.DispatchFull, "DispatchFull", "DispatchFull");
GenSeedUser(1, ct, AuthorizationRoles.InventoryLimited, "InventoryLimited", "InventoryLimited"); GenSeedUser(1, AuthorizationRoles.InventoryLimited, "InventoryLimited", "InventoryLimited");
GenSeedUser(1, ct, AuthorizationRoles.InventoryFull, "InventoryFull", "InventoryFull"); GenSeedUser(1, AuthorizationRoles.InventoryFull, "InventoryFull", "InventoryFull");
GenSeedUser(1, ct, AuthorizationRoles.AccountingFull, "Accounting", "Accounting"); GenSeedUser(1, AuthorizationRoles.AccountingFull, "Accounting", "Accounting");
GenSeedUser(1, ct, AuthorizationRoles.TechLimited, "TechLimited", "TechLimited"); GenSeedUser(1, AuthorizationRoles.TechLimited, "TechLimited", "TechLimited");
GenSeedUser(1, ct, AuthorizationRoles.TechFull, "TechFull", "TechFull"); GenSeedUser(1, AuthorizationRoles.TechFull, "TechFull", "TechFull");
GenSeedUser(1, ct, AuthorizationRoles.SubContractorLimited, "SubContractorLimited", "SubContractorLimited"); GenSeedUser(1, AuthorizationRoles.SubContractorLimited, "SubContractorLimited", "SubContractorLimited");
GenSeedUser(1, ct, AuthorizationRoles.SubContractorFull, "SubContractorFull", "SubContractorFull"); GenSeedUser(1, AuthorizationRoles.SubContractorFull, "SubContractorFull", "SubContractorFull");
GenSeedUser(1, ct, AuthorizationRoles.ClientLimited, "ClientLimited", "ClientLimited"); GenSeedUser(1, AuthorizationRoles.ClientLimited, "ClientLimited", "ClientLimited");
GenSeedUser(1, ct, AuthorizationRoles.ClientFull, "ClientFull", "ClientFull"); GenSeedUser(1, AuthorizationRoles.ClientFull, "ClientFull", "ClientFull");
GenSeedUser(1, ct, AuthorizationRoles.OpsAdminLimited, "OpsAdminLimited", "OpsAdminLimited"); GenSeedUser(1, AuthorizationRoles.OpsAdminLimited, "OpsAdminLimited", "OpsAdminLimited");
GenSeedUser(1, ct, AuthorizationRoles.OpsAdminFull, "OpsAdminFull", "OpsAdminFull"); GenSeedUser(1, AuthorizationRoles.OpsAdminFull, "OpsAdminFull", "OpsAdminFull");
//PRIVACY TEST USER - this is used for a test to see if user info leaks into the logs //PRIVACY TEST USER - this is used for a test to see if user info leaks into the logs
GenSeedUser(1, ct, AuthorizationRoles.OpsAdminLimited, "TEST_PRIVACY_USER_ACCOUNT", "TEST_PRIVACY_USER_ACCOUNT"); GenSeedUser(1, AuthorizationRoles.OpsAdminLimited, "TEST_PRIVACY_USER_ACCOUNT", "TEST_PRIVACY_USER_ACCOUNT");
} }
@@ -225,8 +226,9 @@ namespace AyaNova.Util
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
//Seed user - default login / pw is first name //Seed user - default login / pw is first name
// //
public static void GenSeedUser(int count, AyContext ct, AuthorizationRoles roles, string login = null, string password = null) public static void GenSeedUser(int count, AuthorizationRoles roles, string login = null, string password = null)
{ {
AyContext ct = ServiceProviderProvider.DBContext;
for (int x = 0; x < count; x++) for (int x = 0; x < count; x++)
{ {
@@ -256,35 +258,46 @@ namespace AyaNova.Util
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
//Seed widget for testing //Seed widget for testing
// //
public static void GenSeedWidget(int count, AyContext ct) public static void GenSeedWidget(int count)
{ {
var s="blah"; //get a context just for this op to save memory on changetracking
AyContext ct = ServiceProviderProvider.DBContext;
var f = new Bogus.Faker();
for (int x = 0; x < count; x++) for (int x = 0; x < count; x++)
{ {
Widget o = new Widget(); Widget o = new Widget();
var f = new Bogus.Faker();
o.Name = f.Commerce.ProductName(); o.Name = f.Commerce.ProductName();
o.Active = f.Random.Bool(); o.Active = f.Random.Bool();
o.StartDate = f.Date.Between(DateTime.Now, DateTime.Now.AddMinutes(60)); o.StartDate = f.Date.Between(DateTime.Now, DateTime.Now.AddMinutes(60));
o.EndDate = f.Date.Between(DateTime.Now.AddMinutes(90), DateTime.Now.AddHours(5)); o.EndDate = f.Date.Between(DateTime.Now.AddMinutes(90), DateTime.Now.AddHours(5));
o.DollarAmount = Convert.ToDecimal(f.Commerce.Price()); o.DollarAmount = Convert.ToDecimal(f.Commerce.Price());
o.OwnerId = 1; o.OwnerId = 1;
//this is nonsense but just to test an enum //this is nonsense but just to test an enum
o.Roles = AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited; o.Roles = AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited;
ct.Widget.Add(o); ct.Widget.Add(o);
// ct.SaveChanges();
//Log
EventLogProcessor.AddEntryNoSave(new Event(o.OwnerId, o.Id, AyaType.Widget, AyaEvent.Created), ct);
} }
//Save the changes to get the ID values
ct.SaveChanges(); ct.SaveChanges();
var v=s;
//Now that we have the ID values bulk add the event log entries
//To save a db call iterate the local collection in the context, but...
//can't modify the context in the foreach, even if it's another collection entirely, so need to save the id's in a temporary list
List<long> WidgetsAdded = new List<long>();
foreach (Widget w in ct.Widget.Local)
{
WidgetsAdded.Add(w.Id);
}
//Now we have all the id's can actually add them to the context
foreach (long l in WidgetsAdded)
{
EventLogProcessor.AddEntryNoSave(new Event(1, l, AyaType.Widget, AyaEvent.Created), ct);
}
//Now save the Event Log entries
ct.SaveChanges();
} }
}//eoc }//eoc