using System; using System.Linq; using AyaNova.Models; namespace AyaNova.Util { /// /// 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 /// internal static class ServerGlobalOpsSettings { internal static DateTime BackupTime { get; set; } internal static DateTime LastBackup { get; set; } internal static int BackupSetsToKeep { get; set; } internal static bool BackupAttachments { get; set; } /// /// Populate and / or create the settings /// internal static void Initialize(GlobalOpsSettings global, AyContext ct = null) { if (global == null) { //fetch or create as not provided (meaning this was called from Startup.cs) global = ct.GlobalOpsSettings.FirstOrDefault(z => z.Id == 1); if (global == null) { global = new GlobalOpsSettings(); ct.GlobalOpsSettings.Add(global); ct.SaveChanges(); } } //We have the object, now copy the static values here BackupAttachments = global.BackupAttachments; BackupSetsToKeep = global.BackupSetsToKeep; BackupTime = global.BackupTime; LastBackup = global.LastBackup; } }//eoc }//eons