private static ProxyAddressTemplate Parse(string proxyAddressTemplateString, string prefixString, string addressTemplateString)
        {
            if (prefixString == null)
            {
                throw new ArgumentNullException("prefixString");
            }
            if (addressTemplateString == null)
            {
                throw new ArgumentNullException("addressTemplateString");
            }
            ProxyAddressPrefix proxyAddressPrefix;

            if (prefixString.Length == 0 && SmtpProxyAddressTemplate.IsValidSmtpAddressTemplate(addressTemplateString))
            {
                proxyAddressPrefix = ProxyAddressPrefix.Smtp;
            }
            else
            {
                proxyAddressPrefix = ProxyAddressPrefix.GetPrefix(prefixString);
            }
            bool flag = StringComparer.Ordinal.Equals(proxyAddressPrefix.PrimaryPrefix, prefixString);
            ProxyAddressTemplate result;

            try
            {
                ProxyAddressTemplate proxyAddressTemplate = proxyAddressPrefix.GetProxyAddressTemplate(addressTemplateString, flag);
                proxyAddressTemplate.RawProxyAddressBaseString = proxyAddressTemplateString;
                result = proxyAddressTemplate;
            }
            catch (ArgumentOutOfRangeException parseException)
            {
                result = new InvalidProxyAddressTemplate(proxyAddressTemplateString, proxyAddressPrefix, addressTemplateString, flag, parseException);
            }
            return(result);
        }
Exemplo n.º 2
0
        private static ProxyAddress Parse(string proxyAddressString, string prefixString, string addressString)
        {
            if (prefixString == null)
            {
                throw new ArgumentNullException("prefixString");
            }
            if (addressString == null)
            {
                throw new ArgumentNullException("addressString");
            }
            ProxyAddressPrefix proxyAddressPrefix;

            if (prefixString.Length == 0 && SmtpAddress.IsValidSmtpAddress(addressString))
            {
                proxyAddressPrefix = ProxyAddressPrefix.Smtp;
            }
            else
            {
                try
                {
                    proxyAddressPrefix = ProxyAddressPrefix.GetPrefix(prefixString);
                }
                catch (ArgumentOutOfRangeException parseException)
                {
                    return(new InvalidProxyAddress(proxyAddressString, new CustomProxyAddressPrefix("ERROR"), proxyAddressString ?? (prefixString + ':' + addressString), true, parseException));
                }
                catch (ArgumentException ex)
                {
                    return(new InvalidProxyAddress(proxyAddressString, new CustomProxyAddressPrefix("ERROR"), proxyAddressString ?? (prefixString + ':' + addressString), true, new ArgumentOutOfRangeException(ex.Message, ex)));
                }
            }
            bool         isPrimaryAddress = StringComparer.Ordinal.Equals(proxyAddressPrefix.PrimaryPrefix, prefixString);
            ProxyAddress result;

            try
            {
                ProxyAddress proxyAddress = proxyAddressPrefix.GetProxyAddress(addressString, isPrimaryAddress);
                proxyAddress.RawProxyAddressBaseString = proxyAddressString;
                result = proxyAddress;
            }
            catch (ArgumentOutOfRangeException parseException2)
            {
                result = new InvalidProxyAddress(proxyAddressString, proxyAddressPrefix, addressString, isPrimaryAddress, parseException2);
            }
            return(result);
        }