Esempio n. 1
0
 //Private methods
 internal void SetToReplayMode()
 {
     _cacheState          = CachingReaderState.Replay;
     _currentContentIndex = 0;
     _currentAttrIndex    = -1;
     Read(); //Position on first node recorded to begin replaying
 }
Esempio n. 2
0
        public override void Skip()
        {
            switch (this.cachedNode.NodeType)
            {
            case XmlNodeType.Element:
                break;

            case XmlNodeType.Attribute:
                this.MoveToElement();
                break;

            default:
                this.Read();
                return;
            }
            if ((this.coreReader.NodeType != XmlNodeType.EndElement) && !this.readAhead)
            {
                int num = this.coreReader.Depth - 1;
                while (this.coreReader.Read() && (this.coreReader.Depth > num))
                {
                }
            }
            this.coreReader.Read();
            this.cacheState = CachingReaderState.ReaderClosed;
            this.cacheHandler(this);
        }
Esempio n. 3
0
        // Skips to the end tag of the current element.
        public override void Skip()
        {
            //Skip on caching reader should move to the end of the subtree, past all cached events
            switch (_cachedNode.NodeType)
            {
            case XmlNodeType.Element:
                if (_coreReader.NodeType != XmlNodeType.EndElement && !_readAhead)
                {     //will be true for IsDefault cases where we peek only one node ahead
                    int startDepth = _coreReader.Depth - 1;
                    while (_coreReader.Read() && _coreReader.Depth > startDepth)
                    {
                        ;
                    }
                }
                _coreReader.Read();
                _cacheState = CachingReaderState.ReaderClosed;
                _cacheHandler(this);
                break;

            case XmlNodeType.Attribute:
                MoveToElement();
                goto case XmlNodeType.Element;

            default:
                Debug.Assert(_cacheState == CachingReaderState.Replay);
                Read();
                break;
            }
        }
Esempio n. 4
0
 internal void SetToReplayMode()
 {
     this.cacheState          = CachingReaderState.Replay;
     this.currentContentIndex = 0;
     this.currentAttrIndex    = -1;
     this.Read();
 }
 private void Init() {
     coreReaderNameTable = coreReader.NameTable;
     cacheState = CachingReaderState.Init;
     contentIndex = 0;
     currentAttrIndex = -1;
     currentContentIndex = -1;
     attributeCount = 0;
     cachedNode = null;
     readAhead = false;
     //Initialize the cachingReader with start state
     if (coreReader.NodeType == XmlNodeType.Element) {
         ValidatingReaderNodeData element = AddContent(coreReader.NodeType);
         element.SetItemData(coreReader.LocalName, coreReader.Prefix, coreReader.NamespaceURI, coreReader.Depth);  //Only created for element node type
         element.SetLineInfo(lineInfo);
         RecordAttributes();
     }
 }
Esempio n. 6
0
 private void Init()
 {
     this.coreReaderNameTable = this.coreReader.NameTable;
     this.cacheState          = CachingReaderState.Init;
     this.contentIndex        = 0;
     this.currentAttrIndex    = -1;
     this.currentContentIndex = -1;
     this.attributeCount      = 0;
     this.cachedNode          = null;
     this.readAhead           = false;
     if (this.coreReader.NodeType == XmlNodeType.Element)
     {
         ValidatingReaderNodeData data = this.AddContent(this.coreReader.NodeType);
         data.SetItemData(this.coreReader.LocalName, this.coreReader.Prefix, this.coreReader.NamespaceURI, this.coreReader.Depth);
         data.SetLineInfo(this.lineInfo);
         this.RecordAttributes();
     }
 }
Esempio n. 7
0
 private void Init()
 {
     _coreReaderNameTable = _coreReader.NameTable;
     _cacheState          = CachingReaderState.Init;
     _contentIndex        = 0;
     _currentAttrIndex    = -1;
     _currentContentIndex = -1;
     _attributeCount      = 0;
     _cachedNode          = null;
     _readAhead           = false;
     //Initialize the cachingReader with start state
     if (_coreReader.NodeType == XmlNodeType.Element)
     {
         ValidatingReaderNodeData element = AddContent(_coreReader.NodeType);
         element.SetItemData(_coreReader.LocalName, _coreReader.Prefix, _coreReader.NamespaceURI, _coreReader.Depth);  //Only created for element node type
         element.SetLineInfo(_lineInfo);
         RecordAttributes();
     }
 }
