Inheritance: IPathSegment
Ejemplo n.º 1
0
        static void ActualXElementSegment(XmlPathSegment pathSegment, IndexedPathSegmentTreeNode <string> newIndexedValueTreeNode, XElement parentCurentElement)
        {
            var childElements =
                parentCurentElement.Elements(pathSegment.ActualSegment).ToList();

            newIndexedValueTreeNode.EnumerableValue = childElements;

            if (childElements.Count == 0)
            {
                newIndexedValueTreeNode.CurrentValue        = string.Empty;
                newIndexedValueTreeNode.EnumerationComplete = true;
            }
            else
            {
                newIndexedValueTreeNode.Enumerator =
                    newIndexedValueTreeNode.EnumerableValue.GetEnumerator();

                newIndexedValueTreeNode.Enumerator.Reset();

                if (!newIndexedValueTreeNode.Enumerator.MoveNext())
                {
                    newIndexedValueTreeNode.CurrentValue        = string.Empty;
                    newIndexedValueTreeNode.EnumerationComplete = true;
                }
                else
                {
                    newIndexedValueTreeNode.CurrentValue = newIndexedValueTreeNode.Enumerator.Current;
                }
            }
        }
Ejemplo n.º 2
0
        IndexedPathSegmentTreeNode <string> CreatePathSegmentIndexedPathSegmentTreeNode(
            XmlPathSegment pathSegment, IPathSegment parentPathSegment, IndexedPathSegmentTreeNode <string> parentNode)
        {
            var newIndexedValueTreeNode = new IndexedPathSegmentTreeNode <string>();

            if (parentNode.EnumerationComplete)
            {
                newIndexedValueTreeNode.CurrentValue        = string.Empty;
                newIndexedValueTreeNode.EnumerationComplete = true;
            }
            else
            {
                if (parentNode.CurrentValue is XDocument)
                {
                    var document = parentNode.CurrentValue as XDocument;
                    newIndexedValueTreeNode.CurrentValue = document.Root;
                }
                else
                {
                    XElementSegment(pathSegment, parentPathSegment, parentNode, newIndexedValueTreeNode);
                }
            }

            return(newIndexedValueTreeNode);
        }
Ejemplo n.º 3
0
        static List <string> AddAttribute(List <string> returnData, XmlPathSegment pathSegment, XElement childElement)
        {
            var attribute = childElement.Attribute(pathSegment.ActualSegment);

            if (attribute != null)
            {
                returnData.Add(attribute.Value);
            }
            else
            {
                throw new Exception(string.Format("Attribute {0} not found.", pathSegment.ActualSegment));
            }
            return(returnData);
        }
Ejemplo n.º 4
0
        public override IPathSegment CreatePathSegment(string pathSegmentString)
        {
            XmlPathSegment xmlPathSegment;

            if (pathSegmentString.EndsWith(EnumerableSymbol))
            {
                xmlPathSegment = new XmlPathSegment(pathSegmentString.TrimEnd(EnumerableSymbol.ToArray()), true);
            }
            else
            {
                xmlPathSegment = new XmlPathSegment(pathSegmentString, false);
            }
            return(xmlPathSegment);
        }
