Configurable connection string

This commit is contained in:
Kwoth 2016-11-15 10:54:56 +01:00
parent 12587a648e
commit bd0b668c0d
5 changed files with 16 additions and 17 deletions

View File

@ -44,6 +44,9 @@ namespace NadekoBot
static NadekoBot()
{
SetupLogger();
Credentials = new BotCredentials();
using (var uow = DbHandler.UnitOfWork())
{
AllGuildConfigs = uow.GuildConfigs.GetAll();
@ -52,16 +55,10 @@ namespace NadekoBot
public async Task RunAsync(params string[] args)
{
SetupLogger();
_log = LogManager.GetCurrentClassLogger();
_log.Info("Starting NadekoBot v" + StatsService.BotVersion);
Credentials = new BotCredentials();
//create client
Client = new ShardedDiscordClient(new DiscordSocketConfig
{
@ -122,7 +119,7 @@ namespace NadekoBot
await Task.Delay(-1).ConfigureAwait(false);
}
private void SetupLogger()
private static void SetupLogger()
{
try
{

View File

@ -12,7 +12,7 @@ namespace NadekoBot.Services.Database.Impl
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Filename=./data/NadekoBot.db");
optionsBuilder.UseSqlite(NadekoBot.Credentials.Db.ConnectionString);
}
}
}

View File

@ -15,11 +15,13 @@ namespace NadekoBot.Services
private static DbHandler _instance = null;
public static DbHandler Instance = _instance ?? (_instance = new DbHandler());
private string connectionString { get; }
static DbHandler() { }
private DbHandler() {
dbType = typeof(NadekoSqliteContext);
connectionString = NadekoBot.Credentials.Db.ConnectionString;
//switch (NadekoBot.Credentials.Db.Type.ToUpperInvariant())
//{
// case "SQLITE":
@ -35,7 +37,7 @@ namespace NadekoBot.Services
}
public NadekoContext GetDbContext() =>
Activator.CreateInstance(dbType) as NadekoContext;
new NadekoSqliteContext();
public IUnitOfWork GetUnitOfWork() =>
new UnitOfWork(GetDbContext());

View File

@ -15,14 +15,14 @@ namespace NadekoBot.Services
string MashapeKey { get; }
string LoLApiKey { get; }
DB Db { get; }
DBConfig Db { get; }
bool IsOwner(IUser u);
}
public class DB
public class DBConfig
{
public DB(string type, string connString)
public DBConfig(string type, string connString)
{
this.Type = type;
this.ConnectionString = connString;

View File

@ -28,7 +28,7 @@ namespace NadekoBot.Services.Impl
public string OsuApiKey { get; }
public string SoundCloudClientId { get; }
public DB Db { get; }
public DBConfig Db { get; }
public int TotalShards { get; }
public string CarbonKey { get; }
@ -69,7 +69,7 @@ namespace NadekoBot.Services.Impl
SoundCloudClientId = data[nameof(SoundCloudClientId)];
CarbonKey = data[nameof(CarbonKey)];
var dbSection = data.GetSection("db");
Db = new DB(string.IsNullOrWhiteSpace(dbSection["Type"])
Db = new DBConfig(string.IsNullOrWhiteSpace(dbSection["Type"])
? "sqlite"
: dbSection["Type"],
string.IsNullOrWhiteSpace(dbSection["ConnectionString"])
@ -95,7 +95,7 @@ namespace NadekoBot.Services.Impl
public string OsuApiKey { get; set; } = "";
public string SoundCloudClientId { get; set; } = "";
public string CarbonKey { get; set; } = "";
public DB Db { get; set; } = new DB("sqlite", "Filename=./data/NadekoBot.db");
public DBConfig Db { get; set; } = new DBConfig("sqlite", "Filename=./data/NadekoBot.db");
public int TotalShards { get; set; } = 1;
}