Esempio n. 8
0
        // Reads the next node from the stream/TextReader.
        public override bool Read()
        {
            switch (_cacheState)
            {
            case CachingReaderState.Init:
                _cacheState = CachingReaderState.Record;
                goto case CachingReaderState.Record;

            case CachingReaderState.Record:
                ValidatingReaderNodeData recordedNode = null;
                if (_coreReader.Read())
                {
                    switch (_coreReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        //Dont record element within the content of a union type since the main reader will break on this and the underlying coreReader will be positioned on this node
                        _cacheState = CachingReaderState.ReaderClosed;
                        return(false);

                    case XmlNodeType.EndElement:
                        recordedNode = AddContent(_coreReader.NodeType);
                        recordedNode.SetItemData(_coreReader.LocalName, _coreReader.Prefix, _coreReader.NamespaceURI, _coreReader.Depth);          //Only created for element node type
                        recordedNode.SetLineInfo(_lineInfo);
                        break;

                    case XmlNodeType.Comment:
                    case XmlNodeType.ProcessingInstruction:
                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        recordedNode = AddContent(_coreReader.NodeType);
                        recordedNode.SetItemData(_coreReader.Value);
                        recordedNode.SetLineInfo(_lineInfo);
                        recordedNode.Depth = _coreReader.Depth;
                        break;

                    default:
                        break;
                    }
                    _cachedNode = recordedNode;
                    return(true);
                }
                else
                {
                    _cacheState = CachingReaderState.ReaderClosed;
                    return(false);
                }

            case CachingReaderState.Replay:
                if (_currentContentIndex >= _contentIndex)
                {     //When positioned on the last cached node, switch back as the underlying coreReader is still positioned on this node
                    _cacheState = CachingReaderState.ReaderClosed;
                    _cacheHandler(this);
                    if (_coreReader.NodeType != XmlNodeType.Element || _readAhead)
                    {     //Only when coreReader not positioned on Element node, read ahead, otherwise it is on the next element node already, since this was not cached
                        return(_coreReader.Read());
                    }
                    return(true);
                }
                _cachedNode = _contentEvents[_currentContentIndex];
                if (_currentContentIndex > 0)
                {
                    ClearAttributesInfo();
                }
                _currentContentIndex++;
                return(true);

            default:
                return(false);
            }
        }
