Merge-Commit

This commit is contained in:
2025-10-09 12:56:32 +02:00
105 changed files with 5560 additions and 2267 deletions

View File

@@ -0,0 +1,85 @@
using BeWoDatabaseUpdater.Extensions;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Threading.Tasks;
namespace BeWoDatabaseUpdater
{
public static class MySqlBeWoHelper
{
private static readonly object _Lock = new();
public static async Task<List<string>> LoadBeWoDatabaseNames(string connectionString)
{
var connection = new MySqlConnection(connectionString);
var result = new List<string>();
try
{
await connection.OpenAsync();
var command = new MySqlCommand("SELECT TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES tables WHERE tables.TABLE_NAME = 'bewofile';") { Connection = connection };
await using var dataReader = command.ExecuteReader();
while(await dataReader.ReadAsync())
{
var schemaName = dataReader["TABLE_SCHEMA"]?.ToString();
if(schemaName is not null)
{
result.AddIfNotIn(schemaName);
}
}
}
catch(Exception exception)
{
Console.WriteLine(exception);
}
finally
{
if(connection.State is ConnectionState.Open or ConnectionState.Executing)
{
await connection.CloseAsync();
}
}
return result;
}
public static Dictionary<int, string> DistinctErrors = [];
public static void WriteSqlErrorsToFile()
{
lock(_Lock)
{
File.WriteAllLines(Program.FailedSqlCommandsFilePath, DistinctErrors.Values);
}
}
public static void ExecuteUpdateOrCreateAsync(string sql, string filePath, string connectionString)
{
var connection = new MySqlConnection(connectionString);
try
{
connection.Open();
new MySqlCommand(sql, connection).ExecuteNonQuery();
}
catch(MySqlException exception)
{
var errorMessage = $"{exception.Number} {new FileInfo(filePath).Name}: {exception.Message}";
DistinctErrors.AddAndIgnoreDuplicates(exception.Number, errorMessage);
}
finally
{
connection.Close();
}
}
}
}

View File

@@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace BeWoDatabaseUpdater.Utils
{
public class FilePath2MySqlCommands(string filePath, List<string> commands)
{
public string FilePath { get; set; } = filePath;
public List<string> Commands { get; set; } = commands ?? [];
}
}

View File

@@ -0,0 +1,21 @@
using System;
namespace BeWoDatabaseUpdater.Utils
{
public static class Utils
{
public static void ConsoleWriteException(Exception exception)
{
ConsoleWriteError(exception.ToString());
}
public static void ConsoleWriteError(string errorMessage)
{
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(errorMessage);
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
}
}
}