예제 #1
0
            public bool MoveNext()
            {
                while (!CurrentEnumerator.MoveNext())
                {
                    if (!MoveNextNode())
                    {
                        return(false);
                    }
                    OnMoveNextNode();
                }

                return(true);
            }
        private bool ReadNextNode()
        {
            // attributes must not be taken into account while enumerating nodes
            if (CurrentEnumerator is IEnumerator <IXmlAttributeBuilder> )
            {
                _nodeType = XmlNodeType.Element;
                _enumerators.RemoveLast();
            }

            // ensure child nodes are enumerated
            if (_nodeType == XmlNodeType.Element && CurrentNode.HasChildNodes())
            {
                _enumerators.AddLast(CurrentNode.GetChildNodes().GetConservativeEnumerator());
            }

            // loop so as to skip empty Text nodes
            while (CurrentEnumerator.MoveNext())
            {
                if (CurrentNode is IXmlElementBuilder)
                {
                    _nodeType = XmlNodeType.Element;
                    return(true);
                }
                if (CurrentNode is IXmlTextBuilder)
                {
                    if (!CurrentNode.Value.IsNullOrEmpty())
                    {
                        _nodeType = XmlNodeType.Text;
                        return(true);
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            _enumerators.RemoveLast();

            // a non-empty element ---its children have just been enumerated--- requires an extra Read() for the closing tag
            if (CurrentNode is IXmlElementBuilder)
            {
                _nodeType = XmlNodeType.EndElement;
                return(true);
            }

            _nodeType = XmlNodeType.None;
            return(false);
        }
 /// <summary>
 /// Parses the attribute value into one or more <see cref="XmlNodeType.Text"/>, <see
 /// cref="XmlNodeType.EntityReference"/>, or <see cref="XmlNodeType.EndEntity"/> nodes.
 /// </summary>
 /// <returns>
 /// <c>true</c> if there are nodes to return. <c>false</c> if the reader is not positioned on an attribute node
 /// when the initial call is made or if all the attribute values have been read. An empty attribute, such as,
 /// <c>misc=""</c>, returns <c>true</c>
 /// with a single node with a value of <c>String.Empty</c>.
 /// </returns>
 /// <remarks>
 /// Use this method after calling <see cref="MoveToAttribute(string)"/> to read through the text or entity
 /// reference nodes that make up the attribute value. The <see cref="XmlReader.Depth"/> of the attribute value
 /// nodes is one plus the depth of the attribute node; it increments and decrements by one when you step into and
 /// out of general entity references.
 /// </remarks>
 public override bool ReadAttributeValue()
 {
     if (CurrentNode is IXmlAttributeBuilder)
     {
         var enumerable = Enumerable.Repeat(new XmlTextBuilder {
             Value = CurrentNode.Value
         }, 1);
         _enumerators.AddLast(enumerable.GetConservativeEnumerator());
         CurrentEnumerator.MoveNext();
         _nodeType = XmlNodeType.Text;
         return(true);
     }
     _enumerators.RemoveLast();
     return(false);
 }
예제 #4
0
        public bool MoveNext()
        {
            if (CurrentEnumerator.MoveNext())
            {
                return(true);
            }
            if (_index + 1 == _enumerators.Length)
            {
                return(false);
            }

            _index++;

            return(CurrentEnumerator.MoveNext());
        }
 /// <summary>
 /// Moves to the next attribute.
 /// </summary>
 /// <returns>
 /// <c>true</c> if there is a next attribute; <c>false</c> if there are no more attributes.
 /// </returns>
 /// <remarks>
 /// If the current node is an element node, this method is equivalent to <see cref="MoveToFirstAttribute"/>. If
 /// <see cref="MoveToNextAttribute"/> returns <c>true</c>, the reader moves to the next attribute; otherwise, the
 /// position of the reader does not change.
 /// </remarks>
 public override bool MoveToNextAttribute()
 {
     if (CurrentNode is IXmlTextBuilder && ParentNode is IXmlAttributeBuilder)
     {
         _enumerators.RemoveLast();
     }
     if (CurrentNode is IXmlElementBuilder && CurrentNode.HasAttributes())
     {
         _enumerators.AddLast(CurrentNode.GetAttributes().GetConservativeEnumerator());
     }
     if (CurrentEnumerator is IEnumerator <IXmlAttributeBuilder> && CurrentEnumerator.MoveNext())
     {
         _nodeType = XmlNodeType.Attribute;
         return(true);
     }
     return(false);
 }
예제 #6
0
        public override void Update(DwarfTime gameTime)
        {
            CompositeLibrary.Update();
            MainWindow.LocalBounds = new Rectangle(EdgePadding, EdgePadding, Game.GraphicsDevice.Viewport.Width - EdgePadding * 2, Game.GraphicsDevice.Viewport.Height - EdgePadding * 2);
            Input.Update();
            GUI.Update(gameTime);

            if (CurrentAction != null)
            {
                if (CurrentCoroutine == null)
                {
                    CurrentCoroutine  = CurrentAction.Action();
                    CurrentEnumerator = CurrentCoroutine.GetEnumerator();
                }

                if (CurrentCoroutine != null)
                {
                    SpeechNode node = CurrentEnumerator.Current;

                    if (node != null)
                    {
                        Transition(node);
                        CurrentCoroutine = null;
                        CurrentAction    = null;
                    }
                    else
                    {
                        if (!CurrentEnumerator.MoveNext())
                        {
                            CurrentCoroutine  = null;
                            CurrentAction     = null;
                            CurrentEnumerator = null;
                            Transition(DialougeTree);
                        }
                    }
                }
            }

            base.Update(gameTime);
        }
예제 #7
0
            protected override void OnMoveNextNode()
            {
                base.OnMoveNextNode();

                CurrentEnumerator.MoveNext();   // Пропуск первой станции, т.к. она уже была в конце предыдущего маршрута
            }
        private string ReadNextNode()
        {
            if (CurrentEnumerator.MoveNext())
            {
                if (CurrentNode is IXmlAttributeBuilder)
                {
                    return(CurrentNode.Prefix.IsNullOrEmpty()
                                                ? string.Format(" {0}=\"{1}\"", CurrentNode.LocalName, CurrentNode.Value)
                                                : string.Format(" {0}:{1}=\"{2}\"", CurrentNode.Prefix, CurrentNode.LocalName, CurrentNode.Value));
                }
                if (CurrentNode is IXmlElementBuilder)
                {
                    if (CurrentNode.HasAttributes())
                    {
                        var result = CurrentNode.Prefix.IsNullOrEmpty()
                                                        ? string.Format("<{0}", CurrentNode.LocalName)
                                                        : string.Format("<{0}:{1}", CurrentNode.Prefix, CurrentNode.LocalName);
                        _enumerators.AddLast(CurrentNode.GetAttributes().GetConservativeEnumerator());
                        return(result);
                    }

                    if (CurrentNode.HasChildNodes())
                    {
                        var result = CurrentNode.Prefix.IsNullOrEmpty()
                                                        ? string.Format("<{0}>", CurrentNode.LocalName)
                                                        : string.Format("<{0}:{1}>", CurrentNode.Prefix, CurrentNode.LocalName);
                        _enumerators.AddLast(CurrentNode.GetChildNodes().GetConservativeEnumerator());
                        return(result);
                    }
                    return(CurrentNode.Prefix.IsNullOrEmpty()
                                                ? string.Format("<{0} />", CurrentNode.LocalName)
                                                : string.Format("<{0}:{1} />", CurrentNode.Prefix, CurrentNode.LocalName));
                }
                if (CurrentNode is IXmlTextBuilder)
                {
                    return(CurrentNode.Value);
                }
                throw new NotImplementedException();
            }

            if (CurrentNode is IXmlAttributeBuilder)
            {
                _enumerators.RemoveLast();
                if (CurrentNode.HasChildNodes())
                {
                    _enumerators.AddLast(CurrentNode.GetChildNodes().GetConservativeEnumerator());
                    return(">");
                }
                return(" />");
            }

            _enumerators.RemoveLast();

            if (CurrentNode is IXmlElementBuilder)
            {
                return(CurrentNode.Prefix.IsNullOrEmpty()
                                        ? string.Format("</{0}>", CurrentNode.LocalName)
                                        : string.Format("</{0}:{1}>", CurrentNode.Prefix, CurrentNode.LocalName));
            }

            return(null);
        }
예제 #9
0
 public void Reset()
 {
     _index = 0;
     CurrentEnumerator.Reset();
 }