Exemplo n.º 1
0
        public static XNodeFilter ImageFilter(XNode node, Func <XNode, XNodeFilter> filter = null)
        {
            XNodeFilter xnodeFilter = XNodeFilter.SelectNode;

            if (filter != null)
            {
                xnodeFilter = filter(node);
            }
            if (!(node is XElement) || ((XElement)node).Name != "img")
            {
                xnodeFilter |= XNodeFilter.DontSelectNode;
            }
            return(xnodeFilter);
        }
Exemplo n.º 2
0
        public static XNodeFilter TextFilter(XNode node, Func <XNode, XNodeFilter> filter = null)
        {
            XNodeFilter xnodeFilter = XNodeFilter.SelectNode;

            if (filter != null)
            {
                xnodeFilter = filter(node);
            }
            if (!(node is XText))
            {
                xnodeFilter |= XNodeFilter.DontSelectNode;
            }
            return(xnodeFilter);
        }
Exemplo n.º 3
0
 public static IEnumerable <XXElement> zFilterElements(this IEnumerable <XXElement> elements, Func <XXElement, XNodeFilter> filter)
 {
     foreach (XXElement element in elements)
     {
         XNodeFilter xNodeFilter = filter(element);
         if ((xNodeFilter & XNodeFilter.Stop) == XNodeFilter.Stop)
         {
             break;
         }
         if ((xNodeFilter & XNodeFilter.DontSelectNode) != XNodeFilter.DontSelectNode)
         {
             yield return(element);
         }
     }
 }
