Addition of global business settings for static server use (equivalent of v7 Global object)

This commit is contained in:
2020-03-24 23:41:13 +00:00
parent 942a43da6c
commit fa1e65935e
6 changed files with 82 additions and 5 deletions

View File

@@ -22,8 +22,8 @@ namespace AyaNova.Util
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
private const int DESIRED_SCHEMA_LEVEL = 10;
internal const long EXPECTED_COLUMN_COUNT = 100;
internal const long EXPECTED_INDEX_COUNT = 27;
internal const long EXPECTED_COLUMN_COUNT = 102;
internal const long EXPECTED_INDEX_COUNT = 28;
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
@@ -138,6 +138,10 @@ namespace AyaNova.Util
{
LogUpdateMessage(log);
//create global biz settings table
await ExecQueryAsync("CREATE TABLE aglobalbizsettings (id integer NOT NULL PRIMARY KEY, " +
"searchcasesensitiveonly bool default false)");
//create aevent biz event log table
await ExecQueryAsync("CREATE TABLE aevent (id BIGSERIAL PRIMARY KEY, created timestamp not null, userid bigint not null," +
"ayid bigint not null, aytype integer not null, ayevent integer not null, textra varchar(255))");

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Extensions.Configuration;

View File

@@ -0,0 +1,47 @@
using System.Collections.Generic;
using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using AyaNova.Models;
namespace AyaNova.Util
{
/// <summary>
/// Contains static mirror copy in memory of global settings values that are set from DB during boot
/// and accessible to Biz admin user (equivalent of v7's global object)
/// used by many areas of the biz logic and processing too often to fetch on every request
/// set at boot and on any update to the db global biz settings record
/// </summary>
internal static class ServerGlobalBizSettings
{
internal static bool SearchCaseSensitiveOnly { get; set; }
/// <summary>
/// Populate and / or create the settings
/// </summary>
internal static void Initialize(GlobalBizSettings global, AyContext ct = null)
{
if (global == null)
{
//fetch or create as not provided (meaning this was called from Startup.cs)
global = ct.GlobalBizSettings.FirstOrDefault(m => m.Id == 1);
if (global == null)
{
global = new GlobalBizSettings();
ct.GlobalBizSettings.Add(global);
ct.SaveChanges();
}
}
SearchCaseSensitiveOnly = global.SearchCaseSensitiveOnly;
}
}//eoc
}//eons