2025-05-02 11:39:41 +08:00
|
|
|
|
using MongoDB.Bson;
|
|
|
|
|
using MongoDB.Bson.Serialization.Serializers;
|
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2025-05-02 15:46:46 +08:00
|
|
|
|
using System.Data;
|
2025-05-02 11:39:41 +08:00
|
|
|
|
using System.Data.Common;
|
2025-05-02 15:46:46 +08:00
|
|
|
|
using System.Net.Http.Headers;
|
2025-05-02 11:39:41 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace MongoDb.Ado.data
|
|
|
|
|
{
|
|
|
|
|
public class DbDataReaderFactory
|
|
|
|
|
{
|
2025-05-02 16:55:48 +08:00
|
|
|
|
public readonly static Dictionary<string, IQueryHandler> Items = new Dictionary<string, IQueryHandler>(StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
{
|
|
|
|
|
{ "find", new QueryFindHandler() },
|
2025-05-02 17:03:48 +08:00
|
|
|
|
{ "aggregate", new QueryAggregateHandler() },
|
2025-05-02 16:55:48 +08:00
|
|
|
|
};
|
2025-05-02 11:39:41 +08:00
|
|
|
|
public DbDataReader Handle(string operation, IMongoCollection<BsonDocument> collection, string json)
|
|
|
|
|
{
|
2025-05-02 17:00:36 +08:00
|
|
|
|
MongoDbMethodUtils.ValidateOperation(operation);
|
2025-05-02 11:39:41 +08:00
|
|
|
|
var doc = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonValue>(json);
|
2025-05-02 16:55:48 +08:00
|
|
|
|
DbDataReaderFactory.Items.TryGetValue(operation, out var handler);
|
|
|
|
|
if (handler==null)
|
2025-05-02 11:39:41 +08:00
|
|
|
|
{
|
2025-05-04 18:39:11 +08:00
|
|
|
|
ExecuteHandlerFactory.Handler(operation, json, collection,new HandlerContext());
|
2025-05-02 15:46:46 +08:00
|
|
|
|
return new DataTable().CreateDataReader();
|
2025-05-02 11:39:41 +08:00
|
|
|
|
}
|
2025-05-02 16:55:48 +08:00
|
|
|
|
return handler.Handler(collection, doc);
|
2025-05-02 11:39:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|