public LimiterManager(IDbConnection db) { this.db = db; var sql = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder) new SqliteQueryCreator() : (IQueryBuilder) new MysqlQueryCreator()); sql.EnsureTableStructure(new SqlTable("Limiters", new SqlColumn("AccountName", MySqlDbType.VarChar, 32) { Primary = true }, new SqlColumn("Chests", MySqlDbType.Text), new SqlColumn(db.GetSqlType() == SqlType.Mysql ? "`Limit`" : "Limit", MySqlDbType.Int32) )); using (var result = db.QueryReader("SELECT * FROM `Limiters`")) { while (result.Read()) { Limiter limiter = new Limiter(result.Get <string>("AccountName"), result.Get <int>("Limit")); limiter.LoadChests(result.Get <string>("Chests")); limiters.Add(limiter); } } }
public Task <ReturnTypes> ReloadAsync() { return(Task.Run(() => { try { lock (syncLock) { limiters.Clear(); using (var result = db.QueryReader("SELECT * FROM `Limiters`")) { while (result.Read()) { Limiter limiter = new Limiter(result.Get <string>("AccountName"), result.Get <int>("Limit")); limiter.LoadChests(result.Get <string>("Chests")); limiters.Add(limiter); } } return ReturnTypes.Success; } } catch (Exception ex) { TShock.Log.ConsoleError(ex.ToString()); return ReturnTypes.Exception; } })); }