private void ProcessVisitors(XDocument doc, IXmlVisitor visitor)
        {
            Stack <XNode> nodes = new Stack <XNode>();

            if (visitor.BeginFromProject)
            {
                nodes.Push(doc.Root);
            }
            else
            {
                foreach (XNode node in doc.Root.Nodes().Reverse())
                {
                    nodes.Push(node);
                }
            }

            while (nodes.Any())
            {
                XNode node      = nodes.Pop();
                bool  @continue = visitor.Visit(node);

                if (!@continue)
                {
                    continue;
                }

                if (node is XElement asElement)
                {
                    foreach (XNode child in asElement.Nodes().Reverse())
                    {
                        nodes.Push(child);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the abstract <see cref="XmlVisitorDecorator"/>
        /// class.
        /// </summary>
        /// <param name="decoratedVisitor"></param>
        protected XmlVisitorDecorator(IXmlVisitor decoratedVisitor)
        {
            if (decoratedVisitor == null)
            {
                throw new ArgumentNullException("decoratedVisitor");
            }

            DecoratedVisitor = decoratedVisitor;
        }
Example #3
0
        /// <summary>
        /// Adds XmlVisitor to the traverser.
        /// </summary>
        public void AddVisitor(IXmlVisitor visitor)
        {
            Preconditions.NotNull(visitor, "visitor");

            this.OnTraverseStart += visitor.TraverseStart;
            this.OnEnteringNode += visitor.EnteringNode;
            this.OnLeavingNode += visitor.LeavingNode;
            this.OnTraverseEnd += visitor.TraverseEnd;
        }
Example #4
0
        /// <summary>
        /// Adds XmlVisitor to the traverser.
        /// </summary>
        public void AddVisitor(IXmlVisitor visitor)
        {
            Preconditions.NotNull(visitor, "visitor");

            this.OnTraverseStart += visitor.TraverseStart;
            this.OnEnteringNode  += visitor.EnteringNode;
            this.OnLeavingNode   += visitor.LeavingNode;
            this.OnTraverseEnd   += visitor.TraverseEnd;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlTraverser"/> class.
        /// </summary>
        /// <param name="visitor">The <see cref="IXmlVisitor"/> passed into
        /// various nodes of the Xml.</param>
        /// <exception cref="ArgumentNullException">visitor is null.</exception>
        public XmlTraverser(IXmlVisitor visitor)
        {
            if (visitor == null)
            {
                throw new ArgumentNullException("visitor");
            }

            _visitor = visitor;
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PipelineXmlValidator"/>
        /// class.
        /// </summary>
        /// <param name="visitor">The <see cref="IXmlVisitor"/> this
        /// <see cref="XmlVisitorDecorate"/> decorates.</param>
        /// <param name="availableFactories">The set of available factory names for
        /// the nodes.</param>
        public PipelineXmlValidator(IXmlVisitor visitor, IEnumerable <string> availableFactories)
            : base(visitor)
        {
            if (availableFactories == null)
            {
                throw new ArgumentNullException("availableFactories");
            }

            _availableFactories = availableFactories;
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlValidatorArgs"/>
        /// class.
        /// </summary>
        /// <param name="visitor">The <see cref="IXmlVisitor"/> that is
        /// decorated by the validator.</param>
        /// <exception cref="ArgumentNullException">visitor is null.</exception>
        public XmlValidatorArgs(IXmlVisitor visitor)
        {
            if (visitor == null)
            {
                throw new ArgumentNullException("visitor");
            }

            Visitor      = visitor;
            ThrowOnError = false;
        }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefinitionXmlValidator"/>
 /// class.
 /// </summary>
 /// <param name="visitor">The <see cref="IXmlVisitor"/> this
 /// <see cref="XmlVisitorDecorate"/> decorates.</param>
 public DefinitionXmlValidator(IXmlVisitor visitor)
     : base(visitor)
 {
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JobXmlValidator"/> class.
 /// </summary>
 /// <param name="visitor">The <see cref="IXmlVisitor"/> this
 /// <see cref="XmlVisitorDecorate"/> decorates.</param>
 public JobXmlValidator(IXmlVisitor visitor)
     : base(visitor)
 {
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationVisitor"/>
 /// class.
 /// </summary>
 /// <param name="visitor">The <see cref="IXmlVisitor"/> that is called
 /// when nodes are validated correctly.</param>
 /// <exception cref="NullReferenceException">visitor is null.</exception>
 protected ValidationVisitor(IXmlVisitor visitor)
     : base(visitor)
 {
 }
Example #11
0
 public void Accept(IXmlVisitor visitor)
 {
     visitor.Visit(this);
 }