예제 #1
0
        /// <summary>
        /// Get a Single Location Node
        /// </summary>
        /// <param name="node">The parent node of the location</param>
        /// <param name="location">The location to get</param>
        /// <param name="index">Output Index of the location in the parent node</param>
        /// <returns>The location's node</returns>
        public Node GetSingleLocation(Node node, string location, out int?index, string[] subPaths)
        {
            index    = null;
            location = NormalizeLocation(node, subPaths != null ? subPaths[0] : location, out index);
            if (location == null || location.ToLower().Equals("node"))
            {
                return(node);
            }
            Node root = (CurrentProgram ?? node.GetProgramNode());

            root = root ?? node.Root;
            var result = root.Get(subPaths != null ? subPaths[0] : location);

            if (result != null)
            {
                if (subPaths != null)
                {//Check if a subpath matches
                    for (int i = 1; i < subPaths.Length; i++)
                    {
                        int  nbParent   = subPaths[i].LastIndexOf('/') + 1;
                        Node parent     = result;
                        int  matchIndex = 0;
                        for (int j = 0; j < nbParent; j++)
                        {
                            matchIndex = parent.Parent.IndexOf(parent);
                            parent     = parent.Parent;
                        }
                        int?index2    = null;
                        var subResult = GetSingleSubLocation(parent, subPaths[i].Substring(nbParent), out index2, matchIndex + 1);
                        if (subResult != null)
                        {
                            index = index2;
                            if (subResult.CodeElement == null)
                            {
                                if (subResult.Parent == parent)
                                {
                                    index = null;
                                }
                                else
                                {
                                    result = subResult;
                                }
                            }
                            else
                            {
                                result = subResult;
                            }
                            break;
                        }
                    }
                }
                return(result);
            }
            result = Create(root, subPaths != null ? subPaths[0] : location);
            if (result != null)
            {
                return(result);
            }
            throw new System.ArgumentException("Undefined URI: " + location);
        }
예제 #2
0
        /// <summary>
        /// Determines if the given location exists
        /// </summary>
        /// <param name="node">The parent node of the location</param>
        /// <param name="location">The loctaion to test.</param>
        /// <returns>true if the location exists, fals eotherwise</returns>
        public bool IsLocationExists(Node node, string location, out int?index)
        {
            index    = null;
            location = NormalizeLocation(node, location, out index);
            if (location == null || location.ToLower().Equals("node"))
            {
                return(true);
            }
            var root   = CurrentProgram ?? (node.GetProgramNode() ?? node.Root);
            var result = root.Get(location);

            return(result != null);
        }
예제 #3
0
        /// <summary>
        /// Get a Single Location Node
        /// </summary>
        /// <param name="node">The parent node of the location</param>
        /// <param name="location">The location to get</param>
        /// <param name="index">Output Index of the location in the parent node</param>
        /// <returns>The location's node</returns>
        public Node GetSingleLocation(Node node, string location, out int?index)
        {
            index    = null;
            location = NormalizeLocation(node, location, out index);
            if (location == null || location.ToLower().Equals("node"))
            {
                return(node);
            }
            var root   = CurrentProgram ?? (node.GetProgramNode() ?? node.Root);
            var result = root.Get(location);

            if (result != null)
            {
                return(result);
            }
            result = Create(root, location);
            if (result != null)
            {
                return(result);
            }
            throw new System.ArgumentException("Undefined URI: " + location);
        }