//Private methods
        internal void SetToReplayMode() {
            cacheState = CachingReaderState.Replay;
            currentContentIndex = 0;
            currentAttrIndex = -1;
            Read(); //Position on first node recorded to begin replaying
        }
        // Skips to the end tag of the current element.
        public override void Skip() {
            //Skip on caching reader should move to the end of the subtree, past all cached events
            switch (cachedNode.NodeType) {
                case XmlNodeType.Element:
                    if (coreReader.NodeType != XmlNodeType.EndElement && !readAhead) { //will be true for IsDefault cases where we peek only one node ahead
                        int startDepth = coreReader.Depth - 1;
                        while (coreReader.Read() && coreReader.Depth > startDepth) 
                        ;
                    }
                    coreReader.Read();
                    cacheState = CachingReaderState.ReaderClosed;
                    cacheHandler(this);
                    break;
    
                case XmlNodeType.Attribute:
                    MoveToElement();
                    goto case XmlNodeType.Element;

                default:
                    Debug.Assert(cacheState == CachingReaderState.Replay);
                    Read();
                    break;
            }
        }
 // Closes the stream, changes the ReadState to Closed, and sets all the properties back to zero.
 public override void Close() {
     coreReader.Close();
     cacheState = CachingReaderState.ReaderClosed;
 }
        // Reads the next node from the stream/TextReader.
        public override bool Read() {
            switch (cacheState) {
                case CachingReaderState.Init:
                    cacheState = CachingReaderState.Record;
                    goto case CachingReaderState.Record;

                case CachingReaderState.Record: 
                    ValidatingReaderNodeData recordedNode = null;
                    if (coreReader.Read()) {
                        switch(coreReader.NodeType) {
                            case XmlNodeType.Element:
                                //Dont record element within the content of a union type since the main reader will break on this and the underlying coreReader will be positioned on this node
                                cacheState = CachingReaderState.ReaderClosed;
                                return false;

                            case XmlNodeType.EndElement:
                                recordedNode = AddContent(coreReader.NodeType);
                                recordedNode.SetItemData(coreReader.LocalName, coreReader.Prefix, coreReader.NamespaceURI, coreReader.Depth);  //Only created for element node type
                                recordedNode.SetLineInfo(lineInfo);
                                break;

                            case XmlNodeType.Comment:
                            case XmlNodeType.ProcessingInstruction:
                            case XmlNodeType.Text:
                            case XmlNodeType.Whitespace:
                            case XmlNodeType.SignificantWhitespace:
                                recordedNode = AddContent(coreReader.NodeType);
                                recordedNode.SetItemData(coreReader.Value);
                                recordedNode.SetLineInfo(lineInfo);
                                recordedNode.Depth = coreReader.Depth;
                                break;

                            default:
                                break;       
                        }
                        cachedNode = recordedNode;
                        return true;    
                    }
                    else {
                        cacheState = CachingReaderState.ReaderClosed;
                        return false;
                    }    

                case CachingReaderState.Replay:
                    if (currentContentIndex >= contentIndex) { //When positioned on the last cached node, switch back as the underlying coreReader is still positioned on this node
                        cacheState = CachingReaderState.ReaderClosed;
                        cacheHandler(this);
                        if (coreReader.NodeType != XmlNodeType.Element || readAhead) { //Only when coreReader not positioned on Element node, read ahead, otherwise it is on the next element node already, since this was not cached
                            return coreReader.Read();
                        }
                        return true;                        
                    }
                    cachedNode = contentEvents[currentContentIndex];
                    if (currentContentIndex > 0) {
                        ClearAttributesInfo();
                    }
                    currentContentIndex++;
                    return true;

                default:
                    return false;
            }
        }
 private void Init()
 {
     this.coreReaderNameTable = this.coreReader.NameTable;
     this.cacheState = CachingReaderState.Init;
     this.contentIndex = 0;
     this.currentAttrIndex = -1;
     this.currentContentIndex = -1;
     this.attributeCount = 0;
     this.cachedNode = null;
     this.readAhead = false;
     if (this.coreReader.NodeType == XmlNodeType.Element)
     {
         ValidatingReaderNodeData data = this.AddContent(this.coreReader.NodeType);
         data.SetItemData(this.coreReader.LocalName, this.coreReader.Prefix, this.coreReader.NamespaceURI, this.coreReader.Depth);
         data.SetLineInfo(this.lineInfo);
         this.RecordAttributes();
     }
 }
Esempio n. 14
0
 public override void Close()
 {
     this.coreReader.Close();
     this.cacheState = CachingReaderState.ReaderClosed;
 }
Esempio n. 15
0
 // Closes the stream, changes the ReadState to Closed, and sets all the properties back to zero.
 public override void Close()
 {
     _coreReader.Close();
     _cacheState = CachingReaderState.ReaderClosed;
 }
