From 0341fb3f66f8cc4f4d7ecc395ef8a80b4413029e Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Mon, 21 Aug 2023 16:23:34 +0100 Subject: [PATCH 1/3] Update settings engine to ensure settings are loaded on first query if they aren't loaded by another manner --- Settings_Engine/Compute/LoadSettings.cs | 8 +++++++- Settings_Engine/Objects/Global.cs | 1 + Settings_Engine/Query/GetSettings.cs | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Settings_Engine/Compute/LoadSettings.cs b/Settings_Engine/Compute/LoadSettings.cs index a47ab7de8..d735d1a77 100644 --- a/Settings_Engine/Compute/LoadSettings.cs +++ b/Settings_Engine/Compute/LoadSettings.cs @@ -35,11 +35,15 @@ public static partial class Compute { [Description("Load all the JSON settings stored within the provided folder into memory. If no folder is provided, the default folder of %ProgramData%/BHoM/Settings is used instead. All JSON files are scraped within the directory (including subdirectories) and deserialised to ISettings objects.")] [Input("settingsFolder", "Optional input to determine where to load settings from. Defaults to %ProgramData%/BHoM/Settings if no folder is provided.")] - public static void LoadSettings(string settingsFolder = null) + [Input("forceLoad", "Optional input to determine whether settings should be loaded even if they have already been loaded. If true, and settings have previously been loaded, then settings will be reloaded from the provided folder path.")] + public static void LoadSettings(string settingsFolder = null, bool forceLoad = false) { if (string.IsNullOrEmpty(settingsFolder)) settingsFolder = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData), "BHoM", "Settings"); //Defaults to C:/ProgramData/BHoM/Settings if no folder is provided + if (Global.BHoMSettingsLoaded[settingsFolder] && !forceLoad) + return; //Settings from this folder have already been loaded, and we're not force loading them, so don't waste time reloading them + var settingsFiles = Directory.EnumerateFiles(settingsFolder, "*.json", SearchOption.AllDirectories); foreach (var file in settingsFiles) @@ -69,6 +73,8 @@ public static void LoadSettings(string settingsFolder = null) BH.Engine.Base.Compute.RecordWarning(ex, $"Cannot deserialise the contents of {file} to an ISettings object."); } } + + Global.BHoMSettingsLoaded[settingsFolder] = true; } } } diff --git a/Settings_Engine/Objects/Global.cs b/Settings_Engine/Objects/Global.cs index d753b1e9d..8465095d0 100644 --- a/Settings_Engine/Objects/Global.cs +++ b/Settings_Engine/Objects/Global.cs @@ -35,6 +35,7 @@ internal static class Global /***************************************************/ internal static ConcurrentDictionary BHoMSettings { get; set; } = new ConcurrentDictionary(); internal static ConcurrentDictionary BHoMSettingsFilePaths { get; set; } = new ConcurrentDictionary(); //Store where settings came from for saving on shut down + internal static ConcurrentDictionary BHoMSettingsLoaded { get; set; } = new ConcurrentDictionary(); //Store whether a file path has been loaded or not } } diff --git a/Settings_Engine/Query/GetSettings.cs b/Settings_Engine/Query/GetSettings.cs index cd6223f23..06aba18d8 100644 --- a/Settings_Engine/Query/GetSettings.cs +++ b/Settings_Engine/Query/GetSettings.cs @@ -37,6 +37,8 @@ public static partial class Query [Output("settings", "The requested settings if they exist in memory. If they don't exist, a default is returned instead.")] public static object GetSettings(Type type) { + Compute.LoadSettings(); //Just in case - load up the defaults + ISettings settings = null; if (!Global.BHoMSettings.TryGetValue(type, out settings)) { From 712c78eeafd0cb7bd5a7bb6c9ec8236b930e10a8 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Mon, 21 Aug 2023 16:23:44 +0100 Subject: [PATCH 2/3] Update codeowners to include engine changes --- .github/CODEOWNERS | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8ac764983..3c23037bd 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,7 +1,7 @@ # BHoM_Engine REPO CODEOWNERS # default global -* @al-fisher @rwemay @adecler +* @al-fisher @rwemay @adecler @FraserGreenroyd # project owners @@ -9,15 +9,15 @@ #NEED OWNER: /Acoustic_Engine /Analytical_Engine @al-fisher @rwemay @IsakNaslundBh @FraserGreenroyd #NEED OWNER: /Architecture_Engine -/BHoM_Engine @adecler @al-fisher -/Data_Engine @adecler @epignatelli +/BHoM_Engine @adecler @al-fisher @FraserGreenroyd +/Data_Engine @adecler @IsakNaslundBH /Diffing_Engine @alelom @al-fisher @adecler -/Environment_Engine @FraserGreenroyd @tg359 -/Geometry_Engine @pawelbaran @al-fisher @epignatelli +/Environment_Engine @FraserGreenroyd @tg359 @jamesramsden-bh +/Geometry_Engine @pawelbaran @al-fisher @IsakNaslundBH /Humans_Engine @al-fisher @rwemay /Library_Engine @adecler @IsakNaslundBh /Matter_Engine @al-fisher @IsakNaslundBh @pawelbaran -/MEP_Engine @kayleighhoude @FraserGreenroyd +/MEP_Engine @kayleighhoude @FraserGreenroyd @travispotterBH /Physical_Engine @al-fisher @rwemay @IsakNaslundBh @FraserGreenroyd /Planning_Engine @rwemay @al-fisher /Programming_Engine @adecler @FraserGreenroyd @al-fisher @@ -25,6 +25,8 @@ /Results_Engine @IsakNaslundBh @FraserGreenroyd @rwemay #NEED OWNER: /SVG_Engine /Serialiser_Engine @adecler @FraserGreenroyd +/Settings_Engine @FraserGreenroyd @adecler /Spatial_Engine @al-fisher @IsakNaslundBh @pawelbaran #NEED OWNER: /Speech_Engine -/Structure_Engine @IsakNaslundBh @rwemay \ No newline at end of file +/Structure_Engine @IsakNaslundBh @rwemay +/Versioning_Engine @adecler @FraserGreenroyd @IsakNaslundBh \ No newline at end of file From 8fbbc1f10b521ca669ac76294e58a3211c21f415 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Mon, 21 Aug 2023 17:07:54 +0100 Subject: [PATCH 3/3] Update loading check --- Settings_Engine/Compute/LoadSettings.cs | 5 +++-- Settings_Engine/Objects/Global.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Settings_Engine/Compute/LoadSettings.cs b/Settings_Engine/Compute/LoadSettings.cs index d735d1a77..5e17520f1 100644 --- a/Settings_Engine/Compute/LoadSettings.cs +++ b/Settings_Engine/Compute/LoadSettings.cs @@ -28,6 +28,7 @@ using System.ComponentModel; using System.IO; using System.Text; +using System.Linq; namespace BH.Engine.Settings { @@ -41,7 +42,7 @@ public static void LoadSettings(string settingsFolder = null, bool forceLoad = f if (string.IsNullOrEmpty(settingsFolder)) settingsFolder = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData), "BHoM", "Settings"); //Defaults to C:/ProgramData/BHoM/Settings if no folder is provided - if (Global.BHoMSettingsLoaded[settingsFolder] && !forceLoad) + if (Global.BHoMSettingsLoaded.Contains(settingsFolder) && !forceLoad) return; //Settings from this folder have already been loaded, and we're not force loading them, so don't waste time reloading them var settingsFiles = Directory.EnumerateFiles(settingsFolder, "*.json", SearchOption.AllDirectories); @@ -74,7 +75,7 @@ public static void LoadSettings(string settingsFolder = null, bool forceLoad = f } } - Global.BHoMSettingsLoaded[settingsFolder] = true; + Global.BHoMSettingsLoaded.Add(settingsFolder); } } } diff --git a/Settings_Engine/Objects/Global.cs b/Settings_Engine/Objects/Global.cs index 8465095d0..6384f7b18 100644 --- a/Settings_Engine/Objects/Global.cs +++ b/Settings_Engine/Objects/Global.cs @@ -35,7 +35,7 @@ internal static class Global /***************************************************/ internal static ConcurrentDictionary BHoMSettings { get; set; } = new ConcurrentDictionary(); internal static ConcurrentDictionary BHoMSettingsFilePaths { get; set; } = new ConcurrentDictionary(); //Store where settings came from for saving on shut down - internal static ConcurrentDictionary BHoMSettingsLoaded { get; set; } = new ConcurrentDictionary(); //Store whether a file path has been loaded or not + internal static ConcurrentBag BHoMSettingsLoaded { get; set; } = new ConcurrentBag(); //Store whether a file path has been loaded or not } }