예제 #1
0
        public static HierarchicalName Create(HierarchicalName baseName, string datasetName)
        {
            if (baseName == null || string.IsNullOrEmpty(datasetName))
            {
                return(null);
            }
            StringBuilder sb = new StringBuilder();

            char[] chars = datasetName.Trim().ToCharArray();
            for (int i = 0; i < chars.Length; i++)
            {
                char curChar = chars[i];
                if (char.IsLetterOrDigit(curChar) || curChar == '.' || curChar == '_' || curChar == ' ')
                {
                    sb.Append(curChar);
                }
                else if (curChar == '/' || curChar == '\\')
                {
                    string tmp = sb.ToString().Trim();
                    if (!string.IsNullOrEmpty(tmp))
                    {
                        break;
                    }
                }
                else
                {
                    return(null); //bad character, we fail
                }
            }
            if (chars.Length != sb.Length)
            {
                return(null);  //we prematurely ended
            }
            return(new HierarchicalName(baseName.nameParts, sb.ToString()));
        }
예제 #2
0
        public static HierarchicalName Create(IEnumerable <string> nameParts)
        {
            if (nameParts == null)
            {
                return(null);
            }
            List <string> tmpL = new List <string>();

            foreach (string s in nameParts)
            {
                tmpL.Add(s.Trim());
            }
            if (tmpL.Count < 1)
            {
                return(null);
            }
            for (int j = 0; j < tmpL.Count; j++)
            {
                string s = tmpL[j];
                if (string.IsNullOrEmpty(s))
                {
                    return(null);
                }
                StringBuilder sb    = new StringBuilder();
                char[]        chars = s.Trim().ToCharArray();
                for (int i = 0; i < chars.Length; i++)
                {
                    char curChar = chars[i];
                    if (char.IsLetterOrDigit(curChar) || curChar == '.' || curChar == '_' || curChar == ' ')
                    {
                        sb.Append(curChar);
                    }
                    else if (curChar == '/' || curChar == '\\')
                    {
                        string tmp = sb.ToString().Trim();
                        if (!string.IsNullOrEmpty(tmp))
                        {
                            break;
                        }
                    }
                    else
                    {
                        return(null); //bad character, we fail
                    }
                }
                if (chars.Length != sb.Length)
                {
                    return(null);  //we prematurely ended
                }
                tmpL[j] = sb.ToString();
            }
            HierarchicalName dn = new HierarchicalName(new string[tmpL.Count - 1], tmpL[tmpL.Count - 1]);

            for (int i = 0; i < dn.nameParts.Length; i++)
            {
                dn.nameParts[i] = tmpL[i];
            }
            return(dn);
        }
예제 #3
0
        public static HierarchicalName Create(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            char[]        chars = name.ToCharArray();
            StringBuilder sb    = new StringBuilder();
            List <string> parts = new List <string>();

            for (int i = 0; i < chars.Length; i++)
            {
                char curChar = chars[i];
                if (char.IsLetterOrDigit(curChar) || curChar == '.' || curChar == '_' || curChar == ' ')
                {
                    sb.Append(curChar);
                }
                else if (curChar == '/' || curChar == '\\')
                {
                    string tmp = sb.ToString().Trim();
                    if (!string.IsNullOrEmpty(tmp))
                    {
                        parts.Add(tmp);
                    }
                }
                else
                {
                    return(null); //bad character, we fail
                }
            }
            if (sb.Length > 0)
            {
                string tmp = sb.ToString().Trim();
                if (!string.IsNullOrEmpty(tmp))
                {
                    parts.Add(tmp);
                }
            }
            HierarchicalName dn = new HierarchicalName(new string[parts.Count - 1], parts[parts.Count - 1]);

            for (int i = 0; i < dn.nameParts.Length; i++)
            {
                dn.nameParts[i] = parts[i];
            }
            return(dn);
        }