mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-11-07 12:07:05 +01:00
Replace MenuManagerCS2 with Panorama UI Kit for the admin menus and css_vote. Layout names (menu, vote, banner, toast) are configurable under MenuConfig and preloaded on startup; MenuType is removed and ConfigVersion bumped to 26. - Drop MenuManagerApi.dll and the old chat menu classes - Reference PanoramaUiKit.Shared.dll, bump CounterStrikeSharp to 1.0.376 - Add .editorconfig and CODING_CONVENTIONS.md, apply them codebase-wide - Remove the CS2-SimpleAdmin-docs site - Rewrite README for the fork
69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using MySqlConnector;
|
|
|
|
namespace CS2_SimpleAdmin.Database;
|
|
|
|
public class Database(string dbConnectionString)
|
|
{
|
|
public MySqlConnection GetConnection()
|
|
{
|
|
try
|
|
{
|
|
MySqlConnection connection = new MySqlConnection(dbConnectionString);
|
|
connection.Open();
|
|
|
|
// using var cmd = connection.CreateCommand();
|
|
// cmd.CommandText = "SET NAMES 'utf8mb4' COLLATE 'utf8mb4_general_ci';";
|
|
// cmd.ExecuteNonQueryAsync();
|
|
|
|
return connection;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
CS2_SimpleAdmin._logger?.LogCritical($"Unable to connect to database: {ex.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<MySqlConnection> GetConnectionAsync()
|
|
{
|
|
try
|
|
{
|
|
MySqlConnection connection = new MySqlConnection(dbConnectionString);
|
|
await connection.OpenAsync();
|
|
|
|
// await using var cmd = connection.CreateCommand();
|
|
// cmd.CommandText = "SET NAMES 'utf8mb4' COLLATE 'utf8mb4_general_ci';";
|
|
// await cmd.ExecuteNonQueryAsync();
|
|
|
|
return connection;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
CS2_SimpleAdmin._logger?.LogCritical($"Unable to connect to database: {ex.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
// public async Task DatabaseMigration()
|
|
// {
|
|
// Migration migrator = new(this);
|
|
// await migrator.ExecuteMigrationsAsync();
|
|
// }
|
|
|
|
public bool CheckDatabaseConnection(out string? exception)
|
|
{
|
|
using MySqlConnection connection = GetConnection();
|
|
exception = null;
|
|
|
|
try
|
|
{
|
|
return connection.Ping();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
exception = ex.Message;
|
|
return false;
|
|
}
|
|
}
|
|
}
|