public void CanReadFeed() { using (var stream = new FileStream(AtomFeedPath, FileMode.Open, FileAccess.Read)) { var reader = XmlReader.Create(stream, XmlReaderSettings); var feed = new AtomFeed(); feed.ReadXmlAsync(reader).Wait(); } }
/// <summary> /// Initializes a new instance of the <see cref="BaseResource"/> class. /// </summary> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> protected BaseResource(AtomFeed feed) { this.Initialize(feed); }
/// <summary> /// Initializes an unitialized resource collection. /// </summary> /// <typeparam name="TCollection"> /// Type of the resource collection to be initialized. /// </typeparam> /// <typeparam name="TResource"> /// Type of the resources in the resource collection to be initialized. /// </typeparam> /// <param name="collection"> /// The resource collection to be initialized. /// </param> /// <param name="feed"> /// A Splunk atom feed entry containing resource data. /// </param> protected internal static void Initialize <TCollection, TResource>(TCollection collection, AtomFeed feed) where TCollection : BaseResource, new() where TResource : BaseResource, new() { Contract.Requires <ArgumentNullException>(feed != null); collection.EnsureUninitialized(); dynamic expando = new Dictionary <string, object>(); expando["GeneratorVersion"] = feed.GeneratorVersion; expando["Id"] = feed.Id; expando["Title"] = feed.Title; expando["Updated"] = feed.Updated; expando["Author"] = feed.Author; if (feed.Links != null) { expando["Links"] = feed.Links; } if (feed.Messages != null) { expando["Messages"] = feed.Messages; } if (!feed.Pagination.Equals(Pagination.None)) { expando["Pagination"] = feed.Pagination; } if (feed.Entries != null) { var resources = new List <TResource>(); foreach (var entry in feed.Entries) { var resource = new TResource(); resource.Initialize(entry, feed.GeneratorVersion); resources.Add(resource); } expando["Resources"] = new ReadOnlyCollection <TResource>(resources); } collection.Object = expando; collection.MarkInitialized(); }
/// <summary> /// Initializes a new instance of the <see cref="Resource"/> class. /// </summary> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> protected internal Resource(AtomFeed feed) { this.Initialize(feed); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationStanza"/> /// class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="feed"> /// A Splunk response atom feed. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> or <paramref name="feed"/> are <c>null</c>. /// </exception> /// <exception cref="InvalidDataException"> /// <paramref name="feed"/> is in an invalid format. /// </exception> protected internal ConfigurationStanza(Context context, AtomFeed feed) { this.Initialize(context, feed); }
/// <summary> /// Updates the <see cref="Snapshot"/> of the current /// <see cref= "BaseEntity<TResource>"/> in derived types. /// </summary> /// <remarks> /// Derived types must implement this method. /// </remarks> /// <param name="feed"> /// A Splunk <see cref="AtomFeed"/>. /// </param> protected abstract void CreateSnapshot(AtomFeed feed);
/// <inheritdoc/> protected override void CreateSnapshot(AtomFeed feed) { this.Snapshot = new ResourceCollection(); this.Snapshot.Initialize <TResource>(feed); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationCollection"/> /// class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="feed"> /// A Splunk response atom feed. /// </param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="context"/> or <paramref name="feed"/> are <c>null</c>. /// </exception> /// <exception cref="System.IO.InvalidDataException"> /// <paramref name="feed"/> is in an invalid format. /// </exception> protected internal ApplicationCollection(Context context, AtomFeed feed) { this.Initialize(context, feed); }
/// <summary> /// Initializes a new instance of the <see cref="ServerMessageCollection"/> /// class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="feed"> /// A Splunk response atom feed. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> or <paramref name="feed"/> are <c>null</c>. /// </exception> /// <exception cref="System.IO.InvalidDataException"> /// <paramref name="feed"/> is in an invalid format. /// </exception> protected internal ServerMessageCollection(Context context, AtomFeed feed) { this.Initialize(context, feed); }
/// <summary> /// Initializes a new instance of the <see cref="ServerSettings"/> class. /// </summary> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> protected internal ServerSettings(AtomFeed feed) { this.Initialize(feed); }
/// <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="feed"> /// A Splunk response atom feed. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> or <paramref name="feed"/> are <c>null</c>. /// </exception> /// <exception cref="System.IO.InvalidDataException"> /// <paramref name="feed"/> is in an invalid format. /// </exception> protected internal Index(Context context, AtomFeed feed) { this.Initialize(context, feed); }
/// <inheritdoc/> public virtual async Task<ServerInfo> GetInfoAsync() { using (var response = await this.Context.GetAsync(this.Namespace, Info).ConfigureAwait(false)) { await response.EnsureStatusCodeAsync(HttpStatusCode.OK).ConfigureAwait(false); var feed = new AtomFeed(); await feed.ReadXmlAsync(response.XmlReader).ConfigureAwait(false); var info = new ServerInfo(feed); return info; } }
/// <inheritdoc/> public virtual async Task<ServerSettings> UpdateSettingsAsync(ServerSettingValues values) { using (var response = await this.Context.PostAsync(this.Namespace, Settings, values).ConfigureAwait(false)) { await response.EnsureStatusCodeAsync(HttpStatusCode.OK).ConfigureAwait(false); var feed = new AtomFeed(); await feed.ReadXmlAsync(response.XmlReader).ConfigureAwait(false); var settings = new ServerSettings(feed); return settings; } }
/// <inheritdoc/> public virtual async Task<ServerSettings> GetSettingsAsync() { using (var response = await this.Context.GetAsync(this.Namespace, Settings)) { await response.EnsureStatusCodeAsync(HttpStatusCode.OK); var feed = new AtomFeed(); await feed.ReadXmlAsync(response.XmlReader); var settings = new ServerSettings(feed); return settings; } }
/// <summary> /// Initializes a new instance of the <see cref="ServerInfo"/> class. /// </summary> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> protected internal ServerInfo(AtomFeed feed) { this.Initialize(feed); }
/// <summary> /// Infrastructure. Initializes the current uninitialized /// <see cref= "Resource"/>. /// </summary> /// <remarks> /// This method may be called once to intialize a <see cref="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="InvalidDataException"> /// Thrown when an Invalid Data error condition occurs. /// </exception> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> /// <seealso cref="M:Splunk.Client.BaseResource.Initialize(AtomFeed)"/> /// /// ### <exception cref="ArgumentNullException"> /// <paramref name="context"/> or <paramref name="feed"/> are <c>null</c>. /// </exception> /// ### <exception cref="InvalidOperationException"> /// The current <see cref="Resource"/> is already initialized. /// </exception> protected internal override void Initialize(AtomFeed feed) { if (feed.Entries.Count != 1) { var text = string.Format(CultureInfo.CurrentCulture, "feed.Entries.Count = {0}", feed.Entries.Count); throw new InvalidDataException(text); } this.Initialize(feed.Entries[0], feed.GeneratorVersion); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationUpdateInfo"/> /// class. /// </summary> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> internal ApplicationUpdateInfo(AtomFeed feed) { this.Initialize(feed); }
/// <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="feed"> /// A Splunk atom feed response. /// </param> protected internal EntityCollection(Context context, AtomFeed feed) { // We cannot use the base constructor because it will use base.CreateResource, not this.CreateResource this.Initialize(context, feed); }
/// <summary> /// Initializes a new instance of the <see cref="SavedSearchCollection"/> /// class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="feed"> /// A Splunk response atom feed. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> or <paramref name="feed"/> are <c>null</c>. /// </exception> /// <exception cref="System.IO.InvalidDataException"> /// <paramref name="feed"/> is in an invalid format. /// </exception> protected internal SavedSearchCollection(Context context, AtomFeed feed) { this.Initialize(context, feed); }
/// <summary> /// Initializes a new instance of the <see cref="BaseEntity<TResource>"/> class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="feed"> /// A Splunk response atom feed. /// </param> protected BaseEntity(Context context, AtomFeed feed) { this.Initialize(context, feed); }
/// <summary> /// Creates a snapshot. /// </summary> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> protected override void CreateSnapshot(AtomFeed feed) { Contract.Requires <ArgumentNullException>(feed != null); }
/// <summary> /// Infrastructure. Initializes the current uninitialized /// <see cref= "ResourceCollection"/>. /// </summary> /// <remarks> /// This method may be called once to initialize a /// <see cref="ResourceCollection"/> /// 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> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> /// <seealso cref="M:Splunk.Client.BaseResource.Initialize(AtomFeed)"/> /// <exception cref="ArgumentNullException"> /// <paramref name="feed"/> is <c>null</c>. /// </exception> /// <exception cref="InvalidOperationException"> /// The current <see cref="ResourceCollection"/> is already initialized. /// </exception> protected internal override void Initialize(AtomFeed feed) { BaseResource.Initialize <ResourceCollection, Resource>(this, feed); }
/// <summary> /// Asynchronously retrieves the list of all Splunk system capabilities. /// </summary> /// <returns> /// An object representing the list of all Splunk system capabilities. /// </returns> /// <remarks> /// This method uses the <a href="http://goo.gl/kgTKvM">GET /// authorization/capabilities</a> endpoint to construct a list of all /// Splunk system capabilities. /// </remarks> public async Task<dynamic> GetCapabilitiesAsync() { using (var response = await this.Context.GetAsync(this.Namespace, AuthorizationCapabilities)) { await response.EnsureStatusCodeAsync(HttpStatusCode.OK); var feed = new AtomFeed(); await feed.ReadXmlAsync(response.XmlReader); if (feed.Entries.Count != 1) { throw new InvalidDataException(); // TODO: Diagnostics } var entry = feed.Entries[0]; dynamic capabilities = entry.Content.Capabilities; // TODO: Static type (?) return capabilities; } }
/// <summary> /// Infrastructure. Initializes the current uninitialized /// <see cref= "ResourceCollection"/>. /// </summary> /// <remarks> /// This method may be called once to initialize a /// <see cref="ResourceCollection"/> /// 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> /// <typeparam name="TResource"> /// Type of the resource. /// </typeparam> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="feed"/> is <c>null</c>. /// </exception> /// <exception cref="InvalidOperationException"> /// The current <see cref="ResourceCollection"/> is already initialized. /// </exception> protected internal virtual void Initialize <TResource>(AtomFeed feed) where TResource : BaseResource, new() { BaseResource.Initialize <ResourceCollection, TResource>(this, feed); }
/// <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="feed"/> is <c>null</c>. /// </exception> /// <exception cref="InvalidOperationException"> /// The current resource is already initialized. /// </exception> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> protected internal abstract void Initialize(AtomFeed feed);
/// <summary> /// Initializes a new instance of the <see cref="Entity<TResource>"/> class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="feed"> /// A Splunk response atom feed. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> or <paramref name="feed"/> are /// <c>null</c>. /// </exception> protected internal Entity(Context context, AtomFeed feed) { this.Initialize(context, feed); }
protected internal override void Initialize(AtomFeed feed) { Contract.Requires <ArgumentNullException>(feed != null); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationArchiveInfo"/> /// class. /// </summary> /// <param name="feed"> /// An object representing a Splunk atom feed response. /// </param> internal ApplicationArchiveInfo(AtomFeed feed) { this.Initialize(feed); }
/// <summary> /// Initializes a new instance of the <see cref="StoragePasswordCollection"/> /// class. /// </summary> /// <param name="context"> /// An object representing a Splunk server session. /// </param> /// <param name="feed"> /// A Splunk response atom feed. /// </param> /// /// <exception cref="System.ArgumentNullException"> /// <paramref name="context"/> or <paramref name="feed"/> are <c>null</c>. /// </exception> /// <exception cref="System.IO.InvalidDataException"> /// <paramref name="feed"/> is in an invalid format. /// </exception> protected internal StoragePasswordCollection(Context context, AtomFeed feed) { this.Initialize(context, feed); }
/// <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; }