From aaf80a7ae29f73faec08cfd2fe49df7ff6544efb Mon Sep 17 00:00:00 2001 From: Sean Garrett Date: Sat, 24 Jun 2023 12:41:17 +0100 Subject: [PATCH] Cancellation Tokens for Text Index and GetIndex --- .../IndexTests/GetIndexNamesAsyncTests.cs | 8 + .../BaseMongoRepository.Index.cs | 291 +++++++++++------- .../IBaseMongoRepository.Index.cs | 151 ++++++++- .../BaseMongoRepository.TKey.Index.cs | 146 +++++---- .../IBaseMongoRepository.TKey.Index.cs | 129 +++++++- 5 files changed, 535 insertions(+), 190 deletions(-) create mode 100644 CoreUnitTests/KeyTypedRepositoryTests/IndexTests/GetIndexNamesAsyncTests.cs diff --git a/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/GetIndexNamesAsyncTests.cs b/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/GetIndexNamesAsyncTests.cs new file mode 100644 index 0000000..087cfc6 --- /dev/null +++ b/CoreUnitTests/KeyTypedRepositoryTests/IndexTests/GetIndexNamesAsyncTests.cs @@ -0,0 +1,8 @@ +using CoreUnitTests.Infrastructure; + +namespace CoreUnitTests.KeyTypedRepositoryTests.IndexTests; + +public class GetIndexNamesAsyncTests : TestKeyedMongoRepositoryContext +{ + +} diff --git a/MongoDbGenericRepository/BaseMongoRepository.Index.cs b/MongoDbGenericRepository/BaseMongoRepository.Index.cs index 90741a6..c32dde0 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Index.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Index.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Linq.Expressions; +using System.Threading; using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository @@ -36,93 +37,195 @@ namespace MongoDbGenericRepository set { _mongoDbIndexHandler = value; } } - /// - /// Returns the names of the indexes present on a collection. - /// - /// The type representing a Document. - /// An optional partition key - /// A list containing the names of the indexes on on the concerned collection. - public async Task> GetIndexesNamesAsync(string partitionKey = null) + /// + public async Task> GetIndexesNamesAsync() where TDocument : IDocument { - return await MongoDbIndexHandler.GetIndexesNamesAsync(partitionKey); + return await GetIndexesNamesAsync(null, CancellationToken.None); } - /// - /// Returns the names of the indexes present on a collection. - /// - /// The type representing a Document. - /// The type for the key of the document. - /// An optional partition key - /// A list containing the names of the indexes on on the concerned collection. - public virtual async Task> GetIndexesNamesAsync(string partitionKey = null) + + /// + public async Task> GetIndexesNamesAsync(CancellationToken cancellationToken) + where TDocument : IDocument + { + return await GetIndexesNamesAsync(null, cancellationToken); + } + + /// + public async Task> GetIndexesNamesAsync(string partitionKey) + where TDocument : IDocument + { + return await GetIndexesNamesAsync(partitionKey); + } + + /// + public async Task> GetIndexesNamesAsync(string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await GetIndexesNamesAsync(partitionKey, cancellationToken); + } + + /// + public virtual async Task> GetIndexesNamesAsync() where TDocument : IDocument where TKey : IEquatable { - return await MongoDbIndexHandler.GetIndexesNamesAsync(partitionKey); + return await GetIndexesNamesAsync(null, CancellationToken.None); } - /// - /// Create a text index on the given field. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - public async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument - { - return await MongoDbIndexHandler.CreateTextIndexAsync(field, indexCreationOptions, partitionKey); - } - - /// - /// Create a text index on the given field. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + /// + public virtual async Task> GetIndexesNamesAsync(CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbIndexHandler.CreateTextIndexAsync(field, indexCreationOptions, partitionKey); + return await GetIndexesNamesAsync(null, cancellationToken); } - /// - /// Creates an index on the given field in ascending order. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - public async Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + /// + public virtual async Task> GetIndexesNamesAsync(string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await GetIndexesNamesAsync(partitionKey, CancellationToken.None); + } + + /// + public virtual async Task> GetIndexesNamesAsync(string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbIndexHandler.GetIndexesNamesAsync(partitionKey, cancellationToken); + } + + /// + public async Task CreateTextIndexAsync(Expression> field) where TDocument : IDocument { - return await MongoDbIndexHandler.CreateAscendingIndexAsync(field, indexCreationOptions, partitionKey); + return await CreateTextIndexAsync(field, null, null, CancellationToken.None); } - /// - /// Creates an index on the given field in ascending order. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. + /// + public async Task CreateTextIndexAsync(Expression> field, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, null, null, cancellationToken); + } + + /// + public async Task CreateTextIndexAsync(Expression> field, string partitionKey) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, null, partitionKey, CancellationToken.None); + } + + /// + public async Task CreateTextIndexAsync(Expression> field, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, null, partitionKey, cancellationToken); + } + + /// + public async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, indexCreationOptions, null, CancellationToken.None); + } + + /// + public async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, indexCreationOptions, null, cancellationToken); + } + + /// + public async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); + } + + /// + public async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateTextIndexAsync(field, null, null, CancellationToken.None); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateTextIndexAsync(field, null, null, cancellationToken); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateTextIndexAsync(field, null, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateTextIndexAsync(field, null, partitionKey, cancellationToken); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateTextIndexAsync(field, indexCreationOptions, null, CancellationToken.None); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateTextIndexAsync(field, indexCreationOptions, null, cancellationToken); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable + { + return await CreateTextIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable + { + return await MongoDbIndexHandler.CreateTextIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); + } + + /// + public async Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + { + return await CreateAscendingIndexAsync(field, indexCreationOptions, partitionKey); + } + + /// public virtual async Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -130,20 +233,11 @@ namespace MongoDbGenericRepository return await MongoDbIndexHandler.CreateAscendingIndexAsync(field, indexCreationOptions, partitionKey); } - /// - /// Creates an index on the given field in descending order. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. + /// public async Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { - return await MongoDbIndexHandler.CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey); + return await CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey); } /// @@ -154,20 +248,11 @@ namespace MongoDbGenericRepository return await MongoDbIndexHandler.CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey); } - /// - /// Creates a hashed index on the given field. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. + /// public async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { - return await MongoDbIndexHandler.CreateHashedIndexAsync(field, indexCreationOptions, partitionKey); + return await CreateHashedIndexAsync(field, indexCreationOptions, partitionKey); } /// @@ -178,20 +263,11 @@ namespace MongoDbGenericRepository return await MongoDbIndexHandler.CreateHashedIndexAsync(field, indexCreationOptions, partitionKey); } - /// - /// Creates a combined text index. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The fields we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + /// + public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { - return await MongoDbIndexHandler.CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey); + return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey); } /// @@ -202,16 +278,11 @@ namespace MongoDbGenericRepository return await MongoDbIndexHandler.CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey); } - /// - /// Drops the index given a field name - /// - /// The type representing a Document. - /// The name of the index - /// An optional partition key + /// public async Task DropIndexAsync(string indexName, string partitionKey = null) where TDocument : IDocument { - await MongoDbIndexHandler.DropIndexAsync(indexName, partitionKey); + await DropIndexAsync(indexName, partitionKey); } /// diff --git a/MongoDbGenericRepository/IBaseMongoRepository.Index.cs b/MongoDbGenericRepository/IBaseMongoRepository.Index.cs index 3db3ecf..b3de813 100644 --- a/MongoDbGenericRepository/IBaseMongoRepository.Index.cs +++ b/MongoDbGenericRepository/IBaseMongoRepository.Index.cs @@ -1,16 +1,38 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { /// - /// The interface exposing index management functionality for Guid Keyed repositories. + /// The interface exposing index management functionality for Guid Keyed repositories. /// public interface IBaseMongoRepository_Index : IBaseMongoRepository_Index { + /// + /// Returns the names of the indexes present on a collection. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A list containing the names of the indexes on on the concerned collection. + Task> GetIndexesNamesAsync() + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns the names of the indexes present on a collection. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The cancellation token + /// A list containing the names of the indexes on on the concerned collection. + Task> GetIndexesNamesAsync(CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + /// /// Returns the names of the indexes present on a collection. /// @@ -18,13 +40,110 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// An optional partition key /// A list containing the names of the indexes on on the concerned collection. - Task> GetIndexesNamesAsync(string partitionKey = null) + Task> GetIndexesNamesAsync(string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns the names of the indexes present on a collection. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// An optional partition key + /// The cancellation token + /// A list containing the names of the indexes on on the concerned collection. + Task> GetIndexesNamesAsync(string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// /// Create a text index on the given field. - /// IndexCreationOptions can be supplied to further specify + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// The cancellation token + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// An optional partition key + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// An optional partition key + /// The cancellation token + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// The cancellation token + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify /// how the creation should be done. /// /// The type representing a Document. @@ -33,13 +152,29 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable; /// /// Creates an index on the given field in ascending order. - /// IndexCreationOptions can be supplied to further specify + /// IndexCreationOptions can be supplied to further specify /// how the creation should be done. /// /// The type representing a Document. @@ -54,7 +189,7 @@ namespace MongoDbGenericRepository /// /// Creates an index on the given field in descending order. - /// IndexCreationOptions can be supplied to further specify + /// IndexCreationOptions can be supplied to further specify /// how the creation should be done. /// /// The type representing a Document. @@ -69,7 +204,7 @@ namespace MongoDbGenericRepository /// /// Creates a hashed index on the given field. - /// IndexCreationOptions can be supplied to further specify + /// IndexCreationOptions can be supplied to further specify /// how the creation should be done. /// /// The type representing a Document. @@ -84,7 +219,7 @@ namespace MongoDbGenericRepository /// /// Creates a combined text index. - /// IndexCreationOptions can be supplied to further specify + /// IndexCreationOptions can be supplied to further specify /// how the creation should be done. /// /// The type representing a Document. diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs index b7e56ce..e24022c 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; +using CancellationToken = System.Threading.CancellationToken; namespace MongoDbGenericRepository { @@ -38,104 +39,119 @@ namespace MongoDbGenericRepository set { _mongoDbIndexHandler = value; } } - /// - /// Returns the names of the indexes present on a collection. - /// - /// The type representing a Document. - /// An optional partition key - /// A list containing the names of the indexes on on the concerned collection. - public virtual async Task> GetIndexesNamesAsync(string partitionKey = null) + /// + public virtual async Task> GetIndexesNamesAsync() + where TDocument : IDocument + { + return await MongoDbIndexHandler.GetIndexesNamesAsync(); + } + + /// + public virtual async Task> GetIndexesNamesAsync(CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbIndexHandler.GetIndexesNamesAsync(cancellationToken: cancellationToken); + } + + /// + public virtual async Task> GetIndexesNamesAsync(string partitionKey) where TDocument : IDocument { return await MongoDbIndexHandler.GetIndexesNamesAsync(partitionKey); } - /// - /// Create a text index on the given field. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + /// + public virtual async Task> GetIndexesNamesAsync(string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { - return await MongoDbIndexHandler.CreateTextIndexAsync(field, indexCreationOptions, partitionKey); + return await MongoDbIndexHandler.GetIndexesNamesAsync(partitionKey, cancellationToken); } - /// - /// Creates an index on the given field in ascending order. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. + /// + public virtual async Task CreateTextIndexAsync(Expression> field) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, null, null, CancellationToken.None); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, null, null, cancellationToken); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, indexCreationOptions, null, CancellationToken.None); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, indexCreationOptions, null, cancellationToken); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, string partitionKey) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, null, partitionKey, CancellationToken.None); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await CreateTextIndexAsync(field, null, partitionKey, cancellationToken); + } + + /// + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument + { + return await MongoDbIndexHandler.CreateTextIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); + } + + /// public virtual async Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await MongoDbIndexHandler.CreateAscendingIndexAsync(field, indexCreationOptions, partitionKey); } - /// - /// Creates an index on the given field in descending order. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. + /// public virtual async Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await MongoDbIndexHandler.CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey); } - /// - /// Creates a hashed index on the given field. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. + /// public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await MongoDbIndexHandler.CreateHashedIndexAsync(field, indexCreationOptions, partitionKey); } - /// - /// Creates a combined text index. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The fields we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. + /// public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await MongoDbIndexHandler.CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey); } - /// - /// Drops the index given a field name - /// - /// The type representing a Document. - /// The name of the index - /// An optional partition key + /// public virtual async Task DropIndexAsync(string indexName, string partitionKey = null) where TDocument : IDocument { diff --git a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs index 951904b..cb97145 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; using MongoDbGenericRepository.Models; @@ -12,18 +13,118 @@ namespace MongoDbGenericRepository /// public interface IBaseMongoRepository_Index where TKey : IEquatable { + /// + /// Returns the names of the indexes present on a collection. + /// + /// The type representing a Document. + /// A list containing the names of the indexes on on the concerned collection. + Task> GetIndexesNamesAsync() + where TDocument : IDocument; + + /// + /// Returns the names of the indexes present on a collection. + /// + /// The type representing a Document. + /// The cancellation token. + /// A list containing the names of the indexes on on the concerned collection. + Task> GetIndexesNamesAsync(CancellationToken cancellationToken) + where TDocument : IDocument; + /// /// Returns the names of the indexes present on a collection. /// /// The type representing a Document. /// An optional partition key /// A list containing the names of the indexes on on the concerned collection. - Task> GetIndexesNamesAsync(string partitionKey = null) + Task> GetIndexesNamesAsync(string partitionKey) + where TDocument : IDocument; + + /// + /// Returns the names of the indexes present on a collection. + /// + /// The type representing a Document. + /// An optional partition key + /// The cancellation token + /// A list containing the names of the indexes on on the concerned collection. + Task> GetIndexesNamesAsync(string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument; /// /// Create a text index on the given field. - /// IndexCreationOptions can be supplied to further specify + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field) + where TDocument : IDocument; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// The cancellation token. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// Options for creating an index. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) + where TDocument : IDocument; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// Options for creating an index. + /// The cancellation token. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, string partitionKey) + where TDocument : IDocument; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, string partitionKey, CancellationToken cancellationToken) + where TDocument : IDocument; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify /// how the creation should be done. /// /// The type representing a Document. @@ -31,12 +132,26 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) + where TDocument : IDocument; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The cancellation token. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument; /// /// Creates an index on the given field in ascending order. - /// IndexCreationOptions can be supplied to further specify + /// IndexCreationOptions can be supplied to further specify /// how the creation should be done. /// /// The type representing a Document. @@ -49,7 +164,7 @@ namespace MongoDbGenericRepository /// /// Creates an index on the given field in descending order. - /// IndexCreationOptions can be supplied to further specify + /// IndexCreationOptions can be supplied to further specify /// how the creation should be done. /// /// The type representing a Document. @@ -62,7 +177,7 @@ namespace MongoDbGenericRepository /// /// Creates a hashed index on the given field. - /// IndexCreationOptions can be supplied to further specify + /// IndexCreationOptions can be supplied to further specify /// how the creation should be done. /// /// The type representing a Document. @@ -75,7 +190,7 @@ namespace MongoDbGenericRepository /// /// Creates a combined text index. - /// IndexCreationOptions can be supplied to further specify + /// IndexCreationOptions can be supplied to further specify /// how the creation should be done. /// /// The type representing a Document.