2023-09-01 22:33:36 +00:00
|
|
|
using BotSharp.Plugin.MongoStorage.Collections;
|
2023-08-26 04:41:01 +00:00
|
|
|
|
2023-09-01 22:33:36 +00:00
|
|
|
namespace BotSharp.Plugin.MongoStorage;
|
2023-08-26 04:41:01 +00:00
|
|
|
|
|
|
|
|
public class MongoDbContext
|
|
|
|
|
{
|
|
|
|
|
private readonly MongoClient _mongoClient;
|
|
|
|
|
private readonly string _mongoDbDatabaseName;
|
|
|
|
|
|
|
|
|
|
public MongoDbContext(string mongoDbConnectionString)
|
|
|
|
|
{
|
|
|
|
|
_mongoClient = new MongoClient(mongoDbConnectionString);
|
|
|
|
|
_mongoDbDatabaseName = GetDatabaseName(mongoDbConnectionString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetDatabaseName(string mongoDbConnectionString)
|
|
|
|
|
{
|
|
|
|
|
var databaseName = mongoDbConnectionString.Substring(mongoDbConnectionString.LastIndexOf("/", StringComparison.InvariantCultureIgnoreCase) + 1);
|
|
|
|
|
if (databaseName.Contains("?"))
|
|
|
|
|
{
|
|
|
|
|
databaseName = databaseName.Substring(0, databaseName.IndexOf("?", StringComparison.InvariantCultureIgnoreCase));
|
|
|
|
|
}
|
|
|
|
|
return databaseName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IMongoDatabase Database { get { return _mongoClient.GetDatabase(_mongoDbDatabaseName); } }
|
|
|
|
|
|
|
|
|
|
public IMongoCollection<AgentCollection> Agents
|
|
|
|
|
=> Database.GetCollection<AgentCollection>("OneBrainAgents");
|
|
|
|
|
|
|
|
|
|
public IMongoCollection<ConversationCollection> Conversations
|
|
|
|
|
=> Database.GetCollection<ConversationCollection>("OneBrainConversations");
|
|
|
|
|
|
2023-09-06 04:41:49 +00:00
|
|
|
public IMongoCollection<ConversationDialogCollection> ConversationDialogs
|
|
|
|
|
=> Database.GetCollection<ConversationDialogCollection>("OneBrainConversationDialogs");
|
|
|
|
|
|
2023-08-26 04:41:01 +00:00
|
|
|
public IMongoCollection<UserCollection> Users
|
|
|
|
|
=> Database.GetCollection<UserCollection>("OneBrainUsers");
|
|
|
|
|
|
|
|
|
|
public IMongoCollection<UserAgentCollection> UserAgents
|
|
|
|
|
=> Database.GetCollection<UserAgentCollection>("OneBrainUserAgents");
|
2023-09-02 22:41:58 +00:00
|
|
|
|
|
|
|
|
public IMongoCollection<RoutingItemCollection> RoutingItems
|
|
|
|
|
=> Database.GetCollection<RoutingItemCollection>("OneBrainRoutingItems");
|
|
|
|
|
|
|
|
|
|
public IMongoCollection<RoutingProfileCollection> RoutingProfiles
|
|
|
|
|
=> Database.GetCollection<RoutingProfileCollection>("OneBrainRoutingProfiles");
|
2023-08-26 04:41:01 +00:00
|
|
|
}
|