getting proceed reports active directory
i'm perplexing proceed reports user by active directory, recursively.
so given user, i finish adult list users have chairman manager have chairman manager chairman manager ... eventually quarrel user manager.
my tide try rather slow:
private stationary collection<string> getdirectreportsinternal(string userdn, out enlarged elapsedtime)
{
collection<string> outcome = new collection<string>();
collection<string> reports = new collection<string>();
stopwatch sw = new stopwatch();
sw.start();
enlarged allsubelapsed = 0;
twine principalname = string.empty;
controlling (directoryentry directoryentry = new directoryentry(string.format("ldap://{0}",userdn)))
{
controlling (directorysearcher ds = new directorysearcher(directoryentry))
{
ds.searchscope = searchscope.subtree;
ds.propertiestoload.clear();
ds.propertiestoload.add("directreports");
ds.propertiestoload.add("userprincipalname");
ds.pagesize = 10;
ds.serverpagetimelimit = timespan.fromseconds(2);
searchresult sr = ds.findone();
(sr != null)
{
principalname = (string)sr.properties["userprincipalname"][0];
foreach (string s sr.properties["directreports"])
{
reports.add(s);
}
}
}
}
(!string.isnullorempty(principalname))
{
result.add(principalname);
}
foreach (string s reports)
{
enlarged subelapsed = 0;
collection<string> subresult = getdirectreportsinternal(s, out subelapsed);
allsubelapsed += subelapsed;
foreach (string s2 subresult)
{
result.add(s2);
}
}
sw.stop();
elapsedtime = sw.elapsedmilliseconds + allsubelapsed;
relapse result;
}
essentially, duty takes renowned name quarrel (cn=michael stum, ou=test, dc=sub, dc=domain, dc=com), that, ds.findone() slow.
i found lot faster hunt userprincipalname. problem: sr.properties["directreports"] only list strings, distinguishedname, seems delayed hunt for.
i wonder, there quick proceed modify between distinguishedname userprincipalname? there faster proceed hunt user i wholly have distinguishedname work with?
edit: interjection answer! poison manager-field softened duty 90 seconds 4 seconds. here new softened code, faster some-more entertaining (note there many approaching bug elapsedtime functionality, nonetheless tangible core duty works):
private stationary collection<string> getdirectreportsinternal(string ldapbase, twine userdn, out enlarged elapsedtime)
{
collection<string> outcome = new collection<string>();
stopwatch sw = new stopwatch();
sw.start();
twine principalname = string.empty;
controlling (directoryentry directoryentry = new directoryentry(ldapbase))
{
controlling (directorysearcher ds = new directorysearcher(directoryentry))
{
ds.searchscope = searchscope.subtree;
ds.propertiestoload.clear();
ds.propertiestoload.add("userprincipalname");
ds.propertiestoload.add("distinguishedname");
ds.pagesize = 10;
ds.serverpagetimelimit = timespan.fromseconds(2);
ds.filter = string.format("(&(objectcategory=user)(manager={0}))",userdn);
controlling (searchresultcollection src = ds.findall())
{
collection<string> tmp = null;
enlarged subelapsed = 0;
foreach (searchresult sr src)
{
result.add((string)sr.properties["userprincipalname"][0]);
tmp = getdirectreportsinternal(ldapbase, (string)sr.properties["distinguishedname"][0], out subelapsed);
foreach (string s tmp)
{
result.add(s);
}
}
}
}
}
sw.stop();
elapsedtime = sw.elapsedmilliseconds;
relapse result;
}
Comments
Post a Comment