2025-05-02 16:30:22 +08:00
|
|
|
|
using MongoDB.Bson;
|
|
|
|
|
using MongoDB.Bson.Serialization.Serializers;
|
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.Common;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MongoDb.Ado.data
|
|
|
|
|
{
|
|
|
|
|
public class DbDataReaderFactoryAsync
|
|
|
|
|
{
|
2025-05-02 16:55:48 +08:00
|
|
|
|
public readonly static Dictionary<string, IQueryHandlerAsync> Items = new Dictionary<string, IQueryHandlerAsync>(StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
{
|
|
|
|
|
{ "find", new QueryFindHandlerAsync() },
|
|
|
|
|
{ "aggregate", new QueryFindHandlerAsync() },
|
|
|
|
|
};
|
2025-05-02 16:56:33 +08:00
|
|
|
|
public async Task<DbDataReader> HandleAsync(string operation, IMongoCollection<BsonDocument> collection, string json)
|
2025-05-02 16:30:22 +08:00
|
|
|
|
{
|
|
|
|
|
var doc = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonValue>(json);
|
2025-05-02 16:55:48 +08:00
|
|
|
|
DbDataReaderFactoryAsync.Items.TryGetValue(operation, out var handler);
|
|
|
|
|
if (handler == null)
|
2025-05-02 16:30:22 +08:00
|
|
|
|
{
|
2025-05-02 16:55:48 +08:00
|
|
|
|
await ExecuteHandlerFactoryAsync.HandlerAsync(operation, json, collection);
|
2025-05-02 16:30:22 +08:00
|
|
|
|
return new DataTable().CreateDataReader();
|
|
|
|
|
}
|
2025-05-02 16:55:48 +08:00
|
|
|
|
return await handler.HandlerAsync(collection, doc);
|
2025-05-02 16:30:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|