Exemplo n.º 1
0
        /// <summary>
        /// Get the fully qualified name of a node
        /// This function is very slow, so is probably useful for debugging only.
        /// </summary>
        /// <returns></returns>
        public string GetFullyQualifiedName()
        {
            List <string> stack = new List <string>();

            stack.Add(GetDisplayName(true));
            PropertyNode tmpn   = GetParent();
            bool         atroot = false;

            while (!atroot)
            {
                stack.Add(tmpn.GetDisplayName(true));
                if (tmpn.GetParent() == null)
                {
                    atroot = true;
                }
                else
                {
                    tmpn = tmpn.GetParent();
                }
            }

            string fqname = "";

            for (int i = stack.Count - 1; i > 0; i--)
            {
                fqname += stack[i];
                fqname += "/";
            }
            fqname += stack[0];
            return(fqname);
        }
Exemplo n.º 2
0
        // Internal function for parsing property paths. last_index provides
        // and index value for the last node name token, if supplied.
        protected static PropertyNode FindNode(PropertyNode current, List <PathComponent> components,
                                               int position, bool create)
        {
            // Run off the end of the list
            if (current == null)
            {
                return(null);
            }

            // Success! This is the one we want.
            else if (position >= components.Count)
            {
                return(current.GetAttribute(PropertyNode.Attribute.REMOVED) ? null : current);
            }

            // Empty component means root.
            else if (components[position].name == "")
            {
                return(FindNode(current.GetRootNode(), components, position + 1, create));
            }

            // . means current directory
            else if (components[position].name == ".")
            {
                return(FindNode(current, components, position + 1, create));
            }

            // .. means parent directory
            else if (components[position].name == "..")
            {
                PropertyNode parent = current.GetParent();
                if (parent == null)
                {
                    throw new Exception("Attempt to move past root with '..'");
                }
                else
                {
                    return(FindNode(parent, components, position + 1, create));
                }
            }

            // Otherwise, a child name
            else
            {
                PropertyNode child = current.GetChild(components[position].name,
                                                      components[position].index,
                                                      create);
                return(FindNode(child, components, position + 1, create));
            }
        }