Ejemplo n.º 5
0
        static void XElementSegment(XmlPathSegment pathSegment, IPathSegment parentPathSegment, IndexedPathSegmentTreeNode <string> parentNode, IndexedPathSegmentTreeNode <string> newIndexedValueTreeNode)
        {
            var parentCurentElement = parentNode.CurrentValue as XElement;

            if (parentPathSegment != null && parentPathSegment.IsEnumarable)
            {
                if (parentCurentElement != null)
                {
                    ActualXElementSegment(pathSegment, newIndexedValueTreeNode, parentCurentElement);
                }
            }
            else
            {
                if (pathSegment.IsAttribute)
                {
                    if (parentCurentElement != null)
                    {
                        newIndexedValueTreeNode.CurrentValue = parentCurentElement.Attribute(pathSegment.ActualSegment);
                    }

                    if (newIndexedValueTreeNode.CurrentValue == null)
                    {
                        newIndexedValueTreeNode.CurrentValue        = string.Empty;
                        newIndexedValueTreeNode.EnumerationComplete = true;
                    }
                }
                else
                {
                    if (parentCurentElement != null)
                    {
                        newIndexedValueTreeNode.CurrentValue = parentCurentElement
                                                               .Element(pathSegment.ActualSegment)
                                                               ?? parentCurentElement.Descendants()
                                                               .FirstOrDefault(o => o.Name.LocalName == pathSegment.ActualSegment);
                    }

                    if (newIndexedValueTreeNode.CurrentValue == null)
                    {
                        newIndexedValueTreeNode.CurrentValue        = string.Empty;
                        newIndexedValueTreeNode.EnumerationComplete = true;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        protected override void BuildIndexedTree(IList <IPath> paths, Dictionary <IPath, List <IPathSegment> > indexedPathSegments, IndexedPathSegmentTreeNode <string> rootIndexedValueTreeNode)
        {
            foreach (IPath path in paths)
            {
                IndexedPathSegmentTreeNode <string> IndexedPathSegmentTreeNode = rootIndexedValueTreeNode;
                int pathSegmentCount = 0;

                while (pathSegmentCount < indexedPathSegments[path].Count)
                {
                    IndexedPathSegmentTreeNode <string> tmpIndexedPathSegmentTreeNode = null;
                    XmlPathSegment pathSegment = indexedPathSegments[path][pathSegmentCount] as XmlPathSegment;
                    XmlPathSegment parentPathSegment;

                    if (pathSegmentCount > 0)
                    {
                        parentPathSegment = indexedPathSegments[path][pathSegmentCount - 1] as XmlPathSegment;
                    }
                    else
                    {
                        parentPathSegment = null;
                    }

                    if (IndexedPathSegmentTreeNode != null && (pathSegment != null && !IndexedPathSegmentTreeNode.TryGetValue(pathSegment.ActualSegment, out tmpIndexedPathSegmentTreeNode)))
                    {
                        IndexedPathSegmentTreeNode <string> newIndexedPathSegmentTreeNode = CreatePathSegmentIndexedPathSegmentTreeNode(pathSegment, parentPathSegment, IndexedPathSegmentTreeNode);
                        IndexedPathSegmentTreeNode.Add(pathSegment.ActualSegment, newIndexedPathSegmentTreeNode);
                        IndexedPathSegmentTreeNode = newIndexedPathSegmentTreeNode;
                    }
                    else
                    {
                        IndexedPathSegmentTreeNode = tmpIndexedPathSegmentTreeNode;
                    }

                    pathSegmentCount++;
                }
            }
        }
Ejemplo n.º 7
0
 void SelectEnumarable(IList <IPathSegment> pathSegments, List <string> returnData, int i, XmlPathSegment pathSegment, bool lastSegment, List <XElement> childElements)
 {
     if (lastSegment)
     {
         foreach (XElement childElement in childElements)
         {
             if (pathSegment.IsAttribute)
             {
                 returnData.AddRange(AddAttribute(returnData, pathSegment, childElement));
             }
             else
             {
                 returnData.Add(childElement.Value);
             }
         }
     }
     else
     {
         foreach (XElement childElement in childElements)
         {
             returnData.AddRange(SelectEnumberable(pathSegments.Skip(i + 1).ToList(),
                                                   pathSegment, childElement));
         }
     }
 }
Ejemplo n.º 8
0
        List <string> SelectEnumerable(IList <IPathSegment> pathSegments, List <string> returnData, int i, XmlPathSegment pathSegment, bool lastSegment, XElement currentElement)
        {
            if (currentElement != null && pathSegment != null)
            {
                var childElements =
                    currentElement.Elements(pathSegment.ActualSegment).ToList();

                if (childElements.Count > 0)
                {
                    SelectEnumarable(pathSegments, returnData, i, pathSegment, lastSegment, childElements);
                }
            }
            return(returnData);
        }
Ejemplo n.º 9
0
        private static XElement SelectEnumerable(ref List <string> returnData, XElement currentElement, XmlPathSegment pathSegment, bool lastSegment)
        {
            if (pathSegment != null && pathSegment.IsAttribute)
            {
                var attribute = currentElement?.Attribute(pathSegment.ActualSegment);

                if (attribute != null)
                {
                    currentElement = null;

                    if (lastSegment)
                    {
                        returnData.Add(attribute.Value);
                    }
                }
            }
            else
            {
                if (currentElement != null && pathSegment != null)
                {
                    currentElement = currentElement.Element(pathSegment.ActualSegment);
                }

                if (currentElement != null && lastSegment)
                {
                    returnData.Add(currentElement.Value);
                }
            }

            return(currentElement);
        }
Ejemplo n.º 10
0
        private IndexedPathSegmentTreeNode<string> CreatePathSegmentIndexedPathSegmentTreeNode(
            XmlPathSegment pathSegment, IPathSegment parentPathSegment, IndexedPathSegmentTreeNode<string> parentNode)
        {
            var newIndexedValueTreeNode = new IndexedPathSegmentTreeNode<string>();

            if (parentNode.EnumerationComplete)
            {
                newIndexedValueTreeNode.CurrentValue = string.Empty;
                newIndexedValueTreeNode.EnumerationComplete = true;
            }
            else
            {
                if (parentNode.CurrentValue is XDocument)
                {
                    var document = parentNode.CurrentValue as XDocument;
                    newIndexedValueTreeNode.CurrentValue = document.Root;
                }
                else
                {
                    var parentCurentElement = parentNode.CurrentValue as XElement;

                    if (parentPathSegment != null && parentPathSegment.IsEnumarable)
                    {
                        if (parentCurentElement != null)
                        {
                            List<XElement> childElements =
                                parentCurentElement.Elements(pathSegment.ActualSegment).ToList();
                            newIndexedValueTreeNode.EnumerableValue = childElements;

                            if (childElements.Count == 0)
                            {
                                newIndexedValueTreeNode.CurrentValue = string.Empty;
                                newIndexedValueTreeNode.EnumerationComplete = true;
                            }
                            else
                            {
                                newIndexedValueTreeNode.Enumerator =
                                    newIndexedValueTreeNode.EnumerableValue.GetEnumerator();

                                newIndexedValueTreeNode.Enumerator.Reset();

                                if (!newIndexedValueTreeNode.Enumerator.MoveNext())
                                {
                                    newIndexedValueTreeNode.CurrentValue = string.Empty;
                                    newIndexedValueTreeNode.EnumerationComplete = true;
                                }
                                else
                                {
                                    newIndexedValueTreeNode.CurrentValue = newIndexedValueTreeNode.Enumerator.Current;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (pathSegment.IsAttribute)
                        {
                            if (parentCurentElement != null)
                            {
                                newIndexedValueTreeNode.CurrentValue =
                                    parentCurentElement.Attribute(pathSegment.ActualSegment);
                            }

                            if (newIndexedValueTreeNode.CurrentValue == null)
                            {
                                newIndexedValueTreeNode.CurrentValue = string.Empty;
                                newIndexedValueTreeNode.EnumerationComplete = true;
                            }
                        }
                        else
                        {
                            if (parentCurentElement != null)
                            {
                                newIndexedValueTreeNode.CurrentValue =
                                    parentCurentElement.Element(pathSegment.ActualSegment);
                            }

                            if (newIndexedValueTreeNode.CurrentValue == null)
                            {
                                newIndexedValueTreeNode.CurrentValue = string.Empty;
                                newIndexedValueTreeNode.EnumerationComplete = true;
                            }
                        }
                    }
                }
            }

            return newIndexedValueTreeNode;
        }
Ejemplo n.º 11
0
 public override IPathSegment CreatePathSegment(string pathSegmentString)
 {
     XmlPathSegment xmlPathSegment;
     if (pathSegmentString.EndsWith(EnumerableSymbol))
     {
         xmlPathSegment = new XmlPathSegment(pathSegmentString.TrimEnd(EnumerableSymbol.ToArray()), true);
     }
     else
     {
         xmlPathSegment = new XmlPathSegment(pathSegmentString, false);
     }
     return xmlPathSegment;
 }
Ejemplo n.º 12
0
        private IEnumerable <string> SelectEnumberable(IList <IPathSegment> pathSegments, IPathSegment parentPathSegment, XElement element)
        {
            List <string> returnData     = new List <string>();
            XElement      currentElement = element;

            if (pathSegments.Count > 0)
            {
                for (int i = 0; i < pathSegments.Count; i++)
                {
                    XmlPathSegment pathSegment = pathSegments[i] as XmlPathSegment;
                    XmlPathSegment previousPathSegment;

                    if (i > 0)
                    {
                        previousPathSegment = pathSegments[i - 1] as XmlPathSegment;
                    }
                    else
                    {
                        previousPathSegment = parentPathSegment as XmlPathSegment;
                    }

                    bool lastSegment = (i == pathSegments.Count - 1);

                    if (previousPathSegment != null && previousPathSegment.IsEnumarable)
                    {
                        if (currentElement != null)
                        {
                            if (pathSegment != null)
                            {
                                List <XElement> childElements = currentElement.Elements(pathSegment.ActualSegment).ToList();

                                if (childElements.Count > 0)
                                {
                                    if (lastSegment)
                                    {
                                        foreach (XElement childElement in childElements)
                                        {
                                            if (pathSegment.IsAttribute)
                                            {
                                                XAttribute attribute = childElement.Attribute(pathSegment.ActualSegment);

                                                if (attribute != null)
                                                {
                                                    returnData.Add(attribute.Value);
                                                }
                                                else
                                                {
                                                    throw new Exception(string.Format("Attribute {0} not found.", pathSegment.ActualSegment));
                                                }
                                            }
                                            else
                                            {
                                                returnData.Add(childElement.Value);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        foreach (XElement childElement in childElements)
                                        {
                                            returnData.AddRange(SelectEnumberable(pathSegments.Skip(i + 1).ToList(), pathSegment, childElement));
                                        }
                                    }
                                }
                            }
                        }

                        return(returnData);
                    }
                    if (pathSegment != null && pathSegment.IsAttribute)
                    {
                        if (currentElement != null)
                        {
                            XAttribute attribute = currentElement.Attribute(pathSegment.ActualSegment);

                            if (attribute != null)
                            {
                                currentElement = null;

                                if (lastSegment)
                                {
                                    returnData.Add(attribute.Value);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (currentElement != null)
                        {
                            if (pathSegment != null)
                            {
                                currentElement = currentElement.Element(pathSegment.ActualSegment);
                            }
                        }

                        if (currentElement != null && lastSegment)
                        {
                            returnData.Add(currentElement.Value);
                        }
                    }
                }
            }
            else if (currentElement.Name == parentPathSegment.ActualSegment)
            {
                returnData.Add(currentElement.Value);
            }

            return(returnData);
        }
Ejemplo n.º 13
0
        private IndexedPathSegmentTreeNode <string> CreatePathSegmentIndexedPathSegmentTreeNode(XmlPathSegment pathSegment, IPathSegment parentPathSegment, IndexedPathSegmentTreeNode <string> parentNode)
        {
            IndexedPathSegmentTreeNode <string> newIndexedValueTreeNode = new IndexedPathSegmentTreeNode <string>();

            if (parentNode.EnumerationComplete)
            {
                newIndexedValueTreeNode.CurrentValue        = string.Empty;
                newIndexedValueTreeNode.EnumerationComplete = true;
            }
            else
            {
                if (parentNode.CurrentValue is XDocument)
                {
                    XDocument document = parentNode.CurrentValue as XDocument;
                    newIndexedValueTreeNode.CurrentValue = document.Root;
                }
                else
                {
                    XElement parentCurentElement = parentNode.CurrentValue as XElement;

                    if (parentPathSegment != null && parentPathSegment.IsEnumarable)
                    {
                        if (parentCurentElement != null)
                        {
                            List <XElement> childElements = parentCurentElement.Elements(pathSegment.ActualSegment).ToList();
                            newIndexedValueTreeNode.EnumerableValue = childElements;

                            if (childElements.Count == 0)
                            {
                                newIndexedValueTreeNode.CurrentValue        = string.Empty;
                                newIndexedValueTreeNode.EnumerationComplete = true;
                            }
                            else
                            {
                                newIndexedValueTreeNode.Enumerator = newIndexedValueTreeNode.EnumerableValue.GetEnumerator();

                                newIndexedValueTreeNode.Enumerator.Reset();

                                if (!newIndexedValueTreeNode.Enumerator.MoveNext())
                                {
                                    newIndexedValueTreeNode.CurrentValue        = string.Empty;
                                    newIndexedValueTreeNode.EnumerationComplete = true;
                                }
                                else
                                {
                                    newIndexedValueTreeNode.CurrentValue = newIndexedValueTreeNode.Enumerator.Current;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (pathSegment.IsAttribute)
                        {
                            if (parentCurentElement != null)
                            {
                                newIndexedValueTreeNode.CurrentValue = parentCurentElement.Attribute(pathSegment.ActualSegment);
                            }

                            if (newIndexedValueTreeNode.CurrentValue == null)
                            {
                                newIndexedValueTreeNode.CurrentValue        = string.Empty;
                                newIndexedValueTreeNode.EnumerationComplete = true;
                            }
                        }
                        else
                        {
                            if (parentCurentElement != null)
                            {
                                newIndexedValueTreeNode.CurrentValue = parentCurentElement.Element(pathSegment.ActualSegment);
                            }

                            if (newIndexedValueTreeNode.CurrentValue == null)
                            {
                                newIndexedValueTreeNode.CurrentValue        = string.Empty;
                                newIndexedValueTreeNode.EnumerationComplete = true;
                            }
                        }
                    }
                }
            }

            return(newIndexedValueTreeNode);
        }