diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/DbDataReaderFactoryAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/DbDataReaderFactoryAsync.cs index 43b883876..a528cfdf5 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/DbDataReaderFactoryAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteDbDataReaderItemsAsync/DbDataReaderFactoryAsync.cs @@ -7,6 +7,7 @@ using System.Data; using System.Data.Common; using System.Net.Http.Headers; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data @@ -18,16 +19,16 @@ namespace MongoDb.Ado.data { "find", new QueryFindHandlerAsync() }, { "aggregate", new QueryAggregateHandlerAsync() }, }; - public async Task HandleAsync(string operation, IMongoCollection collection, string json) + public async Task HandleAsync(string operation, IMongoCollection collection, string json, CancellationToken cancellationToken) { MongoDbMethodUtils.ValidateOperation(operation); var doc = MongoDB.Bson.Serialization.BsonSerializer.Deserialize(json); DbDataReaderFactoryAsync.Items.TryGetValue(operation, out var handler); if (handler == null) { - await ExecuteHandlerFactoryAsync.HandlerAsync(operation, json, collection); + await ExecuteHandlerFactoryAsync.HandlerAsync(operation, json, collection, cancellationToken); return new DataTable().CreateDataReader(); - } + } return await handler.HandlerAsync(collection, doc); } diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/DeleteHandlerAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/DeleteHandlerAsync.cs index acff45561..14c984360 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/DeleteHandlerAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/DeleteHandlerAsync.cs @@ -3,18 +3,20 @@ using MongoDB.Driver; using System; using System.Collections.Generic; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data { public class DeleteHandlerAsync : IMongoOperationHandlerAsync { + public CancellationToken token { get; set; } public string operation { get; set; } public async Task HandleAsync(IMongoCollection collection, string json) { var doc = BsonDocument.Parse(json); var filter = doc["filter"].AsBsonDocument; - var result =await collection.DeleteOneAsync(filter); + var result =await collection.DeleteOneAsync(filter,token); return (int)result.DeletedCount; } } diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/DeleteManyHandlerAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/DeleteManyHandlerAsync.cs index c023960b9..8bde3d6e7 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/DeleteManyHandlerAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/DeleteManyHandlerAsync.cs @@ -5,11 +5,13 @@ using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; +using System.Threading; namespace MongoDb.Ado.data { public class DeleteManyHandlerAsync : IMongoOperationHandlerAsync { + public CancellationToken token { get; set; } public string operation { get; set; } public async Task HandleAsync(IMongoCollection collection, string json) { @@ -18,7 +20,7 @@ namespace MongoDb.Ado.data foreach (var doc in documents) { var filter = doc["filter"].AsBsonDocument; - var result =await collection.DeleteManyAsync(filter); + var result =await collection.DeleteManyAsync(filter,token); total += (int)result.DeletedCount; } return total; diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/ExecuteHandlerFactoryAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/ExecuteHandlerFactoryAsync.cs index efaf368ba..acff1890e 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/ExecuteHandlerFactoryAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/ExecuteHandlerFactoryAsync.cs @@ -4,6 +4,7 @@ using MongoDB.Driver; using System; using System.Collections.Generic; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data @@ -22,7 +23,7 @@ namespace MongoDb.Ado.data }; - public static Task HandlerAsync(string operation, string json, IMongoCollection collection) + public static Task HandlerAsync(string operation, string json, IMongoCollection collection,CancellationToken cancellationToken) { MongoDbMethodUtils.ValidateOperation(operation); var handlers = ExecuteHandlerFactoryAsync.Items; @@ -30,6 +31,7 @@ namespace MongoDb.Ado.data if (!handlers.TryGetValue(operation, out var handler)) throw new NotSupportedException($"不支持的操作类型: {operation}"); handler.operation = operation; + handler.token = cancellationToken; return handler.HandleAsync(collection, json); } diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/IMongoOperationHandler.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/IMongoOperationHandler.cs index 4255a11ab..4269cbba0 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/IMongoOperationHandler.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/IMongoOperationHandler.cs @@ -3,6 +3,7 @@ using MongoDB.Driver; using System; using System.Collections.Generic; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data @@ -10,6 +11,8 @@ namespace MongoDb.Ado.data public interface IMongoOperationHandlerAsync { string operation { get; set; } + CancellationToken token { get; set; } + Task HandleAsync(IMongoCollection collection, string json); } } diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/InsertHandlerAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/InsertHandlerAsync.cs index 3b6b120bd..f6483f4b7 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/InsertHandlerAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/InsertHandlerAsync.cs @@ -3,12 +3,14 @@ using MongoDB.Driver; using System; using System.Collections.Generic; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data { public class InsertHandlerAsync : IMongoOperationHandlerAsync { + public CancellationToken token { get; set; } public string operation { get; set; } public async Task HandleAsync(IMongoCollection collection, string json) { diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/InsertManyHandlerAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/InsertManyHandlerAsync.cs index 8508e7ac5..18058dd23 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/InsertManyHandlerAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/InsertManyHandlerAsync.cs @@ -5,11 +5,13 @@ using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; +using System.Threading; namespace MongoDb.Ado.data { public class InsertManyHandlerAsync : IMongoOperationHandlerAsync { + public CancellationToken token { get; set; } public string operation { get; set; } public async Task HandleAsync(IMongoCollection collection, string json) { diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/NonFindHandlerAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/NonFindHandlerAsync.cs index a0568ebff..7ff64f326 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/NonFindHandlerAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/NonFindHandlerAsync.cs @@ -3,17 +3,19 @@ using MongoDB.Driver; using System; using System.Collections.Generic; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data { public class NonFindHandlerAsync : IMongoOperationHandlerAsync { + public CancellationToken token { get; set; } public string operation { get; set; } public async Task HandleAsync(IMongoCollection collection, string json) { - using (var dr = await new DbDataReaderFactoryAsync().HandleAsync(operation, collection, json)) + using (var dr = await new DbDataReaderFactoryAsync().HandleAsync(operation, collection, json,token)) { if (dr.Read()) { diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/UpdateHandler.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/UpdateHandler.cs index fe5bb4456..9cea06d44 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/UpdateHandler.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/UpdateHandler.cs @@ -3,19 +3,21 @@ using MongoDB.Driver; using System; using System.Collections.Generic; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data { public class UpdateHandlerAsync : IMongoOperationHandlerAsync { + public CancellationToken token { get; set; } public string operation { get; set; } public async Task HandleAsync(IMongoCollection collection, string json) { var doc = BsonDocument.Parse(json); var filter = doc["filter"].AsBsonDocument; var update = doc["update"].AsBsonDocument; - var result =await collection.UpdateOneAsync(filter, update); + var result =await collection.UpdateOneAsync(filter, update,null,token); return (int)result.ModifiedCount; } } diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/UpdateManyHandler.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/UpdateManyHandler.cs index e97d731c1..9731ddf36 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/UpdateManyHandler.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItemsAsync/UpdateManyHandler.cs @@ -5,11 +5,13 @@ using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; +using System.Threading; namespace MongoDb.Ado.data { public class UpdateManyHandlerAsync : IMongoOperationHandlerAsync { + public CancellationToken token { get; set; } public string operation { get; set; } public async Task HandleAsync(IMongoCollection collection, string json) { diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteScalarItemsAsync/ExecuteScalarHandlerAsync.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteScalarItemsAsync/ExecuteScalarHandlerAsync.cs index e5fe3d958..e03f4c781 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteScalarItemsAsync/ExecuteScalarHandlerAsync.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteScalarItemsAsync/ExecuteScalarHandlerAsync.cs @@ -4,15 +4,16 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MongoDb.Ado.data { public class ExecuteScalarHandlerAsync { - public async Task HandleAsync(string operation, IMongoCollection collection, string json) + public async Task HandleAsync(string operation, IMongoCollection collection, string json,CancellationToken cancellationToken) { - using (var dbReader = await new DbDataReaderFactoryAsync().HandleAsync(operation, collection, json)) + using (var dbReader = await new DbDataReaderFactoryAsync().HandleAsync(operation, collection, json,cancellationToken)) { if (dbReader.Read()) { diff --git a/Src/Asp.NetCore2/MongoDb.Ado.data/MongoDbCommand.cs b/Src/Asp.NetCore2/MongoDb.Ado.data/MongoDbCommand.cs index 6ccb9a165..c1976ce33 100644 --- a/Src/Asp.NetCore2/MongoDb.Ado.data/MongoDbCommand.cs +++ b/Src/Asp.NetCore2/MongoDb.Ado.data/MongoDbCommand.cs @@ -83,19 +83,19 @@ namespace MongoDb.Ado.data { var (operation, collectionName, json) = ParseCommand(_commandText); var collection = GetCollection(collectionName); - return ExecuteHandlerFactoryAsync.HandlerAsync(operation, json, collection); + return ExecuteHandlerFactoryAsync.HandlerAsync(operation, json, collection, cancellationToken); } public override Task ExecuteScalarAsync(CancellationToken cancellationToken) { var (operation, collectionName, json) = ParseCommand(_commandText); var collection = GetCollection(collectionName); - return new ExecuteScalarHandlerAsync().HandleAsync(operation, collection, json); + return new ExecuteScalarHandlerAsync().HandleAsync(operation, collection, json, cancellationToken); } protected override Task ExecuteDbDataReaderAsync(CommandBehavior behavior,CancellationToken cancellationToken) { var (operation, collectionName, json) = ParseCommand(_commandText); var collection = GetCollection(collectionName); - return new DbDataReaderFactoryAsync().HandleAsync(operation, collection, json); + return new DbDataReaderFactoryAsync().HandleAsync(operation, collection, json, cancellationToken); }