refactor(DirectorySearchOptions): Machen Sie ServerName und Root erforderlich und UserCacheExpirationDays nullable double.
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user