This commit is contained in:
@@ -52,7 +52,7 @@ namespace AyaNova.Api.Controllers
|
||||
/// <param name="timeZoneOffset">Value in hours of local time zone offset from UTC / GMT. This ensures that data is generated relative to the desired time zone</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("seed/{size}/{timeZoneOffset}")]
|
||||
public async Task<IActionResult> SeedTrialDatabase([FromRoute] string size,[FromRoute] decimal timeZoneOffset )
|
||||
public async Task<IActionResult> SeedTrialDatabase([FromRoute] string size, [FromRoute] decimal timeZoneOffset)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
@@ -69,32 +69,16 @@ namespace AyaNova.Api.Controllers
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Current license is not a trial license key. Only a trial can be seeded."));
|
||||
}
|
||||
|
||||
Seeder.SeedLevel seedLevel = Seeder.SeedLevel.SmallOneManShopTrialDataSet;
|
||||
switch (size.ToLowerInvariant())
|
||||
{
|
||||
case "small":
|
||||
seedLevel = Seeder.SeedLevel.SmallOneManShopTrialDataSet;
|
||||
break;
|
||||
case "medium":
|
||||
seedLevel = Seeder.SeedLevel.MediumLocalServiceCompanyTrialDataSet;
|
||||
break;
|
||||
case "large":
|
||||
seedLevel = Seeder.SeedLevel.LargeCorporateMultiRegionalTrialDataSet;
|
||||
break;
|
||||
case "huge":
|
||||
seedLevel = Seeder.SeedLevel.HugeForLoadTest;
|
||||
break;
|
||||
default:
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, "size", "Valid values are \"small\", \"medium\", \"large\", \"huge\""));
|
||||
}
|
||||
|
||||
Seeder.SeedLevel seedLevel = Seeder.StringToSeedLevel(size);
|
||||
if (seedLevel == Seeder.SeedLevel.NotValid)
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, "size", "Valid values are \"small\", \"medium\", \"large\", \"huge\""));
|
||||
|
||||
//Create the job here
|
||||
|
||||
JObject o = JObject.FromObject(new
|
||||
{
|
||||
seedLevel = seedLevel,
|
||||
timeZoneOffset=timeZoneOffset
|
||||
timeZoneOffset = timeZoneOffset
|
||||
});
|
||||
|
||||
OpsJob j = new OpsJob();
|
||||
|
||||
@@ -413,20 +413,28 @@ namespace AyaNova
|
||||
// ******************** TESTING WIPE DB *****************************
|
||||
//
|
||||
//Set this to true to wipe the db and reinstall a trial license and re-seed the data
|
||||
var TESTING_REFRESH_DB = true;//#######################################################################################
|
||||
//DEPRECATED, now use boot setting AYANOVA_SERVER_TEST_MODE
|
||||
// var TESTING_REFRESH_DB = true;//#######################################################################################
|
||||
|
||||
#if (DEBUG)
|
||||
// #if (DEBUG)
|
||||
|
||||
//TESTING
|
||||
if (TESTING_REFRESH_DB)
|
||||
ServerBootConfig.AYANOVA_PERMANENTLY_ERASE_DATABASE = TESTING_REFRESH_DB;
|
||||
//TESTING
|
||||
#endif
|
||||
// //TESTING
|
||||
// if (TESTING_REFRESH_DB)
|
||||
// ServerBootConfig.AYANOVA_PERMANENTLY_ERASE_DATABASE = TESTING_REFRESH_DB;
|
||||
// //TESTING
|
||||
// #endif
|
||||
|
||||
|
||||
if (ServerBootConfig.AYANOVA_PERMANENTLY_ERASE_DATABASE)
|
||||
if (ServerBootConfig.AYANOVA_PERMANENTLY_ERASE_DATABASE || ServerBootConfig.AYANOVA_SERVER_TEST_MODE)
|
||||
{
|
||||
_newLog.LogWarning("BOOT: AYANOVA_PERMANENTLY_ERASE_DATABASE is true, dropping and recreating database");
|
||||
if (ServerBootConfig.AYANOVA_SERVER_TEST_MODE)
|
||||
{
|
||||
_newLog.LogWarning("BOOT: AYANOVA_SERVER_TEST_MODE is true, dropping and recreating database");
|
||||
}
|
||||
else
|
||||
{
|
||||
_newLog.LogWarning("BOOT: AYANOVA_PERMANENTLY_ERASE_DATABASE is true, dropping and recreating database");
|
||||
}
|
||||
Util.DbUtil.DropAndRecreateDbAsync(_newLog).Wait();
|
||||
AySchema.CheckAndUpdateAsync(dbContext, _newLog).Wait();
|
||||
}
|
||||
@@ -451,17 +459,16 @@ namespace AyaNova
|
||||
lb.ValidateTranslationsAsync().Wait();
|
||||
|
||||
|
||||
|
||||
#if (DEBUG)
|
||||
//TESTING
|
||||
if (TESTING_REFRESH_DB)
|
||||
if (ServerBootConfig.AYANOVA_SERVER_TEST_MODE)
|
||||
{
|
||||
_newLog.LogInformation($"BOOT: server test mode seeding, level is {ServerBootConfig.AYANOVA_SERVER_TEST_MODE_SEEDLEVEL}, tz offset is {ServerBootConfig.AYANOVA_SERVER_TEST_MODE_TZ_OFFSET}");
|
||||
AyaNova.Core.License.FetchKeyAsync(apiServerState, dbContext, _newLog).Wait();
|
||||
//NOTE: For unit testing make sure the time zone is same as tester to ensure list filter by date tests will work because server is on same page as user in terms of time
|
||||
Util.Seeder.SeedDatabaseAsync(Util.Seeder.SeedLevel.SmallOneManShopTrialDataSet, -8).Wait();//#############################################################################################
|
||||
Util.Seeder.SeedDatabaseAsync(Util.Seeder.StringToSeedLevel(ServerBootConfig.AYANOVA_SERVER_TEST_MODE_SEEDLEVEL), ServerBootConfig.AYANOVA_SERVER_TEST_MODE_TZ_OFFSET).Wait();
|
||||
}
|
||||
//TESTING
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//AUTOID VALUES INITIALIZATION
|
||||
|
||||
@@ -15,10 +15,29 @@ namespace AyaNova.Util
|
||||
|
||||
public static class Seeder
|
||||
{
|
||||
public enum SeedLevel { SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet, HugeForLoadTest };
|
||||
public enum SeedLevel { NotValid, SmallOneManShopTrialDataSet, MediumLocalServiceCompanyTrialDataSet, LargeCorporateMultiRegionalTrialDataSet, HugeForLoadTest };
|
||||
public static int SeededUserCount = 0;
|
||||
|
||||
public static SeedLevel StringToSeedLevel(string size)
|
||||
{
|
||||
switch (size.ToLowerInvariant())
|
||||
{
|
||||
case "small":
|
||||
return SeedLevel.SmallOneManShopTrialDataSet;
|
||||
|
||||
case "medium":
|
||||
return SeedLevel.MediumLocalServiceCompanyTrialDataSet;
|
||||
|
||||
case "large":
|
||||
return SeedLevel.LargeCorporateMultiRegionalTrialDataSet;
|
||||
|
||||
case "huge":
|
||||
return SeedLevel.HugeForLoadTest;
|
||||
|
||||
default:
|
||||
return SeedLevel.NotValid;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
//Seed database for trial and testing purposes
|
||||
|
||||
@@ -25,6 +25,10 @@ namespace AyaNova.Util
|
||||
|
||||
#endif
|
||||
|
||||
//TEST MODE - BOOT WILL ERASE DB AND GENERATE SAMPLE DATA EVERY TIME
|
||||
internal static bool AYANOVA_SERVER_TEST_MODE { get; set; }
|
||||
internal static decimal AYANOVA_SERVER_TEST_MODE_TZ_OFFSET { get; set; }
|
||||
internal static string AYANOVA_SERVER_TEST_MODE_SEEDLEVEL { get; set; }
|
||||
|
||||
//CONTENTROOTPATH
|
||||
internal static string AYANOVA_CONTENT_ROOT_PATH { get; set; } //Note: set in startup.cs, not in program.cs as it requires startup IHostingEnvironment
|
||||
@@ -79,6 +83,14 @@ namespace AyaNova.Util
|
||||
|
||||
#region SERVER BASICS
|
||||
|
||||
//TEST MODE?
|
||||
bTemp = config.GetValue<bool?>("AYANOVA_SERVER_TEST_MODE");
|
||||
AYANOVA_SERVER_TEST_MODE = (null == bTemp) ? false : (bool)bTemp;
|
||||
AYANOVA_SERVER_TEST_MODE_SEEDLEVEL = config.GetValue<string>("AYANOVA_SERVER_TEST_MODE_SEEDLEVEL");
|
||||
AYANOVA_SERVER_TEST_MODE_SEEDLEVEL = string.IsNullOrWhiteSpace(AYANOVA_SERVER_TEST_MODE_SEEDLEVEL) ? "small" : AYANOVA_SERVER_TEST_MODE_SEEDLEVEL;
|
||||
decimal? dTemp = config.GetValue<decimal?>("AYANOVA_SERVER_TEST_MODE_TZ_OFFSET");
|
||||
AYANOVA_SERVER_TEST_MODE_TZ_OFFSET = (null == dTemp) ? 0 : (decimal)dTemp;
|
||||
|
||||
//LANGUAGE
|
||||
//TranslationBiz will validate this later at boot pfc and ensure a sane default is set (English)
|
||||
AYANOVA_DEFAULT_TRANSLATION = config.GetValue<string>("AYANOVA_DEFAULT_TRANSLATION");
|
||||
|
||||
Reference in New Issue
Block a user