1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Threading ;
4
+ using System . Threading . Tasks ;
5
+ using Seq . Api . Model ;
6
+ using Seq . Api . Model . Indexing ;
7
+
8
+ namespace Seq . Api . ResourceGroups
9
+ {
10
+ /// <summary>
11
+ /// Perform operations on expression indexes.
12
+ /// </summary>
13
+ public class ExpressionIndexesResourceGroup : ApiResourceGroup
14
+ {
15
+ internal ExpressionIndexesResourceGroup ( ILoadResourceGroup connection ) : base ( "ExpressionIndexes" , connection )
16
+ {
17
+ }
18
+
19
+ /// <summary>
20
+ /// Retrieve expression indexes.
21
+ /// </summary>
22
+ /// <param name="cancellationToken"><see cref="CancellationToken"/> allowing the operation to be canceled.</param>
23
+ /// <returns>A list containing matching expression indexes.</returns>
24
+ public async Task < List < ExpressionIndexEntity > > ListAsync ( CancellationToken cancellationToken = default )
25
+ {
26
+ return await GroupListAsync < ExpressionIndexEntity > ( "Items" , cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
27
+ }
28
+
29
+ /// <summary>
30
+ /// Retrieve the expression index with the given id; throws if the entity does not exist.
31
+ /// </summary>
32
+ /// <param name="id">The id of the expression index.</param>
33
+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param>
34
+ /// <returns>The expression index.</returns>
35
+ public async Task < ExpressionIndexEntity > FindAsync ( string id , CancellationToken cancellationToken = default )
36
+ {
37
+ if ( id == null ) throw new ArgumentNullException ( nameof ( id ) ) ;
38
+ return await GroupGetAsync < ExpressionIndexEntity > ( "Item" , new Dictionary < string , object > { { "id" , id } } , cancellationToken ) . ConfigureAwait ( false ) ;
39
+ }
40
+
41
+ /// <summary>
42
+ /// Construct an expression index with server defaults pre-initialized.
43
+ /// </summary>
44
+ /// <param name="cancellationToken"><see cref="CancellationToken"/> allowing the operation to be canceled.</param>
45
+ /// <returns>The unsaved expression index.</returns>
46
+ public async Task < ExpressionIndexEntity > TemplateAsync ( CancellationToken cancellationToken = default )
47
+ {
48
+ return await GroupGetAsync < ExpressionIndexEntity > ( "Template" , cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
49
+ }
50
+
51
+ /// <summary>
52
+ /// Add a new expression index.
53
+ /// </summary>
54
+ /// <param name="entity">The expression index to add.</param>
55
+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param>
56
+ /// <returns>The expression index, with server-allocated properties such as <see cref="Entity.Id"/> initialized.</returns>
57
+ public async Task < ExpressionIndexEntity > AddAsync ( ExpressionIndexEntity entity , CancellationToken cancellationToken = default )
58
+ {
59
+ return await GroupCreateAsync < ExpressionIndexEntity , ExpressionIndexEntity > ( entity , cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
60
+ }
61
+
62
+ /// <summary>
63
+ /// Remove an existing expression index.
64
+ /// </summary>
65
+ /// <param name="entity">The expression index to remove.</param>
66
+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param>
67
+ /// <returns>A task indicating completion.</returns>
68
+ public async Task RemoveAsync ( ExpressionIndexEntity entity , CancellationToken cancellationToken = default )
69
+ {
70
+ await Client . DeleteAsync ( entity , "Self" , entity , cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
71
+ }
72
+ }
73
+ }
0 commit comments