Пример #1
0
        internal MatchNode(MatchNode original)
        {
            this.Match = original.Match;

            this.SetAttributes(original.GetAttributes().ToList());
            foreach (var item in original.ChildElements)
            {
                this.AppendChild(item.CloneNode(true));
            }
        }
Пример #2
0
        private void AssertNotImportant(List <OpenXmlElement> chain, OpenXmlElement openXmlElement, MatchNode errorHintParent, MatchNode errorHint1, MatchNode errorHint2)
        {
            var index = chain.IndexOf(openXmlElement);

            for (int i = index; i < chain.Count; i++)
            {
                var current = chain[i];
                var next    = i == chain.Count - 1 ? null : chain[i + 1];

                var important = current.ChildElements.Where(c => c != next && IsImportant(c, NodeProvider));

                if (important.Any())
                {
                    string hint = errorHintParent != errorHint1 && errorHintParent != errorHint2 ? " in " + errorHintParent.Match : "";

                    throw new InvalidOperationException($"Node {errorHint1.Match} is not at the same level than {errorHint2.Match}{hint}. Important nodes could be removed in the chain:\r\n\r\n" +
                                                        chain.Skip(chain.IndexOf(openXmlElement)).Select((a, p) => (a.GetType().Name + " with text:" + a.InnerText).Indent(p * 4)).ToString("\r\n\r\n"));
                }
            }
        }
Пример #3
0
        protected void NormalizeInterval(ref MatchNodePair first, ref MatchNodePair last, MatchNode errorHintParent)
        {
            if (first.MatchNode == last.MatchNode)
            {
                throw new ArgumentException("first and last are the same node");
            }

            var chainFirst = ((OpenXmlElement)first.MatchNode).Follow(a => a.Parent).Reverse().ToList();
            var chainLast  = ((OpenXmlElement)last.MatchNode).Follow(a => a.Parent).Reverse().ToList();

            var result = chainFirst.Zip(chainLast, (f, l) => new { f, l }).First(a => a.f != a.l);

            AssertNotImportant(chainFirst, result.f !, errorHintParent, first.MatchNode, last.MatchNode); /*CSBUG*/
            AssertNotImportant(chainLast, result.l !, errorHintParent, last.MatchNode, first.MatchNode);

            first.AscendantNode = result.f !;
            last.AscendantNode  = result.l !;
        }
 public MatchNodePair(MatchNode matchNode)
 {
     this.MatchNode = matchNode;
     this.AscendantNode = null;
 }
        private void AssertNotImportant(List<OpenXmlElement> chain, OpenXmlElement openXmlElement, MatchNode errorHintParent, MatchNode errorHint1, MatchNode errorHint2)
        {
            var index = chain.IndexOf(openXmlElement);

            for (int i = index; i < chain.Count; i++)
            {
                var current = chain[i];
                var next = i == chain.Count - 1 ? null : chain[i + 1];

                var important = current.ChildElements.Where(c => c != next && IsImportant(c));

                if (important.Any())
                    throw new InvalidOperationException("Node {0} is not at the same level than {1}{2}. Important nodes could be removed close to {0}:\r\n{3}".FormatWith(
                        errorHint1.Match,
                        errorHint2.Match,
                        errorHintParent != errorHint1 && errorHintParent != errorHint2 ? " in " + errorHintParent.Match : "",
                        current.NiceToString()));
            }
        }
        protected void NormalizeInterval(ref MatchNodePair first, ref MatchNodePair last, MatchNode errorHintParent)
        {
            if (first.MatchNode == last.MatchNode)
                throw new ArgumentException("first and last are the same node");

            var chainFirst = ((OpenXmlElement)first.MatchNode).Follow(a => a.Parent).Reverse().ToList();
            var chainLast = ((OpenXmlElement)last.MatchNode).Follow(a => a.Parent).Reverse().ToList();

            var result = chainFirst.Zip(chainLast, (f, l) => new { f, l }).First(a => a.f != a.l);
            AssertNotImportant(chainFirst, result.f, errorHintParent, first.MatchNode, last.MatchNode);
            AssertNotImportant(chainLast, result.l, errorHintParent, last.MatchNode, first.MatchNode);

            first.AscendantNode = result.f;
            last.AscendantNode = result.l;
        }
Пример #7
0
 public MatchNodePair(MatchNode matchNode)
 {
     this.MatchNode     = matchNode;
     this.AscendantNode = null;
 }