Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings_Engine: Ensure settings are loaded when queried #3151

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
# BHoM_Engine REPO CODEOWNERS

# default global
* @al-fisher @rwemay @adecler
* @al-fisher @rwemay @adecler @FraserGreenroyd


# project owners

#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
/Reflection_Engine @adecler @FraserGreenroyd @al-fisher
/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
/Structure_Engine @IsakNaslundBh @rwemay
/Versioning_Engine @adecler @FraserGreenroyd @IsakNaslundBh
9 changes: 8 additions & 1 deletion Settings_Engine/Compute/LoadSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Linq;

namespace BH.Engine.Settings
{
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.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);

foreach (var file in settingsFiles)
Expand Down Expand Up @@ -69,6 +74,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.Add(settingsFolder);
}
}
}
1 change: 1 addition & 0 deletions Settings_Engine/Objects/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal static class Global
/***************************************************/
internal static ConcurrentDictionary<Type, ISettings> BHoMSettings { get; set; } = new ConcurrentDictionary<Type, ISettings>();
internal static ConcurrentDictionary<Type, string> BHoMSettingsFilePaths { get; set; } = new ConcurrentDictionary<Type, string>(); //Store where settings came from for saving on shut down
internal static ConcurrentBag<string> BHoMSettingsLoaded { get; set; } = new ConcurrentBag<string>(); //Store whether a file path has been loaded or not
}
}

Expand Down
2 changes: 2 additions & 0 deletions Settings_Engine/Query/GetSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down