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