using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using MongoDbGenericRepository.DataAccess.Index; using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { /// /// The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. /// Its constructor must be given a connection string and a database name. /// public abstract partial class BaseMongoRepository : IBaseMongoRepository_Index { private IMongoDbIndexHandler _mongoDbIndexHandler; /// /// The MongoDb accessor to manage indexes. /// protected virtual IMongoDbIndexHandler MongoDbIndexHandler { get { if (_mongoDbIndexHandler != null) { return _mongoDbIndexHandler; } lock (_initLock) { if (_mongoDbIndexHandler == null) { _mongoDbIndexHandler = new MongoDbIndexHandler(MongoDbContext); } } return _mongoDbIndexHandler; } set => _mongoDbIndexHandler = value; } /// public async Task> GetIndexesNamesAsync() where TDocument : IDocument { return await GetIndexesNamesAsync(null, CancellationToken.None); } /// 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 GetIndexesNamesAsync(null, CancellationToken.None); } /// public virtual async Task> GetIndexesNamesAsync(CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await GetIndexesNamesAsync(null, cancellationToken); } /// 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 CreateTextIndexAsync(field, null, null, CancellationToken.None); } /// 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) where TDocument : IDocument { return await CreateAscendingIndexAsync(field, null, null, CancellationToken.None); } /// public async Task CreateAscendingIndexAsync(Expression> field, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateAscendingIndexAsync(field, null, null, cancellationToken); } /// public async Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) where TDocument : IDocument { return await CreateAscendingIndexAsync(field, indexCreationOptions, null, CancellationToken.None); } /// public async Task CreateAscendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateAscendingIndexAsync(field, indexCreationOptions, null, cancellationToken); } /// public async Task CreateAscendingIndexAsync(Expression> field, string partitionKey) where TDocument : IDocument { return await CreateAscendingIndexAsync(field, null, partitionKey, CancellationToken.None); } /// public async Task CreateAscendingIndexAsync( Expression> field, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateAscendingIndexAsync(field, null, partitionKey, cancellationToken); } /// public async Task CreateAscendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) where TDocument : IDocument { return await CreateAscendingIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); } /// public async Task CreateAscendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateAscendingIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); } /// public virtual async Task CreateAscendingIndexAsync(Expression> field) where TDocument : IDocument where TKey : IEquatable { return await CreateAscendingIndexAsync(field, null, null, CancellationToken.None); } /// public virtual async Task CreateAscendingIndexAsync( Expression> field, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateAscendingIndexAsync(field, null, null, cancellationToken); } /// public virtual async Task CreateAscendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions) where TDocument : IDocument where TKey : IEquatable { return await CreateAscendingIndexAsync(field, indexCreationOptions, null, CancellationToken.None); } /// public virtual async Task CreateAscendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateAscendingIndexAsync(field, indexCreationOptions, null, cancellationToken); } /// public virtual async Task CreateAscendingIndexAsync(Expression> field, string partitionKey) where TDocument : IDocument where TKey : IEquatable { return await CreateAscendingIndexAsync(field, null, partitionKey, CancellationToken.None); } /// public virtual async Task CreateAscendingIndexAsync( Expression> field, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateAscendingIndexAsync(field, null, partitionKey, cancellationToken); } /// public virtual async Task CreateAscendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) where TDocument : IDocument where TKey : IEquatable { return await CreateAscendingIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); } /// public virtual async Task CreateAscendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await MongoDbIndexHandler.CreateAscendingIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); } /// public async Task CreateDescendingIndexAsync(Expression> field) where TDocument : IDocument { return await CreateDescendingIndexAsync(field, null, null, CancellationToken.None); } /// public async Task CreateDescendingIndexAsync(Expression> field, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateDescendingIndexAsync(field, null, null, cancellationToken); } /// public async Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) where TDocument : IDocument { return await CreateDescendingIndexAsync(field, indexCreationOptions, null, CancellationToken.None); } /// public async Task CreateDescendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateDescendingIndexAsync(field, indexCreationOptions, null, cancellationToken); } /// public async Task CreateDescendingIndexAsync(Expression> field, string partitionKey) where TDocument : IDocument { return await CreateDescendingIndexAsync(field, null, partitionKey, CancellationToken.None); } /// public async Task CreateDescendingIndexAsync( Expression> field, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateDescendingIndexAsync(field, null, partitionKey, cancellationToken); } /// public async Task CreateDescendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) where TDocument : IDocument { return await CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); } /// public async Task CreateDescendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); } /// public virtual async Task CreateDescendingIndexAsync(Expression> field) where TDocument : IDocument where TKey : IEquatable { return await CreateDescendingIndexAsync(field, null, null, CancellationToken.None); } /// public virtual async Task CreateDescendingIndexAsync( Expression> field, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateDescendingIndexAsync(field, null, null, cancellationToken); } /// public virtual async Task CreateDescendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions) where TDocument : IDocument where TKey : IEquatable { return await CreateDescendingIndexAsync(field, indexCreationOptions, null, CancellationToken.None); } /// public virtual async Task CreateDescendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateDescendingIndexAsync(field, indexCreationOptions, null, cancellationToken); } /// public virtual async Task CreateDescendingIndexAsync(Expression> field, string partitionKey) where TDocument : IDocument where TKey : IEquatable { return await CreateDescendingIndexAsync(field, null, partitionKey, CancellationToken.None); } /// public virtual async Task CreateDescendingIndexAsync( Expression> field, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateDescendingIndexAsync(field, null, partitionKey, cancellationToken); } /// public virtual async Task CreateDescendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) where TDocument : IDocument where TKey : IEquatable { return await CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); } /// public virtual async Task CreateDescendingIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await MongoDbIndexHandler.CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); } /// public async Task CreateHashedIndexAsync(Expression> field) where TDocument : IDocument { return await CreateHashedIndexAsync(field, null, null, CancellationToken.None); } /// public async Task CreateHashedIndexAsync(Expression> field, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateHashedIndexAsync(field, null, null, cancellationToken); } /// public async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions) where TDocument : IDocument { return await CreateHashedIndexAsync(field, indexCreationOptions, null, CancellationToken.None); } /// public async Task CreateHashedIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateHashedIndexAsync(field, indexCreationOptions, null, cancellationToken); } /// public async Task CreateHashedIndexAsync(Expression> field, string partitionKey) where TDocument : IDocument { return await CreateHashedIndexAsync(field, null, partitionKey, CancellationToken.None); } /// public async Task CreateHashedIndexAsync( Expression> field, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateHashedIndexAsync(field, null, partitionKey, cancellationToken); } /// public async Task CreateHashedIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) where TDocument : IDocument { return await CreateHashedIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); } /// public async Task CreateHashedIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateHashedIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); } /// public virtual async Task CreateHashedIndexAsync(Expression> field) where TDocument : IDocument where TKey : IEquatable { return await CreateHashedIndexAsync(field, null, null, CancellationToken.None); } /// public virtual async Task CreateHashedIndexAsync( Expression> field, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateHashedIndexAsync(field, null, null, cancellationToken); } /// public virtual async Task CreateHashedIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions) where TDocument : IDocument where TKey : IEquatable { return await CreateHashedIndexAsync(field, indexCreationOptions, null, CancellationToken.None); } /// public virtual async Task CreateHashedIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateHashedIndexAsync(field, indexCreationOptions, null, cancellationToken); } /// public virtual async Task CreateHashedIndexAsync(Expression> field, string partitionKey) where TDocument : IDocument where TKey : IEquatable { return await CreateHashedIndexAsync(field, null, partitionKey, CancellationToken.None); } /// public virtual async Task CreateHashedIndexAsync( Expression> field, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateHashedIndexAsync(field, null, partitionKey, cancellationToken); } /// public virtual async Task CreateHashedIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey) where TDocument : IDocument where TKey : IEquatable { return await CreateHashedIndexAsync(field, indexCreationOptions, partitionKey, CancellationToken.None); } /// public virtual async Task CreateHashedIndexAsync( Expression> field, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await MongoDbIndexHandler.CreateHashedIndexAsync(field, indexCreationOptions, partitionKey, cancellationToken); } /// public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields) where TDocument : IDocument { return await CreateCombinedTextIndexAsync(fields, null, null, CancellationToken.None); } /// public async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateCombinedTextIndexAsync(fields, null, null, cancellationToken); } /// public async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, IndexCreationOptions indexCreationOptions) where TDocument : IDocument { return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, null, CancellationToken.None); } /// public async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, null, cancellationToken); } /// public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, string partitionKey) where TDocument : IDocument { return await CreateCombinedTextIndexAsync(fields, null, partitionKey, CancellationToken.None); } /// public async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateCombinedTextIndexAsync(fields, null, partitionKey, cancellationToken); } /// public async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey) where TDocument : IDocument { return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey, CancellationToken.None); } /// public async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey, cancellationToken); } /// public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields) where TDocument : IDocument where TKey : IEquatable { return await CreateCombinedTextIndexAsync(fields, null, null, CancellationToken.None); } /// public virtual async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateCombinedTextIndexAsync(fields, null, null, cancellationToken); } /// public virtual async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, IndexCreationOptions indexCreationOptions) where TDocument : IDocument where TKey : IEquatable { return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, null, CancellationToken.None); } /// public virtual async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, IndexCreationOptions indexCreationOptions, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, null, cancellationToken); } /// public virtual async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, string partitionKey) where TDocument : IDocument where TKey : IEquatable { return await CreateCombinedTextIndexAsync(fields, null, partitionKey, CancellationToken.None); } /// public virtual async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await CreateCombinedTextIndexAsync(fields, null, partitionKey, cancellationToken); } /// public virtual async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey) where TDocument : IDocument where TKey : IEquatable { return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey, CancellationToken.None); } /// public virtual async Task CreateCombinedTextIndexAsync( IEnumerable>> fields, IndexCreationOptions indexCreationOptions, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { return await MongoDbIndexHandler.CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey, cancellationToken); } /// public async Task DropIndexAsync(string indexName) where TDocument : IDocument { await DropIndexAsync(indexName, null, CancellationToken.None); } /// public async Task DropIndexAsync(string indexName, CancellationToken cancellationToken) where TDocument : IDocument { await DropIndexAsync(indexName, null, cancellationToken); } /// public async Task DropIndexAsync(string indexName, string partitionKey) where TDocument : IDocument { await DropIndexAsync(indexName, partitionKey, CancellationToken.None); } /// public async Task DropIndexAsync(string indexName, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument { await DropIndexAsync(indexName, partitionKey, cancellationToken); } /// public virtual async Task DropIndexAsync(string indexName) where TDocument : IDocument where TKey : IEquatable { await DropIndexAsync(indexName, null, CancellationToken.None); } /// public virtual async Task DropIndexAsync(string indexName, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { await DropIndexAsync(indexName, null, cancellationToken); } /// public virtual async Task DropIndexAsync(string indexName, string partitionKey) where TDocument : IDocument where TKey : IEquatable { await DropIndexAsync(indexName, partitionKey, CancellationToken.None); } /// public virtual async Task DropIndexAsync(string indexName, string partitionKey, CancellationToken cancellationToken) where TDocument : IDocument where TKey : IEquatable { await MongoDbIndexHandler.DropIndexAsync(indexName, partitionKey, cancellationToken); } } }