|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Threading; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Seq.Api.Model.Alerting; |
| 6 | +using Seq.Api.Model.Indexes; |
| 7 | +using Seq.Api.Model.Indexing; |
| 8 | +using Seq.Api.Model.Signals; |
| 9 | + |
| 10 | +namespace Seq.Api.ResourceGroups |
| 11 | +{ |
| 12 | + /// <summary> |
| 13 | + /// Statistics about indexes. |
| 14 | + /// </summary> |
| 15 | + public class IndexesResourceGroup : ApiResourceGroup |
| 16 | + { |
| 17 | + internal IndexesResourceGroup(ILoadResourceGroup connection) |
| 18 | + : base("Indexes", connection) |
| 19 | + { |
| 20 | + } |
| 21 | + /// <summary> |
| 22 | + /// Retrieve the index with the given id; throws if the entity does not exist. |
| 23 | + /// </summary> |
| 24 | + /// <param name="id">The id of the index.</param> |
| 25 | + /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param> |
| 26 | + /// <returns>The index.</returns> |
| 27 | + public async Task<SignalEntity> FindAsync(string id, CancellationToken cancellationToken = default) |
| 28 | + { |
| 29 | + if (id == null) throw new ArgumentNullException(nameof(id)); |
| 30 | + return await GroupGetAsync<SignalEntity>("Item", new Dictionary<string, object> { { "id", id } }, cancellationToken).ConfigureAwait(false); |
| 31 | + } |
| 32 | + |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Retrieve statistics on all indexes. |
| 36 | + /// </summary> |
| 37 | + /// <param name="cancellationToken"><see cref="CancellationToken"/> allowing the operation to be canceled.</param> |
| 38 | + /// <returns>A list containing matching expression indexes.</returns> |
| 39 | + public async Task<List<IndexEntity>> ListAsync(CancellationToken cancellationToken = default) |
| 40 | + { |
| 41 | + return await GroupListAsync<IndexEntity>("Items", cancellationToken: cancellationToken).ConfigureAwait(false); |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Suppress an index. Not all index types can be suppressed: signal indexes do support suppression, in the case |
| 46 | + /// of which the <see cref="SignalEntity.IsIndexSuppressed"/> flag will be set to <c langword="false"/>. |
| 47 | + /// Expression indexes can only be suppressed by deleting the associated <see cref="ExpressionIndexEntity"/> |
| 48 | + /// and alert indexes can only be suppressed by deleting the corresponding <see cref="AlertEntity"/>. |
| 49 | + /// </summary> |
| 50 | + /// <param name="entity">The index to suppress.</param> |
| 51 | + /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param> |
| 52 | + /// <returns>A task indicating completion.</returns> |
| 53 | + public async Task SuppressAsync(IndexEntity entity, CancellationToken cancellationToken = default) |
| 54 | + { |
| 55 | + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments