/// <summary> /// read the m2:count tag in the feed /// </summary> private void ReadCountValue() { Debug.Assert(this.countValue == CountStateInitial, "Count value is not in the initial state"); if (this.materializer.CurrentFeed != null && this.materializer.CurrentFeed.Count.HasValue) { this.countValue = this.materializer.CurrentFeed.Count.Value; return; } // find the first element tag while (this.reader.NodeType != XmlNodeType.Element && this.reader.Read()) { } if (this.reader.EOF) { throw new InvalidOperationException(Strings.MaterializeFromAtom_CountNotPresent); } // the tag Should only be <feed> or <links> tag: Debug.Assert( (Util.AreSame(XmlConstants.AtomNamespace, this.reader.NamespaceURI) && Util.AreSame(XmlConstants.AtomFeedElementName, this.reader.LocalName)) || (Util.AreSame(XmlConstants.DataWebNamespace, this.reader.NamespaceURI) && Util.AreSame(XmlConstants.LinkCollectionElementName, this.reader.LocalName)), "<feed> or <links> tag expected"); // Create the XElement for look-ahead // DEVNOTE([....]): // This is not streaming friendly! XElement element = XElement.Load(this.reader); this.reader.Close(); // Read the count value from the xelement XElement countNode = element.Descendants(XNamespace.Get(XmlConstants.DataWebMetadataNamespace) + XmlConstants.RowCountElement).FirstOrDefault(); if (countNode == null) { throw new InvalidOperationException(Strings.MaterializeFromAtom_CountNotPresent); } else { if (!long.TryParse(countNode.Value, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out this.countValue)) { throw new FormatException(Strings.MaterializeFromAtom_CountFormatError); } if (this.countValue < 0) { throw new FormatException(Strings.MaterializeFromAtom_CountFormatError); } } this.reader = new System.Data.Services.Client.Xml.XmlAtomErrorReader(element.CreateReader()); this.parser.ReplaceReader(this.reader); }
private static AtomDataKind ParseStateForReader(XmlReader reader) { Debug.Assert(reader != null, "reader != null"); Debug.Assert( reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement, "reader.NodeType == XmlNodeType.Element || EndElement -- otherwise can't determine"); AtomDataKind result = AtomDataKind.Custom; string elementName = reader.LocalName; string namespaceURI = reader.NamespaceURI; if (Util.AreSame(XmlConstants.AtomNamespace, namespaceURI)) { if (Util.AreSame(XmlConstants.AtomEntryElementName, elementName)) { result = AtomDataKind.Entry; } else if (Util.AreSame(XmlConstants.AtomFeedElementName, elementName)) { result = AtomDataKind.Feed; } else if (Util.AreSame(XmlConstants.AtomLinkElementName, elementName) && Util.AreSame(XmlConstants.AtomLinkNextAttributeString, reader.GetAttribute(XmlConstants.AtomLinkRelationAttributeName))) { result = AtomDataKind.PagingLinks; } } else if (Util.AreSame(XmlConstants.DataWebMetadataNamespace, namespaceURI)) { if (Util.AreSame(XmlConstants.RowCountElement, elementName)) { result = AtomDataKind.FeedCount; } } return(result); }