public void Reset() { if (!this.dontReset) { this.dontReset = true; if (this.hasCache) { XmlNodeType nodeType = this.reader.NodeType; if (nodeType == XmlNodeType.Text || nodeType == XmlNodeType.CDATA || nodeType == XmlNodeType.Whitespace || nodeType == XmlNodeType.SignificantWhitespace) { this.reader.Read(); } switch (this.state) { case XmlReaderBinarySupport.CommandState.ReadElementContentAsBase64: case XmlReaderBinarySupport.CommandState.ReadElementContentAsBinHex: this.reader.Read(); break; } } this.base64CacheStartsAt = -1; this.state = XmlReaderBinarySupport.CommandState.None; this.hasCache = false; this.dontReset = false; } }
private void CheckState(bool element, XmlReaderBinarySupport.CommandState action) { if (this.state == XmlReaderBinarySupport.CommandState.None) { if (this.textCache == null) { this.textCache = new StringBuilder(); } else { this.textCache.Length = 0; } if (action == XmlReaderBinarySupport.CommandState.None) { return; } if (this.reader.ReadState != ReadState.Interactive) { return; } XmlNodeType nodeType = this.reader.NodeType; switch (nodeType) { case XmlNodeType.Element: if (element) { if (!this.reader.IsEmptyElement) { this.reader.Read(); } this.state = action; return; } goto IL_C6; default: if (nodeType != XmlNodeType.Whitespace && nodeType != XmlNodeType.SignificantWhitespace) { goto IL_C6; } break; case XmlNodeType.Text: case XmlNodeType.CDATA: break; } if (!element) { this.state = action; return; } IL_C6: throw new XmlException((!element) ? "Reader is not positioned on a text node." : "Reader is not positioned on an element."); } else { if (this.state == action) { return; } throw this.StateError(action); } }
private InvalidOperationException StateError(XmlReaderBinarySupport.CommandState action) { return(new InvalidOperationException(string.Format("Invalid attempt to read binary content by {0}, while once binary reading was started by {1}", action, this.state))); }
public int ReadValueChunk(char[] buffer, int offset, int length) { XmlReaderBinarySupport.CommandState commandState = this.state; if (this.state == XmlReaderBinarySupport.CommandState.None) { this.CheckState(false, XmlReaderBinarySupport.CommandState.None); } if (offset < 0) { throw XmlReaderBinarySupport.CreateArgumentOutOfRangeException("offset", offset, "Offset must be non-negative integer."); } if (length < 0) { throw XmlReaderBinarySupport.CreateArgumentOutOfRangeException("length", length, "Length must be non-negative integer."); } if (buffer.Length < offset + length) { throw new ArgumentOutOfRangeException("buffer length is smaller than the sum of offset and length."); } if (length == 0) { return(0); } if (!this.hasCache && this.reader.IsEmptyElement) { return(0); } bool flag = true; while (flag && this.textCache.Length < length) { XmlNodeType nodeType = this.reader.NodeType; if (nodeType != XmlNodeType.Text && nodeType != XmlNodeType.CDATA && nodeType != XmlNodeType.Whitespace && nodeType != XmlNodeType.SignificantWhitespace) { flag = false; } else { if (this.hasCache) { XmlNodeType nodeType2 = this.reader.NodeType; if (nodeType2 != XmlNodeType.Text && nodeType2 != XmlNodeType.CDATA && nodeType2 != XmlNodeType.Whitespace && nodeType2 != XmlNodeType.SignificantWhitespace) { flag = false; } else { this.Read(); } } this.textCache.Append(this.reader.Value); this.hasCache = true; } } this.state = commandState; int num = this.textCache.Length; if (num > length) { num = length; } string text = this.textCache.ToString(0, num); this.textCache.Remove(0, text.Length); text.CopyTo(0, buffer, offset, text.Length); if (num < length && flag) { return(num + this.ReadValueChunk(buffer, offset + num, length - num)); } return(num); }