- Rimossa la sezione "Impostazioni Export" dalla UI e dal code-behind, inclusi controlli, eventi e file legacy di export. - Aggiunta configurazione del livello minimo di log (ErrorOnly, Normal, Informational, Debug, Trace) con guida e legenda colori. - La funzione di log ora filtra i messaggi in base al livello selezionato. - Aggiornati modelli di impostazioni e enum LogLevel per supportare i nuovi livelli. - Refactoring commenti e uniformità sezioni impostazioni. - Migliorata la chiarezza del log di avvio applicazione.
322 lines
15 KiB
C#
322 lines
15 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using AutoBidder.Utilities;
|
|
|
|
namespace AutoBidder
|
|
{
|
|
/// <summary>
|
|
/// Settings and configuration event handlers - REFACTORED
|
|
/// </summary>
|
|
public partial class MainWindow
|
|
{
|
|
/// <summary>
|
|
/// Carica TUTTE le impostazioni salvate nei controlli UI
|
|
/// </summary>
|
|
private void LoadDefaultSettings()
|
|
{
|
|
try
|
|
{
|
|
var settings = Utilities.SettingsManager.Load();
|
|
|
|
// Carica impostazioni predefinite aste
|
|
DefaultBidBeforeDeadlineMs.Text = settings.DefaultBidBeforeDeadlineMs.ToString();
|
|
DefaultCheckAuctionOpen.IsChecked = settings.DefaultCheckAuctionOpenBeforeBid;
|
|
DefaultMinPrice.Text = settings.DefaultMinPrice.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
|
|
DefaultMaxPrice.Text = settings.DefaultMaxPrice.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
|
|
DefaultMaxClicks.Text = settings.DefaultMaxClicks.ToString();
|
|
|
|
// Carica limiti log
|
|
Settings.MaxLogLinesPerAuctionTextBox.Text = settings.MaxLogLinesPerAuction.ToString();
|
|
Settings.MaxGlobalLogLinesTextBox.Text = settings.MaxGlobalLogLines.ToString();
|
|
|
|
// ?? NUOVO: Carica limite storia puntate
|
|
Settings.MaxBidHistoryEntriesTextBox.Text = settings.MaxBidHistoryEntries.ToString();
|
|
|
|
// ?? NUOVO: Carica limite minimo puntate
|
|
MinimumRemainingBidsTextBox.Text = settings.MinimumRemainingBids.ToString();
|
|
|
|
// ?? NUOVO: Carica livello log
|
|
var logLevelErrorOnly = Settings.FindName("LogLevelErrorOnly") as System.Windows.Controls.RadioButton;
|
|
var logLevelNormal = Settings.FindName("LogLevelNormal") as System.Windows.Controls.RadioButton;
|
|
var logLevelInformational = Settings.FindName("LogLevelInformational") as System.Windows.Controls.RadioButton;
|
|
var logLevelDebug = Settings.FindName("LogLevelDebug") as System.Windows.Controls.RadioButton;
|
|
var logLevelTrace = Settings.FindName("LogLevelTrace") as System.Windows.Controls.RadioButton;
|
|
|
|
switch (settings.MinLogLevel)
|
|
{
|
|
case "ErrorOnly":
|
|
if (logLevelErrorOnly != null) logLevelErrorOnly.IsChecked = true;
|
|
break;
|
|
case "Informational":
|
|
if (logLevelInformational != null) logLevelInformational.IsChecked = true;
|
|
break;
|
|
case "Debug":
|
|
if (logLevelDebug != null) logLevelDebug.IsChecked = true;
|
|
break;
|
|
case "Trace":
|
|
if (logLevelTrace != null) logLevelTrace.IsChecked = true;
|
|
break;
|
|
case "Normal":
|
|
default:
|
|
if (logLevelNormal != null) logLevelNormal.IsChecked = true;
|
|
break;
|
|
}
|
|
|
|
// Aggiorna indicatore visivo
|
|
UpdateMinBidsIndicator(settings.MinimumRemainingBids);
|
|
|
|
// Carica stato iniziale aste
|
|
// ? NUOVO: Se RememberAuctionStates è attivo, seleziona "Ricorda Stato"
|
|
if (settings.RememberAuctionStates)
|
|
{
|
|
Settings.LoadAuctionsRemember.IsChecked = true;
|
|
}
|
|
else
|
|
{
|
|
// Altrimenti usa DefaultStartAuctionsOnLoad
|
|
switch (settings.DefaultStartAuctionsOnLoad)
|
|
{
|
|
case "Active":
|
|
Settings.LoadAuctionsActive.IsChecked = true;
|
|
break;
|
|
case "Paused":
|
|
Settings.LoadAuctionsPaused.IsChecked = true;
|
|
break;
|
|
case "Stopped":
|
|
default:
|
|
Settings.LoadAuctionsStopped.IsChecked = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
switch (settings.DefaultNewAuctionState)
|
|
{
|
|
case "Active":
|
|
Settings.NewAuctionActive.IsChecked = true;
|
|
break;
|
|
case "Paused":
|
|
Settings.NewAuctionPaused.IsChecked = true;
|
|
break;
|
|
case "Stopped":
|
|
default:
|
|
Settings.NewAuctionStopped.IsChecked = true;
|
|
break;
|
|
}
|
|
|
|
Log($"[OK] Impostazioni caricate: Anticipo={settings.DefaultBidBeforeDeadlineMs}ms, LogAsta={settings.MaxLogLinesPerAuction}, LogGlobale={settings.MaxGlobalLogLines}, MinBids={settings.MinimumRemainingBids}", Utilities.LogLevel.Info);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log($"[ERRORE] Caricamento impostazioni predefinite: {ex.Message}", Utilities.LogLevel.Error);
|
|
}
|
|
}
|
|
|
|
private void SaveDefaultsButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// ? Carica le impostazioni esistenti per non perdere gli altri valori
|
|
var settings = Utilities.SettingsManager.Load() ?? new Utilities.AppSettings();
|
|
|
|
// === SEZIONE DEFAULTS: Validazione e Salvataggio ===
|
|
if (int.TryParse(DefaultBidBeforeDeadlineMs.Text, out var bidMs) && bidMs >= 0 && bidMs <= 5000)
|
|
{
|
|
settings.DefaultBidBeforeDeadlineMs = bidMs;
|
|
}
|
|
else
|
|
{
|
|
Log("[ERRORE] Valore anticipo puntata non valido (deve essere 0-5000ms)", LogLevel.Error);
|
|
return;
|
|
}
|
|
|
|
settings.DefaultCheckAuctionOpenBeforeBid = DefaultCheckAuctionOpen.IsChecked ?? false;
|
|
|
|
if (double.TryParse(DefaultMinPrice.Text.Replace(',', '.'), System.Globalization.NumberStyles.Any,
|
|
System.Globalization.CultureInfo.InvariantCulture, out var minPrice))
|
|
{
|
|
settings.DefaultMinPrice = minPrice;
|
|
}
|
|
|
|
if (double.TryParse(DefaultMaxPrice.Text.Replace(',', '.'), System.Globalization.NumberStyles.Any,
|
|
System.Globalization.CultureInfo.InvariantCulture, out var maxPrice))
|
|
{
|
|
settings.DefaultMaxPrice = maxPrice;
|
|
}
|
|
|
|
if (int.TryParse(DefaultMaxClicks.Text, out var maxClicks))
|
|
{
|
|
settings.DefaultMaxClicks = maxClicks;
|
|
}
|
|
|
|
// === SEZIONE DEFAULTS: Limiti Log ===
|
|
if (int.TryParse(Settings.MaxLogLinesPerAuctionTextBox.Text, out var maxLogPerAuction) && maxLogPerAuction > 0)
|
|
{
|
|
settings.MaxLogLinesPerAuction = maxLogPerAuction;
|
|
}
|
|
else
|
|
{
|
|
Log("[ERRORE] Valore max log per asta non valido (deve essere > 0)", LogLevel.Error);
|
|
}
|
|
|
|
if (int.TryParse(Settings.MaxGlobalLogLinesTextBox.Text, out var maxGlobalLog) && maxGlobalLog > 0)
|
|
{
|
|
settings.MaxGlobalLogLines = maxGlobalLog;
|
|
}
|
|
else
|
|
{
|
|
Log("[ERRORE] Valore max log globale non valido (deve essere > 0)", LogLevel.Error);
|
|
}
|
|
|
|
// ?? NUOVO: Salva limite storia puntate
|
|
if (int.TryParse(Settings.MaxBidHistoryEntriesTextBox.Text, out var maxBidHistory) && maxBidHistory >= 0)
|
|
{
|
|
settings.MaxBidHistoryEntries = maxBidHistory;
|
|
|
|
if (maxBidHistory > 0)
|
|
{
|
|
Log($"[HISTORY] Impostato limite storia puntate: {maxBidHistory}", LogLevel.Info);
|
|
}
|
|
else
|
|
{
|
|
Log("[HISTORY] Limite storia puntate disabilitato (mostra tutte)", LogLevel.Info);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Log("[ERRORE] Valore limite storia puntate non valido (deve essere >= 0)", LogLevel.Error);
|
|
}
|
|
|
|
// ?? NUOVO: Salva limite minimo puntate
|
|
if (int.TryParse(MinimumRemainingBidsTextBox.Text, out var minBids) && minBids >= 0)
|
|
{
|
|
settings.MinimumRemainingBids = minBids;
|
|
|
|
// Aggiorna indicatore visivo
|
|
UpdateMinBidsIndicator(minBids);
|
|
|
|
if (minBids > 0)
|
|
{
|
|
Log($"[LIMIT] Impostato limite minimo puntate: {minBids}", LogLevel.Info);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Log("[ERRORE] Valore limite minimo puntate non valido (deve essere >= 0)", LogLevel.Error);
|
|
}
|
|
|
|
// ?? NUOVO: Salva livello log
|
|
var logLevelErrorOnly = Settings.FindName("LogLevelErrorOnly") as System.Windows.Controls.RadioButton;
|
|
var logLevelNormal = Settings.FindName("LogLevelNormal") as System.Windows.Controls.RadioButton;
|
|
var logLevelInformational = Settings.FindName("LogLevelInformational") as System.Windows.Controls.RadioButton;
|
|
var logLevelDebug = Settings.FindName("LogLevelDebug") as System.Windows.Controls.RadioButton;
|
|
var logLevelTrace = Settings.FindName("LogLevelTrace") as System.Windows.Controls.RadioButton;
|
|
|
|
string selectedLogLevel = "Normal"; // Default
|
|
if (logLevelErrorOnly?.IsChecked == true)
|
|
selectedLogLevel = "ErrorOnly";
|
|
else if (logLevelInformational?.IsChecked == true)
|
|
selectedLogLevel = "Informational";
|
|
else if (logLevelDebug?.IsChecked == true)
|
|
selectedLogLevel = "Debug";
|
|
else if (logLevelTrace?.IsChecked == true)
|
|
selectedLogLevel = "Trace";
|
|
else if (logLevelNormal?.IsChecked == true)
|
|
selectedLogLevel = "Normal";
|
|
|
|
settings.MinLogLevel = selectedLogLevel;
|
|
|
|
Log($"[LOG] Livello log impostato: {selectedLogLevel}", LogLevel.Info);
|
|
|
|
// === SEZIONE DEFAULTS: Stati Iniziali Aste ===
|
|
var loadAuctionsRemember = Settings.FindName("LoadAuctionsRemember") as System.Windows.Controls.RadioButton;
|
|
var loadAuctionsActive = Settings.FindName("LoadAuctionsActive") as System.Windows.Controls.RadioButton;
|
|
var loadAuctionsPaused = Settings.FindName("LoadAuctionsPaused") as System.Windows.Controls.RadioButton;
|
|
|
|
// ? NUOVO: Gestione "Ricorda Stato"
|
|
if (loadAuctionsRemember?.IsChecked == true)
|
|
{
|
|
// Attiva RememberAuctionStates
|
|
settings.RememberAuctionStates = true;
|
|
// DefaultStartAuctionsOnLoad diventa irrilevante, ma lo lasciamo a "Stopped" per compatibilità
|
|
settings.DefaultStartAuctionsOnLoad = "Stopped";
|
|
}
|
|
else
|
|
{
|
|
// Disattiva RememberAuctionStates e usa DefaultStartAuctionsOnLoad
|
|
settings.RememberAuctionStates = false;
|
|
settings.DefaultStartAuctionsOnLoad = loadAuctionsActive?.IsChecked == true ? "Active" :
|
|
loadAuctionsPaused?.IsChecked == true ? "Paused" :
|
|
"Stopped";
|
|
}
|
|
|
|
var newAuctionActive = Settings.FindName("NewAuctionActive") as System.Windows.Controls.RadioButton;
|
|
var newAuctionPaused = Settings.FindName("NewAuctionPaused") as System.Windows.Controls.RadioButton;
|
|
|
|
settings.DefaultNewAuctionState = newAuctionActive?.IsChecked == true ? "Active" :
|
|
newAuctionPaused?.IsChecked == true ? "Paused" :
|
|
"Stopped";
|
|
|
|
Utilities.SettingsManager.Save(settings);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log($"[ERRORE] Salvataggio impostazioni: {ex.Message}", LogLevel.Error);
|
|
}
|
|
}
|
|
|
|
private void CancelDefaultsButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// Ricarica defaults salvati
|
|
LoadDefaultSettings();
|
|
MessageBox.Show(this, "Impostazioni predefinite ripristinate.", "Annulla", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log($"[ERRORE] Ripristino impostazioni: {ex.Message}", LogLevel.Error);
|
|
MessageBox.Show(this, "Errore durante ripristino: " + ex.Message, "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
// === HANDLER PER PULSANTI UNIFICATI ===
|
|
|
|
private void SaveAllSettings_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// Salva tutte le impostazioni (ora solo defaults, export rimosso)
|
|
SaveDefaultsButton_Click(sender, e);
|
|
|
|
MessageBox.Show(
|
|
"Tutte le impostazioni sono state salvate con successo.\n\nLe nuove impostazioni verranno applicate alle aste future.",
|
|
"Impostazioni Salvate",
|
|
MessageBoxButton.OK,
|
|
MessageBoxImage.Information
|
|
);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log($"[ERRORE] Salvataggio impostazioni: {ex.Message}", LogLevel.Error);
|
|
MessageBox.Show(this, "Errore durante salvataggio: " + ex.Message, "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
|
|
private void CancelAllSettings_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// Annulla tutte le modifiche
|
|
LoadDefaultSettings();
|
|
MessageBox.Show(this, "Impostazioni ripristinate alle ultime salvate.", "Annulla", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log($"[ERRORE] Ripristino impostazioni: {ex.Message}", LogLevel.Error);
|
|
MessageBox.Show(this, "Errore durante ripristino: " + ex.Message, "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|