예제 #1
0
        public static bool TryGetCanonical(IList <string> components, bool stripDdas, out string canonicalAddress)
        {
            if (components.Count > X400AddressParser.CanonicalOrder.Length)
            {
                canonicalAddress = null;
                return(false);
            }
            int num = X400AddressParser.CanonicalOrder.Length;

            if (stripDdas)
            {
                num -= 4;
            }
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < num; i++)
            {
                X400ComponentType x400ComponentType = X400AddressParser.CanonicalOrder[i];
                if (x400ComponentType < (X400ComponentType)components.Count)
                {
                    string text = components[(int)x400ComponentType];
                    if (text != null)
                    {
                        X400AddressParser.AddComponent(stringBuilder, x400ComponentType, text);
                    }
                }
            }
            canonicalAddress = stringBuilder.ToString();
            return(true);
        }
예제 #2
0
        public static bool TryGetCanonical(string inputAddress, bool stripDdas, out string canonicalAddress, out bool endingWithSemicolon)
        {
            canonicalAddress = null;
            IList <string> components = null;

            return(X400AddressParser.TryParse(inputAddress, 21, false, false, out components, out endingWithSemicolon) && X400AddressParser.TryGetCanonical(components, stripDdas, out canonicalAddress));
        }
예제 #3
0
        public static bool TryParse(string s, out X400Domain result)
        {
            IList <string> list;

            if (X400AddressParser.TryParse(s, out list))
            {
                int i = list.Count - 1;
                while (i >= 0 && string.IsNullOrEmpty(list[i]))
                {
                    list.RemoveAt(i--);
                }
                for (i = 0; i < list.Count; i++)
                {
                    if (list[i] == string.Empty)
                    {
                        list[i] = null;
                    }
                    else if (!X400Domain.IsValidComponent(i, list[i]))
                    {
                        result = null;
                        return(false);
                    }
                }
                if (list.Count > 0 && list.Count < 8)
                {
                    result = new X400Domain(list);
                    return(true);
                }
            }
            result = null;
            return(false);
        }
예제 #4
0
        public static bool GetCanonical(string inputAddress, bool stripDdas, out string canonicalAddress)
        {
            bool result = false;

            if (X400AddressParser.TryGetCanonical(inputAddress, stripDdas, out canonicalAddress, out result))
            {
                return(result);
            }
            throw new ArgumentOutOfRangeException(DataStrings.InvalidX400AddressSpace(inputAddress));
        }
예제 #5
0
        public static string ToCanonicalString(IList <string> components)
        {
            string result = null;

            if (X400AddressParser.TryGetCanonical(components, false, out result))
            {
                return(result);
            }
            throw new ArgumentOutOfRangeException();
        }
예제 #6
0
        private static bool TryParse(string s, bool addressSpace, bool locallyScoped, out RoutingX400Address address)
        {
            address = null;
            IList <string> list = null;

            if (!X400AddressParser.TryParse(s, 8, addressSpace, locallyScoped, out list))
            {
                return(false);
            }
            int i = 8;

            if (addressSpace)
            {
                while (i > 0)
                {
                    if (list[i - 1] != null)
                    {
                        break;
                    }
                    list.RemoveAt(--i);
                }
                while (i > 0)
                {
                    string text = list[i - 1];
                    if (text == null || !text.Equals("*", StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    list.RemoveAt(--i);
                }
            }
            while (i > 0)
            {
                if (list[i - 1] == null)
                {
                    list[i - 1] = string.Empty;
                }
                i--;
            }
            address = new RoutingX400Address(list);
            return(true);
        }
예제 #7
0
        private static bool TryParse(string s, int maxComponentsCount, bool addressSpace, bool locallyScoped, out IList <string> components, out bool endingWithSemicolon)
        {
            if (maxComponentsCount <= 0 || maxComponentsCount > 21)
            {
                throw new InvalidOperationException("maxComponentsCount is out of range");
            }
            endingWithSemicolon = false;
            components          = null;
            if (s == null)
            {
                return(false);
            }
            int  num = 0;
            char c   = '/';

            if (s.Length >= 2 && s[0] == c)
            {
                num++;
            }
            else
            {
                c = ';';
            }
            List <string> list = new List <string>(maxComponentsCount);

            for (int i = 0; i < maxComponentsCount; i++)
            {
                list.Add(null);
            }
            int num2   = 0;
            int j      = num;
            int length = s.Length;

            while (j < length)
            {
                while (j < length && (' ' == s[j] || '\t' == s[j]))
                {
                    j++;
                }
                if (j == length)
                {
                    break;
                }
                int num3 = s.IndexOfAny(X400AddressParser.KeySeparators, j);
                if (-1 == num3 || j == num3)
                {
                    return(false);
                }
                X400ComponentType componentType = X400AddressParser.GetComponentType(s, j, num3 - j);
                if (X400ComponentType.Unsupported == componentType)
                {
                    return(false);
                }
                if ((componentType == X400ComponentType.DDA && s[num3] != X400AddressParser.KeySeparators[1]) || (componentType != X400ComponentType.DDA && s[num3] != X400AddressParser.KeySeparators[0]))
                {
                    return(false);
                }
                if (addressSpace && X400ComponentType.X121Address == componentType)
                {
                    return(false);
                }
                string text;
                j = X400AddressParser.GetUnescapedValue(s, num3 + 1, locallyScoped, c, out text, out endingWithSemicolon);
                if (X400AddressParser.MaxComponentLengths[(int)componentType] < text.Length)
                {
                    return(false);
                }
                if (componentType == X400ComponentType.DDA && num2++ == 4)
                {
                    return(false);
                }
                if (maxComponentsCount > (int)componentType)
                {
                    if (componentType != X400ComponentType.DDA)
                    {
                        list[(int)componentType] = text;
                    }
                    else
                    {
                        int num4 = 17 + num2 - 1;
                        if (num4 < maxComponentsCount)
                        {
                            list[num4] = text;
                        }
                    }
                }
            }
            bool flag = false;

            for (int k = 4; k <= 7; k++)
            {
                if (flag)
                {
                    list[k] = null;
                }
                else
                {
                    flag = string.IsNullOrEmpty(list[k]);
                }
            }
            components = list;
            return(true);
        }
예제 #8
0
        public static bool TryParse(string s, out IList <string> components)
        {
            bool flag;

            return(X400AddressParser.TryParse(s, 21, false, false, out components, out flag));
        }
예제 #9
0
        public static bool TryParse(string s, int maxComponentsCount, bool addressSpace, bool locallyScoped, out IList <string> components)
        {
            bool flag;

            return(X400AddressParser.TryParse(s, maxComponentsCount, addressSpace, locallyScoped, out components, out flag));
        }
예제 #10
0
 public X400ProxyAddress(string address, bool isPrimaryAddress) : this(X400AddressParser.GetCanonical(address, false, out address), address, isPrimaryAddress)
 {
 }
예제 #11
0
 public override string ToString()
 {
     return(X400AddressParser.ToCanonicalString(this.components));
 }