From 658c7539897df671ff5b7a665493f6bf7a611911 Mon Sep 17 00:00:00 2001 From: Alexandre SPIESER Date: Wed, 10 Mar 2021 08:44:50 +0000 Subject: [PATCH] Added cancellation tokens (ongoing) --- .../CoreIntegrationTests.csproj | 4 +- .../IBaseMongoRepository_Update.cs | 3 + ...aseMongoRepository_Update_ClientSession.cs | 67 +++++++------ .../Abstractions/IBaseReadOnlyRepository.cs | 13 ++- ...aseMongoRepository.Update.ClientSession.cs | 20 ++-- .../DataAccess/Base/DataAccessBase.cs | 11 ++- .../DataAccess/Read/MongoDbReader.Main.cs | 98 ++++++++++++++----- .../Models/IndexCreationOptions.cs | 4 - .../MongoDbGenericRepository.csproj | 21 ++-- .../ReadOnlyMongoRepository.cs | 21 ++-- 10 files changed, 161 insertions(+), 101 deletions(-) diff --git a/CoreIntegrationTests/CoreIntegrationTests.csproj b/CoreIntegrationTests/CoreIntegrationTests.csproj index 69f6379..b89f770 100644 --- a/CoreIntegrationTests/CoreIntegrationTests.csproj +++ b/CoreIntegrationTests/CoreIntegrationTests.csproj @@ -7,8 +7,8 @@ - - + + all diff --git a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update.cs b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update.cs index d30bc5c..86ec936 100644 --- a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update.cs +++ b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository { + /// + /// The IBaseMongoRepository_Update interface exposing update functionality for documents with Guid Ids. + /// public interface IBaseMongoRepository_Update : IBaseMongoRepository_Update { /// diff --git a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs index 8ed2e1e..9e9223b 100644 --- a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs +++ b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs @@ -7,6 +7,9 @@ using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository.DataAccess.Update { + /// + /// The IBaseMongoRepository_Update_ClientSession interface exposing update functionality with a IClientSessionHandle. + /// public interface IBaseMongoRepository_Update_ClientSession { /// @@ -14,10 +17,14 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. + /// The type of the field to update. /// The client session. - /// The document with the modifications you want to persist. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -27,10 +34,14 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. + /// The type of the field to update. /// The client session. - /// The document with the modifications you want to persist. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -40,11 +51,13 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. + /// The type of the field to update. /// The client session. /// The document to modify. - /// The update definition. + /// The field to update. + /// The value of the field. /// The optional cancellation token. - /// + /// A boolean value indicating success. bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -55,10 +68,9 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The type representing a Document. /// The type of the primary key for a Document. /// The client session. - /// The document to modify. - /// The update definition. + /// The document with the modifications you want to persist. /// The optional cancellation token. - /// + /// A boolean value indicating success. bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -68,13 +80,11 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. - /// The type of the field to update. - /// The client session. + /// The client session. /// The document to modify. - /// The field to update. - /// The value of the field. + /// The update definition. /// The optional cancellation token. - /// + /// A boolean value indicating success. bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -86,11 +96,12 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The type of the primary key for a Document. /// The type of the field to update. /// The client session. - /// The document to modify. + /// The filter for the update. /// The field to update. /// The value of the field. + /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -118,13 +129,12 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The type representing a Document. /// The type of the primary key for a Document. /// The type of the field to update. - /// The client session. - /// The filter for the update. + /// The client session. + /// The document to modify. /// The field to update. /// The value of the field. - /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -134,14 +144,10 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. - /// The type of the field to update. /// The client session. - /// The filter for the update. - /// The field to update. - /// The value of the field. - /// The optional partition key. + /// The document with the modifications you want to persist. /// The optional cancellation token. - /// + /// A boolean value indicating success. Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -151,14 +157,11 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. - /// The type of the field to update. /// The client session. - /// The filter for the update. - /// The field to update. - /// The value of the field. - /// The optional partition key. + /// The document to modify. + /// The update definition. /// The optional cancellation token. - /// + /// A boolean value indicating success. Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; diff --git a/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs b/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs index 1c4866d..9370653 100644 --- a/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs +++ b/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository @@ -32,7 +33,8 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// The Id of the document you want to get. /// An optional partition key. - Task GetByIdAsync(TKey id, string partitionKey = null) + /// An optional cancellation Token. + Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -54,7 +56,8 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - Task GetOneAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -88,7 +91,8 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - Task AnyAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -110,7 +114,8 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - Task> GetAllAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; diff --git a/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs b/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs index 86d3b9b..aa661b0 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs @@ -18,7 +18,7 @@ namespace MongoDbGenericRepository /// The client session. /// The document with the modifications you want to persist. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -34,7 +34,7 @@ namespace MongoDbGenericRepository /// The client session. /// The document with the modifications you want to persist. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -51,7 +51,7 @@ namespace MongoDbGenericRepository /// The document to modify. /// The update definition. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -68,7 +68,7 @@ namespace MongoDbGenericRepository /// The document to modify. /// The update definition. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -87,7 +87,7 @@ namespace MongoDbGenericRepository /// The field to update. /// The value of the field. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -106,7 +106,7 @@ namespace MongoDbGenericRepository /// The field to update. /// The value of the field. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -126,7 +126,7 @@ namespace MongoDbGenericRepository /// The value of the field. /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual async Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -146,7 +146,7 @@ namespace MongoDbGenericRepository /// The value of the field. /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual async Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -166,7 +166,7 @@ namespace MongoDbGenericRepository /// The value of the field. /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -186,7 +186,7 @@ namespace MongoDbGenericRepository /// The value of the field. /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable diff --git a/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs b/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs index f7a4949..c0d324f 100644 --- a/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs +++ b/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs @@ -7,10 +7,20 @@ using System.Linq.Expressions; namespace MongoDbGenericRepository.DataAccess.Base { + /// + /// A base class for accessing the Database and its Collections. + /// public class DataAccessBase { + /// + /// The MongoDbContext + /// protected IMongoDbContext MongoDbContext; + /// + /// The constructor of the DataAccessBase class + /// + /// public DataAccessBase(IMongoDbContext mongoDbContext) { MongoDbContext = mongoDbContext; @@ -108,7 +118,6 @@ namespace MongoDbGenericRepository.DataAccess.Base LanguageOverride = indexCreationOptions.LanguageOverride, ExpireAfter = indexCreationOptions.ExpireAfter, DefaultLanguage = indexCreationOptions.DefaultLanguage, - BucketSize = indexCreationOptions.BucketSize, Bits = indexCreationOptions.Bits, Background = indexCreationOptions.Background, Version = indexCreationOptions.Version diff --git a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs index b07dc0f..375c7fb 100644 --- a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs +++ b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository.DataAccess.Read @@ -25,12 +26,13 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key for a Document. /// The Id of the document you want to get. /// An optional partition key. - public async virtual Task GetByIdAsync(TKey id, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { var filter = Builders.Filter.Eq("Id", id); - return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(); + return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(cancellationToken); } /// @@ -55,11 +57,12 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task GetOneAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(); + return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(cancellationToken); } /// @@ -97,11 +100,12 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task AnyAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - var count = await HandlePartitioned(partitionKey).CountDocumentsAsync(filter); + var count = await HandlePartitioned(partitionKey).CountDocumentsAsync(filter, cancellationToken: cancellationToken); return (count > 0); } @@ -127,11 +131,12 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task> GetAllAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await HandlePartitioned(partitionKey).Find(filter).ToListAsync(); + return await HandlePartitioned(partitionKey).Find(filter).ToListAsync(cancellationToken); } /// @@ -155,11 +160,12 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partitionKey - public async virtual Task CountAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await HandlePartitioned(partitionKey).CountDocumentsAsync(filter); + return await HandlePartitioned(partitionKey).CountDocumentsAsync(filter, cancellationToken: cancellationToken); } /// @@ -187,15 +193,16 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key. /// A LINQ expression filter. /// A property selector to order by descending. - /// An optional partitionKey. - public async virtual Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// An optional partitionKey.An optional cancellation Token. + public async virtual Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { return await GetCollection(partitionKey).Find(Builders.Filter.Where(filter)) .SortByDescending(maxValueSelector) .Limit(1) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(cancellationToken); } /// @@ -224,14 +231,15 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. - public async virtual Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { return await GetCollection(partitionKey).Find(Builders.Filter.Where(filter)) .SortBy(minValueSelector) .Limit(1) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(cancellationToken); } /// @@ -257,16 +265,18 @@ namespace MongoDbGenericRepository.DataAccess.Read /// /// The document type. /// The type of the primary key. + /// The type of the field for which you want the maximum value. /// A LINQ expression filter. - /// A property selector to order by ascending. + /// A property selector to order by ascending. /// An optional partitionKey. - public async virtual Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { return await GetMaxMongoQuery(filter, maxValueSelector, partitionKey) .Project(maxValueSelector) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(cancellationToken); } /// @@ -296,11 +306,12 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partition key. - public virtual async Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public virtual async Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await GetMinMongoQuery(filter, minValueSelector, partitionKey).Project(minValueSelector).FirstOrDefaultAsync(); + return await GetMinMongoQuery(filter, minValueSelector, partitionKey).Project(minValueSelector).FirstOrDefaultAsync(cancellationToken); } /// @@ -366,13 +377,14 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. + /// An optional cancellation Token. public virtual async Task SumByAsync(Expression> filter, Expression> selector, - string partitionKey = null) + string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await GetQuery(filter, partitionKey).SumAsync(selector); + return await GetQuery(filter, partitionKey).SumAsync(selector, cancellationToken); } /// @@ -451,6 +463,36 @@ namespace MongoDbGenericRepository.DataAccess.Read .ToList(); } + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// A LINQ expression filter. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + /// An optional cancellation Token. + public virtual async Task> GroupByAsync( + Expression> filter, + Expression> selector, + Expression, TProjection>> projection, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new() + { + var collection = HandlePartitioned(partitionKey); + return await collection.Aggregate() + .Match(Builders.Filter.Where(filter)) + .Group(selector, projection) + .ToListAsync(cancellationToken); + } + /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// @@ -462,13 +504,15 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. + /// An optional cancellation Token. public virtual async Task> GetSortedPaginatedAsync( Expression> filter, Expression> sortSelector, bool ascending = true, int skipNumber = 0, int takeNumber = 50, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -481,7 +525,7 @@ namespace MongoDbGenericRepository.DataAccess.Read .Sort(sorting) .Skip(skipNumber) .Limit(takeNumber) - .ToListAsync(); + .ToListAsync(cancellationToken); } /// @@ -494,12 +538,14 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. + /// An optional cancellation Token. public virtual async Task> GetSortedPaginatedAsync( Expression> filter, SortDefinition sortDefinition, int skipNumber = 0, int takeNumber = 50, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -508,7 +554,7 @@ namespace MongoDbGenericRepository.DataAccess.Read .Sort(sortDefinition) .Skip(skipNumber) .Limit(takeNumber) - .ToListAsync(); + .ToListAsync(cancellationToken); } } } diff --git a/MongoDbGenericRepository/Models/IndexCreationOptions.cs b/MongoDbGenericRepository/Models/IndexCreationOptions.cs index a117b2a..ad2d60c 100644 --- a/MongoDbGenericRepository/Models/IndexCreationOptions.cs +++ b/MongoDbGenericRepository/Models/IndexCreationOptions.cs @@ -52,10 +52,6 @@ namespace MongoDbGenericRepository.Models /// public string DefaultLanguage { get; set; } /// - /// Gets or sets the size of a geohash bucket. - /// - public double? BucketSize { get; set; } - /// /// Gets or sets the precision, in bits, used with geohash indexes. /// public int? Bits { get; set; } diff --git a/MongoDbGenericRepository/MongoDbGenericRepository.csproj b/MongoDbGenericRepository/MongoDbGenericRepository.csproj index f569520..402a376 100644 --- a/MongoDbGenericRepository/MongoDbGenericRepository.csproj +++ b/MongoDbGenericRepository/MongoDbGenericRepository.csproj @@ -2,8 +2,9 @@ net452;netstandard2.0;netstandard1.5; + true MongoDbGenericRepository - 1.4.5 + 1.4.6 Alexandre Spieser MongoDb Generic Repository A generic repository implementation using the MongoDB C# Sharp 2.0 driver. @@ -14,25 +15,17 @@ Copyright 2020 (c) Alexandre Spieser. All rights reserved. MongoDb Repository Generic NoSql true - 1.4.5 + 1.4.6 https://github.com/alexandre-spieser/mongodb-generic-repository Git - - bin\Release\net45\MongoDbGenericRepository.xml - - - - - - - - D:\development\mongodb-generic-repository\MongoDbGenericRepository\MongoDbGenericRepository.xml - + + bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml + - + diff --git a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs index e9ed276..260625e 100644 --- a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs +++ b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository @@ -49,11 +50,12 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// The Id of the document you want to get. /// An optional partition key. - public async virtual Task GetByIdAsync(TKey id, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.GetByIdAsync(id, partitionKey); + return await MongoDbReader.GetByIdAsync(id, partitionKey, cancellationToken); } /// @@ -77,11 +79,12 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task GetOneAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.GetOneAsync(filter, partitionKey); + return await MongoDbReader.GetOneAsync(filter, partitionKey, cancellationToken); } /// @@ -119,11 +122,12 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task AnyAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.AnyAsync(filter, partitionKey); + return await MongoDbReader.AnyAsync(filter, partitionKey, cancellationToken); } /// @@ -147,11 +151,12 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task> GetAllAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.GetAllAsync(filter, partitionKey); + return await MongoDbReader.GetAllAsync(filter, partitionKey, cancellationToken); } ///