2013-09-25 43 views
0

我正在使用自定義的UserPrincipalEx-class,因爲我想查詢Active Directory以獲取自定義屬性「costCenter」。自定義的UserPrincipalEx-Class因此添加了一個DirectoryProperty(「costCenter」)。基本和長期運行(3分鐘)的版本是這樣的:查詢具有自定義屬性的所有用戶的Active Directory

// create domain context 
PrincipalContext context = new PrincipalContext(ContextType.Domain, "myDomainController"); 

// define the query-by-example principal 
UserPrincipal qbeUser = new UserPrincipal(context); 

// create the principal searcher  
PrincipalSearcher searcher = new PrincipalSearcher(qbeUser); 

// find all matches 
foreach (var hit in searcher.FindAll()) 
{ 
    //do incredible stuff here 
} 

現在,使用自定義類「UserPrincipalEx」,即擴展自定義屬性「costCenter」:

UserPrincipalEx qbeUser = new UserPrincipalEx(context); 
qbeUser.costCenter = "123"; 

品牌查詢執行速度幾乎和光一樣快。但我真正需要的是查詢所有隻有具有成本中心的用戶(並非全部這樣做)。

所以我的問題是:如何使用擴展的「查詢範例」主體來搜索只有自定義屬性的主體?

回答

0

我回復到爲了加快整件事使用

Parallel.ForEach 

。 ForEach-Loop在IEnumerable上運行,並使用我感興趣的自定義屬性的所有值,使用其中一個值修飾UserPrincipalEx-屬性並將結果添加到列表中。

不是我真正在找的東西,而是有效的:從3分鐘到15秒。

相關問題