refactor(DirectorySearchOptions): Machen Sie ServerName und Root erforderlich und UserCacheExpirationDays nullable double.
This commit is contained in:
parent
725b186db6
commit
63ab47a288
@ -14,9 +14,9 @@
|
|||||||
<PackageIcon>core_icon.png</PackageIcon>
|
<PackageIcon>core_icon.png</PackageIcon>
|
||||||
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
||||||
<PackageTags>digital data core application clean architecture</PackageTags>
|
<PackageTags>digital data core application clean architecture</PackageTags>
|
||||||
<Version>3.0.1</Version>
|
<Version>3.1.0</Version>
|
||||||
<AssemblyVersion>3.0.1</AssemblyVersion>
|
<AssemblyVersion>3.1.0</AssemblyVersion>
|
||||||
<FileVersion>3.0.1</FileVersion>
|
<FileVersion>3.1.0</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -5,21 +5,24 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DirectorySearchOptions
|
public class DirectorySearchOptions
|
||||||
{
|
{
|
||||||
|
//TODO: Merge with Root and rename as path
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or initializes the name of the server to be used in the directory search.
|
/// Gets or initializes the name of the server to be used in the directory search.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? ServerName { get; init; }
|
public required string ServerName { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or initializes the root directory path for the search.
|
/// Gets or initializes the root directory path for the search.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Root { get; init; }
|
public required string Root { get; init; }
|
||||||
|
|
||||||
|
//TODO: Convert to timespan
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or initializes the number of days before the user cache expires.
|
/// Gets or initializes the number of days before the user cache expires.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int UserCacheExpirationDays { get; init; }
|
public double? UserCacheExpirationDays { get; init; }
|
||||||
|
|
||||||
|
//TODO: Rename as CustomSearchFilters
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or initializes the custom search filters to be applied during directory searches.
|
/// Gets or initializes the custom search filters to be applied during directory searches.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -15,7 +15,7 @@ namespace DigitalData.Core.Application
|
|||||||
public string ServerName { get; }
|
public string ServerName { get; }
|
||||||
public string Root { get; }
|
public string Root { get; }
|
||||||
public string SearchRootPath { get; }
|
public string SearchRootPath { get; }
|
||||||
private readonly DateTimeOffset _userCacheExpiration;
|
private readonly DateTimeOffset? _userCacheExpiration;
|
||||||
public Dictionary<string, string> CustomSearchFilters { get; }
|
public Dictionary<string, string> CustomSearchFilters { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -32,19 +32,16 @@ namespace DigitalData.Core.Application
|
|||||||
|
|
||||||
var dirSearchOptions = options.Value;
|
var dirSearchOptions = options.Value;
|
||||||
|
|
||||||
ServerName = dirSearchOptions.ServerName ?? throw new InvalidOperationException("The server name for directory search is not configured. Please specify the 'DirectorySearch:ServerName' in the configuration.");
|
ServerName = dirSearchOptions.ServerName;
|
||||||
|
|
||||||
Root = dirSearchOptions.Root ?? throw new InvalidOperationException("The root for directory search is not configured. Please specify the 'DirectorySearch:Root' in the configuration.");
|
Root = dirSearchOptions.Root;
|
||||||
|
|
||||||
SearchRootPath = $"LDAP://{ServerName}/{Root}";
|
SearchRootPath = $"LDAP://{ServerName}/{Root}";
|
||||||
|
|
||||||
CustomSearchFilters = dirSearchOptions.CustomSearchFilters;
|
CustomSearchFilters = dirSearchOptions.CustomSearchFilters;
|
||||||
|
|
||||||
var dayCounts = dirSearchOptions.UserCacheExpirationDays;
|
if(dirSearchOptions.UserCacheExpirationDays is double expirationDays)
|
||||||
if (dayCounts == default)
|
_userCacheExpiration = DateTimeOffset.Now.Date.AddDays(expirationDays);
|
||||||
_userCacheExpiration = default;
|
|
||||||
else
|
|
||||||
_userCacheExpiration = DateTimeOffset.Now.Date.AddDays(dayCounts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -123,13 +120,12 @@ namespace DigitalData.Core.Application
|
|||||||
/// <param name="dirEntryPassword">The directory entry password.</param>
|
/// <param name="dirEntryPassword">The directory entry password.</param>
|
||||||
public void SetSearchRootCache(string dirEntryUsername, string dirEntryPassword)
|
public void SetSearchRootCache(string dirEntryUsername, string dirEntryPassword)
|
||||||
{
|
{
|
||||||
if (_userCacheExpiration == default)
|
if (_userCacheExpiration is DateTimeOffset cacheExpiration)
|
||||||
_memoryCache.Set(key: dirEntryUsername, new DirectoryEntry(path: SearchRootPath, username: dirEntryUsername, password: dirEntryPassword));
|
_memoryCache.Set(key: dirEntryUsername, new DirectoryEntry(path: SearchRootPath, username: dirEntryUsername, password: dirEntryPassword), absoluteExpiration: cacheExpiration);
|
||||||
else
|
else
|
||||||
_memoryCache.Set(key: dirEntryUsername, new DirectoryEntry(path: SearchRootPath, username: dirEntryUsername, password: dirEntryPassword), absoluteExpiration: _userCacheExpiration);
|
_memoryCache.Set(key: dirEntryUsername, new DirectoryEntry(path: SearchRootPath, username: dirEntryUsername, password: dirEntryPassword));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the search root from the cache.
|
/// Gets the search root from the cache.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user