/// <summary> /// Converts a SearchResult returned from a query to the active directory store into /// an ActiveDirectoryContact including the setting of the Manager & Manages properties /// when the withManagerAndManages parameter is set to true. /// </summary> /// <param name="result">Object returned from query to active directory store.</param> /// <param name="withManagerAndManages">Flag indicating whether to set Manager & Manages property.</param> /// <returns>Contact with properties populated.</returns> private ActiveDirectoryContact ConvertSearchResultToContact(SearchResult result, bool withManagerAndManages) { if (result == null) return null; var contact = new ActiveDirectoryContact(); contact.DistinguishedName = GetProperty(result, "distinguishedName"); contact.FirstName = GetProperty(result, "givenName"); contact.LastName = GetProperty(result, "sn"); contact.Username = GetProperty(result, "cn"); contact.Telephone = GetProperty(result, "telephoneNumber"); contact.Email = GetProperty(result, "mail"); contact.Company = GetProperty(result, "company"); contact.DisplayName = GetProperty(result, "displayName"); contact.Office = GetProperty(result, "physicalDeliveryOfficeName"); contact.Mobile = GetProperty(result, "mobile"); contact.JobRole = GetProperty(result, "title"); contact.Fax = GetProperty(result, "facsimileTelephoneNumber"); contact.HomePhoneNumber = GetProperty(result, "ipPhone"); contact.IpPhoneNumber = GetProperty(result, "facsimileTelephoneNumber"); contact.Pager = GetProperty(result, "pager"); if (withManagerAndManages) return AddManagerHeirachies(contact, result); return contact; }
/// <summary> /// Adds the ActiveDirectoryContact that represents the Manager and a list of /// ActiveDirectoryContacts that represent the contacts that the contact /// inputted manages. /// </summary> /// <param name="contact">Contact that should have its Manages and Manager properties /// fulfilled.</param> /// <param name="result">Object returned from a query to the active directory store.</param> /// <returns>Contact with values set of Manages and Manager.</returns> private ActiveDirectoryContact AddManagerHeirachies(ActiveDirectoryContact contact, SearchResult result) { if (contact == null) return null; var managerDn = GetProperty(result, "manager"); var managesDns = GetListProperty(result, "directReports"); if (!string.IsNullOrWhiteSpace(managerDn)) contact.Manager = GetContactByDistinguishedName(managerDn, false); if (managesDns != null && managesDns.Count > 0) { contact.Manages = new List<ActiveDirectoryContact>(); foreach (var dn in managesDns) contact.Manages.Add(GetContactByDistinguishedName(dn, false)); } return contact; }