private void LogQueryResults(
            ExchangeUserDict userCollection, string[] searchTerms, string ldapAttribute)
        {
            if (userCollection.Count != searchTerms.Length)
            {
                if (ldapAttribute == "sAMAccountName")
                {
                    foreach (string term in searchTerms)
                    {
                        if (!userCollection.ContainsKey(term.ToLower()))
                        {
                            log.InfoFormat("Unable to find Active Directory user where '{0}'='{1}'.", ldapAttribute, term);
                        }
                    }
                }
                else if (ldapAttribute == "mail")
                {
                    foreach (string email in searchTerms)
                    {
                        string login = email.Split('@')[0];

                        if (!userCollection.ContainsKey(login.ToLower()))
                        {
                            log.InfoFormat("Unable to find Active Directory user where '{0}'='{1}'.", ldapAttribute, email);
                        }
                    }
                }
                else
                {
                    log.InfoFormat(
                        "Unable to find all users in Active Directory.  [Users={0}]",
                        string.Join(";", searchTerms));
                }
            }
        }
        private ExchangeUserDict CreateExchangeUserCollection(SearchResultCollection searchResults)
        {
            ExchangeUserDict userCollection = new ExchangeUserDict();

            if (searchResults != null)
            {
                /* For each result set in the result set */
                foreach (System.DirectoryServices.SearchResult result in searchResults)
                {
                    /* Extract the property collection and create a new exchange user with it
                     * Add the new user to the result set and use the account name as the index for
                     * the dictionary collection */
                    ResultPropertyCollection property = result.Properties;
                    ExchangeUser             user     = new ExchangeUser(property);

                    if (!user.IsValid)
                    {
                        log.WarnFormat("User '{0}' is invalid and will not be synchronized.", user.CommonName);
                    }
                    else if (userCollection.ContainsKey(user.Email.ToLower()))
                    {
                        log.WarnFormat("User '{0}' was returned multiple times in the LDAP query. " +
                                       "Only the first instance was added.", user.Email);
                    }
                    else
                    {
                        userCollection.Add(user.Email.ToLower(), user);
                        log.InfoFormat("Found and added '{0}' as an ExchangeUser.", user.Email);
                    }

                    log.DebugFormat("LDAP object debug info: {0}", user);
                }
            }

            return(userCollection);
        }