Enhance UI, add AI integration, improve logging and database stats
This commit is contained in:
@@ -59,10 +59,16 @@ public partial class MainForm : Form
|
||||
btn_serverstart.Click += Btn_serverstart_Click;
|
||||
btn_localWebserver.Click += Btn_localWebserver_Click;
|
||||
btn_syncmarkets.Click += syncMarketsaToolStripMenuItem_Click;
|
||||
btn_dbUpdate.Click += btn_dbUpdate_Click;
|
||||
|
||||
Log.Information("MainForm initialized. Ready.");
|
||||
Log.Information("Press 'Start Server' to begin polling & discovery.");
|
||||
Log.Information("Press 'Start Local Webserver' to launch the WebUI on http://localhost:{Port}", _settings.WebserverPort);
|
||||
|
||||
_ = UpdateDbSizeAsync();
|
||||
var dbSizeTimer = new System.Windows.Forms.Timer { Interval = 6 * 60 * 60 * 1000 };
|
||||
dbSizeTimer.Tick += async (s, e) => await UpdateDbSizeAsync();
|
||||
dbSizeTimer.Start();
|
||||
}
|
||||
|
||||
private async void Btn_serverstart_Click(object? sender, EventArgs e)
|
||||
@@ -193,11 +199,67 @@ public partial class MainForm : Form
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Manual market sync failed");
|
||||
MessageBox.Show($"Market sync failed: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Error syncing markets: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
btn_syncmarkets.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async void btn_dbUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_workerRunning)
|
||||
{
|
||||
MessageBox.Show("Database update cannot be run while background workers are running.",
|
||||
"Workers Busy", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
btn_dbUpdate.Enabled = false;
|
||||
Log.Information("Manual database update triggered...");
|
||||
await _webServer!.UpdateDatabaseAsync();
|
||||
Log.Information("Database updated successfully.");
|
||||
MessageBox.Show("Database update completed successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Manual database update failed");
|
||||
MessageBox.Show($"Database update failed: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
btn_dbUpdate.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateDbSizeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Build the connection string
|
||||
var csBuilder = new MySqlConnector.MySqlConnectionStringBuilder(_settings.ConnectionString);
|
||||
if (string.IsNullOrWhiteSpace(csBuilder.Database))
|
||||
return; // Not ready or valid yet
|
||||
|
||||
using var conn = new MySqlConnector.MySqlConnection(_settings.ConnectionString);
|
||||
await conn.OpenAsync();
|
||||
using var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = "SELECT SUM(data_length + index_length) / 1024 / 1024 FROM information_schema.tables WHERE table_schema = DATABASE();";
|
||||
|
||||
var result = await cmd.ExecuteScalarAsync();
|
||||
if (result != DBNull.Value && result != null)
|
||||
{
|
||||
var sizeMb = Convert.ToDouble(result);
|
||||
this.Invoke(() => label_dbSize.Text = $"DB Size: {sizeMb:F2} MB");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Invoke(() => label_dbSize.Text = "DB Size: Error");
|
||||
Log.Debug(ex, "Failed to fetch DB size for status bar");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user