From 2d2b13cf00b56f7b2dad5addaf84718b20102982 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 6 Sep 2021 23:09:12 +0000 Subject: [PATCH] --- .vscode/launch.json | 2 +- server/AyaNova/biz/GlobalBizSettingsBiz.cs | 3 +-- server/AyaNova/util/DbUtil.cs | 27 +++++++------------ .../AyaNova/util/ServerGlobalBizSettings.cs | 10 ++++--- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index b77f3b95..fcc80a75 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -53,7 +53,7 @@ "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", "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_TZ_OFFSET": "-7", "AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\" diff --git a/server/AyaNova/biz/GlobalBizSettingsBiz.cs b/server/AyaNova/biz/GlobalBizSettingsBiz.cs index d8df839c..d7074293 100644 --- a/server/AyaNova/biz/GlobalBizSettingsBiz.cs +++ b/server/AyaNova/biz/GlobalBizSettingsBiz.cs @@ -84,8 +84,7 @@ namespace AyaNova.Biz } //Log modification and save context await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, AyaEvent.Modified), ct); - //Update the static copy for the server - ServerGlobalBizSettings.Initialize(putObject); + return putObject; } diff --git a/server/AyaNova/util/DbUtil.cs b/server/AyaNova/util/DbUtil.cs index cb59b0aa..7a428783 100644 --- a/server/AyaNova/util/DbUtil.cs +++ b/server/AyaNova/util/DbUtil.cs @@ -210,7 +210,7 @@ namespace AyaNova.Util // Create the database desired using (var cmd = new Npgsql.NpgsqlCommand()) { - cmd.Connection = cnCreate; + cmd.Connection = cnCreate; cmd.CommandText = "CREATE DATABASE \"" + _dbName + "\" WITH ENCODING \"UTF8\" TEMPLATE=template0;"; cmd.ExecuteNonQuery(); _log.LogInformation("Database \"{0}\" created successfully!", _dbName); @@ -261,7 +261,7 @@ namespace AyaNova.Util cmd.Connection = conn; cmd.CommandText = "DROP DATABASE \"" + _dbName + "\";"; await cmd.ExecuteNonQueryAsync(); - cmd.Connection = conn; + cmd.Connection = conn; cmd.CommandText = "CREATE DATABASE \"" + _dbName + "\" WITH ENCODING \"UTF8\" TEMPLATE=template0;"; await cmd.ExecuteNonQueryAsync(); _log.LogDebug("Database created"); @@ -277,11 +277,10 @@ namespace AyaNova.Util ///////////////////////////////////////////////////////// // Erase all user entered data from the db // This is called by seeder for trial seeding purposes - // and by v8 migrate v7 exporter + // and by v8 migrate v7 exporter and by license controller when erasing db internal static async Task EmptyBizDataFromDatabaseForSeedingOrImportingAsync(ILogger _log) { - _log.LogInformation("Erasing Database \"{0}\"", _dbName); AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = (AyaNova.Api.ControllerHelpers.ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(AyaNova.Api.ControllerHelpers.ApiServerState)); @@ -325,8 +324,12 @@ namespace AyaNova.Util cmd.CommandText = "update aglobalbizsettings set taxpartpurchaseid=null,taxpartsaleid=null,taxratesaleid=null;"; await cmd.ExecuteNonQueryAsync(); + //reset global settings cache taxes + ServerGlobalBizSettings.Cache.TaxPartPurchaseId = null; + ServerGlobalBizSettings.Cache.TaxPartSaleId = null; + ServerGlobalBizSettings.Cache.TaxRateSaleId = null; - cmd.CommandText = "update aworkorder set fromcsrid=null;"; + cmd.CommandText = "update aworkorder set fromcsrid=null;"; await cmd.ExecuteNonQueryAsync(); } @@ -399,7 +402,7 @@ namespace AyaNova.Util await EraseTableAsync("apm", conn); //--- - await EraseTableAsync("afileattachment", conn); + await EraseTableAsync("afileattachment", conn); await EraseTableAsync("awidget", conn); await EraseTableAsync("aevent", conn); await EraseTableAsync("adatalistsavedfilter", conn); @@ -412,18 +415,11 @@ namespace AyaNova.Util await EraseTableAsync("apurchaseorderitem", conn); await EraseTableAsync("apurchaseorder", conn); - - - await EraseTableAsync("apartassemblyitem", conn); await EraseTableAsync("apartassembly", conn); await EraseTableAsync("apartinventory", conn); await EraseTableAsync("apart", conn); - - - - await EraseTableAsync("aloanunit", conn); await EraseTableAsync("aunitmodel", conn); await EraseTableAsync("avendor", conn); @@ -457,7 +453,7 @@ namespace AyaNova.Util await EraseTableAsync("aworkorderitemstatus", conn); await EraseTableAsync("aworkorderitempriority", conn); await EraseTableAsync("ataskgroup", conn);//items cascade - + //after cleanup @@ -489,9 +485,6 @@ namespace AyaNova.Util cmd.CommandText = "ALTER SEQUENCE apm_serial_seq RESTART WITH 1;"; await cmd.ExecuteNonQueryAsync(); - - - } await conn.CloseAsync(); diff --git a/server/AyaNova/util/ServerGlobalBizSettings.cs b/server/AyaNova/util/ServerGlobalBizSettings.cs index f2e7b350..04ba1c72 100644 --- a/server/AyaNova/util/ServerGlobalBizSettings.cs +++ b/server/AyaNova/util/ServerGlobalBizSettings.cs @@ -12,14 +12,16 @@ namespace AyaNova.Util /// internal static class ServerGlobalBizSettings { - internal static GlobalBizSettings Cache {get;set;} + internal static GlobalBizSettings Cache { get; set; } /// /// Populate and / or create the settings /// - internal static void Initialize(GlobalBizSettings global, AyContext ct = null) + internal static void Initialize(GlobalBizSettings global, AyContext ct) { if (global == null) - { + { + + //fetch or create as not provided (meaning this was called from Startup.cs) global = ct.GlobalBizSettings.FirstOrDefault(z => z.Id == 1); if (global == null) @@ -29,7 +31,7 @@ namespace AyaNova.Util ct.SaveChanges(); } } - Cache = global; + Cache = global; } }//eoc }//eons \ No newline at end of file