/// <summary> /// Intializes a new instance of the <see cref="EntitySnapshot"/> class. /// </summary> /// <param name="entry"> /// An object representing a Splunk entity atom entry. /// </param> public EntitySnapshot(AtomEntry entry) { Contract.Requires<ArgumentNullException>(entry != null); if (entry.Content == null) { this.adapter = ExpandoAdapter.Empty; } else { dynamic content = entry.Content as ExpandoObject; if (content == null) { content = new ExpandoObject(); content.Value = entry.Content; } this.adapter = new ExpandoAdapter(content); } this.author = entry.Author; this.id = entry.Id; this.links = entry.Links; this.published = entry.Published; this.title = entry.Title; this.updated = entry.Updated; }
public void CanReadEntry() { var expected = new List<string>() { "AtomEntry(Title=search *, Author=admin, Id=https://localhost:8089/services/search/jobs/1392687998.313, Published=2/17/2014 5:46:39 PM, Updated=2/17/2014 5:46:39 PM)" }; var stream = new FileStream(AtomFeedPath, FileMode.Open, FileAccess.Read); var reader = XmlReader.Create(stream, XmlReaderSettings); bool result = reader.ReadToFollowingAsync("entry").Result; var entry = new AtomEntry(); entry.ReadXmlAsync(reader).Wait(); }
/// <summary> /// Initializes a new instance of the /// <see cref="EntityCollection<TEntity,TResource>"/> /// class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="entry"> /// A entry in a Splunk atom feed response. /// </param> /// <param name="generatorVersion"> /// The generator version. /// </param> protected internal EntityCollection(Context context, AtomEntry entry, Version generatorVersion) { // We cannot use the base constructor because it will use base.CreateEntity, not this.CreateEntity this.Initialize(context, entry, generatorVersion); }
public async Task ReadXmlAsync(XmlReader reader) { Contract.Requires <ArgumentNullException>(reader != null, "reader"); if (reader.ReadState == ReadState.Initial) { await reader.ReadAsync(); if (reader.NodeType == XmlNodeType.XmlDeclaration) { await reader.ReadAsync(); } } else { reader.MoveToElement(); } if (!(reader.NodeType == XmlNodeType.Element && (reader.Name == "feed" || reader.Name == "entry"))) { throw new InvalidDataException(); // TODO: Diagnostics } string rootElementName = reader.Name; var entries = new List <AtomEntry>(); this.Entries = entries; var links = new Dictionary <string, Uri>(); this.Links = links; var messages = new List <Message>(); this.Messages = messages; 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(); if (!(reader.NodeType == XmlNodeType.Element && reader.Name == "name")) { throw new InvalidDataException(); // TODO: Diagnostics } this.Author = await reader.ReadElementContentAsync(StringConverter.Instance); if (!(reader.NodeType == XmlNodeType.EndElement && reader.Name == "author")) { throw new InvalidDataException(); // TODO: Diagnostics } await reader.ReadAsync(); break; case "generator": string build = reader.GetAttribute("build"); if (build == null) { throw new InvalidDataException(); // TODO: Diagnostics } string version = reader.GetAttribute("version"); if (version == null) { throw new InvalidDataException(); // TODO: Diagnostics } this.GeneratorVersion = VersionConverter.Instance.Convert(string.Join(".", version, build)); await reader.ReadAsync(); break; case "updated": this.Updated = await reader.ReadElementContentAsync(DateTimeConverter.Instance); break; case "entry": var entry = new AtomEntry(); await entry.ReadXmlAsync(reader); entries.Add(entry); break; case "link": string href = reader.GetAttribute("href"); if (string.IsNullOrWhiteSpace(href)) { throw new InvalidDataException(); // TODO: Diagnostics } string rel = reader.GetAttribute("rel"); if (string.IsNullOrWhiteSpace(rel)) { throw new InvalidDataException(); // TODO: Diagnostics } links[rel] = UriConverter.Instance.Convert(href); await reader.ReadAsync(); break; case "s:messages": bool isEmptyElement = reader.IsEmptyElement; await reader.ReadAsync(); if (isEmptyElement) { continue; } while (reader.NodeType == XmlNodeType.Element && reader.Name == "s:msg") { string value = reader.GetAttribute("type"); if (value == null) { throw new InvalidDataException(); // TODO: Diagnostics } MessageType type = EnumConverter <MessageType> .Instance.Convert(value); string text = await reader.ReadElementContentAsStringAsync(); messages.Add(new Message(type, text)); } if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name != "s:messages") { throw new InvalidDataException(); // TODO: Diagnostics } 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("Found invalid data while decoding: {0}", reader)); } } if (!(reader.NodeType == XmlNodeType.EndElement && reader.Name == rootElementName)) { throw new InvalidDataException(); // TODO: Diagnostics } await reader.ReadAsync(); }
/// <summary> /// Initializes a new instance of the <see cref="Resource"/> class. /// </summary> /// <param name="entry"> /// An object representing a Splunk atom entry response. /// </param> /// <param name="generatorVersion"> /// The version of the generator producing the <see cref="AtomFeed"/> /// feed containing <paramref name="entry"/>. /// </param> protected internal Resource(AtomEntry entry, Version generatorVersion) : base(entry, generatorVersion) { }
/// <summary> /// Initializes a new instance of the <see cref="BaseResource"/> class. /// </summary> /// <param name="entry"> /// An object representing a Splunk atom entry response. /// </param> /// <param name="generatorVersion"> /// The version of the generator producing the <see cref="AtomFeed"/> /// feed containing <paramref name="entry"/>. /// </param> protected BaseResource(AtomEntry entry, Version generatorVersion) { this.Initialize(entry, generatorVersion); }
/// <summary> /// Infrastructure. Initializes the current uninitialized resource. /// </summary> /// <remarks> /// This method may be called once to initialize a resource instantiated /// by the default constructor. Override this method to provide special /// initialization code. Call this base method before initialization /// is complete. /// <note type="note"> /// This method supports the Splunk client infrastructure and is not /// intended to be used directly from your code. /// </note> /// </remarks> /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/>, or <paramref name="generatorVersion"/> /// are <c>null</c>. /// </exception> /// <exception cref="InvalidOperationException"> /// The current resource is already initialized. /// </exception> /// <param name="entry"> /// An object representing a Splunk atom entry response. /// </param> /// <param name="generatorVersion"> /// The version of the generator producing the <see cref="AtomFeed"/> /// containing <paramref name="entry"/>. /// </param> protected internal abstract void Initialize(AtomEntry entry, Version generatorVersion);
/// <summary> /// Updates the content of the current <see cref= "BaseEntity<TResource>"/>. /// </summary> /// <param name="entry"> /// A Splunk <see cref="AtomEntry"/>. /// </param> /// <param name="generatorVersion"> /// The version of the generator producing the <see cref="AtomFeed"/> feed /// containing <paramref name="entry"/>. /// </param> protected abstract void CreateSnapshot(AtomEntry entry, Version generatorVersion);
protected internal override void Initialize(Context context, AtomEntry entry) { this.data = new DataCache(entry); base.Initialize(context, entry); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationSetting"/> /// class. /// </summary> /// <param name="entry"> /// An object representing a Splunk atom entry response. /// </param> /// <param name="generatorVersion"> /// The version of the generator producing the <see cref="AtomFeed"/> /// feed containing <paramref name="entry"/>. /// </param> protected internal ConfigurationSetting(AtomEntry entry, Version generatorVersion) { this.Initialize(entry, generatorVersion); }
public async Task ReadXmlAsync(XmlReader reader) { Contract.Requires<ArgumentNullException>(reader != null, "reader"); if (reader.ReadState == ReadState.Initial) { await reader.ReadAsync(); if (reader.NodeType == XmlNodeType.XmlDeclaration) { await reader.ReadAsync(); } } else { reader.MoveToElement(); } if (!(reader.NodeType == XmlNodeType.Element && (reader.Name == "feed" || reader.Name == "entry"))) { throw new InvalidDataException(); // TODO: Diagnostics } string rootElementName = reader.Name; var entries = new List<AtomEntry>(); this.Entries = entries; var links = new Dictionary<string, Uri>(); this.Links = links; var messages = new List<Message>(); this.Messages = messages; 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(); if (!(reader.NodeType == XmlNodeType.Element && reader.Name == "name")) { throw new InvalidDataException(); // TODO: Diagnostics } this.Author = await reader.ReadElementContentAsync(StringConverter.Instance); if (!(reader.NodeType == XmlNodeType.EndElement && reader.Name == "author")) { throw new InvalidDataException(); // TODO: Diagnostics } await reader.ReadAsync(); break; case "generator": string build = reader.GetAttribute("build"); if (build == null) { throw new InvalidDataException(); // TODO: Diagnostics } string version = reader.GetAttribute("version"); if (version == null) { throw new InvalidDataException(); // TODO: Diagnostics } this.GeneratorVersion = VersionConverter.Instance.Convert(string.Join(".", version, build)); await reader.ReadAsync(); break; case "updated": this.Updated = await reader.ReadElementContentAsync(DateTimeConverter.Instance); break; case "entry": var entry = new AtomEntry(); await entry.ReadXmlAsync(reader); entries.Add(entry); break; case "link": string href = reader.GetAttribute("href"); if (string.IsNullOrWhiteSpace(href)) { throw new InvalidDataException(); // TODO: Diagnostics } string rel = reader.GetAttribute("rel"); if (string.IsNullOrWhiteSpace(rel)) { throw new InvalidDataException(); // TODO: Diagnostics } links[rel] = UriConverter.Instance.Convert(href); await reader.ReadAsync(); break; case "s:messages": bool isEmptyElement = reader.IsEmptyElement; await reader.ReadAsync(); if (isEmptyElement) { continue; } while (reader.NodeType == XmlNodeType.Element && reader.Name == "s:msg") { string value = reader.GetAttribute("type"); if (value == null) { throw new InvalidDataException(); // TODO: Diagnostics } MessageType type = EnumConverter<MessageType>.Instance.Convert(value); string text = await reader.ReadElementContentAsStringAsync(); messages.Add(new Message(type, text)); } if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name != "s:messages") { throw new InvalidDataException(); // TODO: Diagnostics } 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("Found invalid data while decoding: {0}", reader)); } } if (!(reader.NodeType == XmlNodeType.EndElement && reader.Name == rootElementName)) { throw new InvalidDataException(); // TODO: Diagnostics } await reader.ReadAsync(); }
/// <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); } }
/// <inheritdoc/> protected internal override void Initialize(AtomEntry entry, Version generatorVersion) { BaseResource.Initialize(this, entry, generatorVersion); }
/// <inheritdoc/> protected override void CreateSnapshot(AtomEntry entry, Version generatorVersion) { this.Snapshot = new ResourceCollection(); this.Snapshot.Initialize(entry, generatorVersion); }
/// <summary> /// Initializes a new instance of the <see cref="Application"/> class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="entry"> /// A Splunk response atom feed. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> or <paramref name="entry"/> are <c>null</c>. /// </exception> /// <exception cref="InvalidDataException"> /// <paramref name="entry"/> is in an invalid format. /// </exception> protected internal Job(Context context, AtomEntry entry) { this.Initialize(context, entry, new Version(0, 0)); }
/// <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> /// Creates a snapshot. /// </summary> /// <param name="entry"> /// The entry. /// </param> /// <param name="generatorVersion"> /// The generator version. /// </param> protected override void CreateSnapshot(AtomEntry entry, Version generatorVersion) { Contract.Requires <ArgumentNullException>(entry != null); Contract.Requires <ArgumentNullException>(generatorVersion != null); }
/// <summary> /// Initializes a new instance of the <see cref="ServerInfo"/> class. /// </summary> /// <param name="entry"> /// An object representing a Splunk atom entry response. /// </param> /// <param name="generatorVersion"> /// The version of the generator producing the <see cref="AtomFeed"/> /// feed containing <paramref name="entry"/>. /// </param> protected internal ServerInfo(AtomEntry entry, Version generatorVersion) : base(entry, generatorVersion) { }
/// <summary> /// /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="namespace"> /// An object identifying a Splunk service namespace. /// </param> /// <param name="collection"> /// </param> /// <param name="entry"> /// </param> protected internal override void Initialize(Context context, AtomEntry entry) { this.snapshot = new EntitySnapshot(entry); base.Initialize(context, entry); }
protected internal override void Initialize(AtomEntry entry, Version generatorVersion) { Contract.Requires <ArgumentNullException>(entry != null); Contract.Requires <ArgumentNullException>(generatorVersion != null); }
/// <summary> /// Initializes a new instance of the <see cref="ServerSettings"/> class. /// </summary> /// <param name="entry"> /// An object representing a Splunk atom entry response. /// </param> /// <param name="generatorVersion"> /// The version of the generator producing the <see cref="AtomFeed"/> /// feed containing <paramref name="entry"/>. /// </param> protected internal ServerSettings(AtomEntry entry, Version generatorVersion) : base(entry, generatorVersion) { }
/// <summary> /// Refreshes the cached state of the current <see cref="Entity<TEntity>"/>. /// </summary> public override async Task GetAsync() { //// TODO: This retry logic is for jobs. Parmeterize it and move it into the Job class // FJR: I assume the retry logic is for jobs, since nothing else requires this. I suggest moving it // into Job. Also, it's insufficient. If you're just trying to get some state, this will do it, but // as of Splunk 6, getting a 200 and content back does not imply you have all the fields. For pivot // support, they're now shoving fields in as they become ready, so you have to wait until the dispatchState // field of the Atom entry reaches a certain point. RequestException requestException = null; for (int i = 3; i > 0; --i) { try { //// Guarantee: unique result because entities have specific namespaces using (var response = await this.Context.GetAsync(this.Namespace, this.ResourceName)) { //// TODO: Use Response.EnsureStatusCode. Is it true that gets always return HttpStatusCode.OK? if (response.Message.StatusCode == HttpStatusCode.NoContent) { throw new RequestException(response.Message, new Message(MessageType.Warning, string.Format("Resource '{0}/{1}' is not ready.", this.Namespace, this.ResourceName))); } if (!response.Message.IsSuccessStatusCode) { throw new RequestException(response.Message, await Message.ReadMessagesAsync(response.XmlReader)); } var reader = response.XmlReader; await reader.ReadAsync(); if (reader.NodeType == XmlNodeType.XmlDeclaration) { await response.XmlReader.ReadAsync(); } if (reader.NodeType != XmlNodeType.Element) { throw new InvalidDataException(); // TODO: Diagnostics } AtomEntry entry; if (reader.Name == "feed") { AtomFeed feed = new AtomFeed(); await feed.ReadXmlAsync(reader); int count = feed.Entries.Count; foreach (var feedEntry in feed.Entries) { string id = feedEntry.Title; id.Trim(); } if (feed.Entries.Count != 1) { throw new InvalidDataException(); // TODO: Diagnostics } entry = feed.Entries[0]; } else { entry = new AtomEntry(); await entry.ReadXmlAsync(reader); } this.Snapshot = new EntitySnapshot(entry); } return; } catch (RequestException e) { if (e.StatusCode != System.Net.HttpStatusCode.NoContent) { throw; } requestException = e; } await Task.Delay(500); } throw requestException; }