public ADRawEntry FindByAdObjectIdGuidOrSmtpAddressCache(Guid adObjectIdGuid, string[] smtpAddressCache, IEnumerable <PropertyDefinition> adProperties)
        {
            ArgumentValidator.ThrowIfEmpty("adObjectIdGuid", adObjectIdGuid);
            ArgumentValidator.ThrowIfNull("adProperties", adProperties);
            if (this.recipientSession == null)
            {
                DirectoryPersonSearcher.Tracer.TraceError(0L, "No recipient session available to perform search");
                return(null);
            }
            ADObjectId entryId    = new ADObjectId(adObjectIdGuid);
            ADRawEntry adrawEntry = this.recipientSession.ReadADRawEntry(entryId, adProperties);

            if (adrawEntry != null)
            {
                DirectoryPersonSearcher.Tracer.TraceDebug <Guid>(0L, "Found AD entry for AD Object Id Guid:{0}.", adObjectIdGuid);
                return(adrawEntry);
            }
            DirectoryPersonSearcher.Tracer.TraceDebug <Guid>(0L, "Nothing found for AD Object Id:{0}, trying with smtp address cache.", adObjectIdGuid);
            if (smtpAddressCache == null || smtpAddressCache.Length == 0)
            {
                DirectoryPersonSearcher.Tracer.TraceDebug <Guid>(0L, "Nothing in SMTP Address Cache to fallback to in order to find AD Object with Id: {0}.", adObjectIdGuid);
                return(null);
            }
            QueryFilter filterForFindByEmailAddress = DirectoryPersonSearcher.GetFilterForFindByEmailAddress(string.Empty, smtpAddressCache);

            ADRawEntry[] array = DirectoryPersonSearcher.Find(this.recipientSession, filterForFindByEmailAddress, 1, adProperties);
            if (array == null || array.Length == 0)
            {
                DirectoryPersonSearcher.Tracer.TraceDebug(0L, "Found no matching recipient in AD for the smtp address cache.");
                return(null);
            }
            return(array[0]);
        }
 private static ADRawEntry TryFind(IRecipientSession recipientSession, QueryFilter filter)
 {
     ADRawEntry[] array = null;
     try
     {
         array = DirectoryPersonSearcher.Find(recipientSession, filter, 2, ContactInfoForLinkingFromDirectory.RequiredADProperties);
     }
     catch (ADTransientException arg)
     {
         DirectoryPersonSearcher.Tracer.TraceError <ADTransientException>(0L, "Unable to find recipient in AD due exception ", arg);
         return(null);
     }
     if (array == null || array.Length == 0)
     {
         DirectoryPersonSearcher.Tracer.TraceDebug(0L, "Found no matching recipient in AD");
         return(null);
     }
     if (array.Length > 1)
     {
         DirectoryPersonSearcher.Tracer.TraceDebug(0L, "Found more than one matching recipient in AD");
         return(null);
     }
     return(array[0]);
 }