Esempio n. 16
0
        public override bool Read()
        {
            switch (this.cacheState)
            {
            case CachingReaderState.Init:
                this.cacheState = CachingReaderState.Record;
                break;

            case CachingReaderState.Record:
                break;

            case CachingReaderState.Replay:
                if (this.currentContentIndex < this.contentIndex)
                {
                    this.cachedNode = this.contentEvents[this.currentContentIndex];
                    if (this.currentContentIndex > 0)
                    {
                        this.ClearAttributesInfo();
                    }
                    this.currentContentIndex++;
                    return(true);
                }
                this.cacheState = CachingReaderState.ReaderClosed;
                this.cacheHandler(this);
                return(((this.coreReader.NodeType == XmlNodeType.Element) && !this.readAhead) || this.coreReader.Read());

            default:
                return(false);
            }
            ValidatingReaderNodeData data = null;

            if (!this.coreReader.Read())
            {
                this.cacheState = CachingReaderState.ReaderClosed;
                return(false);
            }
            switch (this.coreReader.NodeType)
            {
            case XmlNodeType.Element:
                this.cacheState = CachingReaderState.ReaderClosed;
                return(false);

            case XmlNodeType.Text:
            case XmlNodeType.CDATA:
            case XmlNodeType.ProcessingInstruction:
            case XmlNodeType.Comment:
            case XmlNodeType.Whitespace:
            case XmlNodeType.SignificantWhitespace:
                data = this.AddContent(this.coreReader.NodeType);
                data.SetItemData(this.coreReader.Value);
                data.SetLineInfo(this.lineInfo);
                data.Depth = this.coreReader.Depth;
                break;

            case XmlNodeType.EndElement:
                data = this.AddContent(this.coreReader.NodeType);
                data.SetItemData(this.coreReader.LocalName, this.coreReader.Prefix, this.coreReader.NamespaceURI, this.coreReader.Depth);
                data.SetLineInfo(this.lineInfo);
                break;
            }
            this.cachedNode = data;
            return(true);
        }
        public override void Skip()
        {
            switch (this.cachedNode.NodeType)
            {
                case XmlNodeType.Element:
                    break;

                case XmlNodeType.Attribute:
                    this.MoveToElement();
                    break;

                default:
                    this.Read();
                    return;
            }
            if ((this.coreReader.NodeType != XmlNodeType.EndElement) && !this.readAhead)
            {
                int num = this.coreReader.Depth - 1;
                while (this.coreReader.Read() && (this.coreReader.Depth > num))
                {
                }
            }
            this.coreReader.Read();
            this.cacheState = CachingReaderState.ReaderClosed;
            this.cacheHandler(this);
        }
 internal void SetToReplayMode()
 {
     this.cacheState = CachingReaderState.Replay;
     this.currentContentIndex = 0;
     this.currentAttrIndex = -1;
     this.Read();
 }
        public override bool Read()
        {
            switch (this.cacheState)
            {
                case CachingReaderState.Init:
                    this.cacheState = CachingReaderState.Record;
                    break;

                case CachingReaderState.Record:
                    break;

                case CachingReaderState.Replay:
                    if (this.currentContentIndex < this.contentIndex)
                    {
                        this.cachedNode = this.contentEvents[this.currentContentIndex];
                        if (this.currentContentIndex > 0)
                        {
                            this.ClearAttributesInfo();
                        }
                        this.currentContentIndex++;
                        return true;
                    }
                    this.cacheState = CachingReaderState.ReaderClosed;
                    this.cacheHandler(this);
                    return (((this.coreReader.NodeType == XmlNodeType.Element) && !this.readAhead) || this.coreReader.Read());

                default:
                    return false;
            }
            ValidatingReaderNodeData data = null;
            if (!this.coreReader.Read())
            {
                this.cacheState = CachingReaderState.ReaderClosed;
                return false;
            }
            switch (this.coreReader.NodeType)
            {
                case XmlNodeType.Element:
                    this.cacheState = CachingReaderState.ReaderClosed;
                    return false;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.Comment:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    data = this.AddContent(this.coreReader.NodeType);
                    data.SetItemData(this.coreReader.Value);
                    data.SetLineInfo(this.lineInfo);
                    data.Depth = this.coreReader.Depth;
                    break;

                case XmlNodeType.EndElement:
                    data = this.AddContent(this.coreReader.NodeType);
                    data.SetItemData(this.coreReader.LocalName, this.coreReader.Prefix, this.coreReader.NamespaceURI, this.coreReader.Depth);
                    data.SetLineInfo(this.lineInfo);
                    break;
            }
            this.cachedNode = data;
            return true;
        }