get db name
This commit is contained in:
parent
6554e09a58
commit
bf253a84fd
|
|
@ -4,7 +4,7 @@ public class BotSharpDatabaseSettings : DatabaseBasicSettings
|
|||
{
|
||||
public string[] Assemblies { get; set; }
|
||||
public string FileRepository { get; set; }
|
||||
public BotSharpMongoDbSetting BotSharpMongoDb { get; set; }
|
||||
public string BotSharpMongoDb { get; set; }
|
||||
public string TablePrefix { get; set; }
|
||||
public DbConnectionSetting BotSharp { get; set; }
|
||||
public string Redis { get; set; }
|
||||
|
|
@ -28,10 +28,4 @@ public class DbConnectionSetting
|
|||
{
|
||||
Slavers = new string[0];
|
||||
}
|
||||
}
|
||||
|
||||
public class BotSharpMongoDbSetting
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
public string? DbNameIndex { get; set; }
|
||||
}
|
||||
|
|
@ -8,16 +8,17 @@ public class MongoDbContext
|
|||
private readonly string _mongoDbDatabaseName;
|
||||
private readonly string _collectionPrefix;
|
||||
|
||||
private const string DB_NAME_INDEX = "authSource";
|
||||
|
||||
public MongoDbContext(BotSharpDatabaseSettings dbSettings)
|
||||
{
|
||||
var mongoDbConnectionString = dbSettings.BotSharpMongoDb.ConnectionString;
|
||||
var dbNameIndex = dbSettings.BotSharpMongoDb.DbNameIndex;
|
||||
var mongoDbConnectionString = dbSettings.BotSharpMongoDb;
|
||||
_mongoClient = new MongoClient(mongoDbConnectionString);
|
||||
_mongoDbDatabaseName = GetDatabaseName(mongoDbConnectionString, dbNameIndex);
|
||||
_mongoDbDatabaseName = GetDatabaseName(mongoDbConnectionString);
|
||||
_collectionPrefix = dbSettings.TablePrefix.IfNullOrEmptyAs("BotSharp");
|
||||
}
|
||||
|
||||
private string GetDatabaseName(string mongoDbConnectionString, string? dbNameIndex = null)
|
||||
private string GetDatabaseName(string mongoDbConnectionString)
|
||||
{
|
||||
var dbName = string.Empty;
|
||||
if (!Uri.TryCreate(mongoDbConnectionString, UriKind.Absolute, out var conn))
|
||||
|
|
@ -28,9 +29,9 @@ public class MongoDbContext
|
|||
var query = HttpUtility.ParseQueryString(conn.Query);
|
||||
var keys = query.AllKeys ?? [];
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(dbNameIndex) && keys.Contains(dbNameIndex))
|
||||
if (keys.Contains(DB_NAME_INDEX))
|
||||
{
|
||||
dbName = query[dbNameIndex];
|
||||
dbName = query[DB_NAME_INDEX];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -226,10 +226,7 @@
|
|||
"Database": {
|
||||
"Default": "FileRepository",
|
||||
"TablePrefix": "BotSharp",
|
||||
"BotSharpMongoDb": {
|
||||
"ConnectionString": "",
|
||||
"DbIndex": ""
|
||||
},
|
||||
"BotSharpMongoDb": "",
|
||||
"FileRepository": "data",
|
||||
"Assemblies": [ "BotSharp.Core" ]
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue