diff options
Diffstat (limited to 'VNLib.Plugins.Extensions.Loading.Users')
-rw-r--r-- | VNLib.Plugins.Extensions.Loading.Users/UserLoading.cs | 83 | ||||
-rw-r--r-- | VNLib.Plugins.Extensions.Loading.Users/VNLib.Plugins.Extensions.Loading.Users.csproj | 24 |
2 files changed, 0 insertions, 107 deletions
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 -{ - /// <summary> - /// Contains extension methods for plugins to load the "users" system - /// </summary> - 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<PluginBase, Lazy<IUserManager>> UsersTable = new(); - - /// <summary> - /// Gets or loads the plugin's ambient <see cref="IUserManager"/>, with the specified user-table name, - /// or the default table name - /// </summary> - /// <param name="plugin"></param> - /// <returns>The ambient <see cref="IUserManager"/> for the current plugin</returns> - /// <exception cref="KeyNotFoundException"></exception> - /// <exception cref="ObjectDisposedException"></exception> - public static IUserManager GetUserManager(this PluginBase plugin) - { - plugin.ThrowIfUnloaded(); - //Get stored or load - return UsersTable.GetValue(plugin, LoadUsers).Value; - } - - private static Lazy<IUserManager> 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<IUserManager> loader = pbase.LoadAssembly<IUserManager>(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<IUserManager>(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 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFramework>net6.0</TargetFramework> - <ImplicitUsings>enable</ImplicitUsings> - <Nullable>enable</Nullable> - <PlatformTarget>x64</PlatformTarget> - <Version>1.0.0.1</Version> - <Authors>Vaughn Nugent</Authors> - <Copyright>Copyright © 2022 Vaughn Nugent</Copyright> - <PackageProjectUrl>https://www.vaughnnugent.com/resources</PackageProjectUrl> - <GenerateDocumentationFile>True</GenerateDocumentationFile> - <Platforms>AnyCPU;x64</Platforms> - </PropertyGroup> - - <ItemGroup> - <ProjectReference Include="..\..\..\VNLib\Essentials\VNLib.Plugins.Essentials.csproj" /> - <ProjectReference Include="..\..\Essentials\VNLib.Plugins.Essentials.Users\VNLib.Plugins.Essentials.Users.csproj" /> - <ProjectReference Include="..\..\PluginBase\VNLib.Plugins.PluginBase.csproj" /> - <ProjectReference Include="..\VNLib.Plugins.Extensions.Loading.Sql\VNLib.Plugins.Extensions.Loading.Sql.csproj" /> - <ProjectReference Include="..\VNLib.Plugins.Extensions.Loading\VNLib.Plugins.Extensions.Loading.csproj" /> - </ItemGroup> - -</Project> |