Exemple #1
0
        internal Address[] GetAddresses(DirectAddressCollection addresses)
        {
            Debug.Assert(_settings.HasAddressManager);

            List <Address> managedAddresses;

            string[] emailAddresses = addresses
                                      .Select(address => address.Address)
                                      .ToArray();

            if (_addressCache != null)
            {
                managedAddresses = _addressCache.Get(emailAddresses);

                if (managedAddresses != null && managedAddresses.Count(d => d != null) == addresses.Count())
                {
                    managedAddresses.RemoveAll(d => d == null);
                    return(managedAddresses.ToArray());
                }
            }

            IAddressManager client = CreateAddressManagerClient();

            using (client as IDisposable)
            {
                Address[] addressesFound;

                if (_enabledDomainSearch)
                {
                    addressesFound = client.GetAddressesOrDomain(emailAddresses, EntityStatus.Enabled);
                }
                else
                {
                    addressesFound = client.GetAddresses(emailAddresses, EntityStatus.Enabled);
                }

                managedAddresses = addressesFound.ToList();
            }

            if (_addressCache != null)
            {
                _addressCache.Put(managedAddresses);
            }

            return(managedAddresses.ToArray());
        }