using MongoDbGenericRepository.DataAccess.Index; using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Linq.Expressions; using System.Threading; 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, 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 { return await MongoDbIndexHandler.CreateAscendingIndexAsync(field, indexCreationOptions, partitionKey); } /// public async Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey); } /// public virtual async Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { return await MongoDbIndexHandler.CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey); } /// public async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await CreateHashedIndexAsync(field, indexCreationOptions, partitionKey); } /// public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { return await MongoDbIndexHandler.CreateHashedIndexAsync(field, indexCreationOptions, partitionKey); } /// public async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey); } /// public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { return await MongoDbIndexHandler.CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey); } /// public async Task DropIndexAsync(string indexName, string partitionKey = null) where TDocument : IDocument { await DropIndexAsync(indexName, partitionKey); } /// public virtual async Task DropIndexAsync(string indexName, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { await MongoDbIndexHandler.DropIndexAsync(indexName, partitionKey); } } }