public async Task ImportXmlAsync(XmlReader reader) { if (!reader.IsBeginTag("CLAIM")) { await reader.ReadBeginTagAsync("CLAIM"); } Type = reader.GetRequiredAttribute("type"); Value = reader.GetRequiredAttribute("value"); }
public void ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } reader.MoveToRequiredStartElement(AuthorizationConstants.Elements.Match); this.ClaimType = reader.GetOptionalAttribute(AuthorizationConstants.Attributes.ClaimType); this.Type = new Uri(reader.GetRequiredAttribute(AuthorizationConstants.Attributes.Type)); string required = reader.GetOptionalAttribute(AuthorizationConstants.Attributes.Required); if (string.IsNullOrEmpty(required)) { this.Required = true; } else { this.Required = XmlConvert.ToBoolean(required); } this.Value = reader.GetElementValue(AuthorizationConstants.Elements.Match); if (!reader.IsRequiredEndElement(AuthorizationConstants.Elements.Match)) { throw new SerializationException(String.Format("Unexpected element {0}", reader.LocalName)); } }
/// <summary> /// Reads messages asynchronously. /// </summary> /// <param name="reader"> /// The reader. /// </param> /// <returns> /// The messages. /// </returns> internal static async Task <ReadOnlyCollection <Message> > ReadMessagesAsync(XmlReader reader) { var messages = new List <Message>(); if (await reader.MoveToDocumentElementAsync("response").ConfigureAwait(false)) { await reader.ReadAsync().ConfigureAwait(false); reader.EnsureMarkup(XmlNodeType.Element, "messages"); await reader.ReadAsync().ConfigureAwait(false); while (reader.NodeType == XmlNodeType.Element && reader.Name == "msg") { var name = reader.GetRequiredAttribute("type"); var type = EnumConverter <MessageType> .Instance.Convert(name); var text = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); messages.Add(new Message(type, text)); } reader.EnsureMarkup(XmlNodeType.EndElement, "messages"); } return(new ReadOnlyCollection <Message>(messages)); }
public async Task ImportXmlAsync(XmlReader reader) { if (!reader.IsBeginTag(ROLE_TAG)) { await reader.ReadBeginTagAsync(ROLE_TAG); } Name = reader.GetRequiredAttribute("name"); bool bvalue; if (bool.TryParse(reader.GetAttribute("is_default"), out bvalue)) { IsDefault = bvalue; } if (bool.TryParse(reader.GetAttribute("is_locked"), out bvalue)) { IsLocked = bvalue; } while (await reader.ReadNextTagAsync(ROLE_TAG)) { if (reader.IsBeginTag(CLAIMS_TAG)) { while (await reader.ReadNextTagAsync(CLAIMS_TAG)) { if (reader.IsBeginTag(CLAIM_TAG)) { var claim = new XmlClaim(); await claim.ImportXmlAsync(reader); Claims.Add(claim); } } } } }
/// <summary> /// Asynchronously reads data into the current /// <see cref="SearchResultStream"/>. /// </summary> /// <param name="reader"> /// The <see cref="XmlReader"/> from which to read. /// </param> /// <returns> /// A <see cref="Task"/> representing the operation. /// </returns> public async Task ReadXmlAsync(XmlReader reader) { var fieldNames = new List <string>(); this.FieldNames = new ReadOnlyCollection <string>(fieldNames); this.IsFinal = true; if (!await reader.MoveToDocumentElementAsync("results").ConfigureAwait(false)) { return; } string preview = reader.GetRequiredAttribute("preview"); this.IsFinal = !BooleanConverter.Instance.Convert(preview); if (!await reader.ReadAsync().ConfigureAwait(false)) { return; } reader.EnsureMarkup(XmlNodeType.Element, "meta"); await reader.ReadAsync().ConfigureAwait(false); reader.EnsureMarkup(XmlNodeType.Element, "fieldOrder"); if (reader.IsEmptyElement) { await reader.ReadAsync().ConfigureAwait(false); reader.EnsureMarkup(XmlNodeType.EndElement, "meta"); await reader.ReadAsync().ConfigureAwait(false); } else { await reader.ReadEachDescendantAsync("field", async (r) => { await r.ReadAsync().ConfigureAwait(false); var fieldName = await r.ReadContentAsStringAsync().ConfigureAwait(false); fieldNames.Add(fieldName); }).ConfigureAwait(false); await reader.ReadEndElementSequenceAsync("fieldOrder", "meta").ConfigureAwait(false); } if (reader.NodeType == XmlNodeType.Element && reader.Name == "messages") { //// Skip messages await reader.ReadEachDescendantAsync("msg", (r) => { return(Task.FromResult(true)); }).ConfigureAwait(false); reader.EnsureMarkup(XmlNodeType.EndElement, "messages"); await reader.ReadAsync().ConfigureAwait(false); } }
/// <summary> /// Reads the Xml of a scope transform. /// </summary> /// <param name="reader">An XmlReader for a scope transform.</param> public override void ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } reader.MoveToRequiredStartElement(AuthorizationConstants.Elements.Transform); this.Type = new Uri(reader.GetRequiredAttribute(AuthorizationConstants.Attributes.Type)); while (reader.Read()) { if (reader.IsRequiredStartElement(AuthorizationConstants.Elements.Match)) { this.MatchExpression = Match.Load(reader); } if (reader.IsRequiredStartElement(AuthorizationConstants.Elements.TargetClaim)) { this.TargetClaim = new LiteralClaim(); this.TargetClaim.ClaimType = reader.GetRequiredAttribute(AuthorizationConstants.Attributes.ClaimType); if (!reader.IsEmptyElement) { this.TargetClaim.ClaimValue = reader.GetElementValue(AuthorizationConstants.Elements.TargetClaim); } } if (reader.LocalName == AuthorizationConstants.Elements.Rule || reader.LocalName == AuthorizationConstants.Elements.LogicalAnd || reader.LocalName == AuthorizationConstants.Elements.LogicalOr) { this.Expression = Term.Load(reader); } if (reader.IsRequiredEndElement(AuthorizationConstants.Elements.Transform)) { break; } } }
/// <summary> /// Reads the Xml of an operation. /// </summary> /// <param name="reader">An XmlReader for the operation.</param> public void ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } reader.MoveToRequiredStartElement(AuthorizationConstants.Elements.Operation); this._operationType = new Uri(reader.GetRequiredAttribute(AuthorizationConstants.Attributes.Type)); this._claimValue = reader.GetElementValue(AuthorizationConstants.Elements.Operation); if (!reader.IsRequiredEndElement(AuthorizationConstants.Elements.Operation)) { throw new SerializationException("Unexpected element " + reader.LocalName); } }
/// <summary> /// Asynchronously reads XML data into the current <see cref="AtomEntry"/>. /// </summary> /// <exception cref="InvalidDataException"> /// Thrown when an Invalid Data error condition occurs. /// </exception> /// <param name="reader"> /// The reader from which to read. /// </param> /// <returns> /// A <see cref="Task"/> representing the operation. /// </returns> public async Task ReadXmlAsync(XmlReader reader) { Contract.Requires<ArgumentNullException>(reader != null, "reader"); this.Author = null; this.Content = null; this.Id = null; this.Links = null; this.Published = DateTime.MinValue; this.Title = null; this.Updated = DateTime.MinValue; reader.Requires(await reader.MoveToDocumentElementAsync("entry")); Dictionary<string, Uri> links = null; await reader.ReadAsync(); while (reader.NodeType == XmlNodeType.Element) { string name = reader.Name; switch (name) { case "title": this.Title = await reader.ReadElementContentAsync(StringConverter.Instance); break; case "id": this.Id = await reader.ReadElementContentAsync(UriConverter.Instance); break; case "author": await reader.ReadAsync(); reader.EnsureMarkup(XmlNodeType.Element, "name"); this.Author = await reader.ReadElementContentAsync(StringConverter.Instance); reader.EnsureMarkup(XmlNodeType.EndElement, "author"); await reader.ReadAsync(); break; case "published": this.Published = await reader.ReadElementContentAsync(DateTimeConverter.Instance); break; case "updated": this.Updated = await reader.ReadElementContentAsync(DateTimeConverter.Instance); break; case "link": if (links == null) { links = new Dictionary<string, Uri>(); } var href = reader.GetRequiredAttribute("href"); var rel = reader.GetRequiredAttribute("rel"); links[rel] = UriConverter.Instance.Convert(href); await reader.ReadAsync(); break; case "content": this.Content = await ParsePropertyValueAsync(reader, 0); break; default: throw new InvalidDataException(); // TODO: Diagnostics : unexpected start tag } } reader.EnsureMarkup(XmlNodeType.EndElement, "entry"); await reader.ReadAsync(); if (links != null) { this.Links = new ReadOnlyDictionary<string, Uri>(links); } }
/// <summary> /// Asynchronously reads XML data into the current <see cref="AtomEntry"/>. /// </summary> /// <exception cref="InvalidDataException"> /// Thrown when an Invalid Data error condition occurs. /// </exception> /// <param name="reader"> /// The reader from which to read. /// </param> /// <returns> /// A <see cref="Task"/> representing the operation. /// </returns> public async Task ReadXmlAsync(XmlReader reader) { Contract.Requires <ArgumentNullException>(reader != null, "reader"); this.Author = null; this.Content = null; this.Id = null; this.Links = null; this.Published = DateTime.MinValue; this.Title = null; this.Updated = DateTime.MinValue; reader.Requires(await reader.MoveToDocumentElementAsync("entry").ConfigureAwait(false)); Dictionary <string, Uri> links = null; await reader.ReadAsync().ConfigureAwait(false); while (reader.NodeType == XmlNodeType.Element) { string name = reader.Name; switch (name) { case "title": this.Title = await reader.ReadElementContentAsync(StringConverter.Instance).ConfigureAwait(false); break; case "id": this.Id = await reader.ReadElementContentAsync(UriConverter.Instance).ConfigureAwait(false); break; case "author": await reader.ReadAsync().ConfigureAwait(false); reader.EnsureMarkup(XmlNodeType.Element, "name"); this.Author = await reader.ReadElementContentAsync(StringConverter.Instance).ConfigureAwait(false); reader.EnsureMarkup(XmlNodeType.EndElement, "author"); await reader.ReadAsync().ConfigureAwait(false); break; case "published": this.Published = await reader.ReadElementContentAsync(DateTimeConverter.Instance).ConfigureAwait(false); break; case "updated": this.Updated = await reader.ReadElementContentAsync(DateTimeConverter.Instance).ConfigureAwait(false); break; case "link": if (links == null) { links = new Dictionary <string, Uri>(); } var href = reader.GetRequiredAttribute("href"); var rel = reader.GetRequiredAttribute("rel"); links[rel] = UriConverter.Instance.Convert(href); await reader.ReadAsync().ConfigureAwait(false); break; case "content": this.Content = await ParsePropertyValueAsync(reader, 0).ConfigureAwait(false); break; default: throw new InvalidDataException(); // TODO: Diagnostics : unexpected start tag } } reader.EnsureMarkup(XmlNodeType.EndElement, "entry"); await reader.ReadAsync().ConfigureAwait(false); if (links != null) { this.Links = new ReadOnlyDictionary <string, Uri>(links); } }
/// <summary> /// Asynchronously reads XML data into the current <see cref="AtomFeed"/>. /// </summary> /// <exception cref="InvalidDataException"> /// Thrown when an Invalid Data error condition occurs. /// </exception> /// <param name="reader"> /// The reader from which to read. /// </param> /// <returns> /// A <see cref="Task"/> representing the operation. /// </returns> public async Task ReadXmlAsync(XmlReader reader) { Contract.Requires <ArgumentNullException>(reader != null, "reader"); this.Author = null; this.Entries = null; this.GeneratorVersion = null; this.Id = null; this.Links = null; this.Messages = null; this.Pagination = Pagination.None; this.Title = null; this.Updated = DateTime.MinValue; reader.Requires(await reader.MoveToDocumentElementAsync("feed").ConfigureAwait(false)); var documentElementName = reader.Name; List <AtomEntry> entries = null; Dictionary <string, Uri> links = null; List <Message> messages = null; await reader.ReadAsync().ConfigureAwait(false); while (reader.NodeType == XmlNodeType.Element) { string name = reader.Name; switch (name) { case "title": this.Title = await reader.ReadElementContentAsync(StringConverter.Instance).ConfigureAwait(false); break; case "id": this.Id = await reader.ReadElementContentAsync(UriConverter.Instance).ConfigureAwait(false); break; case "author": await reader.ReadAsync().ConfigureAwait(false); reader.EnsureMarkup(XmlNodeType.Element, "name"); this.Author = await reader.ReadElementContentAsync(StringConverter.Instance).ConfigureAwait(false); reader.EnsureMarkup(XmlNodeType.EndElement, "author"); await reader.ReadAsync().ConfigureAwait(false); break; case "generator": // string build = reader.GetRequiredAttribute("build"); // TODO: Incorporate build number? Build number sometimes adds a fifth digit. string version = reader.GetRequiredAttribute("version"); this.GeneratorVersion = VersionConverter.Instance.Convert(string.Join(".", version)); await reader.ReadAsync().ConfigureAwait(false); break; case "updated": this.Updated = await reader.ReadElementContentAsync(DateTimeConverter.Instance).ConfigureAwait(false); break; case "entry": var entry = new AtomEntry(); if (entries == null) { entries = new List <AtomEntry>(); } entries.Add(entry); await entry.ReadXmlAsync(reader).ConfigureAwait(false); break; case "link": var href = reader.GetRequiredAttribute("href"); var rel = reader.GetRequiredAttribute("rel"); if (links == null) { links = new Dictionary <string, Uri>(); } links[rel] = UriConverter.Instance.Convert(href); await reader.ReadAsync().ConfigureAwait(false); break; case "s:messages": bool isEmptyElement = reader.IsEmptyElement; await reader.ReadAsync().ConfigureAwait(false); if (messages == null) { messages = new List <Message>(); } if (isEmptyElement) { continue; } while (reader.NodeType == XmlNodeType.Element && reader.Name == "s:msg") { var value = reader.GetRequiredAttribute("type"); var type = EnumConverter <MessageType> .Instance.Convert(value); var text = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); messages.Add(new Message(type, text)); } if (reader.NodeType == XmlNodeType.EndElement) { reader.EnsureMarkup(XmlNodeType.EndElement, "s:messages"); await reader.ReadAsync().ConfigureAwait(false); } break; case "opensearch:itemsPerPage": int itemsPerPage = await reader.ReadElementContentAsync(Int32Converter.Instance).ConfigureAwait(false); this.Pagination = new Pagination(itemsPerPage, this.Pagination.StartIndex, this.Pagination.TotalResults); break; case "opensearch:startIndex": int startIndex = await reader.ReadElementContentAsync(Int32Converter.Instance).ConfigureAwait(false); this.Pagination = new Pagination(this.Pagination.ItemsPerPage, startIndex, this.Pagination.TotalResults); break; case "opensearch:totalResults": int totalResults = await reader.ReadElementContentAsync(Int32Converter.Instance).ConfigureAwait(false); this.Pagination = new Pagination(this.Pagination.ItemsPerPage, this.Pagination.StartIndex, totalResults); break; default: throw new InvalidDataException(string.Format("Unexpected start tag: {0}", reader.Name)); // TODO: Improved diagnostics } } reader.EnsureMarkup(XmlNodeType.EndElement, documentElementName); await reader.ReadAsync().ConfigureAwait(false); this.Entries = entries == null ? emptyAtomEntryCollection : new ReadOnlyCollection <AtomEntry>(entries); this.Links = links == null ? emptyLinksDictionary : new ReadOnlyDictionary <string, Uri>(links); this.Messages = messages == null ? emptyMessageCollection : new ReadOnlyCollection <Message>(messages); }
/// <summary> /// Asynchronously reads XML data into the current <see cref="AtomFeed"/>. /// </summary> /// <exception cref="InvalidDataException"> /// Thrown when an Invalid Data error condition occurs. /// </exception> /// <param name="reader"> /// The reader from which to read. /// </param> /// <returns> /// A <see cref="Task"/> representing the operation. /// </returns> public async Task ReadXmlAsync(XmlReader reader) { Contract.Requires<ArgumentNullException>(reader != null, "reader"); this.Author = null; this.Entries = null; this.GeneratorVersion = null; this.Id = null; this.Links = null; this.Messages = null; this.Pagination = Pagination.None; this.Title = null; this.Updated = DateTime.MinValue; reader.Requires(await reader.MoveToDocumentElementAsync("feed")); var documentElementName = reader.Name; List<AtomEntry> entries = null; Dictionary<string, Uri> links = null; List<Message> messages = null; await reader.ReadAsync(); while (reader.NodeType == XmlNodeType.Element) { string name = reader.Name; switch (name) { case "title": this.Title = await reader.ReadElementContentAsync(StringConverter.Instance); break; case "id": this.Id = await reader.ReadElementContentAsync(UriConverter.Instance); break; case "author": await reader.ReadAsync(); reader.EnsureMarkup(XmlNodeType.Element, "name"); this.Author = await reader.ReadElementContentAsync(StringConverter.Instance); reader.EnsureMarkup(XmlNodeType.EndElement, "author"); await reader.ReadAsync(); break; case "generator": // string build = reader.GetRequiredAttribute("build"); // TODO: Incorporate build number? Build number sometimes adds a fifth digit. string version = reader.GetRequiredAttribute("version"); this.GeneratorVersion = VersionConverter.Instance.Convert(string.Join(".", version)); await reader.ReadAsync(); break; case "updated": this.Updated = await reader.ReadElementContentAsync(DateTimeConverter.Instance); break; case "entry": var entry = new AtomEntry(); if (entries == null) { entries = new List<AtomEntry>(); } entries.Add(entry); await entry.ReadXmlAsync(reader); break; case "link": var href = reader.GetRequiredAttribute("href"); var rel = reader.GetRequiredAttribute("rel"); if (links == null) { links = new Dictionary<string, Uri>(); } links[rel] = UriConverter.Instance.Convert(href); await reader.ReadAsync(); break; case "s:messages": bool isEmptyElement = reader.IsEmptyElement; await reader.ReadAsync(); if (messages == null) { messages = new List<Message>(); } if (isEmptyElement) { continue; } while (reader.NodeType == XmlNodeType.Element && reader.Name == "s:msg") { var value = reader.GetRequiredAttribute("type"); var type = EnumConverter<MessageType>.Instance.Convert(value); var text = await reader.ReadElementContentAsStringAsync(); messages.Add(new Message(type, text)); } if (reader.NodeType == XmlNodeType.EndElement) { reader.EnsureMarkup(XmlNodeType.EndElement, "s:messages"); await reader.ReadAsync(); } break; case "opensearch:itemsPerPage": int itemsPerPage = await reader.ReadElementContentAsync(Int32Converter.Instance); this.Pagination = new Pagination(itemsPerPage, this.Pagination.StartIndex, this.Pagination.TotalResults); break; case "opensearch:startIndex": int startIndex = await reader.ReadElementContentAsync(Int32Converter.Instance); this.Pagination = new Pagination(this.Pagination.ItemsPerPage, startIndex, this.Pagination.TotalResults); break; case "opensearch:totalResults": int totalResults = await reader.ReadElementContentAsync(Int32Converter.Instance); this.Pagination = new Pagination(this.Pagination.ItemsPerPage, this.Pagination.StartIndex, totalResults); break; default: throw new InvalidDataException(string.Format("Unexpected start tag: {0}", reader.Name)); // TODO: Improved diagnostics } } reader.EnsureMarkup(XmlNodeType.EndElement, documentElementName); await reader.ReadAsync(); if (entries != null) { this.Entries = new ReadOnlyCollection<AtomEntry>(entries); } if (links != null) { this.Links = new ReadOnlyDictionary<string, Uri>(links); } if (messages != null) { this.Messages = new ReadOnlyCollection<Message>(messages); } }