From ae7d863808c6c00999d20408beeda3731509c40c Mon Sep 17 00:00:00 2001 From: vman Date: Fri, 18 Nov 2022 16:01:38 -0500 Subject: Namespace changes and dynamic user lib loading --- .../UserLoading.cs | 83 ---------------------- .../VNLib.Plugins.Extensions.Loading.Users.csproj | 24 ------- 2 files changed, 107 deletions(-) delete mode 100644 VNLib.Plugins.Extensions.Loading.Users/UserLoading.cs delete mode 100644 VNLib.Plugins.Extensions.Loading.Users/VNLib.Plugins.Extensions.Loading.Users.csproj (limited to 'VNLib.Plugins.Extensions.Loading.Users') diff --git a/VNLib.Plugins.Extensions.Loading.Users/UserLoading.cs b/VNLib.Plugins.Extensions.Loading.Users/UserLoading.cs deleted file mode 100644 index 40e0b03..0000000 --- a/VNLib.Plugins.Extensions.Loading.Users/UserLoading.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System.Text.Json; -using System.Runtime.CompilerServices; - -using VNLib.Utils.Logging; -using VNLib.Utils.Extensions; - -using VNLib.Plugins.Essentials.Users; -using VNLib.Plugins.Extensions.Loading.Sql; - -namespace VNLib.Plugins.Extensions.Loading.Users -{ - /// - /// Contains extension methods for plugins to load the "users" system - /// - public static class UserLoading - { - public const string USER_TABLE_KEY = "user_table"; - public const string USER_CUSTOM_ASSEMBLY = "user_custom_asm"; - - private static readonly ConditionalWeakTable> UsersTable = new(); - - /// - /// Gets or loads the plugin's ambient , with the specified user-table name, - /// or the default table name - /// - /// - /// The ambient for the current plugin - /// - /// - public static IUserManager GetUserManager(this PluginBase plugin) - { - plugin.ThrowIfUnloaded(); - //Get stored or load - return UsersTable.GetValue(plugin, LoadUsers).Value; - } - - private static Lazy LoadUsers(PluginBase pbase) - { - //lazy callack - IUserManager LoadManager() - { - IUserManager man; - - //Try to load a custom user assembly for exporting IUserManager - string? customAsm = pbase.PluginConfig.GetPropString(USER_CUSTOM_ASSEMBLY); - //See if host config defined the path - customAsm ??= pbase.HostConfig.GetPropString(USER_CUSTOM_ASSEMBLY); - - if (!string.IsNullOrWhiteSpace(customAsm)) - { - //Try to load a custom assembly - AssemblyLoader loader = pbase.LoadAssembly(customAsm); - try - { - //Return the loaded instance (may raise exception) - man = loader.Resource; - } - catch - { - loader.Dispose(); - throw; - } - pbase.Log.Verbose("Loaded custom user managment assembly"); - } - else - { - //Default table name to - string? userTableName = "Users"; - //Try to get the user-table element from plugin config - if (pbase.PluginConfig.TryGetProperty(USER_TABLE_KEY, out JsonElement userEl)) - { - userTableName = userEl.GetString(); - } - _ = userTableName ?? throw new KeyNotFoundException($"Missing required key '{USER_TABLE_KEY}' in config"); - //Load user-manager - man = new UserManager(pbase.GetConnectionFactory(), userTableName); - } - return man; - } - return new Lazy(LoadManager, LazyThreadSafetyMode.PublicationOnly); - } - } -} \ No newline at end of file diff --git a/VNLib.Plugins.Extensions.Loading.Users/VNLib.Plugins.Extensions.Loading.Users.csproj b/VNLib.Plugins.Extensions.Loading.Users/VNLib.Plugins.Extensions.Loading.Users.csproj deleted file mode 100644 index f3e58c6..0000000 --- a/VNLib.Plugins.Extensions.Loading.Users/VNLib.Plugins.Extensions.Loading.Users.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - net6.0 - enable - enable - x64 - 1.0.0.1 - Vaughn Nugent - Copyright © 2022 Vaughn Nugent - https://www.vaughnnugent.com/resources - True - AnyCPU;x64 - - - - - - - - - - - -- cgit