Exemplo n.º 4
0
        public static XNodeFilter FormItemFilter(XNode node, Func <XNode, XNodeFilter> filter = null)
        {
            XNodeFilter xnodeFilter = XNodeFilter.SelectNode;

            if (filter != null)
            {
                xnodeFilter = filter(node);
            }
            if (!(node is XElement))
            {
                xnodeFilter |= XNodeFilter.DontSelectNode;
            }
            else
            {
                XElement xe = (XElement)node;
                // return only element : input, select, button
                if (xe.Name != "input" && xe.Name != "select" && xe.Name != "button")
                {
                    xnodeFilter |= XNodeFilter.DontSelectNode;
                }
            }
            return(xnodeFilter);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Finds child nodes under the parent node and places them in the currentList.
        /// </summary>
        /// <param name="currentList">List to be populated with the nodes.</param>
        /// <param name="parent">Parent node under which the nodes should be searched.</param>
        /// <param name="filter">Filter to be used while selecting the node.</param>
        /// <param name="criteria">Criteria to be used by the filter.</param>
        public static void FindNodes(IList <HierarchyNode> currentList, HierarchyNode parent, XNodeFilter filter, object criteria)
        {
            Utilities.ArgumentNotNull("currentList", currentList);
            Utilities.ArgumentNotNull("parent", parent);
            Utilities.ArgumentNotNull("filter", filter);


            for (HierarchyNode child = parent.FirstChild; child != null; child = child.NextSibling)
            {
                if (filter(child, criteria))
                {
                    currentList.Add(child);
                }

                XHelperMethods.FindNodes(currentList, child, filter, criteria);
            }
        }
Exemplo n.º 6
0
        // bug il manque une boucle pour obtenir tous les enfants d'un noeud
        public static IEnumerable <XNode> DescendantNodes_bug(IEnumerable <XNode> nodes, Func <XNode, XNodeFilter> filter = null)
        {
            bool stop = false;

            foreach (XNode node1 in nodes)
            {
                XNodeFilter xnodeFilter = XNodeFilter.SelectNode;
                if (filter != null)
                {
                    xnodeFilter = filter(node1);
                }

                if (__trace)
                {
                    pb.Trace.WriteLine("DescendantNodes : source node {0}, filter {1}", node1.zGetPath(), xnodeFilter);
                }

                if ((xnodeFilter & XNodeFilter.Stop) == XNodeFilter.Stop)
                {
                    break;
                }

                if ((xnodeFilter & XNodeFilter.SkipNode) == XNodeFilter.SkipNode)
                {
                    continue;
                }

                if ((xnodeFilter & XNodeFilter.DontSelectNode) == 0)
                {
                    yield return(node1);
                }

                if (__trace)
                {
                    pb.Trace.WriteLine("DescendantNodes : source node {0}", node1.zGetPath());
                }
                XNode node2      = node1;
                XNode sourceNode = node2;
                while (true)
                {
                    // get child
                    if (node2 is XElement)
                    {
                        // first child node
                        XNode childNode = ((XElement)node2).FirstNode;
                        if (childNode != null)
                        {
                            xnodeFilter = XNodeFilter.SelectNode;
                            if (filter != null)
                            {
                                xnodeFilter = filter(childNode);
                            }
                            if (__trace)
                            {
                                pb.Trace.WriteLine("DescendantNodes : child node  {0}, filter {1}", childNode.zGetPath(), xnodeFilter);
                            }
                            if ((xnodeFilter & XNodeFilter.Stop) == XNodeFilter.Stop)
                            {
                                stop = true;
                                break;
                            }
                            if ((xnodeFilter & XNodeFilter.SkipNode) == 0)
                            {
                                node2 = childNode;
                                //_level++;
                                if ((xnodeFilter & XNodeFilter.DontSelectNode) == 0)
                                {
                                    yield return(node2);
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                    }

                    // get next sibling node or next sibling node of parent node
                    bool getChild = false;
                    bool stopNode = false;
                    while (true)
                    {
                        if (node2 == sourceNode)
                        {
                            stopNode = true;
                            break;
                        }

                        // next sibling node
                        XNode nextNode = node2.NextNode;
                        while (true)
                        {
                            if (nextNode == null)
                            {
                                break;
                            }

                            xnodeFilter = XNodeFilter.SelectNode;
                            if (filter != null)
                            {
                                xnodeFilter = filter(nextNode);
                            }

                            if (__trace)
                            {
                                pb.Trace.WriteLine("DescendantNodes : next node   {0}, filter {1}", nextNode.zGetPath(), xnodeFilter);
                            }

                            if ((xnodeFilter & XNodeFilter.Stop) == XNodeFilter.Stop)
                            {
                                stop = true;
                                break;
                            }

                            if ((xnodeFilter & XNodeFilter.SkipNode) == 0)
                            {
                                node2 = nextNode;
                                if ((xnodeFilter & XNodeFilter.DontSelectNode) == 0)
                                {
                                    yield return(node2);
                                }
                                else
                                {
                                    getChild = true;
                                    break;
                                }
                            }
                            nextNode = nextNode.NextNode;
                        }
                        if (getChild)
                        {
                            break;
                        }

                        // parent node
                        node2 = node2.Parent;
                        //_level--;
                    }
                    if (stop || stopNode)
                    {
                        break;
                    }
                }
                if (stop)
                {
                    break;
                }
            }
        }
Exemplo n.º 7
0
        public static IEnumerable <XNodeInfo> DescendantNodesInfos(IEnumerable <XNode> nodes, Func <XNode, XNodeFilter> filter = null)
        {
            //bool stop = false;
            int level = 1;
            int index = 1;

            foreach (XNode node1 in nodes)
            {
                XNodeFilter xnodeFilter = XNodeFilter.SelectNode;
                if (filter != null)
                {
                    xnodeFilter = filter(node1);
                }

                if (__trace)
                {
                    pb.Trace.WriteLine("DescendantNodesInfos : source node {0}, filter {1}", node1.zGetPath(), xnodeFilter);
                }

                XNodeInfo nodeInfo = new XNodeInfo {
                    Index = index++, Node = node1, Level = level, Ope = NodeOpe.Source, Selected = false, Skip = false, Stop = false
                };

                if ((xnodeFilter & XNodeFilter.Stop) == XNodeFilter.Stop)
                {
                    nodeInfo.Stop = true;
                    yield return(nodeInfo);

                    break;
                }

                if ((xnodeFilter & XNodeFilter.SkipNode) == XNodeFilter.SkipNode)
                {
                    nodeInfo.Skip = true;
                    yield return(nodeInfo);

                    continue;
                }

                if ((xnodeFilter & XNodeFilter.DontSelectNode) == 0)
                {
                    //yield return node1;
                    nodeInfo.Selected = true;
                    yield return(nodeInfo);
                }
                else
                {
                    yield return(nodeInfo);
                }

                if (__trace)
                {
                    pb.Trace.WriteLine("DescendantNodesInfos : source node {0}", node1.zGetPath());
                }
                XNode node2      = node1;
                XNode sourceNode = node2;
                while (true)
                {
                    // get child
                    while (true)
                    {
                        if (!(node2 is XElement))
                        {
                            break;
                        }

                        // first child node
                        XNode childNode = ((XElement)node2).FirstNode;

                        if (childNode == null)
                        {
                            break;
                        }

                        nodeInfo = new XNodeInfo {
                            Index = index++, Node = childNode, Level = level + 1, Ope = NodeOpe.Child, Selected = false, Skip = false, Stop = false
                        };

                        xnodeFilter = XNodeFilter.SelectNode;
                        if (filter != null)
                        {
                            xnodeFilter = filter(childNode);
                        }
                        if (__trace)
                        {
                            pb.Trace.WriteLine("DescendantNodesInfos : child node  {0}, filter {1}", childNode.zGetPath(), xnodeFilter);
                        }

                        if ((xnodeFilter & XNodeFilter.Stop) == XNodeFilter.Stop)
                        {
                            //stop = true;
                            nodeInfo.Stop = true;
                            yield return(nodeInfo);

                            yield break;
                        }

                        if ((xnodeFilter & XNodeFilter.SkipNode) == XNodeFilter.SkipNode)
                        {
                            nodeInfo.Skip = true;
                            yield return(nodeInfo);

                            break;
                        }

                        node2 = childNode;
                        level++;
                        if ((xnodeFilter & XNodeFilter.DontSelectNode) == 0)
                        {
                            //yield return node2;
                            //level++;
                            nodeInfo.Selected = true;
                            yield return(nodeInfo);
                        }
                        else
                        {
                            yield return(nodeInfo);
                        }
                    }
                    //if (stop)
                    //    break;

                    // get next sibling node or next sibling node of parent node
                    bool getChild = false;
                    bool stopNode = false;
                    while (true)
                    {
                        if (node2 == sourceNode)
                        {
                            stopNode = true;
                            break;
                        }

                        // next sibling node
                        XNode nextNode = node2.NextNode;
                        while (true)
                        {
                            if (nextNode == null)
                            {
                                break;
                            }

                            nodeInfo = new XNodeInfo {
                                Index = index++, Node = nextNode, Level = level, Ope = NodeOpe.Siblin, Selected = false, Skip = false, Stop = false
                            };

                            xnodeFilter = XNodeFilter.SelectNode;
                            if (filter != null)
                            {
                                xnodeFilter = filter(nextNode);
                            }

                            if (__trace)
                            {
                                pb.Trace.WriteLine("DescendantNodesInfos : next node   {0}, filter {1}", nextNode.zGetPath(), xnodeFilter);
                            }

                            if ((xnodeFilter & XNodeFilter.Stop) == XNodeFilter.Stop)
                            {
                                //stop = true;
                                nodeInfo.Stop = true;
                                yield return(nodeInfo);

                                yield break;
                            }

                            if ((xnodeFilter & XNodeFilter.SkipNode) == 0)
                            {
                                node2 = nextNode;
                                if ((xnodeFilter & XNodeFilter.DontSelectNode) == 0)
                                {
                                    nodeInfo.Selected = true;
                                    yield return(nodeInfo);
                                }
                                else
                                {
                                    yield return(nodeInfo);
                                }
                                //else
                                //{
                                getChild = true;
                                break;
                                //}
                            }
                            else
                            {
                                nodeInfo.Skip = true;
                                yield return(nodeInfo);
                            }
                            nextNode = nextNode.NextNode;
                        }
                        if (getChild)
                        {
                            break;
                        }

                        // parent node
                        node2 = node2.Parent;
                        level--;

                        nodeInfo = new XNodeInfo {
                            Index = index++, Node = node2, Level = level, Ope = NodeOpe.Close, Selected = false, Skip = false, Stop = false
                        };
                        yield return(nodeInfo);
                    }
                    //if (stop || stopNode)
                    if (stopNode)
                    {
                        break;
                    }
                }
                //if (stop)
                //    break;
            }
        }