1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
/// <summary>
/// Cherche une entrée dans l'annuaire et renvoie un objet construit à partir de ses informations.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="ldapFilter">Le filtre de recherche au format LDAP</param>
/// <param name="CreateObject">Méthode de construction de l'objet à retourner</param>
/// <returns>L'objet construit à partir de l'entrée d'annuaire</returns>
private T LoadObject<T>(string ldapFilter, Converter<DirectoryEntry, T> CreateObject)
{
try
{
using (DirectoryEntry myDE =
new DirectoryEntry(this.activeDirectoryPath, this.activeDirectoryUserName, this.activeDirectoryUserPassword))
{
T result = default(T);
DirectorySearcher myDS = new DirectorySearcher(myDE);
myDS.Filter = ldapFilter;
myDS.SearchScope = SearchScope.Subtree;
SearchResult searchResult = myDS.FindOne();
if (searchResult != null)
result = CreateObject(searchResult.GetDirectoryEntry());
return result;
}
}
catch (Exception ex)
{
throw new Exception(String.Format("AdAccesUsersGroups.SearchObject : {0}", ex.Message));
}
} |
Partager