/// <summary> /// synchronize root OU, return both users and sub-OUs /// </summary> /// <param name="entry"></param> private Dictionary <string, AdNode> SyncRootOU(DirectoryEntry entry) { Dictionary <string, AdNode> result = new Dictionary <string, AdNode>(); // key = id AdNode root = new AdNode(entry, ""); if (root.Type == AdType.OU) { result[root.Id] = root; SyncSubOU(result, entry, root.Id); } return(result); }
/// <summary> /// synchronize sub OU and all its users recursively /// </summary> /// <param name="entry"></param> /// <param name="parentId"></param> private void SyncSubOU(Dictionary <string, AdNode> result, DirectoryEntry entry, string parentId) { foreach (DirectoryEntry subEntry in entry.Children) { AdNode adn = new AdNode(subEntry, parentId); if (adn.Type != AdType.OTHER) { // add without duplication if (!result.ContainsKey(adn.Id)) { result[adn.Id] = adn; } if (adn.Type == AdType.OU) { SyncSubOU(result, subEntry, adn.Id); } } } }