Cleanup some warnings.
This commit is contained in:
@@ -26,7 +26,7 @@ namespace Framework.Database
|
||||
|
||||
public class AsyncCallbackProcessor<T> where T : ISqlCallback
|
||||
{
|
||||
List<T> _callbacks = new List<T>();
|
||||
List<T> _callbacks = new();
|
||||
|
||||
public T AddCallback(T query)
|
||||
{
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace Framework.Database
|
||||
{
|
||||
public static class DB
|
||||
{
|
||||
public static LoginDatabase Login = new LoginDatabase();
|
||||
public static CharacterDatabase Characters = new CharacterDatabase();
|
||||
public static WorldDatabase World = new WorldDatabase();
|
||||
public static HotfixDatabase Hotfix = new HotfixDatabase();
|
||||
public static LoginDatabase Login = new();
|
||||
public static CharacterDatabase Characters = new();
|
||||
public static WorldDatabase World = new();
|
||||
public static HotfixDatabase Hotfix = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Framework.Database
|
||||
bool updatesEnabled = database.IsAutoUpdateEnabled(_updateFlags);
|
||||
_open.Add(() =>
|
||||
{
|
||||
MySqlConnectionInfo connectionObject = new MySqlConnectionInfo
|
||||
MySqlConnectionInfo connectionObject = new()
|
||||
{
|
||||
Host = ConfigMgr.GetDefaultValue(baseDBName + "DatabaseInfo.Host", ""),
|
||||
Port = ConfigMgr.GetDefaultValue(baseDBName + "DatabaseInfo.Port", ""),
|
||||
@@ -161,10 +161,10 @@ namespace Framework.Database
|
||||
|
||||
bool _autoSetup;
|
||||
DatabaseTypeFlags _updateFlags;
|
||||
List<Func<bool>> _open = new List<Func<bool>>();
|
||||
List<Func<bool>> _populate = new List<Func<bool>>();
|
||||
List<Func<bool>> _update = new List<Func<bool>>();
|
||||
List<Func<bool>> _prepare = new List<Func<bool>>();
|
||||
List<Func<bool>> _open = new();
|
||||
List<Func<bool>> _populate = new();
|
||||
List<Func<bool>> _update = new();
|
||||
List<Func<bool>> _prepare = new();
|
||||
}
|
||||
|
||||
public enum DatabaseTypeFlags
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace Framework.Database
|
||||
bool redundancyChecks = ConfigMgr.GetDefaultValue("Updates.Redundancy", true);
|
||||
bool archivedRedundancy = ConfigMgr.GetDefaultValue("Updates.Redundancy", true);
|
||||
|
||||
UpdateResult result = new UpdateResult();
|
||||
UpdateResult result = new();
|
||||
|
||||
// Count updates
|
||||
foreach (var entry in appliedFiles)
|
||||
@@ -193,7 +193,7 @@ namespace Framework.Database
|
||||
}
|
||||
|
||||
uint speed = 0;
|
||||
AppliedFileEntry file = new AppliedFileEntry(availableQuery.GetFileName(), hash, availableQuery.state, 0);
|
||||
AppliedFileEntry file = new(availableQuery.GetFileName(), hash, availableQuery.state, 0);
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
@@ -320,7 +320,7 @@ namespace Framework.Database
|
||||
|
||||
List<FileEntry> GetFileList()
|
||||
{
|
||||
List<FileEntry> fileList = new List<FileEntry>();
|
||||
List<FileEntry> fileList = new();
|
||||
|
||||
SQLResult result = _database.Query("SELECT `path`, `state` FROM `updates_include`");
|
||||
if (result.IsEmpty())
|
||||
@@ -350,7 +350,7 @@ namespace Framework.Database
|
||||
|
||||
Dictionary<string, AppliedFileEntry> ReceiveAppliedFiles()
|
||||
{
|
||||
Dictionary<string, AppliedFileEntry> map = new Dictionary<string, AppliedFileEntry>();
|
||||
Dictionary<string, AppliedFileEntry> map = new();
|
||||
|
||||
SQLResult result = _database.Query("SELECT `name`, `hash`, `state`, UNIX_TIMESTAMP(`timestamp`) FROM `updates` ORDER BY `name` ASC");
|
||||
if (result.IsEmpty())
|
||||
@@ -358,7 +358,7 @@ namespace Framework.Database
|
||||
|
||||
do
|
||||
{
|
||||
AppliedFileEntry entry = new AppliedFileEntry(result.Read<string>(0), result.Read<string>(1), result.Read<string>(2).ToEnum<State>(), result.Read<ulong>(3));
|
||||
AppliedFileEntry entry = new(result.Read<string>(0), result.Read<string>(1), result.Read<string>(2).ToEnum<State>(), result.Read<ulong>(3));
|
||||
map.Add(entry.Name, entry);
|
||||
}
|
||||
while (result.NextRow());
|
||||
@@ -368,7 +368,7 @@ namespace Framework.Database
|
||||
|
||||
IEnumerable<FileEntry> GetFilesFromDirectory(string directory, State state)
|
||||
{
|
||||
Queue<string> queue = new Queue<string>();
|
||||
Queue<string> queue = new();
|
||||
queue.Enqueue(directory);
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
@@ -395,7 +395,7 @@ namespace Framework.Database
|
||||
|
||||
string CalculateHash(string fileName)
|
||||
{
|
||||
using (SHA1 sha1 = new SHA1Managed())
|
||||
using (SHA1 sha1 = SHA1.Create())
|
||||
{
|
||||
string text = File.ReadAllText(fileName).Replace("\r", "");
|
||||
return sha1.ComputeHash(Encoding.UTF8.GetBytes(text)).ToHexString();
|
||||
|
||||
@@ -48,8 +48,8 @@ namespace Framework.Database
|
||||
|
||||
public abstract class MySqlBase<T>
|
||||
{
|
||||
Dictionary<T, string> _preparedQueries = new Dictionary<T, string>();
|
||||
ProducerConsumerQueue<ISqlOperation> _queue = new ProducerConsumerQueue<ISqlOperation>();
|
||||
Dictionary<T, string> _preparedQueries = new();
|
||||
ProducerConsumerQueue<ISqlOperation> _queue = new();
|
||||
|
||||
MySqlConnectionInfo _connectionInfo;
|
||||
DatabaseUpdater<T> _updater;
|
||||
@@ -115,7 +115,7 @@ namespace Framework.Database
|
||||
|
||||
public void Execute(PreparedStatement stmt)
|
||||
{
|
||||
PreparedStatementTask task = new PreparedStatementTask(stmt);
|
||||
PreparedStatementTask task = new(stmt);
|
||||
_queue.Push(task);
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace Framework.Database
|
||||
|
||||
public QueryCallback AsyncQuery(PreparedStatement stmt)
|
||||
{
|
||||
PreparedStatementTask task = new PreparedStatementTask(stmt, true);
|
||||
PreparedStatementTask task = new(stmt, true);
|
||||
// Store future result before enqueueing - task might get already processed and deleted before returning from this method
|
||||
Task<SQLResult> result = task.GetFuture();
|
||||
_queue.Push(task);
|
||||
@@ -164,7 +164,7 @@ namespace Framework.Database
|
||||
|
||||
public Task<SQLQueryHolder<R>> DelayQueryHolder<R>(SQLQueryHolder<R> holder)
|
||||
{
|
||||
SQLQueryHolderTask<R> task = new SQLQueryHolderTask<R>(holder);
|
||||
SQLQueryHolderTask<R> task = new(holder);
|
||||
// Store future result before enqueueing - task might get already processed and deleted before returning from this method
|
||||
Task<SQLQueryHolder<R>> result = task.GetFuture();
|
||||
_queue.Push(task);
|
||||
@@ -178,7 +178,7 @@ namespace Framework.Database
|
||||
|
||||
public void PrepareStatement(T statement, string sql)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new();
|
||||
int index = 0;
|
||||
for (var i = 0; i < sql.Length; i++)
|
||||
{
|
||||
@@ -257,7 +257,7 @@ namespace Framework.Database
|
||||
|
||||
public TransactionCallback AsyncCommitTransaction(SQLTransaction transaction)
|
||||
{
|
||||
TransactionWithResultTask task = new TransactionWithResultTask(transaction);
|
||||
TransactionWithResultTask task = new(transaction);
|
||||
Task<bool> result = task.GetFuture();
|
||||
_queue.Push(task);
|
||||
return new TransactionCallback(result);
|
||||
@@ -304,7 +304,7 @@ namespace Framework.Database
|
||||
if (ex.InnerException is MySqlException)
|
||||
code = (MySqlErrorCode)((MySqlException)ex.InnerException).Number;
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder($"SqlException: MySqlErrorCode: {code} Message: {ex.Message} SqlQuery: {query} ");
|
||||
StringBuilder stringBuilder = new($"SqlException: MySqlErrorCode: {code} Message: {ex.Message} SqlQuery: {query} ");
|
||||
if (parameters != null)
|
||||
{
|
||||
stringBuilder.Append("Parameters: ");
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Framework.Database
|
||||
public class PreparedStatement
|
||||
{
|
||||
public string CommandText;
|
||||
public Dictionary<int, object> Parameters = new Dictionary<int, object>();
|
||||
public Dictionary<int, object> Parameters = new();
|
||||
|
||||
public PreparedStatement(string commandText)
|
||||
{
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace Framework.Database
|
||||
}
|
||||
|
||||
Task<SQLResult> _result;
|
||||
Queue<QueryCallbackData> _callbacks = new Queue<QueryCallbackData>();
|
||||
Queue<QueryCallbackData> _callbacks = new();
|
||||
}
|
||||
|
||||
struct QueryCallbackData
|
||||
|
||||
@@ -22,8 +22,8 @@ namespace Framework.Database
|
||||
{
|
||||
public class SQLQueryHolder<T>
|
||||
{
|
||||
public Dictionary<T, PreparedStatement> m_queries = new Dictionary<T, PreparedStatement>();
|
||||
Dictionary<T, SQLResult> _results = new Dictionary<T, SQLResult>();
|
||||
public Dictionary<T, PreparedStatement> m_queries = new();
|
||||
Dictionary<T, SQLResult> _results = new();
|
||||
|
||||
public void SetQuery(T index, string sql, params object[] args)
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Framework.Database
|
||||
|
||||
public void Append(PreparedStatement stmt)
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(stmt.CommandText);
|
||||
MySqlCommand cmd = new(stmt.CommandText);
|
||||
foreach (var parameter in stmt.Parameters)
|
||||
cmd.Parameters.AddWithValue("@" + parameter.Key, parameter.Value);
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Framework.Database
|
||||
}
|
||||
|
||||
SQLTransaction m_trans;
|
||||
public static object _deadlockLock = new object();
|
||||
public static object _deadlockLock = new();
|
||||
}
|
||||
|
||||
class TransactionWithResultTask : TransactionTask
|
||||
@@ -119,7 +119,7 @@ namespace Framework.Database
|
||||
|
||||
public Task<bool> GetFuture() { return m_result.Task; }
|
||||
|
||||
TaskCompletionSource<bool> m_result = new TaskCompletionSource<bool>();
|
||||
TaskCompletionSource<bool> m_result = new();
|
||||
}
|
||||
|
||||
public class TransactionCallback : ISqlCallback
|
||||
|
||||
Reference in New Issue
Block a user