Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d578debe2 | ||
|
|
5adc4a6526 | ||
|
|
66e3af043c | ||
|
|
9a632b8d62 | ||
|
|
cb0e838964 | ||
|
|
8954f9aaba | ||
|
|
94843311b4 | ||
|
|
52e5f68da0 | ||
|
|
99b3030180 | ||
|
|
7ca504a70a | ||
|
|
551697d98d | ||
|
|
3db0d946b7 | ||
|
|
d08e54657a | ||
|
|
b810c7f76b | ||
|
|
95018e0d65 | ||
|
|
df9b63dd41 | ||
|
|
7a01251258 | ||
|
|
56484e0bec | ||
|
|
c199e542ba | ||
|
|
d99b5ec923 | ||
|
|
6795282993 | ||
|
|
62d5cebf9c | ||
|
|
ee67bedc31 | ||
|
|
f124f2e4e8 | ||
|
|
570c2e53d6 | ||
|
|
4bfcf147b4 | ||
|
|
c37b5b9f1e |
@@ -414,3 +414,21 @@ FodyWeavers.xsd
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
|
||||
# ---> AutoBidder / Mimante
|
||||
|
||||
# Configurazione di rilascio: contiene un token di Gitea
|
||||
gitea.json
|
||||
|
||||
# Riepilogo della rigiocata sui dossier (target Backtest)
|
||||
*backtest-report.txt
|
||||
|
||||
# Pacchetti prodotti da build/Release.proj
|
||||
bin/installer/
|
||||
|
||||
# Rider / JetBrains
|
||||
.idea/
|
||||
|
||||
# Windows
|
||||
Thumbs.db
|
||||
Desktop.ini
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug AutoBidder (WPF)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/bin/Debug/net10.0-windows/AutoBidder.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false,
|
||||
"enableStepFiltering": true
|
||||
},
|
||||
{
|
||||
"name": "Attach to AutoBidder (processo già avviato)",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processName": "AutoBidder.exe"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
{
|
||||
// Tutte le attività passano da build/Release.proj: la catena è un solo file
|
||||
// MSBuild versionato col codice, e qui restano soltanto i nomi e le domande.
|
||||
// MSBuild non può chiedere niente a nessuno — i prompt stanno in "inputs".
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"detail": "Compilazione di debug, per F5 e per il controllo rapido degli errori.",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/AutoBidder.csproj",
|
||||
"-c",
|
||||
"Debug",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "verifica",
|
||||
"detail": "Compila e lancia i test. Da eseguire dopo ogni modifica.",
|
||||
"type": "process",
|
||||
"command": "dotnet",
|
||||
"args": [
|
||||
"msbuild",
|
||||
"${workspaceFolder}/build/Release.proj",
|
||||
"-t:Verifica",
|
||||
"-nologo",
|
||||
"-v:m"
|
||||
],
|
||||
"group": {
|
||||
"kind": "test",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "backtest",
|
||||
"detail": "Rigioca i dossier delle aste concluse: quante puntate costerebbe ciascun anticipo, e quante ne fermano i controlli di budget.",
|
||||
"type": "process",
|
||||
"command": "dotnet",
|
||||
"args": [
|
||||
"msbuild",
|
||||
"${workspaceFolder}/build/Release.proj",
|
||||
"-t:Backtest",
|
||||
"-nologo",
|
||||
"-v:m"
|
||||
],
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "dedicated"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "backtest (giro veloce, 400 aste)",
|
||||
"detail": "Come sopra ma su un campione: utile mentre si tarano le strategie.",
|
||||
"type": "process",
|
||||
"command": "dotnet",
|
||||
"args": [
|
||||
"msbuild",
|
||||
"${workspaceFolder}/build/Release.proj",
|
||||
"-t:Backtest",
|
||||
"-p:MaxDossier=400",
|
||||
"-nologo",
|
||||
"-v:m"
|
||||
],
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "dedicated"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "crea installatore",
|
||||
"detail": "Verifica, pubblica ed esegue Inno Setup: bin/installer/AutoBidder-<versione>-setup.exe. Crea il tag a pacchetto pronto. Non tocca Gitea.",
|
||||
"type": "process",
|
||||
"command": "dotnet",
|
||||
"args": [
|
||||
"msbuild",
|
||||
"${workspaceFolder}/build/Release.proj",
|
||||
"-t:Pacchetto",
|
||||
"-p:Versione=${input:versione}",
|
||||
"-nologo",
|
||||
"-v:m"
|
||||
],
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "dedicated"
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "crea installatore (senza rieseguire i test)",
|
||||
"detail": "Solo pubblicazione e Inno Setup. Da usare quando i test sono appena passati.",
|
||||
"type": "process",
|
||||
"command": "dotnet",
|
||||
"args": [
|
||||
"msbuild",
|
||||
"${workspaceFolder}/build/Release.proj",
|
||||
"-t:Pacchetto",
|
||||
"-p:Versione=${input:versione}",
|
||||
"-p:SaltaVerifica=true",
|
||||
"-nologo",
|
||||
"-v:m"
|
||||
],
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "dedicated"
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "rilascia su Gitea",
|
||||
"detail": "Verifica, pubblica, installatore, tag e release su Gitea con i file allegati. La versione viene dal tag su HEAD. Richiede build/gitea.json.",
|
||||
"type": "process",
|
||||
"command": "dotnet",
|
||||
"args": [
|
||||
"msbuild",
|
||||
"${workspaceFolder}/build/Release.proj",
|
||||
"-t:Rilascia",
|
||||
"-p:Versione=${input:versione}",
|
||||
"-nologo",
|
||||
"-v:m"
|
||||
],
|
||||
// Le note passano dall'ambiente, non da -p:. MSBuild spezza il valore di
|
||||
// una proprietà sulle virgole e una nota in italiano ne ha quasi sempre
|
||||
// una: si otterrebbe MSB1006 «proprietà non valida». Vedi Release.proj.
|
||||
"options": {
|
||||
"env": {
|
||||
"AUTOBIDDER_NOTE": "${input:note}"
|
||||
}
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "dedicated"
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"id": "versione",
|
||||
"type": "promptString",
|
||||
"description": "Versione — lascia vuoto se hai già taggato (git tag v4.14.0), o per la minor successiva",
|
||||
"default": ""
|
||||
},
|
||||
{
|
||||
"id": "note",
|
||||
"type": "promptString",
|
||||
"description": "Note di rilascio (vuoto = solo il numero di versione)",
|
||||
"default": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,29 +1,16 @@
|
||||
<Application x:Class="Mimante.App"
|
||||
<Application x:Class="AutoBidder.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Mimante"
|
||||
xmlns:local="clr-namespace:AutoBidder"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<!-- Stile pulsanti globale -->
|
||||
<Style x:Key="SmallButtonStyle" TargetType="Button">
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Setter Property="FontWeight" Value="SemiBold" />
|
||||
<Setter Property="FontSize" Value="12" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Cursor" Value="Hand" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
CornerRadius="12"
|
||||
Padding="{TemplateBinding Padding}">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<!-- [0] SLOT TEMA: sostituito a runtime da ThemeManager (Dark/Light) -->
|
||||
<ResourceDictionary Source="Themes/Tokens.Dark.xaml"/>
|
||||
<!-- [1] Stili controlli (usano DynamicResource sui token) -->
|
||||
<ResourceDictionary Source="Themes/Controls.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
|
||||
@@ -1,14 +1,78 @@
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace Mimante
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
// Le descrizioni delle impostazioni vivono nei suggerimenti invece che stampate
|
||||
// sotto ogni campo. Quello predefinito di Windows sparisce dopo cinque secondi:
|
||||
// per un paragrafo di tre righe significa doverlo rincorrere.
|
||||
System.Windows.Controls.ToolTipService.ShowDurationProperty.OverrideMetadata(
|
||||
typeof(DependencyObject), new FrameworkPropertyMetadata(60000));
|
||||
|
||||
// I percorsi vanno decisi per primi: da qui in poi ogni archivio li usa.
|
||||
// Le impostazioni stanno nella radice fissa, quindi si possono leggere anche
|
||||
// prima di sapere dove finiranno gli altri dati.
|
||||
var settings = SettingsManager.Load();
|
||||
AppPaths.Configure(settings.DataFolder, settings.StatsFolder, settings.LogFolder);
|
||||
AppPaths.EnsureFolders();
|
||||
|
||||
// Le versioni precedenti scrivevano parte dei dati in Roaming e parte in Local,
|
||||
// senza sottocartelle: senza questo passaggio storico e aste sparirebbero.
|
||||
AppPaths.MigrateLegacyFiles();
|
||||
|
||||
// I registri su file partono subito: quello che succede durante l'avvio è
|
||||
// proprio ciò che non si riesce a leggere a video.
|
||||
TextLogService.SessionStarted(AppInfo.Version);
|
||||
TextLogService.PurgeOldLogs();
|
||||
|
||||
// Le righe di registro delle aste confluiscono nei rispettivi dossier.
|
||||
AuctionDossier.CaptureAuctionLogs();
|
||||
|
||||
// Lo storico e' cresciuto per mesi con versioni diverse dell'applicazione:
|
||||
// alcuni record hanno campi che allora non esistevano. Quelli deducibili si
|
||||
// ricalcolano qui, una volta, prima che qualcuno li legga. Quelli NON
|
||||
// deducibili non si toccano: se ne occupa la pulizia, che chiede all'utente.
|
||||
try
|
||||
{
|
||||
var repair = CompletedAuctionsStore.RepairOnStartup();
|
||||
if (repair.AnythingDone)
|
||||
{
|
||||
TextLogService.App("INFO", $"[STORICO] Riparati {repair.Total} campi mancanti " +
|
||||
$"(chiavi prodotto {repair.ProductKeys}, esiti {repair.Outcomes}, " +
|
||||
$"nomi {repair.Names})");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TextLogService.App("WARN", $"[STORICO] Riparazione non riuscita: {ex.Message}");
|
||||
}
|
||||
|
||||
// Applica il tema salvato (chiaro/scuro) prima di mostrare la finestra
|
||||
ThemeManager.ApplyFromSettings();
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
// Quello che è ancora in coda va sul disco adesso: un registro che perde
|
||||
// proprio le ultime righe è inutile esattamente quando serve di più.
|
||||
TextLogService.SessionEnded();
|
||||
FileLogWriter.DisposeAll();
|
||||
|
||||
// L'icona di notifica sopravvive al processo se non la si rimuove:
|
||||
// resterebbe nell'area di notifica come icona fantasma.
|
||||
WindowsNotifier.Dispose();
|
||||
|
||||
base.OnExit(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,55 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
<!-- Solo per NotifyIcon: le notifiche moderne richiederebbero un'applicazione
|
||||
registrata, incompatibile con l'avvio da singolo eseguibile. -->
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<AssemblyName>AutoBidder</AssemblyName>
|
||||
<RootNamespace>AutoBidder</RootNamespace>
|
||||
<ApplicationIcon>Icon\favicon.ico</ApplicationIcon>
|
||||
|
||||
<!-- App desktop leggera per Bidoo. Nessun software aggiuntivo:
|
||||
WebView2 runtime è preinstallato su Windows 11. -->
|
||||
<!-- Versione delle sole compilazioni di sviluppo. NON va alzata per rilasciare:
|
||||
nei pacchetti pubblicati questi quattro numeri vengono dal tag git, passati
|
||||
da build/Release.proj a dotnet publish. Vedi Utilities/AppInfo. -->
|
||||
<Version>4.13.0</Version>
|
||||
<AssemblyVersion>4.13.0.0</AssemblyVersion>
|
||||
<FileVersion>4.13.0.0</FileVersion>
|
||||
<InformationalVersion>4.13.0</InformationalVersion>
|
||||
|
||||
<!-- Runtime unico supportato per la pubblicazione self-contained -->
|
||||
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
|
||||
<SatelliteResourceLanguages>it;en</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove=".github\**" />
|
||||
<Compile Remove=".vscode\**" />
|
||||
<EmbeddedResource Remove=".github\**" />
|
||||
<EmbeddedResource Remove=".vscode\**" />
|
||||
<None Remove=".github\**" />
|
||||
<None Remove=".vscode\**" />
|
||||
<Page Remove=".github\**" />
|
||||
<Page Remove=".vscode\**" />
|
||||
<!-- Il progetto di test vive in una sottocartella: senza questa esclusione i
|
||||
progetti SDK-style, che raccolgono **/*.cs, lo compilerebbero qui dentro. -->
|
||||
<Compile Remove="Tests\**" />
|
||||
<None Remove="Tests\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Icon\favicon.ico" />
|
||||
<!-- UseWindowsForms aggiunge questi using in tutti i file, e ogni nome in comune
|
||||
con WPF (UserControl, TextBox, Application, Color...) diventa ambiguo.
|
||||
Serve solo a WindowsNotifier, che li importa per conto proprio. -->
|
||||
<Using Remove="System.Windows.Forms" />
|
||||
<Using Remove="System.Drawing" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1343.22" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.6584" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3351.48" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Incorporata come Resource (non Content) così l'icona della finestra
|
||||
funziona anche in modalitàsingle-file self-contained. -->
|
||||
<Resource Include="Icon\favicon.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,78 +1,55 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.14.36511.14
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoBidder", "AutoBidder.csproj", "{9BBAEF93-DF66-432C-9349-459E272D6538}"
|
||||
EndProject
|
||||
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "Template", "..\Template\Template.wapproj", "{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}"
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoBidder.Tests", "Tests\AutoBidder.Tests.csproj", "{CAC096C0-E399-4268-B2FF-E205947CB733}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|ARM = Debug|ARM
|
||||
Debug|ARM64 = Debug|ARM64
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|ARM = Release|ARM
|
||||
Release|ARM64 = Release|ARM64
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Release|ARM64.Build.0 = Release|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Release|x64.Build.0 = Release|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{9BBAEF93-DF66-432C-9349-459E272D6538}.Release|x86.Build.0 = Release|Any CPU
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|ARM.Build.0 = Debug|ARM
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|ARM.Deploy.0 = Debug|ARM
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|ARM64.Deploy.0 = Debug|ARM64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|x64.Build.0 = Debug|x64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|x64.Deploy.0 = Debug|x64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|x86.Build.0 = Debug|x86
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Debug|x86.Deploy.0 = Debug|x86
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|ARM.Build.0 = Release|ARM
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|ARM.Deploy.0 = Release|ARM
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|ARM64.Deploy.0 = Release|ARM64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|x64.ActiveCfg = Release|x64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|x64.Build.0 = Release|x64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|x64.Deploy.0 = Release|x64
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|x86.ActiveCfg = Release|x86
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|x86.Build.0 = Release|x86
|
||||
{1D9DB6F9-BD2B-4B14-9F2E-104060FAAD1E}.Release|x86.Deploy.0 = Release|x86
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Release|x64.Build.0 = Release|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{CAC096C0-E399-4268-B2FF-E205947CB733} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {1C55CA56-D270-4D9A-91DA-410BF131E905}
|
||||
EndGlobalSection
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
@@ -76,12 +76,150 @@ namespace AutoBidder.Controls
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(RemoveUrlClickedEvent, this));
|
||||
}
|
||||
|
||||
private void RemoveAllButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(RemoveAllClickedEvent, this));
|
||||
}
|
||||
|
||||
private void ExportButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(ExportClickedEvent, this));
|
||||
}
|
||||
|
||||
private void RemoveFinishedButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(RemoveFinishedClickedEvent, this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna i contatori della barra strumenti. Li calcola il chiamante, che ha
|
||||
/// l'elenco completo: qui si presentano soltanto.
|
||||
/// </summary>
|
||||
public void UpdateCounters(int total, int active, int watch, int stopped, int won, int lost)
|
||||
{
|
||||
PillTotal.Text = total == 1 ? "1 asta" : $"{total} aste";
|
||||
PillActive.Text = $"{active} attive";
|
||||
PillWatch.Text = $"{watch} osserva";
|
||||
PillStopped.Text = $"{stopped} ferme";
|
||||
PillWon.Text = $"{won} vinte";
|
||||
PillLost.Text = $"{lost} perse";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stato del motore: traffico prodotto, aggancio all'orologio del server e ritardo
|
||||
/// medio di rete. Tutti e tre i valori arrivano già misurati dal chiamante.
|
||||
/// </summary>
|
||||
public void UpdateEngineStatus(long requestsSent, bool clockSynced, int clockSamples, double avgPingMs)
|
||||
{
|
||||
RequestsText.Text = requestsSent.ToString("N0");
|
||||
|
||||
// Senza campioni non c'è nulla da dire: meglio un trattino di un numero finto.
|
||||
if (clockSamples == 0)
|
||||
{
|
||||
ClockText.Text = "—";
|
||||
SetClockTone("Brush.TextFaint");
|
||||
ClockPill.ToolTip =
|
||||
"Nessuna misura: il motore non sta interrogando Bidoo.\n" +
|
||||
"Il pallino diventa verde quando l'orologio è agganciato e la rete risponde in fretta.";
|
||||
return;
|
||||
}
|
||||
|
||||
ClockText.Text = avgPingMs > 0 ? $"{avgPingMs:F0} ms" : "—";
|
||||
|
||||
var tone = !clockSynced ? "Brush.Warning" : PingTone(avgPingMs);
|
||||
SetClockTone(tone);
|
||||
|
||||
var sync = clockSynced
|
||||
? $"Orologio agganciato al server ({clockSamples} campioni)."
|
||||
: $"Orologio in aggancio: {clockSamples} campioni su 3.";
|
||||
|
||||
ClockPill.ToolTip =
|
||||
$"{sync}\n" +
|
||||
$"Ritardo medio di rete: {avgPingMs:F0} ms — {PingVerdict(avgPingMs)}.\n" +
|
||||
"Tieni l'anticipo puntata sopra questo valore.";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Soglie del ritardo di rete. Sono tarate su ciò che serve al motore: con un
|
||||
/// anticipo tipico di qualche centinaio di millisecondi, oltre i 400 ms di
|
||||
/// round-trip il margine per arrivare in tempo si assottiglia davvero.
|
||||
/// </summary>
|
||||
private static string PingTone(double ms) => ms switch
|
||||
{
|
||||
<= 0 => "Brush.TextFaint",
|
||||
< 150 => "Brush.Success",
|
||||
< 400 => "Brush.Warning",
|
||||
_ => "Brush.Danger"
|
||||
};
|
||||
|
||||
private static string PingVerdict(double ms) => ms switch
|
||||
{
|
||||
<= 0 => "non misurato",
|
||||
< 150 => "rete pronta",
|
||||
< 400 => "rete lenta, alza l'anticipo",
|
||||
_ => "rete molto lenta, puntate a rischio"
|
||||
};
|
||||
|
||||
private void SetClockTone(string brushKey)
|
||||
{
|
||||
ClockDot.SetResourceReference(ForegroundProperty, brushKey);
|
||||
ClockText.SetResourceReference(ForegroundProperty, brushKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stato del conto: puntate, credito e vincite da confermare.
|
||||
///
|
||||
/// <para>I valori arrivano annullabili di proposito: finché non si è connessi, o
|
||||
/// finché una risposta non è arrivata, la barra mostra un trattino invece di uno
|
||||
/// zero. Uno zero inventato è peggio di un dato mancante — è esattamente l'errore
|
||||
/// per cui le aste da confermare risultavano sempre nessuna.</para>
|
||||
/// </summary>
|
||||
public void UpdateAccountStatus(int? remainingBids, decimal? shopCredit, int? auctionsToConfirm)
|
||||
{
|
||||
RemainingBidsText.Text = remainingBids?.ToString("N0") ?? "—";
|
||||
|
||||
ShopCreditText.Text = shopCredit.HasValue ? $"{shopCredit.Value:N2} €" : "— €";
|
||||
|
||||
if (auctionsToConfirm is > 0)
|
||||
{
|
||||
BannerAsteDaRiscattare.Text = auctionsToConfirm.Value.ToString("N0");
|
||||
ToConfirmPill.Visibility = Visibility.Visible;
|
||||
ToConfirmPill.ToolTip = auctionsToConfirm.Value == 1
|
||||
? "1 asta vinta in attesa di conferma su Bidoo"
|
||||
: $"{auctionsToConfirm.Value} aste vinte in attesa di conferma su Bidoo";
|
||||
}
|
||||
else
|
||||
{
|
||||
ToConfirmPill.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Contatori del motore relativi alla sola asta selezionata.</summary>
|
||||
public void UpdateSelectedStats(int resets, int myBids, double avgPingMs, long polls, long pollErrors)
|
||||
{
|
||||
StatResets.Text = resets.ToString();
|
||||
StatMyBids.Text = myBids.ToString();
|
||||
StatPing.Text = avgPingMs > 0 ? $"{avgPingMs:F0} ms" : "—";
|
||||
StatPolls.Text = polls.ToString("N0");
|
||||
StatPollErrors.Text = pollErrors.ToString("N0");
|
||||
StatPollErrors.SetResourceReference(ForegroundProperty,
|
||||
pollErrors > 0 ? "Brush.Warning" : "Brush.Text");
|
||||
}
|
||||
|
||||
/// <summary>Verdetto di convenienza nella scheda Prodotto.</summary>
|
||||
public void SetVerdict(string label, string value, string tone)
|
||||
{
|
||||
VerdictLabel.Text = label;
|
||||
VerdictText.Text = value;
|
||||
VerdictText.SetResourceReference(ForegroundProperty, tone switch
|
||||
{
|
||||
"ok" => "Brush.Success",
|
||||
"danger" => "Brush.Danger",
|
||||
_ => "Brush.Text"
|
||||
});
|
||||
}
|
||||
|
||||
private void MultiAuctionsGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
// Forza il focus sul DataGrid quando viene selezionata una riga
|
||||
@@ -110,13 +248,44 @@ namespace AutoBidder.Controls
|
||||
System.Diagnostics.Debug.WriteLine("[DELETE KEY] Tasto Canc premuto su asta selezionata");
|
||||
|
||||
// Lancia direttamente l'evento senza chiedere conferma
|
||||
// La conferma verrà mostrata dal gestore RemoveUrlButton_Click
|
||||
// La conferma verr� mostrata dal gestore RemoveUrlButton_Click
|
||||
System.Diagnostics.Debug.WriteLine("[DELETE KEY] Lancio evento RemoveUrlClicked");
|
||||
RaiseEvent(new RoutedEventArgs(RemoveUrlClickedEvent, this));
|
||||
|
||||
// Previeni che l'evento venga gestito da altri controlli
|
||||
e.Handled = true;
|
||||
}
|
||||
// NUOVO: Gestione esplicita frecce Su/Gi� per navigazione
|
||||
else if (e.Key == Key.Up && MultiAuctionsGrid.Items.Count > 0)
|
||||
{
|
||||
int currentIndex = MultiAuctionsGrid.SelectedIndex;
|
||||
if (currentIndex > 0)
|
||||
{
|
||||
MultiAuctionsGrid.SelectedIndex = currentIndex - 1;
|
||||
MultiAuctionsGrid.ScrollIntoView(MultiAuctionsGrid.SelectedItem);
|
||||
e.Handled = true; // Previeni ridimensionamento pannelli
|
||||
}
|
||||
}
|
||||
else if (e.Key == Key.Down && MultiAuctionsGrid.Items.Count > 0)
|
||||
{
|
||||
int currentIndex = MultiAuctionsGrid.SelectedIndex;
|
||||
if (currentIndex < MultiAuctionsGrid.Items.Count - 1)
|
||||
{
|
||||
MultiAuctionsGrid.SelectedIndex = currentIndex + 1;
|
||||
MultiAuctionsGrid.ScrollIntoView(MultiAuctionsGrid.SelectedItem);
|
||||
e.Handled = true; // Previeni ridimensionamento pannelli
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveUpButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(MoveUpClickedEvent, this));
|
||||
}
|
||||
|
||||
private void MoveDownButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(MoveDownClickedEvent, this));
|
||||
}
|
||||
|
||||
private void CopyAuctionUrlButton_Click(object sender, RoutedEventArgs e)
|
||||
@@ -143,17 +312,37 @@ namespace AutoBidder.Controls
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(ClearGlobalLogClickedEvent, this));
|
||||
}
|
||||
|
||||
private void OpenAuctionInternalButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(OpenAuctionInternalClickedEvent, this));
|
||||
}
|
||||
|
||||
private void OpenAuctionExternalButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(OpenAuctionExternalClickedEvent, this));
|
||||
}
|
||||
|
||||
private void ExportAuctionButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(ExportAuctionClickedEvent, this));
|
||||
}
|
||||
|
||||
private void RefreshProductInfoButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(RefreshProductInfoClickedEvent, this));
|
||||
}
|
||||
|
||||
private void ConnectionStatusButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(ConnectionStatusClickedEvent, this));
|
||||
}
|
||||
|
||||
private void SelectedBidBeforeDeadlineMs_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(BidBeforeDeadlineMsChangedEvent, this));
|
||||
}
|
||||
|
||||
private void SelectedCheckAuctionOpen_Changed(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(CheckAuctionOpenChangedEvent, this));
|
||||
}
|
||||
|
||||
private void SelectedMinPrice_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(MinPriceChangedEvent, this));
|
||||
@@ -169,7 +358,23 @@ namespace AutoBidder.Controls
|
||||
RaiseEvent(new RoutedEventArgs(MaxClicksChangedEvent, this));
|
||||
}
|
||||
|
||||
private void SelectedMaxSpend_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(MaxSpendChangedEvent, this));
|
||||
}
|
||||
|
||||
private void SelectedStopAtBreakEven_Changed(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(BreakEvenChangedEvent, this));
|
||||
}
|
||||
|
||||
// Routed Events
|
||||
public static readonly RoutedEvent MaxSpendChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"MaxSpendChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent BreakEvenChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"BreakEvenChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent StartClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"StartClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
@@ -184,6 +389,12 @@ namespace AutoBidder.Controls
|
||||
|
||||
public static readonly RoutedEvent RemoveUrlClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"RemoveUrlClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent RemoveFinishedClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"RemoveFinishedClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent RemoveAllClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"RemoveAllClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent ExportClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ExportClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
@@ -209,9 +420,6 @@ namespace AutoBidder.Controls
|
||||
public static readonly RoutedEvent BidBeforeDeadlineMsChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"BidBeforeDeadlineMsChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent CheckAuctionOpenChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"CheckAuctionOpenChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent MinPriceChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"MinPriceChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
@@ -220,6 +428,28 @@ namespace AutoBidder.Controls
|
||||
|
||||
public static readonly RoutedEvent MaxClicksChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"MaxClicksChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent OpenAuctionInternalClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenAuctionInternalClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent OpenAuctionExternalClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenAuctionExternalClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent ExportAuctionClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ExportAuctionClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent RefreshProductInfoClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"RefreshProductInfoClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent ConnectionStatusClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ConnectionStatusClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
// NUOVO: Eventi per riordinamento aste
|
||||
public static readonly RoutedEvent MoveUpClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"MoveUpClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public static readonly RoutedEvent MoveDownClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"MoveDownClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(AuctionMonitorControl));
|
||||
|
||||
public event RoutedEventHandler StartClicked
|
||||
{
|
||||
@@ -250,6 +480,18 @@ namespace AutoBidder.Controls
|
||||
add { AddHandler(RemoveUrlClickedEvent, value); }
|
||||
remove { RemoveHandler(RemoveUrlClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler RemoveAllClicked
|
||||
{
|
||||
add { AddHandler(RemoveAllClickedEvent, value); }
|
||||
remove { RemoveHandler(RemoveAllClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler RemoveFinishedClicked
|
||||
{
|
||||
add { AddHandler(RemoveFinishedClickedEvent, value); }
|
||||
remove { RemoveHandler(RemoveFinishedClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ExportClicked
|
||||
{
|
||||
@@ -299,12 +541,6 @@ namespace AutoBidder.Controls
|
||||
remove { RemoveHandler(BidBeforeDeadlineMsChangedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler CheckAuctionOpenChanged
|
||||
{
|
||||
add { AddHandler(CheckAuctionOpenChangedEvent, value); }
|
||||
remove { RemoveHandler(CheckAuctionOpenChangedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler MinPriceChanged
|
||||
{
|
||||
add { AddHandler(MinPriceChangedEvent, value); }
|
||||
@@ -322,5 +558,60 @@ namespace AutoBidder.Controls
|
||||
add { AddHandler(MaxClicksChangedEvent, value); }
|
||||
remove { RemoveHandler(MaxClicksChangedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler MaxSpendChanged
|
||||
{
|
||||
add { AddHandler(MaxSpendChangedEvent, value); }
|
||||
remove { RemoveHandler(MaxSpendChangedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler BreakEvenChanged
|
||||
{
|
||||
add { AddHandler(BreakEvenChangedEvent, value); }
|
||||
remove { RemoveHandler(BreakEvenChangedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenAuctionInternalClicked
|
||||
{
|
||||
add { AddHandler(OpenAuctionInternalClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenAuctionInternalClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenAuctionExternalClicked
|
||||
{
|
||||
add { AddHandler(OpenAuctionExternalClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenAuctionExternalClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ExportAuctionClicked
|
||||
{
|
||||
add { AddHandler(ExportAuctionClickedEvent, value); }
|
||||
remove { RemoveHandler(ExportAuctionClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler RefreshProductInfoClicked
|
||||
{
|
||||
add { AddHandler(RefreshProductInfoClickedEvent, value); }
|
||||
remove { RemoveHandler(RefreshProductInfoClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ConnectionStatusClicked
|
||||
{
|
||||
add { AddHandler(ConnectionStatusClickedEvent, value); }
|
||||
remove { RemoveHandler(ConnectionStatusClickedEvent, value); }
|
||||
}
|
||||
|
||||
// NUOVO: Handler per eventi riordinamento
|
||||
public event RoutedEventHandler MoveUpClicked
|
||||
{
|
||||
add { AddHandler(MoveUpClickedEvent, value); }
|
||||
remove { RemoveHandler(MoveUpClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler MoveDownClicked
|
||||
{
|
||||
add { AddHandler(MoveDownClickedEvent, value); }
|
||||
remove { RemoveHandler(MoveDownClickedEvent, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,130 +1,318 @@
|
||||
<UserControl x:Class="AutoBidder.Controls.BrowserControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
|
||||
mc:Ignorable="d"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="800" d:DesignWidth="1200"
|
||||
Background="#1E1E1E">
|
||||
|
||||
Background="{DynamicResource Brush.Bg}">
|
||||
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="RoundedButton" TargetType="Button">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
CornerRadius="4"
|
||||
Padding="{TemplateBinding Padding}">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Style x:Key="Glyph" TargetType="TextBlock">
|
||||
<Setter Property="FontFamily" Value="Segoe MDL2 Assets"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
</Style>
|
||||
|
||||
<!-- Nav Button Style (text only) -->
|
||||
<Style x:Key="NavButton" TargetType="Button" BasedOn="{StaticResource RoundedButton}">
|
||||
<Setter Property="MinWidth" Value="50"/>
|
||||
<Setter Property="Height" Value="30"/>
|
||||
<Setter Property="FontSize" Value="11"/>
|
||||
<Setter Property="Padding" Value="8,0"/>
|
||||
</Style>
|
||||
<!-- Scheda di una singola asta del catalogo -->
|
||||
<DataTemplate x:Key="AuctionCardTemplate">
|
||||
<Border Style="{StaticResource AuctionCard}" Width="250">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Immagine prodotto: arriva dalla rete, quindi puo' mancare -->
|
||||
<Border Grid.Row="0" Height="110" CornerRadius="8"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}" Margin="0,0,0,8">
|
||||
<Image Source="{Binding ImageUrl}" Stretch="Uniform" Margin="6"
|
||||
RenderOptions.BitmapScalingMode="HighQuality"/>
|
||||
</Border>
|
||||
|
||||
<TextBlock Grid.Row="1" Text="{Binding Name}" ToolTip="{Binding Name}"
|
||||
FontWeight="SemiBold" TextTrimming="CharacterEllipsis"
|
||||
MaxHeight="34" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource Brush.Text}" Margin="0,0,0,6"/>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" Margin="0,0,0,6">
|
||||
<TextBlock Text="{Binding PriceDisplay}" FontWeight="Bold"
|
||||
Foreground="{DynamicResource Brush.Accent}" Margin="0,0,10,0"/>
|
||||
<TextBlock Text="{Binding TimerDisplay}" Margin="0,0,10,0">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextMuted}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding TimerUrgency}" Value="warn">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Warning}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding TimerUrgency}" Value="danger">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Danger}"/>
|
||||
<Setter Property="FontWeight" Value="Bold"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
<TextBlock Text="{Binding BuyNowDisplay}"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextFaint}"
|
||||
ToolTip="Valore del prodotto (Compra Subito)"/>
|
||||
</StackPanel>
|
||||
|
||||
<Grid Grid.Row="3">
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding LastBidderDisplay}"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"
|
||||
TextTrimming="CharacterEllipsis" MaxWidth="90"/>
|
||||
<!-- Solo l'icona della mano: la parola "manuale" mangiava spazio
|
||||
al nome dell'ultimo puntatore, che è il dato che si legge
|
||||
davvero. Il significato resta nel suggerimento. -->
|
||||
<Border Background="{DynamicResource Brush.WarningSubtle}" CornerRadius="5"
|
||||
Padding="4,1" Margin="6,0,0,0"
|
||||
Visibility="{Binding ManualBadgeVisibility}"
|
||||
ToolTip="Asta solo manuale: non accetta puntate automatiche">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" Text="" FontSize="10"
|
||||
Foreground="{DynamicResource Brush.Warning}"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<!-- Segui il prodotto: le aste future dello stesso articolo
|
||||
entreranno nel monitor da sole. -->
|
||||
<Button Style="{StaticResource MiniIconButton}"
|
||||
ToolTip="{Binding WatchTooltip}"
|
||||
Command="{Binding DataContext.CatalogWatchCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" Text="{Binding WatchGlyph}">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextFaint}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsWatched}" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Gold}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Button>
|
||||
<!-- Mette il prodotto nella scheda Prodotti e ci porta sopra:
|
||||
serve a dargli limiti propri anche senza seguirlo. -->
|
||||
<Button Style="{StaticResource MiniIconButton}"
|
||||
ToolTip="{Binding ConfigureTooltip}"
|
||||
Command="{Binding DataContext.CatalogConfigureCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" Text="">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextFaint}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsListed}" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Accent}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Button>
|
||||
<Button Style="{StaticResource MiniIconButton}"
|
||||
ToolTip="Apri su Bidoo"
|
||||
Command="{Binding DataContext.CatalogOpenCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" Text=""/>
|
||||
</Button>
|
||||
<Button Style="{StaticResource MiniIconButton}"
|
||||
Foreground="{DynamicResource Brush.Accent}"
|
||||
ToolTip="Aggiungi al monitor"
|
||||
Command="{Binding DataContext.CatalogAddCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" Text=""/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Browser Toolbar -->
|
||||
<Border Grid.Row="0" Background="#2D2D30" Padding="10" BorderBrush="#3E3E42" BorderThickness="0,0,0,1">
|
||||
<!-- ═══ Barra strumenti ═══ -->
|
||||
<Border Grid.Row="0" Background="{DynamicResource Brush.Surface}" Padding="10,7"
|
||||
BorderBrush="{DynamicResource Brush.Border}" BorderThickness="0,0,0,1">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Navigation Buttons (TEXT ONLY - NO SYMBOLS) -->
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||
<Button x:Name="BrowserBackButton"
|
||||
Content="Indietro"
|
||||
Margin="0,0,5,0"
|
||||
Background="#3E3E42"
|
||||
Style="{StaticResource NavButton}"
|
||||
Click="BrowserBackButton_Click"
|
||||
ToolTip="Torna alla pagina precedente"/>
|
||||
|
||||
<Button x:Name="BrowserForwardButton"
|
||||
Content="Avanti"
|
||||
Margin="0,0,5,0"
|
||||
Background="#3E3E42"
|
||||
Style="{StaticResource NavButton}"
|
||||
Click="BrowserForwardButton_Click"
|
||||
ToolTip="Vai alla pagina successiva"/>
|
||||
|
||||
<Button x:Name="BrowserRefreshButton"
|
||||
Content="Ricarica"
|
||||
Margin="0,0,5,0"
|
||||
Background="#3E3E42"
|
||||
Style="{StaticResource NavButton}"
|
||||
Click="BrowserRefreshButton_Click"
|
||||
ToolTip="Ricarica la pagina corrente"/>
|
||||
|
||||
<Button x:Name="BrowserHomeButton"
|
||||
Content="Home"
|
||||
Margin="0,0,10,0"
|
||||
Background="#3E3E42"
|
||||
Style="{StaticResource NavButton}"
|
||||
Click="BrowserHomeButton_Click"
|
||||
ToolTip="Vai alla homepage Bidoo"/>
|
||||
<!-- Catalogo e Browser ora sono due schede separate nella barra laterale
|
||||
("Cerca" e "Browser"): l'interruttore interno resta solo come stato
|
||||
pilotato da fuori, non più visibile all'utente. -->
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center"
|
||||
Visibility="Collapsed">
|
||||
<RadioButton x:Name="ModeCatalogRadio" Style="{StaticResource SegmentedButton}"
|
||||
GroupName="ExploreMode" IsChecked="True" Content="Catalogo"
|
||||
Checked="ModeCatalogRadio_Checked"
|
||||
ToolTip="Griglia delle aste: veloce, senza caricare pagine"/>
|
||||
<RadioButton x:Name="ModeBrowserRadio" Style="{StaticResource SegmentedButton}"
|
||||
GroupName="ExploreMode" Content="Browser"
|
||||
Checked="ModeBrowserRadio_Checked"
|
||||
ToolTip="Browser Bidoo integrato: serve per il login (il cookie viene importato da solo)"/>
|
||||
<Border Width="1" Background="{DynamicResource Brush.Border}" Margin="8,4"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Address Bar -->
|
||||
<Border Grid.Column="1"
|
||||
Background="#1E1E1E"
|
||||
BorderBrush="#3E3E42"
|
||||
BorderThickness="1"
|
||||
CornerRadius="4"
|
||||
Margin="10,0">
|
||||
<TextBox x:Name="BrowserAddress"
|
||||
VerticalAlignment="Center"
|
||||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
Foreground="#CCCCCC"
|
||||
Padding="10,0"
|
||||
FontSize="13"
|
||||
IsReadOnly="True"
|
||||
Cursor="Arrow"
|
||||
ToolTip="Indirizzo della pagina corrente (non editabile)"/>
|
||||
<StackPanel Grid.Column="1" x:Name="CatalogToolbarLeft" Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
<Button x:Name="CatalogRefreshButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Ricarica categorie e prezzi" Click="CatalogRefreshButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
<CheckBox x:Name="CatalogAutoRefresh" Content="Prezzi in tempo reale"
|
||||
Margin="10,0,0,0" VerticalAlignment="Center"
|
||||
Checked="CatalogAutoRefresh_Changed" Unchecked="CatalogAutoRefresh_Changed"
|
||||
ToolTip="Aggiorna prezzi e timer sul posto. Spento di default: acceso, i valori cambiano mentre stai leggendo."/>
|
||||
<CheckBox x:Name="CatalogHideManual" Content="Nascondi aste manuali"
|
||||
Margin="14,0,0,0" VerticalAlignment="Center"
|
||||
Checked="CatalogFilterChanged" Unchecked="CatalogFilterChanged"
|
||||
ToolTip="Le aste manuali non accettano puntate automatiche"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Barra indirizzi del browser: occupa lo stesso posto dei filtri -->
|
||||
<Border Grid.Column="1" Grid.ColumnSpan="2" x:Name="BrowserToolbar"
|
||||
Visibility="Collapsed" Margin="0,0,10,0">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Button x:Name="BrowserBackButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Indietro" Click="BrowserBackButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
<Button x:Name="BrowserForwardButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Avanti" Click="BrowserForwardButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
<Button x:Name="BrowserRefreshButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Ricarica" Click="BrowserRefreshButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
<Button x:Name="BrowserHomeButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Homepage Bidoo" Click="BrowserHomeButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<Border Grid.Column="1" Background="{DynamicResource Brush.Bg}"
|
||||
BorderBrush="{DynamicResource Brush.Border}" BorderThickness="1"
|
||||
CornerRadius="8" Margin="8,0,0,0">
|
||||
<TextBox x:Name="BrowserAddress" VerticalAlignment="Center"
|
||||
BorderThickness="0" Background="Transparent"
|
||||
Foreground="{DynamicResource Brush.Text}" Padding="10,0"
|
||||
IsReadOnly="True" Cursor="Arrow"
|
||||
ToolTip="Indirizzo della pagina corrente"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" Margin="10,0,0,0">
|
||||
<Button x:Name="BrowserAddAuctionButton"
|
||||
Content="Aggiungi Asta"
|
||||
Padding="20,7"
|
||||
FontSize="13"
|
||||
Background="#00D800"
|
||||
Style="{StaticResource RoundedButton}"
|
||||
Click="BrowserAddAuctionButton_Click"
|
||||
ToolTip="Aggiungi l'asta corrente al monitoraggio"/>
|
||||
<!-- Campo di ricerca con suggerimento: senza, un riquadro vuoto in barra
|
||||
non si capisce a cosa serva. -->
|
||||
<Grid Grid.Column="2" x:Name="CatalogSearchHost" Margin="16,0,10,0"
|
||||
Width="240" HorizontalAlignment="Right" VerticalAlignment="Center">
|
||||
<TextBox x:Name="CatalogSearchBox"
|
||||
TextChanged="CatalogSearchBox_TextChanged"
|
||||
ToolTip="Filtra per nome prodotto"/>
|
||||
<TextBlock x:Name="CatalogSearchHint" Text="Filtra per nome…"
|
||||
IsHitTestVisible="False" Margin="10,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.TextFaint}"/>
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Style="{StaticResource Pill}">
|
||||
<TextBlock x:Name="CatalogCountText" Text="0 aste"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
</Border>
|
||||
<Button x:Name="BrowserAddAuctionButton" Style="{StaticResource IconButton}"
|
||||
Foreground="{DynamicResource Brush.Accent}" Visibility="Collapsed"
|
||||
ToolTip="Aggiungi al monitor l'asta aperta nel browser"
|
||||
Click="BrowserAddAuctionButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- WebView2 -->
|
||||
<Border Grid.Row="1" Background="#1E1E1E">
|
||||
<wv2:WebView2 x:Name="EmbeddedWebView"
|
||||
Source="https://it.bidoo.com"
|
||||
NavigationStarting="EmbeddedWebView_NavigationStarting"
|
||||
NavigationCompleted="EmbeddedWebView_NavigationCompleted"
|
||||
<!-- Riga vuota: tiene la struttura a tre righe leggibile -->
|
||||
<Border Grid.Row="1" Height="0"/>
|
||||
|
||||
<!-- ═══ Catalogo ═══ -->
|
||||
<Grid Grid.Row="2" x:Name="CatalogPanel">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Categorie -->
|
||||
<Border Grid.Column="0" Width="190" Background="{DynamicResource Brush.Surface}"
|
||||
BorderBrush="{DynamicResource Brush.Border}" BorderThickness="0,0,1,0">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" Padding="6,8">
|
||||
<ItemsControl x:Name="CatalogCategoryList">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<RadioButton Style="{StaticResource CategoryButton}"
|
||||
GroupName="CatalogCategories"
|
||||
Content="{Binding DisplayName}"
|
||||
IsChecked="{Binding IsSelected, Mode=TwoWay}"
|
||||
Checked="CategoryButton_Checked"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
|
||||
<!-- Schede -->
|
||||
<Grid Grid.Column="1">
|
||||
<ScrollViewer x:Name="CatalogScroller" VerticalScrollBarVisibility="Auto" Padding="12,12,2,12">
|
||||
<ItemsControl x:Name="CatalogItems" ItemTemplate="{StaticResource AuctionCardTemplate}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel Orientation="Horizontal"/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- Stato vuoto / caricamento -->
|
||||
<StackPanel x:Name="CatalogEmptyState" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text="" FontSize="34"
|
||||
Foreground="{DynamicResource Brush.TextFaint}"/>
|
||||
<TextBlock x:Name="CatalogEmptyText" Text="Caricamento categorie…"
|
||||
Margin="0,10,0,0" HorizontalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<!-- ═══ Browser integrato ═══ -->
|
||||
<Border Grid.Row="2" x:Name="BrowserPanel" Background="{DynamicResource Brush.Bg}" Visibility="Collapsed">
|
||||
<wv2:WebView2 x:Name="EmbeddedWebView"
|
||||
PreviewMouseRightButtonUp="EmbeddedWebView_PreviewMouseRightButtonUp"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
@@ -7,12 +7,60 @@ namespace AutoBidder.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for BrowserControl.xaml
|
||||
/// REFACTORED: Gestione semplificata e diretta degli eventi WebView2
|
||||
/// </summary>
|
||||
public partial class BrowserControl : UserControl
|
||||
{
|
||||
public BrowserControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// ? NUOVO: Collega eventi NavigationStarting e NavigationCompleted direttamente qui
|
||||
EmbeddedWebView.NavigationStarting += WebView_NavigationStarting;
|
||||
EmbeddedWebView.NavigationCompleted += WebView_NavigationCompleted;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ? NUOVO: Aggiorna address bar quando inizia la navigazione
|
||||
/// </summary>
|
||||
private void WebView_NavigationStarting(object? sender, CoreWebView2NavigationStartingEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Aggiorna immediatamente l'address bar con l'URL di destinazione
|
||||
if (!string.IsNullOrEmpty(e.Uri))
|
||||
{
|
||||
BrowserAddress.Text = e.Uri;
|
||||
}
|
||||
|
||||
// Propaga l'evento al MainWindow
|
||||
var args = new BrowserNavigationEventArgs(BrowserNavigationStartingEvent, this)
|
||||
{
|
||||
Uri = e.Uri
|
||||
};
|
||||
RaiseEvent(args);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ? NUOVO: Aggiorna address bar quando la navigazione � completata
|
||||
/// </summary>
|
||||
private void WebView_NavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Aggiorna l'address bar con l'URL finale (dopo eventuali redirect)
|
||||
var finalUrl = EmbeddedWebView?.Source?.ToString();
|
||||
if (!string.IsNullOrEmpty(finalUrl))
|
||||
{
|
||||
BrowserAddress.Text = finalUrl;
|
||||
}
|
||||
|
||||
// Propaga l'evento al MainWindow
|
||||
RaiseEvent(new RoutedEventArgs(BrowserNavigationCompletedEvent, this));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void BrowserBackButton_Click(object sender, RoutedEventArgs e)
|
||||
@@ -40,25 +88,138 @@ namespace AutoBidder.Controls
|
||||
RaiseEvent(new RoutedEventArgs(BrowserAddAuctionClickedEvent, this));
|
||||
}
|
||||
|
||||
private void EmbeddedWebView_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
|
||||
{
|
||||
var args = new BrowserNavigationEventArgs(BrowserNavigationStartingEvent, this)
|
||||
{
|
||||
Uri = e.Uri
|
||||
};
|
||||
RaiseEvent(args);
|
||||
}
|
||||
|
||||
private void EmbeddedWebView_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(BrowserNavigationCompletedEvent, this));
|
||||
}
|
||||
|
||||
private void EmbeddedWebView_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
// ===== MODALITA' ESPLORA =====
|
||||
|
||||
private void ModeCatalogRadio_Checked(object sender, RoutedEventArgs e) => ApplyMode(catalog: true);
|
||||
|
||||
private void ModeBrowserRadio_Checked(object sender, RoutedEventArgs e) => ApplyMode(catalog: false);
|
||||
|
||||
private void ApplyMode(bool catalog)
|
||||
{
|
||||
// Chiamato anche durante InitializeComponent, quando gli elementi dichiarati piu'
|
||||
// in basso nel XAML non esistono ancora. Vanno verificati tutti: fidarsi
|
||||
// dell'ordine di dichiarazione rende il controllo fragile a ogni riordino.
|
||||
if (CatalogPanel == null || BrowserPanel == null || BrowserToolbar == null ||
|
||||
CatalogToolbarLeft == null || CatalogSearchHost == null ||
|
||||
CatalogCountText == null || BrowserAddAuctionButton == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CatalogPanel.Visibility = catalog ? Visibility.Visible : Visibility.Collapsed;
|
||||
BrowserPanel.Visibility = catalog ? Visibility.Collapsed : Visibility.Visible;
|
||||
|
||||
// I due gruppi di comandi occupano lo stesso spazio: ne vive uno solo per volta.
|
||||
BrowserToolbar.Visibility = catalog ? Visibility.Collapsed : Visibility.Visible;
|
||||
CatalogToolbarLeft.Visibility = catalog ? Visibility.Visible : Visibility.Collapsed;
|
||||
CatalogSearchHost.Visibility = catalog ? Visibility.Visible : Visibility.Collapsed;
|
||||
CatalogCountText.Visibility = catalog ? Visibility.Visible : Visibility.Collapsed;
|
||||
BrowserAddAuctionButton.Visibility = catalog ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
|
||||
/// <summary>Porta in primo piano il browser integrato (usato dal login e dal catalogo).</summary>
|
||||
public void ShowBrowser() => ModeBrowserRadio.IsChecked = true;
|
||||
|
||||
/// <summary>Porta in primo piano il catalogo nativo (scheda "Cerca").</summary>
|
||||
public void ShowCatalog() => ModeCatalogRadio.IsChecked = true;
|
||||
|
||||
/// <summary>True quando l'utente sta guardando il catalogo nativo.</summary>
|
||||
public bool IsCatalogMode => ModeCatalogRadio.IsChecked == true;
|
||||
|
||||
// ===== CATALOGO =====
|
||||
|
||||
/// <summary>
|
||||
/// Impedisce che il riempimento iniziale dell'elenco categorie faccia partire
|
||||
/// un caricamento per ogni voce aggiunta.
|
||||
/// </summary>
|
||||
private bool _catalogReady;
|
||||
|
||||
private void CategoryButton_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!_catalogReady) return;
|
||||
RaiseEvent(new RoutedEventArgs(CatalogCategoryChangedEvent, this));
|
||||
}
|
||||
|
||||
private void CatalogRefreshButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(CatalogRefreshClickedEvent, this));
|
||||
|
||||
private void CatalogSearchBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (CatalogSearchHint != null)
|
||||
{
|
||||
CatalogSearchHint.Visibility = string.IsNullOrEmpty(CatalogSearchBox.Text)
|
||||
? Visibility.Visible
|
||||
: Visibility.Collapsed;
|
||||
}
|
||||
|
||||
RaiseEvent(new RoutedEventArgs(CatalogSearchChangedEvent, this));
|
||||
}
|
||||
|
||||
private void CatalogFilterChanged(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(CatalogSearchChangedEvent, this));
|
||||
|
||||
private void CatalogAutoRefresh_Changed(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(CatalogAutoRefreshChangedEvent, this));
|
||||
|
||||
/// <summary>Riempie l'elenco categorie senza scatenare un caricamento per voce.</summary>
|
||||
public void SetCategories(System.Collections.IEnumerable categories)
|
||||
{
|
||||
_catalogReady = false;
|
||||
try { CatalogCategoryList.ItemsSource = categories; }
|
||||
finally { _catalogReady = true; }
|
||||
}
|
||||
|
||||
/// <summary>Mostra le schede oppure, se non ce ne sono, un messaggio di stato.</summary>
|
||||
public void SetCatalogItems(System.Collections.IList items, int totalCount)
|
||||
{
|
||||
CatalogItems.ItemsSource = items;
|
||||
CatalogCountText.Text = items.Count == 1 ? "1 asta" : $"{items.Count} aste";
|
||||
|
||||
var empty = items.Count == 0;
|
||||
CatalogEmptyState.Visibility = empty ? Visibility.Visible : Visibility.Collapsed;
|
||||
CatalogScroller.Visibility = empty ? Visibility.Collapsed : Visibility.Visible;
|
||||
|
||||
if (empty)
|
||||
{
|
||||
CatalogEmptyText.Text = totalCount > 0
|
||||
? "Nessuna asta corrisponde ai filtri."
|
||||
: "Nessuna asta in questa categoria.";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Messaggio a tutto pannello (caricamento in corso, errore di rete...).</summary>
|
||||
public void SetCatalogMessage(string message)
|
||||
{
|
||||
CatalogEmptyState.Visibility = Visibility.Visible;
|
||||
CatalogScroller.Visibility = Visibility.Collapsed;
|
||||
CatalogEmptyText.Text = message;
|
||||
}
|
||||
|
||||
public bool AutoRefreshEnabled => CatalogAutoRefresh.IsChecked == true;
|
||||
|
||||
/// <summary>
|
||||
/// Allinea l'interruttore all'impostazione salvata senza far partire un giro di
|
||||
/// aggiornamento: chi chiama sta ancora costruendo la pagina.
|
||||
/// </summary>
|
||||
public void SetAutoRefresh(bool enabled)
|
||||
{
|
||||
CatalogAutoRefresh.Checked -= CatalogAutoRefresh_Changed;
|
||||
CatalogAutoRefresh.Unchecked -= CatalogAutoRefresh_Changed;
|
||||
try { CatalogAutoRefresh.IsChecked = enabled; }
|
||||
finally
|
||||
{
|
||||
CatalogAutoRefresh.Checked += CatalogAutoRefresh_Changed;
|
||||
CatalogAutoRefresh.Unchecked += CatalogAutoRefresh_Changed;
|
||||
}
|
||||
}
|
||||
public bool HideManualAuctions => CatalogHideManual.IsChecked == true;
|
||||
public string SearchText => CatalogSearchBox.Text?.Trim() ?? "";
|
||||
|
||||
// Routed Events
|
||||
public static readonly RoutedEvent BrowserBackClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"BrowserBackClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(BrowserControl));
|
||||
@@ -110,6 +271,44 @@ namespace AutoBidder.Controls
|
||||
add { AddHandler(BrowserAddAuctionClickedEvent, value); }
|
||||
remove { RemoveHandler(BrowserAddAuctionClickedEvent, value); }
|
||||
}
|
||||
|
||||
// ===== Eventi del catalogo =====
|
||||
|
||||
public static readonly RoutedEvent CatalogCategoryChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"CatalogCategoryChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(BrowserControl));
|
||||
|
||||
public static readonly RoutedEvent CatalogRefreshClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"CatalogRefreshClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(BrowserControl));
|
||||
|
||||
public static readonly RoutedEvent CatalogAutoRefreshChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"CatalogAutoRefreshChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(BrowserControl));
|
||||
|
||||
public static readonly RoutedEvent CatalogSearchChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"CatalogSearchChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(BrowserControl));
|
||||
|
||||
public event RoutedEventHandler CatalogCategoryChanged
|
||||
{
|
||||
add { AddHandler(CatalogCategoryChangedEvent, value); }
|
||||
remove { RemoveHandler(CatalogCategoryChangedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler CatalogRefreshClicked
|
||||
{
|
||||
add { AddHandler(CatalogRefreshClickedEvent, value); }
|
||||
remove { RemoveHandler(CatalogRefreshClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler CatalogAutoRefreshChanged
|
||||
{
|
||||
add { AddHandler(CatalogAutoRefreshChangedEvent, value); }
|
||||
remove { RemoveHandler(CatalogAutoRefreshChangedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler CatalogSearchChanged
|
||||
{
|
||||
add { AddHandler(CatalogSearchChangedEvent, value); }
|
||||
remove { RemoveHandler(CatalogSearchChangedEvent, value); }
|
||||
}
|
||||
}
|
||||
|
||||
public class BrowserNavigationEventArgs : RoutedEventArgs
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
<UserControl x:Class="AutoBidder.Controls.ExportControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:ctl="clr-namespace:AutoBidder.Controls"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="800" d:DesignWidth="1200"
|
||||
Background="{DynamicResource Brush.Bg}">
|
||||
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="Glyph" TargetType="TextBlock">
|
||||
<Setter Property="FontFamily" Value="Segoe MDL2 Assets"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="FilterLabel" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="Margin" Value="0,8"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- ═══ Barra strumenti ═══ -->
|
||||
<Border Grid.Row="0" Background="{DynamicResource Brush.Surface}" Padding="10,7"
|
||||
BorderBrush="{DynamicResource Brush.Border}" BorderThickness="0,0,0,1">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Button x:Name="PreviewButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Ricalcola quante aste corrispondono ai filtri"
|
||||
Click="PreviewButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
<TextBlock Text="Esporta" FontWeight="SemiBold" Margin="8,0,0,0"
|
||||
FontSize="{StaticResource Font.Size.Lg}"
|
||||
Foreground="{DynamicResource Brush.Text}" VerticalAlignment="Center"/>
|
||||
<Border Width="1" Background="{DynamicResource Brush.Border}" Margin="10,4"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Style="{StaticResource Pill}" ToolTip="Aste che corrispondono ai filtri">
|
||||
<TextBlock x:Name="MatchCountText" Text="—"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.Text}"/>
|
||||
</Border>
|
||||
<Border Style="{StaticResource Pill}" ToolTip="Di queste, quelle seguite dall'inizio alla fine">
|
||||
<TextBlock x:Name="CompleteCountText" Text="—"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Button x:Name="ExportButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.Accent}"
|
||||
Foreground="{DynamicResource Brush.TextOnAccent}"
|
||||
Content="Esporta in un file" Margin="0,0,8,0"
|
||||
Click="ExportButton_Click"/>
|
||||
|
||||
<Button x:Name="OpenFolderButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Content="Apri la cartella" Margin="0,0,8,0"
|
||||
Click="OpenFolderButton_Click"/>
|
||||
|
||||
<Button x:Name="ResetFiltersButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Azzera i filtri" Click="ResetFiltersButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Margin="20,16" MaxWidth="1000" HorizontalAlignment="Left">
|
||||
|
||||
<!-- ═══ Cosa esporta ═══ -->
|
||||
<Border Style="{StaticResource CardBlock}">
|
||||
<StackPanel>
|
||||
<ctl:HelpHeader Title="Cosa finisce nel file"
|
||||
Margin="0,0,0,12"
|
||||
Help="Un unico file JSON con le aste scelte: esito, prezzo finale, valore del prodotto, puntate di ogni utente, ping e latenza, andamento del prezzo e — dove esiste il dossier — ogni singolo evento registrato mentre l'asta era in corso. Il file si spiega da sé: contiene la legenda dei campi, così resta leggibile anche fra sei mesi."/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- ═══ Filtri ═══ -->
|
||||
<Border Style="{StaticResource CardBlock}">
|
||||
<StackPanel>
|
||||
<TextBlock Text="Filtri" Style="{StaticResource BlockTitle}"/>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="230"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Periodo (chiusura)"
|
||||
Style="{StaticResource FilterLabel}"/>
|
||||
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" Margin="0,4">
|
||||
<DatePicker x:Name="FromDatePicker" Width="150"
|
||||
ToolTip="Dalla data di chiusura (vuoto = dall'inizio)"/>
|
||||
<TextBlock Text="→" Margin="8,0" VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
<DatePicker x:Name="ToDatePicker" Width="150"
|
||||
ToolTip="Fino alla data di chiusura (vuoto = fino a oggi)"/>
|
||||
|
||||
<Button Content="Ultimi 7 giorni" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Margin="12,0,0,0" Click="Last7Days_Click"/>
|
||||
<Button Content="Ultimi 30" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Margin="6,0,0,0" Click="Last30Days_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="Prodotto contiene"
|
||||
Style="{StaticResource FilterLabel}"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" x:Name="NameFilterTextBox"
|
||||
Width="320" HorizontalAlignment="Left" Margin="0,4"
|
||||
ToolTip="Parte del nome del prodotto, senza distinzione fra maiuscole"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="Prezzo finale (€)"
|
||||
Style="{StaticResource FilterLabel}"/>
|
||||
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" Margin="0,4">
|
||||
<TextBox x:Name="MinPriceTextBox" Width="100"
|
||||
ToolTip="Prezzo finale minimo (vuoto = nessun limite)"/>
|
||||
<TextBlock Text="→" Margin="8,0" VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
<TextBox x:Name="MaxPriceTextBox" Width="100"
|
||||
ToolTip="Prezzo finale massimo (vuoto = nessun limite)"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Text="Tetto di aste"
|
||||
Style="{StaticResource FilterLabel}"/>
|
||||
<StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" Margin="0,4">
|
||||
<TextBox x:Name="MaxAuctionsTextBox" Width="100" Text="0"
|
||||
ToolTip="0 = tutte. Con gli eventi inclusi, cento aste sono già diversi megabyte."/>
|
||||
<TextBlock Text="0 = tutte quelle che corrispondono" VerticalAlignment="Center"
|
||||
Margin="10,0,0,0" FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- ═══ Quali aste ═══ -->
|
||||
<Border Style="{StaticResource CardBlock}">
|
||||
<StackPanel>
|
||||
<TextBlock Text="Quali aste" Style="{StaticResource BlockTitle}"/>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0">
|
||||
<CheckBox x:Name="IncludeWonCheckBox" IsChecked="True" Margin="0,4"
|
||||
Content="Vinte" Checked="Filter_Changed" Unchecked="Filter_Changed"/>
|
||||
<CheckBox x:Name="IncludeLostCheckBox" IsChecked="True" Margin="0,4"
|
||||
Content="Perse (ci avevo puntato)" Checked="Filter_Changed" Unchecked="Filter_Changed"/>
|
||||
<CheckBox x:Name="IncludeClosedCheckBox" IsChecked="True" Margin="0,4"
|
||||
Content="Solo osservate (mai puntato)"
|
||||
ToolTip="Non le ho giocate, ma dicono a quanto chiude il mercato"
|
||||
Checked="Filter_Changed" Unchecked="Filter_Changed"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="1">
|
||||
<CheckBox x:Name="OnlyCompleteCheckBox" Margin="0,4"
|
||||
Content="Solo quelle seguite dall'inizio alla fine"
|
||||
ToolTip="Sono le più preziose: su un'asta presa a metà non si sa quante puntate erano già state spese"
|
||||
Checked="Filter_Changed" Unchecked="Filter_Changed"/>
|
||||
<CheckBox x:Name="OnlyWithMyBidsCheckBox" Margin="0,4"
|
||||
Content="Solo quelle su cui ho puntato"
|
||||
Checked="Filter_Changed" Unchecked="Filter_Changed"/>
|
||||
<CheckBox x:Name="OnlyWithDossierCheckBox" Margin="0,4"
|
||||
Content="Solo quelle con il dossier degli eventi"
|
||||
Checked="Filter_Changed" Unchecked="Filter_Changed"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<Border Background="{DynamicResource Brush.SurfaceAlt}" CornerRadius="8"
|
||||
Padding="12,10" Margin="0,12,0,0">
|
||||
<StackPanel>
|
||||
<CheckBox x:Name="IncludeEventsCheckBox" IsChecked="True"
|
||||
Content="Includi tutti gli eventi registrati (dossier completo)"
|
||||
ToolTip="Senza, il file contiene solo i riepiloghi: molto più leggero, molto meno utile. Gli eventi sono ogni interrogazione a Bidoo, ogni puntata di ogni utente con l'ora al millisecondo e ogni mia puntata con anticipo pianificato ed effettivo. È il materiale con cui si tara l'anticipo; è anche ciò che fa pesare il file."/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- ═══ Esito ═══ -->
|
||||
<Border Style="{StaticResource CardBlock}">
|
||||
<StackPanel>
|
||||
<TextBlock Text="Ultima esportazione" Style="{StaticResource BlockTitle}"/>
|
||||
|
||||
<Border Background="{DynamicResource Brush.SurfaceAlt}" CornerRadius="8" Padding="12,10">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text="" FontSize="13"
|
||||
Foreground="{DynamicResource Brush.Accent}" Margin="0,0,8,0"/>
|
||||
<TextBlock x:Name="ResultText" VerticalAlignment="Center" TextWrapping="Wrap"
|
||||
Text="Nessuna esportazione in questa sessione."
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Button x:Name="OpenLastFileButton" HorizontalAlignment="Left"
|
||||
Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Content="Apri il file" Margin="0,10,0,0"
|
||||
Visibility="Collapsed" Click="OpenLastFileButton_Click"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Scheda Esporta: sceglie quali aste finiscono in un unico file e lo scrive.
|
||||
///
|
||||
/// <para>Come gli altri pannelli non conosce gli archivi: costruisce un
|
||||
/// <see cref="AuctionExportFilter"/> e lascia il lavoro a
|
||||
/// <see cref="AuctionExporter"/>. Qui dentro c'è solo la traduzione fra i campi
|
||||
/// dell'interfaccia e i criteri — e il conteggio in tempo reale, che serve a non
|
||||
/// scoprire dopo un minuto di scrittura che il filtro non selezionava nulla.</para>
|
||||
/// </summary>
|
||||
public partial class ExportControl : UserControl
|
||||
{
|
||||
private string? _lastExportPath;
|
||||
|
||||
public ExportControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += (_, _) => RefreshPreview();
|
||||
}
|
||||
|
||||
/// <summary>I criteri come sono impostati adesso.</summary>
|
||||
public AuctionExportFilter BuildFilter() => new()
|
||||
{
|
||||
From = FromDatePicker.SelectedDate,
|
||||
To = ToDatePicker.SelectedDate,
|
||||
NameContains = string.IsNullOrWhiteSpace(NameFilterTextBox.Text) ? null : NameFilterTextBox.Text.Trim(),
|
||||
|
||||
IncludeWon = IncludeWonCheckBox.IsChecked == true,
|
||||
IncludeLost = IncludeLostCheckBox.IsChecked == true,
|
||||
IncludeClosed = IncludeClosedCheckBox.IsChecked == true,
|
||||
|
||||
OnlyComplete = OnlyCompleteCheckBox.IsChecked == true,
|
||||
OnlyWithMyBids = OnlyWithMyBidsCheckBox.IsChecked == true,
|
||||
OnlyWithDossier = OnlyWithDossierCheckBox.IsChecked == true,
|
||||
|
||||
MinFinalPrice = ParseNumber(MinPriceTextBox.Text),
|
||||
MaxFinalPrice = ParseNumber(MaxPriceTextBox.Text),
|
||||
MaxAuctions = (int)(ParseNumber(MaxAuctionsTextBox.Text) ?? 0),
|
||||
|
||||
IncludeEvents = IncludeEventsCheckBox.IsChecked == true
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Ricalcola quante aste corrispondono. Si fa a ogni modifica dei filtri: sapere
|
||||
/// prima che il risultato è vuoto — o che sono duemila — evita di scoprirlo a file
|
||||
/// scritto.
|
||||
/// </summary>
|
||||
public void RefreshPreview()
|
||||
{
|
||||
try
|
||||
{
|
||||
var selected = AuctionExporter.Select(BuildFilter());
|
||||
|
||||
MatchCountText.Text = selected.Count == 1 ? "1 asta" : $"{selected.Count} aste";
|
||||
|
||||
var complete = selected.Count(r => r.IsComplete);
|
||||
CompleteCountText.Text = $"{complete} complete";
|
||||
|
||||
ExportButton.IsEnabled = selected.Count > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MatchCountText.Text = "—";
|
||||
CompleteCountText.Text = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Mostra l'esito dell'esportazione appena fatta.</summary>
|
||||
public void ShowResult(AuctionExportResult result)
|
||||
{
|
||||
if (result.Success)
|
||||
{
|
||||
_lastExportPath = result.Path;
|
||||
|
||||
var size = result.Bytes >= 1024 * 1024
|
||||
? $"{result.Bytes / 1024.0 / 1024.0:F1} MB"
|
||||
: $"{Math.Max(1, result.Bytes / 1024)} kB";
|
||||
|
||||
ResultText.Text = $"{result.AuctionCount} aste ({result.WithEvents} con eventi), {size} — {result.Path}";
|
||||
ResultText.SetResourceReference(ForegroundProperty, "Brush.Text");
|
||||
OpenLastFileButton.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
ResultText.Text = result.Message;
|
||||
ResultText.SetResourceReference(ForegroundProperty, "Brush.Warning");
|
||||
OpenLastFileButton.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Percorso dell'ultimo file scritto, per il pulsante "Apri il file".</summary>
|
||||
public string? LastExportPath => _lastExportPath;
|
||||
|
||||
// ── Eventi dell'interfaccia ──────────────────────────────────────
|
||||
|
||||
private void PreviewButton_Click(object sender, RoutedEventArgs e) => RefreshPreview();
|
||||
|
||||
private void Filter_Changed(object sender, RoutedEventArgs e) => RefreshPreview();
|
||||
|
||||
private void Last7Days_Click(object sender, RoutedEventArgs e) => SetPeriod(7);
|
||||
|
||||
private void Last30Days_Click(object sender, RoutedEventArgs e) => SetPeriod(30);
|
||||
|
||||
private void SetPeriod(int days)
|
||||
{
|
||||
FromDatePicker.SelectedDate = DateTime.Today.AddDays(-days);
|
||||
ToDatePicker.SelectedDate = DateTime.Today;
|
||||
RefreshPreview();
|
||||
}
|
||||
|
||||
private void ResetFiltersButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
FromDatePicker.SelectedDate = null;
|
||||
ToDatePicker.SelectedDate = null;
|
||||
NameFilterTextBox.Text = "";
|
||||
MinPriceTextBox.Text = "";
|
||||
MaxPriceTextBox.Text = "";
|
||||
MaxAuctionsTextBox.Text = "0";
|
||||
|
||||
IncludeWonCheckBox.IsChecked = true;
|
||||
IncludeLostCheckBox.IsChecked = true;
|
||||
IncludeClosedCheckBox.IsChecked = true;
|
||||
OnlyCompleteCheckBox.IsChecked = false;
|
||||
OnlyWithMyBidsCheckBox.IsChecked = false;
|
||||
OnlyWithDossierCheckBox.IsChecked = false;
|
||||
IncludeEventsCheckBox.IsChecked = true;
|
||||
|
||||
RefreshPreview();
|
||||
}
|
||||
|
||||
private void ExportButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ExportRequestedEvent, this));
|
||||
|
||||
private void OpenFolderButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenExportFolderClickedEvent, this));
|
||||
|
||||
private void OpenLastFileButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenLastFileClickedEvent, this));
|
||||
|
||||
/// <summary>
|
||||
/// Legge un numero accettando sia la virgola sia il punto: chi scrive "12,50" e chi
|
||||
/// scrive "12.50" intende la stessa cosa, e rifiutarne uno dei due sarebbe pedanteria.
|
||||
/// </summary>
|
||||
private static double? ParseNumber(string? text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text)) return null;
|
||||
|
||||
var clean = text.Trim().Replace(',', '.');
|
||||
|
||||
return double.TryParse(clean, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)
|
||||
? value
|
||||
: null;
|
||||
}
|
||||
|
||||
// ── Routed events ────────────────────────────────────────────────
|
||||
|
||||
public static readonly RoutedEvent ExportRequestedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ExportRequested", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ExportControl));
|
||||
|
||||
public static readonly RoutedEvent OpenExportFolderClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenExportFolderClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ExportControl));
|
||||
|
||||
public static readonly RoutedEvent OpenLastFileClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenLastFileClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ExportControl));
|
||||
|
||||
public event RoutedEventHandler ExportRequested
|
||||
{
|
||||
add { AddHandler(ExportRequestedEvent, value); }
|
||||
remove { RemoveHandler(ExportRequestedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenExportFolderClicked
|
||||
{
|
||||
add { AddHandler(OpenExportFolderClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenExportFolderClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenLastFileClicked
|
||||
{
|
||||
add { AddHandler(OpenLastFileClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenLastFileClickedEvent, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,365 @@
|
||||
<UserControl x:Class="AutoBidder.Controls.FreeBidsControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:ctl="clr-namespace:AutoBidder.Controls"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="800" d:DesignWidth="1200"
|
||||
Background="{DynamicResource Brush.Bg}">
|
||||
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="Glyph" TargetType="TextBlock">
|
||||
<Setter Property="FontFamily" Value="Segoe MDL2 Assets"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="CounterCaption" TargetType="TextBlock">
|
||||
<Setter Property="FontSize" Value="{StaticResource Font.Size.Sm}"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextFaint}"/>
|
||||
<Setter Property="Margin" Value="0,0,0,3"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="CounterValue" TargetType="TextBlock">
|
||||
<Setter Property="FontSize" Value="22"/>
|
||||
<Setter Property="FontWeight" Value="SemiBold"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- ═══ Barra strumenti ═══ -->
|
||||
<Border Grid.Row="0" Background="{DynamicResource Brush.Surface}" Padding="10,7"
|
||||
BorderBrush="{DynamicResource Brush.Border}" BorderThickness="0,0,0,1">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Button x:Name="RefreshButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Aggiorna il saldo puntate" Click="RefreshButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
<TextBlock Text="Puntate" FontWeight="SemiBold" Margin="8,0,0,0"
|
||||
FontSize="{StaticResource Font.Size.Lg}"
|
||||
Foreground="{DynamicResource Brush.Text}" VerticalAlignment="Center"/>
|
||||
<Border Width="1" Background="{DynamicResource Brush.Border}" Margin="10,4"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Style="{StaticResource Pill}" ToolTip="Puntate attualmente sul conto">
|
||||
<TextBlock x:Name="BalanceText" Text="— puntate"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.Text}"/>
|
||||
</Border>
|
||||
<Border Style="{StaticResource Pill}" ToolTip="Stato del riscatto automatico">
|
||||
<TextBlock x:Name="StatusPillText" Text="riscatto spento"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Button x:Name="CheckNowButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.Accent}"
|
||||
Foreground="{DynamicResource Brush.TextOnAccent}"
|
||||
Content="Controlla adesso" Margin="0,0,8,0"
|
||||
ToolTip="Cerca subito ricompense da riscuotere, senza aspettare il prossimo giro"
|
||||
Click="CheckNowButton_Click"/>
|
||||
|
||||
<Button x:Name="OpenExternalButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Margin="0,0,8,0"
|
||||
ToolTip="Apre la pagina delle ricompense nel browser predefinito di Windows"
|
||||
Click="OpenExternalButton_Click">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" Text="" FontSize="11"
|
||||
VerticalAlignment="Center" Margin="0,0,6,0"/>
|
||||
<TextBlock Text="Apri su Bidoo" VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button x:Name="OpenInternalButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Apri le ricompense nel browser integrato (è lì che arrivano le notifiche)"
|
||||
Click="OpenInternalButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Margin="20,16" MaxWidth="1000" HorizontalAlignment="Left">
|
||||
|
||||
<!-- ═══ Riscatto automatico ═══ -->
|
||||
<Border Style="{StaticResource CardBlock}">
|
||||
<StackPanel>
|
||||
<ctl:HelpHeader Title="Riscatto automatico"
|
||||
Margin="0,0,0,12"
|
||||
Help="Bidoo lascia in attesa le ricompense dei giorni scorsi. Con questo acceso, l'applicazione controlla a intervalli regolari e riscuote quello che trova, mentre continua a seguire le aste."/>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="300"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Riscuoti da solo le ricompense"
|
||||
Foreground="{DynamicResource Brush.Text}" Margin="0,8"
|
||||
VerticalAlignment="Center"/>
|
||||
<CheckBox Grid.Row="0" Grid.Column="1" x:Name="AutoClaimCheckBox"
|
||||
Margin="10,8" VerticalAlignment="Center"
|
||||
Checked="AutoClaimCheckBox_Changed" Unchecked="AutoClaimCheckBox_Changed"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="Controlla ogni (minuti)"
|
||||
Foreground="{DynamicResource Brush.Text}" Margin="0,8"
|
||||
VerticalAlignment="Center"
|
||||
ToolTip="Minimo 5 minuti: le ricompense sono giornaliere"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" x:Name="CheckMinutesTextBox"
|
||||
Text="30" Width="90" Margin="10,8" HorizontalAlignment="Left"
|
||||
LostFocus="CheckMinutesTextBox_LostFocus"/>
|
||||
</Grid>
|
||||
|
||||
<Border Background="{DynamicResource Brush.SurfaceAlt}" CornerRadius="8"
|
||||
Padding="12,10" Margin="0,10,0,0">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text="" FontSize="13"
|
||||
Foreground="{DynamicResource Brush.Accent}" Margin="0,0,8,0"/>
|
||||
<TextBlock x:Name="ScheduleText" VerticalAlignment="Center"
|
||||
Text="Riscatto automatico spento."
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- ═══ Contatori ═══ -->
|
||||
<Border Style="{StaticResource CardBlock}">
|
||||
<StackPanel>
|
||||
<Grid Margin="0,0,0,12">
|
||||
<TextBlock Text="Quanto ho riscattato" Style="{StaticResource BlockTitle}"
|
||||
Margin="0"/>
|
||||
<Button x:Name="ResetCountersButton" HorizontalAlignment="Right"
|
||||
Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Danger}"
|
||||
Content="Azzera contatori"
|
||||
Click="ResetCountersButton_Click"/>
|
||||
</Grid>
|
||||
|
||||
<UniformGrid Columns="4">
|
||||
<StackPanel Margin="0,0,16,0">
|
||||
<TextBlock Text="Puntate — questa sessione" Style="{StaticResource CounterCaption}"/>
|
||||
<TextBlock x:Name="SessionBidsText" Text="0" Style="{StaticResource CounterValue}"
|
||||
Foreground="{DynamicResource Brush.Accent}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Margin="0,0,16,0">
|
||||
<TextBlock Text="Puntate — oggi" Style="{StaticResource CounterCaption}"/>
|
||||
<TextBlock x:Name="TodayBidsText" Text="0" Style="{StaticResource CounterValue}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Margin="0,0,16,0">
|
||||
<TextBlock Text="Puntate — da sempre" Style="{StaticResource CounterCaption}"/>
|
||||
<TextBlock x:Name="TotalBidsText" Text="0" Style="{StaticResource CounterValue}"
|
||||
Foreground="{DynamicResource Brush.Gold}"/>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="Ricompense riscosse" Style="{StaticResource CounterCaption}"/>
|
||||
<TextBlock x:Name="TotalClaimedText" Text="0" Style="{StaticResource CounterValue}"/>
|
||||
</StackPanel>
|
||||
</UniformGrid>
|
||||
|
||||
<TextBlock x:Name="CountersDetailText" Margin="0,12,0,0"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextFaint}"
|
||||
Text="Nessun controllo ancora eseguito."/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- ═══ Registro ═══ -->
|
||||
<Border Style="{StaticResource CardBlock}">
|
||||
<StackPanel>
|
||||
<Grid Margin="0,0,0,10">
|
||||
<TextBlock Text="Registro dei riscatti" Style="{StaticResource BlockTitle}"
|
||||
Margin="0"/>
|
||||
<Button x:Name="ClearLogButton" HorizontalAlignment="Right"
|
||||
Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Content="Pulisci" Click="ClearLogButton_Click"/>
|
||||
</Grid>
|
||||
|
||||
<Border Background="{DynamicResource Brush.Bg}" CornerRadius="8"
|
||||
BorderBrush="{DynamicResource Brush.Border}" BorderThickness="1"
|
||||
Height="190">
|
||||
<Grid>
|
||||
<ListBox x:Name="ActivityList" Background="Transparent"
|
||||
BorderThickness="0" Margin="4"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal" Margin="2,1">
|
||||
<TextBlock Text="{Binding Time}" FontSize="11"
|
||||
Foreground="{DynamicResource Brush.TextFaint}"
|
||||
Margin="0,0,10,0" VerticalAlignment="Top"/>
|
||||
<TextBlock Text="{Binding Message}" FontSize="12"
|
||||
TextWrapping="Wrap" MaxWidth="760">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsProblem}" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Warning}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<TextBlock x:Name="ActivityEmptyText"
|
||||
Text="Nessun riscatto registrato in questa sessione."
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
FontSize="12"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- ═══ Collegamenti promozionali pubblicati ═══ -->
|
||||
<Border Style="{StaticResource CardBlock}">
|
||||
<StackPanel>
|
||||
<ctl:HelpHeader Title="Puntate gratis dai collegamenti pubblicati"
|
||||
Margin="0,0,0,12"
|
||||
Help="Bidoo regala puntate con collegamenti già firmati che i siti di raccolta ripubblicano. L'applicazione legge quella pagina, scarta i collegamenti già presi e apre i nuovi con la tua sessione, uno alla volta. I codici presi restano in memoria: senza, ogni giro riaprirebbe gli stessi."/>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
|
||||
<Button x:Name="HarvestButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.Accent}"
|
||||
Foreground="{DynamicResource Brush.TextOnAccent}"
|
||||
Content="Cerca collegamenti adesso" Margin="0,0,8,0"
|
||||
ToolTip="Legge subito la pagina dei collegamenti e riscuote quelli nuovi"
|
||||
Click="HarvestButton_Click"/>
|
||||
|
||||
<Button x:Name="OpenSourceButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Content="Apri la pagina dei collegamenti" Margin="0,0,8,0"
|
||||
ToolTip="Apre nel browser integrato la pagina da cui vengono presi i collegamenti"
|
||||
Click="OpenSourceButton_Click"/>
|
||||
|
||||
<Button x:Name="ForgetPromosButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Content="Dimentica i codici presi"
|
||||
ToolTip="Azzera la memoria dei collegamenti già aperti (serve dopo un cambio di account)"
|
||||
Click="ForgetPromosButton_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
<Border Background="{DynamicResource Brush.SurfaceAlt}" CornerRadius="8"
|
||||
Padding="12,10" Margin="0,0,0,4">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text="" FontSize="13"
|
||||
Foreground="{DynamicResource Brush.Accent}" Margin="0,0,8,0"/>
|
||||
<TextBlock x:Name="HarvestStatusText" VerticalAlignment="Center"
|
||||
TextWrapping="Wrap"
|
||||
Text="Nessuna raccolta ancora eseguita."
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- ═══ Riscatto da codice o collegamento ═══ -->
|
||||
<Border Style="{StaticResource CardBlock}">
|
||||
<StackPanel>
|
||||
<ctl:HelpHeader Title="Codice o collegamento singolo"
|
||||
Margin="0,0,0,12"
|
||||
Help="Per un collegamento ricevuto per email o per messaggio, che la pagina di raccolta non ha. Incollalo intero: viene aperto con la sessione attiva, come se ci avessi cliccato sopra. Quelli che non portano a Bidoo vengono rifiutati. Un codice da solo di norma non basta — questi indirizzi portano una firma (sign) che non si può ricostruire."/>
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox x:Name="PromoCodeTextBox" Width="420" VerticalAlignment="Center"
|
||||
KeyDown="PromoCodeTextBox_KeyDown"
|
||||
ToolTip="Codice promozionale, oppure indirizzo completo del riscatto"/>
|
||||
<Button x:Name="ClaimPromoButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.Accent}"
|
||||
Foreground="{DynamicResource Brush.TextOnAccent}"
|
||||
Content="Riscatta" Margin="8,0,0,0"
|
||||
Click="ClaimPromoButton_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
<Border Background="{DynamicResource Brush.SurfaceAlt}" CornerRadius="8"
|
||||
Padding="12,10" Margin="0,12,0,0">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Column="0" x:Name="ConfigPathText" TextWrapping="Wrap"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"
|
||||
Text="Indirizzi, intestazioni e parametri del riscatto stanno in site-config.json."/>
|
||||
|
||||
<Button Grid.Column="1" x:Name="OpenConfigButton"
|
||||
Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.Surface}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Content="Apri i riferimenti" Margin="10,0,0,0"
|
||||
ToolTip="Apre il file con indirizzi, intestazioni e parametri del riscatto"
|
||||
Click="OpenConfigButton_Click"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- ═══ Cosa resta manuale ═══ -->
|
||||
<Border Style="{StaticResource CardBlock}">
|
||||
<StackPanel>
|
||||
<TextBlock Text="Cosa resta da fare a mano" Style="{StaticResource BlockTitle}"/>
|
||||
|
||||
<Border Style="{StaticResource InfoBox}">
|
||||
<TextBlock TextWrapping="Wrap" FontSize="12" LineHeight="18"
|
||||
Foreground="{DynamicResource Brush.Text}">
|
||||
<Run Text="Le puntate consegnate per notifica non passano da qui." FontWeight="Bold"/>
|
||||
<Run Text=" Bidoo le manda tramite le notifiche push del browser (OneSignal) e per email, con collegamenti personali validi una volta sola: sono legate all'abbonamento del browser, non all'account, quindi non esiste una chiamata da fare con il cookie di sessione. Per quelle apri le ricompense nel browser integrato, concedi le notifiche e lascia la scheda aperta."/>
|
||||
</TextBlock>
|
||||
</Border>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
|
||||
<Button Content="Buoni e voucher" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Margin="0,0,8,0" Click="OpenVouchersButton_Click"/>
|
||||
<Button Content="Acquista puntate" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Click="OpenBuyBidsButton_Click"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,352 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Scheda Puntate: stato del riscatto automatico, contatori e registro.
|
||||
///
|
||||
/// <para>Come gli altri pannelli non conosce né la rete né gli archivi: mostra ciò che
|
||||
/// gli viene passato e segnala le richieste dell'utente con eventi.</para>
|
||||
/// </summary>
|
||||
public partial class FreeBidsControl : UserControl
|
||||
{
|
||||
/// <summary>Una riga del registro dei riscatti.</summary>
|
||||
public sealed record ActivityEntry(string Time, string Message, bool IsProblem);
|
||||
|
||||
/// <summary>
|
||||
/// Il registro è volutamente limitato e solo in memoria: serve a capire cosa è
|
||||
/// successo mentre si guardava altrove, non a essere uno storico — quello sono i
|
||||
/// contatori, che invece durano.
|
||||
/// </summary>
|
||||
private const int MaxActivityEntries = 200;
|
||||
|
||||
private readonly ObservableCollection<ActivityEntry> _activity = new();
|
||||
|
||||
/// <summary>Evita che riempire i campi dalle impostazioni scateni un salvataggio.</summary>
|
||||
private bool _loading;
|
||||
|
||||
public FreeBidsControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
ActivityList.ItemsSource = _activity;
|
||||
}
|
||||
|
||||
// ── Aggiornamento dello stato ────────────────────────────────────
|
||||
|
||||
public void SetBalance(int? bids) =>
|
||||
BalanceText.Text = bids.HasValue
|
||||
? $"{bids.Value} puntate sul conto"
|
||||
: "saldo non disponibile";
|
||||
|
||||
/// <summary>Allinea i campi alle impostazioni salvate senza scatenare eventi.</summary>
|
||||
public void SetOptions(bool autoClaimEnabled, int checkMinutes)
|
||||
{
|
||||
_loading = true;
|
||||
try
|
||||
{
|
||||
AutoClaimCheckBox.IsChecked = autoClaimEnabled;
|
||||
CheckMinutesTextBox.Text = checkMinutes.ToString();
|
||||
}
|
||||
finally { _loading = false; }
|
||||
}
|
||||
|
||||
public bool AutoClaimEnabled => AutoClaimCheckBox.IsChecked == true;
|
||||
|
||||
/// <summary>Codice o collegamento digitato per il riscatto manuale.</summary>
|
||||
public string PromoCode => PromoCodeTextBox.Text?.Trim() ?? "";
|
||||
|
||||
/// <summary>Svuota il campo dopo un riscatto andato a buon fine.</summary>
|
||||
public void ClearPromoCode() => PromoCodeTextBox.Text = "";
|
||||
|
||||
/// <summary>
|
||||
/// Riga di stato della raccolta: da dove legge, quanti codici sono già stati presi e
|
||||
/// com'è andato l'ultimo giro.
|
||||
/// </summary>
|
||||
public void SetHarvestStatus(string sourceUrl, int claimedCodes, string? lastOutcome)
|
||||
{
|
||||
var known = claimedCodes == 1
|
||||
? "1 codice già preso"
|
||||
: $"{claimedCodes} codici già presi";
|
||||
|
||||
HarvestStatusText.Text = lastOutcome == null
|
||||
? $"Sorgente: {sourceUrl} · {known}."
|
||||
: $"Sorgente: {sourceUrl} · {known} · ultimo giro: {lastOutcome}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mostra dove sta il file dei riferimenti, ed eventualmente perché non è stato
|
||||
/// possibile usarlo: sono i valori che decidono ogni chiamata di riscatto, e sapere
|
||||
/// che se ne stanno usando altri è la differenza fra correggere il file e cercare un
|
||||
/// guasto che non c'è.
|
||||
/// </summary>
|
||||
public void SetConfigPath(string path, string? problem)
|
||||
{
|
||||
ConfigPathText.Text = problem == null
|
||||
? $"Indirizzi, intestazioni e parametri del riscatto: {path}"
|
||||
: $"{problem} — {path}";
|
||||
|
||||
ConfigPathText.SetResourceReference(TextBlock.ForegroundProperty,
|
||||
problem == null ? "Brush.TextMuted" : "Brush.Warning");
|
||||
}
|
||||
|
||||
/// <summary>Minuti richiesti, già riportati entro il minimo consentito.</summary>
|
||||
public int CheckMinutes =>
|
||||
int.TryParse(CheckMinutesTextBox.Text?.Trim(), out var minutes) ? Math.Max(5, minutes) : 30;
|
||||
|
||||
/// <summary>Riga di stato: acceso o spento, e quando tocca al prossimo giro.</summary>
|
||||
public void SetSchedule(bool running, DateTime? lastCheck, DateTime? nextCheck)
|
||||
{
|
||||
StatusPillText.Text = running ? "riscatto attivo" : "riscatto spento";
|
||||
StatusPillText.SetResourceReference(TextBlock.ForegroundProperty,
|
||||
running ? "Brush.Success" : "Brush.TextMuted");
|
||||
|
||||
if (!running)
|
||||
{
|
||||
ScheduleText.Text = "Riscatto automatico spento: puoi comunque usare «Controlla adesso».";
|
||||
return;
|
||||
}
|
||||
|
||||
var last = lastCheck.HasValue
|
||||
? $"ultimo controllo alle {lastCheck.Value:HH:mm}"
|
||||
: "nessun controllo ancora eseguito";
|
||||
|
||||
var next = nextCheck.HasValue
|
||||
? $", il prossimo alle {nextCheck.Value:HH:mm}"
|
||||
: "";
|
||||
|
||||
ScheduleText.Text = char.ToUpper(last[0]) + last[1..] + next + ".";
|
||||
}
|
||||
|
||||
/// <summary>Ridisegna i contatori.</summary>
|
||||
public void SetCounters(FreeBidsStats.Snapshot s)
|
||||
{
|
||||
SessionBidsText.Text = s.SessionBids.ToString();
|
||||
TodayBidsText.Text = s.BidsToday.ToString();
|
||||
TotalBidsText.Text = s.TotalBids.ToString();
|
||||
TotalClaimedText.Text = s.TotalClaimed.ToString();
|
||||
|
||||
var lastClaim = s.LastClaimAt.HasValue
|
||||
? $"ultimo riscatto il {s.LastClaimAt.Value:dd/MM/yyyy} alle {s.LastClaimAt.Value:HH:mm}"
|
||||
: "nessun riscatto ancora andato a buon fine";
|
||||
|
||||
CountersDetailText.Text =
|
||||
$"{s.SessionChecks} controlli in questa sessione · {s.TotalChecks} da sempre · " +
|
||||
$"{s.SessionClaimed} ricompense prese in sessione · {lastClaim}.";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunge una riga al registro, a video e su file.
|
||||
///
|
||||
/// <para>Il file serve perché questo pannello è l'unico posto in cui si vede cosa ha
|
||||
/// fatto il riscatto automatico, e il riscatto lavora quando nessuno guarda: senza
|
||||
/// registro su disco, tutto ciò che è successo mentre l'applicazione era chiusa —
|
||||
/// o nelle duecento righe precedenti — sarebbe perso.</para>
|
||||
/// </summary>
|
||||
public void AppendActivity(string message, bool isProblem = false)
|
||||
{
|
||||
TextLogService.FreeBids(message, isProblem);
|
||||
|
||||
_activity.Insert(0, new ActivityEntry(DateTime.Now.ToString("HH:mm:ss"), message, isProblem));
|
||||
|
||||
while (_activity.Count > MaxActivityEntries)
|
||||
_activity.RemoveAt(_activity.Count - 1);
|
||||
|
||||
ActivityEmptyText.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
// ── Eventi dell'interfaccia ──────────────────────────────────────
|
||||
|
||||
private void RefreshButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(RefreshBalanceClickedEvent, this));
|
||||
|
||||
private void CheckNowButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(CheckNowClickedEvent, this));
|
||||
|
||||
private void OpenExternalButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenExternalClickedEvent, this));
|
||||
|
||||
private void OpenInternalButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenInternalClickedEvent, this));
|
||||
|
||||
private void OpenVouchersButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenVouchersClickedEvent, this));
|
||||
|
||||
private void OpenBuyBidsButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenBuyBidsClickedEvent, this));
|
||||
|
||||
private void ResetCountersButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ResetCountersClickedEvent, this));
|
||||
|
||||
private void AutoClaimCheckBox_Changed(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_loading) return;
|
||||
RaiseEvent(new RoutedEventArgs(OptionsChangedEvent, this));
|
||||
}
|
||||
|
||||
private void CheckMinutesTextBox_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_loading) return;
|
||||
|
||||
// Si riscrive il valore corretto: chi ha digitato "2" deve vedere che il
|
||||
// minimo applicato è 5, invece di credere di aver impostato due minuti.
|
||||
var minutes = CheckMinutes;
|
||||
if (CheckMinutesTextBox.Text != minutes.ToString())
|
||||
CheckMinutesTextBox.Text = minutes.ToString();
|
||||
|
||||
RaiseEvent(new RoutedEventArgs(OptionsChangedEvent, this));
|
||||
}
|
||||
|
||||
private void HarvestButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(HarvestClickedEvent, this));
|
||||
|
||||
private void OpenSourceButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenPromoSourceClickedEvent, this));
|
||||
|
||||
private void ForgetPromosButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ForgetPromosClickedEvent, this));
|
||||
|
||||
private void ClaimPromoButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ClaimPromoClickedEvent, this));
|
||||
|
||||
/// <summary>Invio nel campo vale come clic: si incolla e si preme invio.</summary>
|
||||
private void PromoCodeTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
|
||||
{
|
||||
if (e.Key != System.Windows.Input.Key.Enter) return;
|
||||
|
||||
e.Handled = true;
|
||||
RaiseEvent(new RoutedEventArgs(ClaimPromoClickedEvent, this));
|
||||
}
|
||||
|
||||
private void OpenConfigButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenConfigClickedEvent, this));
|
||||
|
||||
private void ClearLogButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_activity.Clear();
|
||||
ActivityEmptyText.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
// ── Routed events ────────────────────────────────────────────────
|
||||
|
||||
public static readonly RoutedEvent RefreshBalanceClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"RefreshBalanceClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent CheckNowClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"CheckNowClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent OpenExternalClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenExternalClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent OpenInternalClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenInternalClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent OpenVouchersClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenVouchersClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent OpenBuyBidsClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenBuyBidsClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent ResetCountersClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ResetCountersClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent OptionsChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OptionsChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent ClaimPromoClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ClaimPromoClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent HarvestClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"HarvestClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent OpenPromoSourceClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenPromoSourceClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent ForgetPromosClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ForgetPromosClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public static readonly RoutedEvent OpenConfigClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenConfigClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FreeBidsControl));
|
||||
|
||||
public event RoutedEventHandler RefreshBalanceClicked
|
||||
{
|
||||
add { AddHandler(RefreshBalanceClickedEvent, value); }
|
||||
remove { RemoveHandler(RefreshBalanceClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler CheckNowClicked
|
||||
{
|
||||
add { AddHandler(CheckNowClickedEvent, value); }
|
||||
remove { RemoveHandler(CheckNowClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenExternalClicked
|
||||
{
|
||||
add { AddHandler(OpenExternalClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenExternalClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenInternalClicked
|
||||
{
|
||||
add { AddHandler(OpenInternalClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenInternalClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenVouchersClicked
|
||||
{
|
||||
add { AddHandler(OpenVouchersClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenVouchersClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenBuyBidsClicked
|
||||
{
|
||||
add { AddHandler(OpenBuyBidsClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenBuyBidsClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ResetCountersClicked
|
||||
{
|
||||
add { AddHandler(ResetCountersClickedEvent, value); }
|
||||
remove { RemoveHandler(ResetCountersClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OptionsChanged
|
||||
{
|
||||
add { AddHandler(OptionsChangedEvent, value); }
|
||||
remove { RemoveHandler(OptionsChangedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ClaimPromoClicked
|
||||
{
|
||||
add { AddHandler(ClaimPromoClickedEvent, value); }
|
||||
remove { RemoveHandler(ClaimPromoClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler HarvestClicked
|
||||
{
|
||||
add { AddHandler(HarvestClickedEvent, value); }
|
||||
remove { RemoveHandler(HarvestClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenPromoSourceClicked
|
||||
{
|
||||
add { AddHandler(OpenPromoSourceClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenPromoSourceClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ForgetPromosClicked
|
||||
{
|
||||
add { AddHandler(ForgetPromosClickedEvent, value); }
|
||||
remove { RemoveHandler(ForgetPromosClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenConfigClicked
|
||||
{
|
||||
add { AddHandler(OpenConfigClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenConfigClickedEvent, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<UserControl x:Class="AutoBidder.Controls.HelpHeader"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
x:Name="Root"
|
||||
HorizontalAlignment="Left">
|
||||
|
||||
<!-- Titolo di sezione con la spiegazione a portata di puntatore.
|
||||
|
||||
Le descrizioni stavano stampate sotto ogni titolo: si leggono una volta e poi
|
||||
restano lì a occupare metà pagina per sempre. Qui il testo c'è ancora — non è
|
||||
stato buttato — ma si mostra passandoci sopra, come per tutti gli altri comandi
|
||||
dell'applicazione. Il pallino accanto al titolo serve a far sapere che c'è. -->
|
||||
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Background="Transparent"
|
||||
Margin="{Binding Margin, ElementName=Root}"
|
||||
ToolTipService.InitialShowDelay="250"
|
||||
ToolTipService.ShowDuration="60000">
|
||||
<StackPanel.ToolTip>
|
||||
<ToolTip Visibility="{Binding HelpVisibility, ElementName=Root}">
|
||||
<TextBlock Text="{Binding Help, ElementName=Root}"
|
||||
TextWrapping="Wrap"
|
||||
MaxWidth="420"/>
|
||||
</ToolTip>
|
||||
</StackPanel.ToolTip>
|
||||
|
||||
<TextBlock Text="{Binding Title, ElementName=Root}"
|
||||
Style="{StaticResource BlockTitle}"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
<TextBlock Text=""
|
||||
FontFamily="Segoe MDL2 Assets"
|
||||
FontSize="12"
|
||||
Margin="6,2,0,0"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.TextFaint}"
|
||||
Visibility="{Binding HelpVisibility, ElementName=Root}"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace AutoBidder.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Titolo di sezione con la spiegazione nel suggerimento invece che stampata sotto.
|
||||
///
|
||||
/// <para>Serve a togliere dalla pagina i paragrafi descrittivi senza perderne il
|
||||
/// contenuto: si leggono una volta e poi restano a occupare spazio a ogni apertura
|
||||
/// delle Impostazioni. Passando il puntatore il testo torna, esattamente come per i
|
||||
/// pulsanti del resto dell'applicazione.</para>
|
||||
///
|
||||
/// <para>Uso: <c><ctl:HelpHeader Title="Motore di Precisione" Help="…"/></c>.
|
||||
/// Senza <see cref="Help"/> si comporta come un titolo semplice, senza pallino.</para>
|
||||
/// </summary>
|
||||
public partial class HelpHeader : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty TitleProperty =
|
||||
DependencyProperty.Register(nameof(Title), typeof(string), typeof(HelpHeader),
|
||||
new PropertyMetadata(""));
|
||||
|
||||
public static readonly DependencyProperty HelpProperty =
|
||||
DependencyProperty.Register(nameof(Help), typeof(string), typeof(HelpHeader),
|
||||
new PropertyMetadata("", OnHelpChanged));
|
||||
|
||||
private static readonly DependencyPropertyKey HelpVisibilityKey =
|
||||
DependencyProperty.RegisterReadOnly(nameof(HelpVisibility), typeof(Visibility), typeof(HelpHeader),
|
||||
new PropertyMetadata(Visibility.Collapsed));
|
||||
|
||||
public static readonly DependencyProperty HelpVisibilityProperty = HelpVisibilityKey.DependencyProperty;
|
||||
|
||||
public HelpHeader() => InitializeComponent();
|
||||
|
||||
/// <summary>Il titolo della sezione.</summary>
|
||||
public string Title
|
||||
{
|
||||
get => (string)GetValue(TitleProperty);
|
||||
set => SetValue(TitleProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>La spiegazione, mostrata al passaggio del puntatore.</summary>
|
||||
public string Help
|
||||
{
|
||||
get => (string)GetValue(HelpProperty);
|
||||
set => SetValue(HelpProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>Il pallino compare solo quando c'è davvero qualcosa da leggere.</summary>
|
||||
public Visibility HelpVisibility => (Visibility)GetValue(HelpVisibilityProperty);
|
||||
|
||||
private static void OnHelpChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var visible = !string.IsNullOrWhiteSpace(e.NewValue as string);
|
||||
d.SetValue(HelpVisibilityKey, visible ? Visibility.Visible : Visibility.Collapsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
<UserControl x:Class="AutoBidder.Controls.ProductsControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:vm="clr-namespace:AutoBidder.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="800" d:DesignWidth="1200"
|
||||
Background="{DynamicResource Brush.Bg}">
|
||||
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="Glyph" TargetType="TextBlock">
|
||||
<Setter Property="FontFamily" Value="Segoe MDL2 Assets"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
</Style>
|
||||
|
||||
<!-- ═══ Modificabile o no: deve vedersi a colpo d'occhio ═══
|
||||
Le celle che si possono scrivere hanno il riquadro di una casella di testo;
|
||||
le statistiche restano testo semplice e smorzato. Senza questa differenza la
|
||||
griglia sembra tutta uguale e non si capisce dove si può intervenire. -->
|
||||
<Style x:Key="EditableCell" TargetType="DataGridCell">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}"/>
|
||||
<Setter Property="VerticalAlignment" Value="Stretch"/>
|
||||
<Setter Property="Cursor" Value="IBeam"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="DataGridCell">
|
||||
<Border x:Name="box"
|
||||
Background="{DynamicResource Brush.Bg}"
|
||||
BorderBrush="{DynamicResource Brush.Border}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="5"
|
||||
Margin="3,3"
|
||||
Padding="6,0">
|
||||
<ContentPresenter VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="box" Property="BorderBrush"
|
||||
Value="{DynamicResource Brush.BorderStrong}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEditing" Value="True">
|
||||
<Setter TargetName="box" Property="BorderBrush"
|
||||
Value="{DynamicResource Brush.Accent}"/>
|
||||
<Setter TargetName="box" Property="Background"
|
||||
Value="{DynamicResource Brush.Surface}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- Il pennino segnala nell'intestazione le colonne che accettano scrittura -->
|
||||
<DataTemplate x:Key="EditableHeader">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding}" VerticalAlignment="Center"/>
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" Text="" FontSize="9"
|
||||
Margin="5,0,0,0" VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.Accent}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
|
||||
<!-- Numeri modificabili: allineati a destra, colore pieno -->
|
||||
<Style x:Key="EditableText" TargetType="TextBlock">
|
||||
<Setter Property="HorizontalAlignment" Value="Right"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}"/>
|
||||
</Style>
|
||||
|
||||
<!-- Statistiche: sola lettura, quindi smorzate -->
|
||||
<Style x:Key="StatText" TargetType="TextBlock">
|
||||
<Setter Property="HorizontalAlignment" Value="Right"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextMuted}"/>
|
||||
</Style>
|
||||
|
||||
<!-- Statistiche estese: il numero da solo non basta, il dettaglio (quartili,
|
||||
campione verificato, frequenza) sta nel suggerimento. -->
|
||||
<Style x:Key="StatsText" TargetType="TextBlock" BasedOn="{StaticResource StatText}">
|
||||
<Setter Property="ToolTip" Value="{Binding StatsExplanation}"/>
|
||||
</Style>
|
||||
|
||||
<!-- Valore, costo reale e risparmio: il ragionamento sta nel suggerimento.
|
||||
In rosso quando vincere costa piu' che comprare: e' il caso che va visto
|
||||
subito, non nascosto in mezzo agli altri numeri. -->
|
||||
<Style x:Key="ValueText" TargetType="TextBlock" BasedOn="{StaticResource StatText}">
|
||||
<Setter Property="ToolTip" Value="{Binding ValueExplanation}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding HasSavings}" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Success}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding SavingsIsNegative}" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Danger}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<!-- Limiti consigliati: il numero da solo non basta, il ragionamento sta nel
|
||||
suggerimento. In arancione quando il tetto non copre il prezzo tipico:
|
||||
è il caso in cui l'articolo, con quelle puntate, non conviene. -->
|
||||
<Style x:Key="AdviceText" TargetType="TextBlock" BasedOn="{StaticResource StatText}">
|
||||
<Setter Property="ToolTip" Value="{Binding AdviceExplanation}"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Info}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding HasAdvice}" Value="False">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextFaint}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding AdviceWarns}" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Warning}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- ═══ Barra strumenti ═══ -->
|
||||
<Border Grid.Row="0" Background="{DynamicResource Brush.Surface}" Padding="10,7"
|
||||
BorderBrush="{DynamicResource Brush.Border}" BorderThickness="0,0,0,1">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Button x:Name="RefreshButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Ricarica elenco e statistiche" Click="RefreshButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
<TextBlock Text="Prodotti" FontWeight="SemiBold" Margin="8,0,0,0"
|
||||
FontSize="{StaticResource Font.Size.Lg}"
|
||||
Foreground="{DynamicResource Brush.Text}" VerticalAlignment="Center"/>
|
||||
<Border Width="1" Background="{DynamicResource Brush.Border}" Margin="10,4"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Border Style="{StaticResource Pill}" ToolTip="Prodotti in elenco">
|
||||
<TextBlock x:Name="ProductsCountText" Text="0 prodotti"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
</Border>
|
||||
<Border Style="{StaticResource Pill}" ToolTip="Prodotti con la stellina accesa">
|
||||
<TextBlock x:Name="ProductsWatchedText" Text="0 seguiti"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.Gold}"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Ricerca + legenda "dove posso scrivere?" -->
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center"
|
||||
Margin="14,0,10,0">
|
||||
<Border Background="{DynamicResource Brush.Bg}"
|
||||
BorderBrush="{DynamicResource Brush.Border}" BorderThickness="1"
|
||||
CornerRadius="6" Padding="8,0" Margin="0,0,12,0"
|
||||
VerticalAlignment="Center">
|
||||
<Grid Width="230">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text="" FontSize="12"
|
||||
Foreground="{DynamicResource Brush.TextFaint}" Margin="0,0,6,0"/>
|
||||
<TextBox x:Name="SearchBox" Width="196" BorderThickness="0"
|
||||
Background="Transparent" VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
TextChanged="SearchBox_TextChanged"
|
||||
ToolTip="Filtra i prodotti per nome mentre scrivi"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Testo guida: sparisce appena si scrive qualcosa -->
|
||||
<TextBlock x:Name="SearchPlaceholder" Text="Cerca un prodotto…"
|
||||
IsHitTestVisible="False" Margin="20,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextFaint}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border Background="{DynamicResource Brush.Bg}"
|
||||
BorderBrush="{DynamicResource Brush.Border}" BorderThickness="1"
|
||||
CornerRadius="4" Width="18" Height="14" VerticalAlignment="Center"/>
|
||||
<TextBlock Text="= modificabile"
|
||||
Margin="6,0,0,0" VerticalAlignment="Center"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextFaint}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Button x:Name="ScanNowButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Content="Cerca aste ora" Margin="0,0,8,0"
|
||||
ToolTip="Cerca subito aste nuove dei prodotti seguiti, senza aspettare il prossimo giro"
|
||||
Click="ScanNowButton_Click"/>
|
||||
|
||||
<Button x:Name="ApplySuggestedButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Content="Usa consigliati" Margin="0,0,8,0"
|
||||
ToolTip="Scrive prezzo minimo e massimo consigliati nel prodotto selezionato. Il consiglio nasce da come è andata finora: il massimo copre l'85% delle chiusure passate (regolabile in Impostazioni), abbassato se il budget non lo regge — valore del prodotto meno il costo delle puntate massime. Il minimo è il decimo percentile: sotto quel prezzo l'asta non si chiude quasi mai."
|
||||
Click="ApplySuggestedButton_Click"/>
|
||||
|
||||
<Button x:Name="ApplyAllSuggestedButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
Content="Usa consigliati su tutti" Margin="0,0,8,0"
|
||||
ToolTip="Scrive i limiti consigliati su tutti i prodotti che hanno abbastanza aste concluse. Chiede conferma e dice quante righe cambierebbe."
|
||||
Click="ApplyAllSuggestedButton_Click"/>
|
||||
|
||||
<Button x:Name="ReapplyButton" Style="{StaticResource SmallRoundedButton}"
|
||||
Background="{DynamicResource Brush.Accent}"
|
||||
Foreground="{DynamicResource Brush.TextOnAccent}"
|
||||
Content="Riapplica" Margin="0,0,8,0"
|
||||
ToolTip="Riscrive i limiti del prodotto selezionato sulle aste già presenti nel monitor"
|
||||
Click="ReapplyButton_Click"/>
|
||||
|
||||
<Button x:Name="RemoveButton" Style="{StaticResource IconButton}"
|
||||
ToolTip="Togli dall'elenco il prodotto selezionato"
|
||||
Click="RemoveButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
<Button x:Name="ClearButton" Style="{StaticResource IconButton}"
|
||||
Foreground="{DynamicResource Brush.Danger}"
|
||||
ToolTip="Svuota l'elenco dei prodotti"
|
||||
Click="ClearButton_Click">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text=""/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- ═══ Elenco prodotti: impostazioni e statistiche sulla stessa riga ═══ -->
|
||||
<Grid Grid.Row="1" Margin="12">
|
||||
<Border Background="{DynamicResource Brush.Surface}"
|
||||
BorderBrush="{DynamicResource Brush.Border}" BorderThickness="1" CornerRadius="12">
|
||||
<DataGrid x:Name="ProductsGrid" AutoGenerateColumns="False"
|
||||
Background="Transparent" Margin="4"
|
||||
CanUserAddRows="False" CanUserDeleteRows="False"
|
||||
SelectionMode="Single" HeadersVisibility="Column"
|
||||
RowHeight="32"
|
||||
HorizontalScrollBarVisibility="Auto"
|
||||
CellEditEnding="ProductsGrid_CellEditEnding"
|
||||
SelectionChanged="ProductsGrid_SelectionChanged">
|
||||
<DataGrid.Columns>
|
||||
<!-- Stellina: acceso = le aste nuove entrano da sole -->
|
||||
<DataGridTemplateColumn Header="" Width="Auto" MinWidth="38" IsReadOnly="True"
|
||||
CanUserSort="False">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Style="{StaticResource MiniIconButton}"
|
||||
ToolTip="{Binding WatchTooltip}"
|
||||
Command="{Binding DataContext.ProductWatchCommand,
|
||||
RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" Text="{Binding WatchGlyph}">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextFaint}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsWatched}" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Gold}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<!-- Auto, non *: con venti colonne accanto lo spazio residuo non basta mai
|
||||
e i nomi lunghi restano tagliati. Cosi' la colonna prende la
|
||||
larghezza del nome piu' lungo e la griglia scorre in orizzontale. -->
|
||||
<DataGridTextColumn Header="Prodotto" Binding="{Binding DisplayName}"
|
||||
Width="Auto" MinWidth="220" IsReadOnly="True"/>
|
||||
|
||||
<!-- ── Limiti propri del prodotto: modificabili ── -->
|
||||
<DataGridTextColumn Header="Min €" Binding="{Binding MinPriceText}"
|
||||
Width="Auto" MinWidth="74"
|
||||
CellStyle="{StaticResource EditableCell}"
|
||||
HeaderTemplate="{StaticResource EditableHeader}"
|
||||
ElementStyle="{StaticResource EditableText}"/>
|
||||
<DataGridTextColumn Header="Max €" Binding="{Binding MaxPriceText}"
|
||||
Width="Auto" MinWidth="74"
|
||||
CellStyle="{StaticResource EditableCell}"
|
||||
HeaderTemplate="{StaticResource EditableHeader}"
|
||||
ElementStyle="{StaticResource EditableText}"/>
|
||||
<DataGridTextColumn Header="Puntate" Binding="{Binding MaxClicksText}"
|
||||
Width="Auto" MinWidth="78"
|
||||
CellStyle="{StaticResource EditableCell}"
|
||||
HeaderTemplate="{StaticResource EditableHeader}"
|
||||
ElementStyle="{StaticResource EditableText}"/>
|
||||
<DataGridTextColumn Header="Entro min" Binding="{Binding MaxStartMinutesText}"
|
||||
Width="Auto" MinWidth="86"
|
||||
CellStyle="{StaticResource EditableCell}"
|
||||
HeaderTemplate="{StaticResource EditableHeader}"
|
||||
ElementStyle="{StaticResource EditableText}"/>
|
||||
|
||||
<!-- Le colonne non stanno nell'albero visuale: un Binding qui non
|
||||
erediterebbe alcun DataContext, quindi il valore è statico. -->
|
||||
<DataGridComboBoxColumn Header="Stato" Width="Auto" MinWidth="112"
|
||||
CellStyle="{StaticResource EditableCell}"
|
||||
HeaderTemplate="{StaticResource EditableHeader}"
|
||||
SelectedItemBinding="{Binding StateChoice}"
|
||||
ItemsSource="{x:Static vm:ProductViewModel.StateChoices}"/>
|
||||
|
||||
<!-- ── Statistiche dello storico: sola lettura ── -->
|
||||
<DataGridTextColumn Header="Aste" Binding="{Binding StatCountDisplay}"
|
||||
Width="Auto" MinWidth="52" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatText}"/>
|
||||
<DataGridTextColumn Header="Vinte" Binding="{Binding StatWonCount}"
|
||||
Width="Auto" MinWidth="56" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatText}"/>
|
||||
<DataGridTextColumn Header="%" Binding="{Binding StatWinRateDisplay}"
|
||||
Width="Auto" MinWidth="52" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatText}"/>
|
||||
<DataGridTextColumn Header="Media" Binding="{Binding StatAverageDisplay}"
|
||||
Width="Auto" MinWidth="78" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatText}"/>
|
||||
<DataGridTextColumn Header="Min" Binding="{Binding StatMinDisplay}"
|
||||
Width="Auto" MinWidth="72" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatText}"/>
|
||||
<DataGridTextColumn Header="Max" Binding="{Binding StatMaxDisplay}"
|
||||
Width="Auto" MinWidth="72" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatText}"/>
|
||||
|
||||
<!-- ── Quanto vale, quanto costa vincerlo davvero ── -->
|
||||
<DataGridTextColumn Header="Valore" Binding="{Binding StatValueDisplay}"
|
||||
Width="Auto" MinWidth="80" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource ValueText}"/>
|
||||
<DataGridTextColumn Header="Punt. vinc." Binding="{Binding StatWinnerBidsDisplay}"
|
||||
Width="Auto" MinWidth="88" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource ValueText}"/>
|
||||
<DataGridTextColumn Header="Costo reale" Binding="{Binding StatWinCostDisplay}"
|
||||
Width="Auto" MinWidth="90" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource ValueText}"/>
|
||||
<DataGridTextColumn Header="Risparmio" Binding="{Binding StatSavingsDisplay}"
|
||||
Width="Auto" MinWidth="84" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource ValueText}"/>
|
||||
|
||||
<!-- ── La forbice, non solo il valore tipico ──
|
||||
Su un articolo dove si vince con 12 puntate o con 900, la sola
|
||||
mediana porta a impostare limiti che non reggono. -->
|
||||
<DataGridTextColumn Header="Punt. min" Binding="{Binding StatMinWinnerBidsDisplay}"
|
||||
Width="Auto" MinWidth="78" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatsText}"/>
|
||||
<DataGridTextColumn Header="Punt. 75°" Binding="{Binding StatP75WinnerBidsDisplay}"
|
||||
Width="Auto" MinWidth="78" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatsText}"/>
|
||||
<DataGridTextColumn Header="Punt. max" Binding="{Binding StatMaxWinnerBidsDisplay}"
|
||||
Width="Auto" MinWidth="80" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatsText}"/>
|
||||
<DataGridTextColumn Header="Risp. min" Binding="{Binding StatMinSavingsDisplay}"
|
||||
Width="Auto" MinWidth="80" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatsText}"/>
|
||||
<DataGridTextColumn Header="Risp. max" Binding="{Binding StatMaxSavingsDisplay}"
|
||||
Width="Auto" MinWidth="80" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatsText}"/>
|
||||
<DataGridTextColumn Header="In utile" Binding="{Binding StatProfitableShareDisplay}"
|
||||
Width="Auto" MinWidth="72" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatsText}"/>
|
||||
<DataGridTextColumn Header="Ogni" Binding="{Binding StatFrequencyDisplay}"
|
||||
Width="Auto" MinWidth="70" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatsText}"/>
|
||||
<DataGridTextColumn Header="Verificate" Binding="{Binding StatWinnerBidsSampleDisplay}"
|
||||
Width="Auto" MinWidth="82" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatsText}"/>
|
||||
<!-- ── Limiti consigliati: sola lettura, più il bottone che li applica ── -->
|
||||
<DataGridTextColumn Header="Min cons." Binding="{Binding SuggestedMinDisplay}"
|
||||
Width="Auto" MinWidth="84" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource AdviceText}"/>
|
||||
<DataGridTextColumn Header="Max cons." Binding="{Binding SuggestedMaxDisplay}"
|
||||
Width="Auto" MinWidth="84" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource AdviceText}"/>
|
||||
<DataGridTextColumn Header="Punt. cons." Binding="{Binding SuggestedMaxBidsDisplay}"
|
||||
Width="Auto" MinWidth="88" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource AdviceText}"/>
|
||||
|
||||
<DataGridTemplateColumn Header="" Width="Auto" MinWidth="40" IsReadOnly="True" CanUserSort="False">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<!-- Applica i consigliati a questa riga soltanto. Il segno di
|
||||
spunta si accende quando i limiti scritti sono già quelli
|
||||
consigliati: serve a vedere a colpo d'occhio quali righe
|
||||
resta da sistemare. -->
|
||||
<Button Style="{StaticResource MiniIconButton}"
|
||||
ToolTip="{Binding AdviceExplanation}"
|
||||
Command="{Binding DataContext.ProductApplyAdviceCommand,
|
||||
RelativeSource={RelativeSource AncestorType=UserControl}}"
|
||||
CommandParameter="{Binding}">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" Text="">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextFaint}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding HasAdvice}" Value="False">
|
||||
<Setter Property="Opacity" Value="0.25"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding MatchesAdvice}" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Success}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding AdviceWarns}" Value="True">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Warning}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</Button>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTextColumn Header="Punt./asta" Binding="{Binding StatAverageBidsDisplay}"
|
||||
Width="Auto" MinWidth="82" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatText}"/>
|
||||
<DataGridTextColumn Header="Aggiunte" Binding="{Binding AutoAddedCountDisplay}"
|
||||
Width="Auto" MinWidth="74" IsReadOnly="True"
|
||||
ElementStyle="{StaticResource StatText}"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Border>
|
||||
|
||||
<!-- Stato vuoto -->
|
||||
<StackPanel x:Name="ProductsEmptyState" VerticalAlignment="Center" HorizontalAlignment="Center"
|
||||
Visibility="Collapsed">
|
||||
<TextBlock Style="{StaticResource Glyph}" Text="" FontSize="34"
|
||||
Foreground="{DynamicResource Brush.TextFaint}"/>
|
||||
<TextBlock Text="Nessun prodotto in elenco."
|
||||
Margin="0,10,0,0" HorizontalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"/>
|
||||
<TextBlock Text="Aggiungili dalla scheda Cerca: la stellina lo segue, l'ingranaggio lo mette qui per dargli dei limiti."
|
||||
Margin="0,4,0,0" HorizontalAlignment="Center" TextWrapping="Wrap" MaxWidth="420"
|
||||
TextAlignment="Center"
|
||||
FontSize="{StaticResource Font.Size.Sm}"
|
||||
Foreground="{DynamicResource Brush.TextFaint}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,227 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using AutoBidder.ViewModels;
|
||||
|
||||
namespace AutoBidder.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Scheda Prodotti: una riga per articolo, con la stellina, i limiti su misura e le
|
||||
/// statistiche dello storico tutte sulla stessa riga.
|
||||
///
|
||||
/// <para>Il controllo non conosce né gli archivi né il monitor: espone eventi e lascia
|
||||
/// decidere a MainWindow, com'è per gli altri pannelli.</para>
|
||||
/// </summary>
|
||||
public partial class ProductsControl : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Elenco completo, indipendente da quello mostrato: la ricerca filtra la vista, non
|
||||
/// i dati. Senza, scrivere nella casella cancellerebbe le righe invece di nasconderle.
|
||||
/// </summary>
|
||||
private IList? _allProducts;
|
||||
|
||||
public ProductsControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>Prodotto selezionato, o <c>null</c> se la griglia è vuota o senza selezione.</summary>
|
||||
public ProductViewModel? SelectedProduct => ProductsGrid.SelectedItem as ProductViewModel;
|
||||
|
||||
/// <summary>
|
||||
/// Riempie l'elenco. Le righe sono già ViewModel: la griglia scrive direttamente
|
||||
/// nelle schede prodotto, e la persistenza avviene alla conferma della cella.
|
||||
/// </summary>
|
||||
public void SetProducts(IList products)
|
||||
{
|
||||
_allProducts = products;
|
||||
ApplySearch();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mostra solo i prodotti il cui nome contiene il testo cercato.
|
||||
///
|
||||
/// <para>Il filtro si applica a una copia: la griglia è modificabile, e gli oggetti
|
||||
/// mostrati sono gli stessi dell'elenco completo — quindi i limiti scritti mentre
|
||||
/// un filtro è attivo restano quando il filtro sparisce.</para>
|
||||
/// </summary>
|
||||
private void ApplySearch()
|
||||
{
|
||||
if (_allProducts == null) return;
|
||||
|
||||
var query = SearchBox.Text?.Trim() ?? "";
|
||||
SearchPlaceholder.Visibility = query.Length == 0 ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
var all = _allProducts.OfType<ProductViewModel>().ToList();
|
||||
|
||||
var shown = query.Length == 0
|
||||
? all
|
||||
: all.Where(p => (p.DisplayName ?? "")
|
||||
.Contains(query, System.StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
|
||||
ProductsGrid.ItemsSource = shown;
|
||||
|
||||
ProductsCountText.Text = query.Length == 0
|
||||
? (all.Count == 1 ? "1 prodotto" : $"{all.Count} prodotti")
|
||||
: $"{shown.Count} di {all.Count}";
|
||||
|
||||
ProductsWatchedText.Text = $"{all.Count(p => p.IsWatched)} seguiti";
|
||||
|
||||
// Con la ricerca attiva e nessun risultato non si mostra il messaggio di elenco
|
||||
// vuoto: direbbe "non segui ancora nessun prodotto", che sarebbe falso.
|
||||
ProductsEmptyState.Visibility = all.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private void SearchBox_TextChanged(object sender, TextChangedEventArgs e) => ApplySearch();
|
||||
|
||||
/// <summary>Riallinea i contatori dopo che una stellina è cambiata.</summary>
|
||||
public void RefreshCounters()
|
||||
{
|
||||
// Si conta sull'elenco completo, non su quello mostrato: con una ricerca attiva
|
||||
// il numero dei seguiti non deve cambiare solo perché sono nascosti.
|
||||
var source = _allProducts ?? ProductsGrid.ItemsSource as IList;
|
||||
if (source == null) return;
|
||||
|
||||
ProductsWatchedText.Text = $"{source.OfType<ProductViewModel>().Count(p => p.IsWatched)} seguiti";
|
||||
}
|
||||
|
||||
/// <summary>Porta la selezione sul prodotto indicato (usato arrivando dalla scheda Cerca).</summary>
|
||||
public void SelectProduct(string identity)
|
||||
{
|
||||
if (ProductsGrid.ItemsSource is not IEnumerable items) return;
|
||||
|
||||
var match = items.OfType<ProductViewModel>()
|
||||
.FirstOrDefault(p => p.Identity == identity);
|
||||
if (match == null) return;
|
||||
|
||||
ProductsGrid.SelectedItem = match;
|
||||
ProductsGrid.ScrollIntoView(match);
|
||||
}
|
||||
|
||||
// ── Eventi dell'interfaccia ──────────────────────────────────────
|
||||
|
||||
private void ProductsGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ProductSelectionChangedEvent, this));
|
||||
|
||||
/// <summary>
|
||||
/// La cella è stata confermata: il valore è già nel ViewModel, resta da renderlo
|
||||
/// durevole. Si rimanda al termine dell'operazione perché durante l'evento la
|
||||
/// modifica non è ancora stata trasferita al modello.
|
||||
/// </summary>
|
||||
private void ProductsGrid_CellEditEnding(object? sender, DataGridCellEditEndingEventArgs e)
|
||||
{
|
||||
if (e.EditAction != DataGridEditAction.Commit) return;
|
||||
|
||||
Dispatcher.BeginInvoke(new System.Action(() =>
|
||||
RaiseEvent(new RoutedEventArgs(ProductLimitsEditedEvent, this))),
|
||||
System.Windows.Threading.DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
private void RefreshButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(RefreshClickedEvent, this));
|
||||
|
||||
private void ScanNowButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ScanNowClickedEvent, this));
|
||||
|
||||
private void ReapplyButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ReapplyClickedEvent, this));
|
||||
|
||||
private void RemoveButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(RemoveClickedEvent, this));
|
||||
|
||||
private void ClearButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ClearClickedEvent, this));
|
||||
|
||||
private void ApplySuggestedButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ApplySuggestedClickedEvent, this));
|
||||
|
||||
private void ApplyAllSuggestedButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ApplyAllSuggestedClickedEvent, this));
|
||||
|
||||
// ── Routed events ────────────────────────────────────────────────
|
||||
|
||||
public static readonly RoutedEvent RefreshClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"RefreshClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ProductsControl));
|
||||
|
||||
public static readonly RoutedEvent ScanNowClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ScanNowClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ProductsControl));
|
||||
|
||||
public static readonly RoutedEvent ReapplyClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ReapplyClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ProductsControl));
|
||||
|
||||
public static readonly RoutedEvent RemoveClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"RemoveClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ProductsControl));
|
||||
|
||||
public static readonly RoutedEvent ClearClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ClearClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ProductsControl));
|
||||
|
||||
public static readonly RoutedEvent ApplySuggestedClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ApplySuggestedClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ProductsControl));
|
||||
|
||||
public static readonly RoutedEvent ApplyAllSuggestedClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ApplyAllSuggestedClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ProductsControl));
|
||||
|
||||
public static readonly RoutedEvent ProductLimitsEditedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ProductLimitsEdited", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ProductsControl));
|
||||
|
||||
public static readonly RoutedEvent ProductSelectionChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ProductSelectionChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ProductsControl));
|
||||
|
||||
public event RoutedEventHandler RefreshClicked
|
||||
{
|
||||
add { AddHandler(RefreshClickedEvent, value); }
|
||||
remove { RemoveHandler(RefreshClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ScanNowClicked
|
||||
{
|
||||
add { AddHandler(ScanNowClickedEvent, value); }
|
||||
remove { RemoveHandler(ScanNowClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ReapplyClicked
|
||||
{
|
||||
add { AddHandler(ReapplyClickedEvent, value); }
|
||||
remove { RemoveHandler(ReapplyClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler RemoveClicked
|
||||
{
|
||||
add { AddHandler(RemoveClickedEvent, value); }
|
||||
remove { RemoveHandler(RemoveClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ClearClicked
|
||||
{
|
||||
add { AddHandler(ClearClickedEvent, value); }
|
||||
remove { RemoveHandler(ClearClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ApplySuggestedClicked
|
||||
{
|
||||
add { AddHandler(ApplySuggestedClickedEvent, value); }
|
||||
remove { RemoveHandler(ApplySuggestedClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ApplyAllSuggestedClicked
|
||||
{
|
||||
add { AddHandler(ApplyAllSuggestedClickedEvent, value); }
|
||||
remove { RemoveHandler(ApplyAllSuggestedClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ProductLimitsEdited
|
||||
{
|
||||
add { AddHandler(ProductLimitsEditedEvent, value); }
|
||||
remove { RemoveHandler(ProductLimitsEditedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ProductSelectionChanged
|
||||
{
|
||||
add { AddHandler(ProductSelectionChangedEvent, value); }
|
||||
remove { RemoveHandler(ProductSelectionChangedEvent, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
@@ -8,47 +9,250 @@ namespace AutoBidder.Controls
|
||||
/// </summary>
|
||||
public partial class SettingsControl : UserControl
|
||||
{
|
||||
/// <summary>Evita che i Checked scattino mentre si sincronizza la UI.</summary>
|
||||
private bool _suppressThemeEvents;
|
||||
|
||||
public SettingsControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += (_, _) => SyncThemeSelection();
|
||||
}
|
||||
|
||||
// Proprietà pubbliche per accesso da MainWindow (AGGIORNATE)
|
||||
public TextBox DefaultBidBeforeDeadlineMsTextBox => DefaultBidBeforeDeadlineMs;
|
||||
public CheckBox DefaultCheckAuctionOpenCheckBox => DefaultCheckAuctionOpen;
|
||||
public TextBox DefaultMinPriceTextBox => DefaultMinPrice;
|
||||
public TextBox DefaultMaxPriceTextBox => DefaultMaxPrice;
|
||||
public TextBox DefaultMaxClicksTextBox => DefaultMaxClicks;
|
||||
|
||||
// Event handlers singoli (per backward compatibility)
|
||||
private void SaveCookieButton_Click(object sender, RoutedEventArgs e)
|
||||
/// <summary>
|
||||
/// Allinea i radio button al tema attualmente applicato.
|
||||
/// </summary>
|
||||
public void SyncThemeSelection()
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(SaveCookieClickedEvent, this));
|
||||
_suppressThemeEvents = true;
|
||||
try
|
||||
{
|
||||
bool dark = Utilities.ThemeManager.IsDark;
|
||||
ThemeDarkRadio.IsChecked = dark;
|
||||
ThemeLightRadio.IsChecked = !dark;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_suppressThemeEvents = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ImportCookieFromBrowserButton_Click(object sender, RoutedEventArgs e)
|
||||
private void ThemeDarkRadio_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(ImportCookieClickedEvent, this));
|
||||
if (_suppressThemeEvents) return;
|
||||
Utilities.ThemeManager.SetAndSave(true);
|
||||
}
|
||||
|
||||
private void CancelCookieButton_Click(object sender, RoutedEventArgs e)
|
||||
private void ThemeLightRadio_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(CancelCookieClickedEvent, this));
|
||||
if (_suppressThemeEvents) return;
|
||||
Utilities.ThemeManager.SetAndSave(false);
|
||||
}
|
||||
|
||||
private void ExportBrowseButton_Click(object sender, RoutedEventArgs e)
|
||||
// Non servono propriet� wrapper - MainWindow.xaml.cs accede direttamente ai controlli tramite:
|
||||
// Settings.DefaultBidBeforeDeadlineMsTextBox (definito nel XAML con x:Name)
|
||||
// Settings.MaxLogLinesPerAuctionTextBox (definito nel XAML con x:Name)
|
||||
// etc.
|
||||
|
||||
// Propriet� per limiti log
|
||||
public TextBox MaxLogLinesPerAuction => MaxLogLinesPerAuctionTextBox;
|
||||
public TextBox MaxGlobalLogLines => MaxGlobalLogLinesTextBox;
|
||||
|
||||
// ?? NUOVO: Propriet� per limite storia puntate
|
||||
public TextBox MaxBidHistoryEntries => MaxBidHistoryEntriesTextBox;
|
||||
|
||||
// ===== ANTICIPO, CARTELLE, ESPORTAZIONE =====
|
||||
|
||||
private void ComputeBidLeadAdviceButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ComputeBidLeadAdviceClickedEvent, this));
|
||||
|
||||
private void ClearBidLeadStatsButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(ClearBidLeadStatsClickedEvent, this));
|
||||
|
||||
private void BrowseDataFolderButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(BrowseDataFolderClickedEvent, this));
|
||||
|
||||
private void BrowseStatsFolderButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(BrowseStatsFolderClickedEvent, this));
|
||||
|
||||
private void OpenDataFolderButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenDataFolderClickedEvent, this));
|
||||
|
||||
private void OpenStatsFolderSettingsButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenStatsFolderClickedEvent, this));
|
||||
|
||||
private void BrowseLogFolderButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(BrowseLogFolderClickedEvent, this));
|
||||
|
||||
private void OpenLogFolderButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RaiseEvent(new RoutedEventArgs(OpenLogFolderClickedEvent, this));
|
||||
|
||||
/// <summary>Riepilogo delle misure sull'anticipo, mostrato nel riquadro informativo.</summary>
|
||||
public void SetBidLeadSummary(string text) => BidLeadSummaryText.Text = text;
|
||||
|
||||
public static readonly RoutedEvent ComputeBidLeadAdviceClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ComputeBidLeadAdviceClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent ClearBidLeadStatsClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ClearBidLeadStatsClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent BrowseDataFolderClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"BrowseDataFolderClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent BrowseStatsFolderClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"BrowseStatsFolderClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent OpenDataFolderClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenDataFolderClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent OpenStatsFolderClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenStatsFolderClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent BrowseLogFolderClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"BrowseLogFolderClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent OpenLogFolderClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenLogFolderClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public event RoutedEventHandler ComputeBidLeadAdviceClicked
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(ExportBrowseClickedEvent, this));
|
||||
add { AddHandler(ComputeBidLeadAdviceClickedEvent, value); }
|
||||
remove { RemoveHandler(ComputeBidLeadAdviceClickedEvent, value); }
|
||||
}
|
||||
|
||||
private void SaveSettingsButton_Click(object sender, RoutedEventArgs e)
|
||||
public event RoutedEventHandler ClearBidLeadStatsClicked
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(SaveSettingsClickedEvent, this));
|
||||
add { AddHandler(ClearBidLeadStatsClickedEvent, value); }
|
||||
remove { RemoveHandler(ClearBidLeadStatsClickedEvent, value); }
|
||||
}
|
||||
|
||||
private void CancelSettingsButton_Click(object sender, RoutedEventArgs e)
|
||||
public event RoutedEventHandler BrowseDataFolderClicked
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(CancelSettingsClickedEvent, this));
|
||||
add { AddHandler(BrowseDataFolderClickedEvent, value); }
|
||||
remove { RemoveHandler(BrowseDataFolderClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler BrowseStatsFolderClicked
|
||||
{
|
||||
add { AddHandler(BrowseStatsFolderClickedEvent, value); }
|
||||
remove { RemoveHandler(BrowseStatsFolderClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenDataFolderClicked
|
||||
{
|
||||
add { AddHandler(OpenDataFolderClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenDataFolderClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenStatsFolderClicked
|
||||
{
|
||||
add { AddHandler(OpenStatsFolderClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenStatsFolderClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler BrowseLogFolderClicked
|
||||
{
|
||||
add { AddHandler(BrowseLogFolderClickedEvent, value); }
|
||||
remove { RemoveHandler(BrowseLogFolderClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenLogFolderClicked
|
||||
{
|
||||
add { AddHandler(OpenLogFolderClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenLogFolderClickedEvent, value); }
|
||||
}
|
||||
|
||||
// ===== AGGIUNTA AUTOMATICA =====
|
||||
//
|
||||
// L'elenco dei prodotti (stellina e limiti su misura) sta nella scheda Prodotti:
|
||||
// qui restano solo gli interruttori che valgono per tutti.
|
||||
|
||||
/// <summary>Stato con cui entrano le aste aggiunte automaticamente ("Watch"/"Stopped"/"Active").</summary>
|
||||
public string AutoAddState
|
||||
{
|
||||
get => (AutoAddStateCombo.SelectedItem as ComboBoxItem)?.Tag as string ?? "Watch";
|
||||
set
|
||||
{
|
||||
foreach (var item in AutoAddStateCombo.Items.OfType<ComboBoxItem>())
|
||||
{
|
||||
if ((item.Tag as string) == value)
|
||||
{
|
||||
AutoAddStateCombo.SelectedItem = item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AutoAddStateCombo.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== SESSIONE / AUTENTICAZIONE =====
|
||||
//
|
||||
// Non c'è più un campo per incollare il cookie a mano: l'accesso si fa dal browser
|
||||
// integrato e vale per tutta l'applicazione. Un secondo modo significava due
|
||||
// sessioni possibili e diverse — quella digitata e quella del browser — con la
|
||||
// domanda "quale sta usando adesso?" senza una risposta visibile.
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna il riquadro di stato della sessione.
|
||||
/// </summary>
|
||||
public void SetSessionStatus(bool connected, string? username = null,
|
||||
int remainingBids = 0, double shopCredit = 0)
|
||||
{
|
||||
if (connected && !string.IsNullOrEmpty(username))
|
||||
{
|
||||
SessionStatusText.Text = $"Connesso come {username}";
|
||||
SessionStatusText.SetResourceReference(ForegroundProperty, "Brush.Success");
|
||||
SessionStatusDetail.Text =
|
||||
$"Puntate residue: {remainingBids} • Credito Shop: EUR {shopCredit:F2}";
|
||||
}
|
||||
else
|
||||
{
|
||||
SessionStatusText.Text = "Non connesso";
|
||||
SessionStatusText.SetResourceReference(ForegroundProperty, "Brush.Danger");
|
||||
SessionStatusDetail.Text = "Nessuna sessione attiva.";
|
||||
}
|
||||
}
|
||||
|
||||
private void ConnectSessionButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(ConnectSessionClickedEvent, this));
|
||||
}
|
||||
|
||||
private void DisconnectSessionButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(DisconnectSessionClickedEvent, this));
|
||||
}
|
||||
|
||||
private void OpenBrowserLoginButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(OpenBrowserLoginClickedEvent, this));
|
||||
}
|
||||
|
||||
public static readonly RoutedEvent ConnectSessionClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ConnectSessionClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent DisconnectSessionClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"DisconnectSessionClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent OpenBrowserLoginClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"OpenBrowserLoginClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public event RoutedEventHandler ConnectSessionClicked
|
||||
{
|
||||
add { AddHandler(ConnectSessionClickedEvent, value); }
|
||||
remove { RemoveHandler(ConnectSessionClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler DisconnectSessionClicked
|
||||
{
|
||||
add { AddHandler(DisconnectSessionClickedEvent, value); }
|
||||
remove { RemoveHandler(DisconnectSessionClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler OpenBrowserLoginClicked
|
||||
{
|
||||
add { AddHandler(OpenBrowserLoginClickedEvent, value); }
|
||||
remove { RemoveHandler(OpenBrowserLoginClickedEvent, value); }
|
||||
}
|
||||
|
||||
private void SaveDefaultsButton_Click(object sender, RoutedEventArgs e)
|
||||
@@ -66,13 +270,7 @@ namespace AutoBidder.Controls
|
||||
{
|
||||
try
|
||||
{
|
||||
// 1. Salva cookie (se presente)
|
||||
RaiseEvent(new RoutedEventArgs(SaveCookieClickedEvent, this));
|
||||
|
||||
// 2. Salva impostazioni export
|
||||
RaiseEvent(new RoutedEventArgs(SaveSettingsClickedEvent, this));
|
||||
|
||||
// 3. Salva impostazioni predefinite aste
|
||||
// Salva impostazioni predefinite aste (export rimosso)
|
||||
RaiseEvent(new RoutedEventArgs(SaveDefaultsClickedEvent, this));
|
||||
|
||||
// UNICO MessageBox di conferma
|
||||
@@ -97,72 +295,16 @@ namespace AutoBidder.Controls
|
||||
private void CancelAllSettings_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Annulla tutte le modifiche
|
||||
RaiseEvent(new RoutedEventArgs(CancelCookieClickedEvent, this));
|
||||
RaiseEvent(new RoutedEventArgs(CancelSettingsClickedEvent, this));
|
||||
RaiseEvent(new RoutedEventArgs(CancelDefaultsClickedEvent, this));
|
||||
}
|
||||
|
||||
// Routed Events
|
||||
public static readonly RoutedEvent SaveCookieClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"SaveCookieClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent ImportCookieClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ImportCookieClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent CancelCookieClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"CancelCookieClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent ExportBrowseClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"ExportBrowseClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent SaveSettingsClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"SaveSettingsClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent CancelSettingsClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"CancelSettingsClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent SaveDefaultsClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"SaveDefaultsClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public static readonly RoutedEvent CancelDefaultsClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"CancelDefaultsClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SettingsControl));
|
||||
|
||||
public event RoutedEventHandler SaveCookieClicked
|
||||
{
|
||||
add { AddHandler(SaveCookieClickedEvent, value); }
|
||||
remove { RemoveHandler(SaveCookieClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ImportCookieClicked
|
||||
{
|
||||
add { AddHandler(ImportCookieClickedEvent, value); }
|
||||
remove { RemoveHandler(ImportCookieClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler CancelCookieClicked
|
||||
{
|
||||
add { AddHandler(CancelCookieClickedEvent, value); }
|
||||
remove { RemoveHandler(CancelCookieClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler ExportBrowseClicked
|
||||
{
|
||||
add { AddHandler(ExportBrowseClickedEvent, value); }
|
||||
remove { RemoveHandler(ExportBrowseClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler SaveSettingsClicked
|
||||
{
|
||||
add { AddHandler(SaveSettingsClickedEvent, value); }
|
||||
remove { RemoveHandler(SaveSettingsClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler CancelSettingsClicked
|
||||
{
|
||||
add { AddHandler(CancelSettingsClickedEvent, value); }
|
||||
remove { RemoveHandler(CancelSettingsClickedEvent, value); }
|
||||
}
|
||||
|
||||
public event RoutedEventHandler SaveDefaultsClicked
|
||||
{
|
||||
add { AddHandler(SaveDefaultsClickedEvent, value); }
|
||||
|
||||
@@ -25,4 +25,4 @@ namespace AutoBidder.Controls
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
<UserControl x:Class="AutoBidder.Controls.StatisticsControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="800" d:DesignWidth="1200"
|
||||
Background="#1E1E1E">
|
||||
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="RoundedButton" TargetType="Button">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
CornerRadius="8"
|
||||
Padding="{TemplateBinding Padding}">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
<Setter Property="FontWeight" Value="Bold"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Setter Property="Padding" Value="15,10"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Header -->
|
||||
<Border Grid.Row="0" Background="#2D2D30" Padding="15" BorderBrush="#3E3E42" BorderThickness="0,0,0,1">
|
||||
<Grid>
|
||||
<TextBlock Text="📊 Dati Statistici - Analisi Aste Chiuse"
|
||||
Foreground="#00D800"
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
<Button x:Name="LoadClosedAuctionsButton"
|
||||
Content="🔄 Carica Statistiche"
|
||||
HorizontalAlignment="Right"
|
||||
Background="#007ACC"
|
||||
Style="{StaticResource RoundedButton}"
|
||||
Click="LoadClosedAuctionsButton_Click"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- DataGrid Statistiche -->
|
||||
<DataGrid Grid.Row="1"
|
||||
x:Name="StatsDataGrid"
|
||||
AutoGenerateColumns="False"
|
||||
IsReadOnly="True"
|
||||
Background="#1E1E1E"
|
||||
Foreground="#CCCCCC"
|
||||
RowBackground="#1E1E1E"
|
||||
AlternatingRowBackground="#252526"
|
||||
GridLinesVisibility="Horizontal"
|
||||
HeadersVisibility="Column"
|
||||
BorderThickness="0"
|
||||
Margin="15">
|
||||
<DataGrid.ColumnHeaderStyle>
|
||||
<Style TargetType="DataGridColumnHeader">
|
||||
<Setter Property="Background" Value="#2D2D30"/>
|
||||
<Setter Property="Foreground" Value="#CCCCCC"/>
|
||||
<Setter Property="FontWeight" Value="Bold"/>
|
||||
<Setter Property="Padding" Value="10,8"/>
|
||||
<Setter Property="BorderThickness" Value="0,0,1,1"/>
|
||||
<Setter Property="BorderBrush" Value="#3E3E42"/>
|
||||
</Style>
|
||||
</DataGrid.ColumnHeaderStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Padding" Value="10,5"/>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="Foreground" Value="#CCCCCC"/>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Prodotto" Binding="{Binding ProductName}" Width="3*"/>
|
||||
<DataGridTextColumn Header="Prezzo Medio" Binding="{Binding AverageFinalPrice, StringFormat=€{0:F2}}" Width="120"/>
|
||||
<DataGridTextColumn Header="Click Medi" Binding="{Binding AverageBidsUsed, StringFormat={}{0:F0}}" Width="100"/>
|
||||
<DataGridTextColumn Header="Vincitore Frequente" Binding="{Binding Winner}" Width="150"/>
|
||||
<DataGridTextColumn Header="# Aste" Binding="{Binding Count}" Width="80"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<!-- Footer: Status -->
|
||||
<Border Grid.Row="2"
|
||||
Background="#252526"
|
||||
Padding="15"
|
||||
BorderBrush="#3E3E42"
|
||||
BorderThickness="0,1,0,0">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0">
|
||||
<TextBlock x:Name="StatsStatusText"
|
||||
Text="Pronto per caricare statistiche"
|
||||
FontSize="13"
|
||||
Foreground="#CCCCCC"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
<TextBlock x:Name="ExportProgressText"
|
||||
Text=""
|
||||
FontSize="11"
|
||||
Foreground="#999999"
|
||||
Margin="0,5,0,0"
|
||||
Visibility="Collapsed"/>
|
||||
</StackPanel>
|
||||
|
||||
<ProgressBar Grid.Column="1"
|
||||
x:Name="ExportProgressBar"
|
||||
Width="200"
|
||||
Height="20"
|
||||
IsIndeterminate="True"
|
||||
Foreground="#007ACC"
|
||||
Background="#1E1E1E"
|
||||
BorderBrush="#3E3E42"
|
||||
Visibility="Collapsed"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,31 +0,0 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace AutoBidder.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for StatisticsControl.xaml
|
||||
/// </summary>
|
||||
public partial class StatisticsControl : UserControl
|
||||
{
|
||||
public StatisticsControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void LoadClosedAuctionsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(LoadClosedAuctionsClickedEvent, this));
|
||||
}
|
||||
|
||||
// Routed Events
|
||||
public static readonly RoutedEvent LoadClosedAuctionsClickedEvent = EventManager.RegisterRoutedEvent(
|
||||
"LoadClosedAuctionsClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(StatisticsControl));
|
||||
|
||||
public event RoutedEventHandler LoadClosedAuctionsClicked
|
||||
{
|
||||
add { AddHandler(LoadClosedAuctionsClickedEvent, value); }
|
||||
remove { RemoveHandler(LoadClosedAuctionsClickedEvent, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,351 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Xml.Linq;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Export functionality event handlers
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private CancellationTokenSource? _exportCts;
|
||||
|
||||
private void LoadExportSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var s = SettingsManager.Load();
|
||||
if (s != null)
|
||||
{
|
||||
ExportPathTextBox.Text = s.ExportPath ?? string.Empty;
|
||||
if (!string.IsNullOrEmpty(s.LastExportExt))
|
||||
{
|
||||
var ext = s.LastExportExt.ToLowerInvariant();
|
||||
if (ext == ".json") ExtJson.IsChecked = true;
|
||||
else if (ext == ".xml") ExtXml.IsChecked = true;
|
||||
else ExtCsv.IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtCsv.IsChecked = true;
|
||||
}
|
||||
|
||||
try { var cbOpen = this.FindName("ExportOpenToolbar") as System.Windows.Controls.CheckBox; if (cbOpen != null) cbOpen.IsChecked = s.ExportOpen; } catch { }
|
||||
try { var cbClosed = this.FindName("ExportClosedToolbar") as System.Windows.Controls.CheckBox; if (cbClosed != null) cbClosed.IsChecked = s.ExportClosed; } catch { }
|
||||
try { var cbUnknown = this.FindName("ExportUnknownToolbar") as System.Windows.Controls.CheckBox; if (cbUnknown != null) cbUnknown.IsChecked = s.ExportUnknown; } catch { }
|
||||
|
||||
try { IncludeUsedBids.IsChecked = s.IncludeOnlyUsedBids; } catch { }
|
||||
try { IncludeLogs.IsChecked = s.IncludeLogs; } catch { }
|
||||
try { IncludeUserBids.IsChecked = s.IncludeUserBids; } catch { }
|
||||
try { IncludeMetadata.IsChecked = s.IncludeMetadata; } catch { }
|
||||
try { RemoveAfterExport.IsChecked = s.RemoveAfterExport; } catch { }
|
||||
try { OverwriteExisting.IsChecked = s.OverwriteExisting; } catch { }
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private async void ExportAllButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = SettingsManager.Load();
|
||||
string ext = ExtJson.IsChecked == true ? ".json" : ExtXml.IsChecked == true ? ".xml" : ".csv";
|
||||
var dlg = new Microsoft.Win32.SaveFileDialog() { FileName = "auctions_export" + ext, Filter = "CSV files|*.csv|JSON files|*.json|XML files|*.xml|All files|*.*" };
|
||||
if (dlg.ShowDialog(this) != true) return;
|
||||
var path = dlg.FileName;
|
||||
|
||||
var all = _auctionMonitor.GetAuctions();
|
||||
var includeOpen = (this.FindName("ExportOpenToolbar") as System.Windows.Controls.CheckBox)?.IsChecked == true;
|
||||
var includeClosed = (this.FindName("ExportClosedToolbar") as System.Windows.Controls.CheckBox)?.IsChecked == true;
|
||||
var includeUnknown = (this.FindName("ExportUnknownToolbar") as System.Windows.Controls.CheckBox)?.IsChecked == true;
|
||||
|
||||
var selection = all.Where(a =>
|
||||
(includeOpen && a.IsActive) ||
|
||||
(includeClosed && !a.IsActive) ||
|
||||
(includeUnknown && ((a.BidHistory == null || a.BidHistory.Count == 0) && (a.BidderStats == null || a.BidderStats.Count == 0)))
|
||||
).ToList();
|
||||
|
||||
if (selection.Count == 0)
|
||||
{
|
||||
MessageBox.Show(this, "Nessuna asta da esportare.", "Esporta Aste", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
Log("[INFO] Esportazione in corso...", LogLevel.Info);
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (path.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var json = System.Text.Json.JsonSerializer.Serialize(selection, new System.Text.Json.JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(path, json, Encoding.UTF8);
|
||||
}
|
||||
else if (path.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var doc = new XDocument(new XElement("Auctions",
|
||||
from a in selection
|
||||
select new XElement("Auction",
|
||||
new XElement("AuctionId", a.AuctionId),
|
||||
new XElement("Name", a.Name),
|
||||
new XElement("OriginalUrl", a.OriginalUrl ?? string.Empty)
|
||||
)
|
||||
));
|
||||
doc.Save(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
CsvExporter.ExportAllAuctions(selection, path);
|
||||
}
|
||||
});
|
||||
|
||||
try { ExportPreferences.SaveLastExportExtension(Path.GetExtension(path)); } catch { }
|
||||
|
||||
MessageBox.Show(this, "Esportazione completata.", "Esporta Aste", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
Log($"[EXPORT] Aste esportate -> {path}", LogLevel.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Esportazione massiva: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show(this, "Errore durante esportazione: " + ex.Message, "Esporta Aste", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async void ExportToolbarButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = SettingsManager.Load();
|
||||
var chosenExt = ExtJson.IsChecked == true ? ".json" : ExtXml.IsChecked == true ? ".xml" : ".csv";
|
||||
|
||||
var includeOpen = (this.FindName("ExportOpenToolbar") as System.Windows.Controls.CheckBox)?.IsChecked == true;
|
||||
var includeClosed = (this.FindName("ExportClosedToolbar") as System.Windows.Controls.CheckBox)?.IsChecked == true;
|
||||
var includeUnknown = (this.FindName("ExportUnknownToolbar") as System.Windows.Controls.CheckBox)?.IsChecked == true;
|
||||
|
||||
var all = _auctionMonitor.GetAuctions();
|
||||
var selection = all.Where(a =>
|
||||
(includeOpen && a.IsActive) ||
|
||||
(includeClosed && !a.IsActive) ||
|
||||
(includeUnknown && ((a.BidHistory == null || a.BidHistory.Count == 0) && (a.BidderStats == null || a.BidderStats.Count == 0)))
|
||||
).ToList();
|
||||
|
||||
if (selection.Count == 0)
|
||||
{
|
||||
MessageBox.Show(this, "Nessuna asta da esportare.", "Esporta Aste", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
string folder;
|
||||
if (!string.IsNullOrWhiteSpace(settings?.ExportPath) && Directory.Exists(settings.ExportPath))
|
||||
{
|
||||
folder = settings.ExportPath!;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show(this, "Percorso export non configurato o non valido.\nConfigura il percorso nelle Impostazioni.", "Percorso Export", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var confirm = MessageBox.Show(this, $"Esportare {selection.Count} asta/e in:\n{folder}\n\nFormato: {chosenExt.ToUpperInvariant()}\n(Un file separato per ogni asta)", "Conferma Esportazione", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (confirm != MessageBoxResult.Yes) return;
|
||||
|
||||
Log("[INFO] Esportazione in corso...", LogLevel.Info);
|
||||
|
||||
int exported = 0;
|
||||
int skipped = 0;
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var a in selection)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filename = $"auction_{a.AuctionId}{chosenExt}";
|
||||
var path = Path.Combine(folder, filename);
|
||||
|
||||
if (File.Exists(path) && settings != null && settings.OverwriteExisting != true)
|
||||
{
|
||||
skipped++;
|
||||
Log($"[SKIP] File già esistente: {filename}", LogLevel.Warn);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (chosenExt.Equals(".json", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// JSON EXPORT - AGGIORNATO
|
||||
var obj = new
|
||||
{
|
||||
AuctionId = a.AuctionId,
|
||||
Name = a.Name,
|
||||
OriginalUrl = a.OriginalUrl,
|
||||
MinPrice = a.MinPrice,
|
||||
MaxPrice = a.MaxPrice,
|
||||
BidBeforeDeadlineMs = a.BidBeforeDeadlineMs,
|
||||
CheckAuctionOpenBeforeBid = a.CheckAuctionOpenBeforeBid,
|
||||
IsActive = a.IsActive,
|
||||
IsPaused = a.IsPaused,
|
||||
BidHistory = a.BidHistory,
|
||||
Bidders = a.BidderStats.Values.ToList(),
|
||||
AuctionLog = a.AuctionLog.ToList()
|
||||
};
|
||||
var json = System.Text.Json.JsonSerializer.Serialize(obj, new System.Text.Json.JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(path, json, Encoding.UTF8);
|
||||
}
|
||||
else if (chosenExt.Equals(".xml", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// XML EXPORT - AGGIORNATO
|
||||
var doc = new XDocument(
|
||||
new XElement("AuctionExport",
|
||||
new XElement("Metadata",
|
||||
new XElement("AuctionId", a.AuctionId),
|
||||
new XElement("Name", a.Name ?? string.Empty),
|
||||
new XElement("OriginalUrl", a.OriginalUrl ?? string.Empty),
|
||||
new XElement("MinPrice", a.MinPrice),
|
||||
new XElement("MaxPrice", a.MaxPrice),
|
||||
new XElement("BidBeforeDeadlineMs", a.BidBeforeDeadlineMs),
|
||||
new XElement("CheckAuctionOpenBeforeBid", a.CheckAuctionOpenBeforeBid),
|
||||
new XElement("IsActive", a.IsActive),
|
||||
new XElement("IsPaused", a.IsPaused)
|
||||
),
|
||||
new XElement("FinalPrice", a.BidHistory?.LastOrDefault()?.Price.ToString("F2", CultureInfo.InvariantCulture) ?? string.Empty),
|
||||
new XElement("TotalBids", a.BidHistory?.Count ?? 0),
|
||||
new XElement("Bidders",
|
||||
from b in a.BidderStats.Values.Where(x => x.BidCount > 0)
|
||||
select new XElement("Bidder",
|
||||
new XAttribute("Username", b.Username ?? string.Empty),
|
||||
new XAttribute("BidCount", b.BidCount),
|
||||
new XElement("LastBidTime", b.LastBidTimeDisplay ?? string.Empty)
|
||||
)
|
||||
),
|
||||
new XElement("AuctionLog",
|
||||
from l in a.AuctionLog
|
||||
select new XElement("Entry", l)
|
||||
),
|
||||
new XElement("BidHistory",
|
||||
from bh in a.BidHistory
|
||||
select new XElement("Entry",
|
||||
new XElement("Timestamp", bh.Timestamp.ToString("o")),
|
||||
new XElement("EventType", bh.EventType),
|
||||
new XElement("Bidder", bh.Bidder),
|
||||
new XElement("Price", bh.Price.ToString("F2", CultureInfo.InvariantCulture)),
|
||||
new XElement("Timer", bh.Timer.ToString("F2", CultureInfo.InvariantCulture)),
|
||||
new XElement("LatencyMs", bh.LatencyMs),
|
||||
new XElement("Success", bh.Success),
|
||||
new XElement("Notes", bh.Notes)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
doc.Save(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
// CSV EXPORT - AGGIORNATO
|
||||
using var sw = new StreamWriter(path, false, Encoding.UTF8);
|
||||
sw.WriteLine("Field,Value");
|
||||
sw.WriteLine($"AuctionId,{a.AuctionId}");
|
||||
sw.WriteLine($"Name,\"{EscapeCsv(a.Name)}\"");
|
||||
sw.WriteLine($"OriginalUrl,\"{EscapeCsv(a.OriginalUrl)}\"");
|
||||
sw.WriteLine($"MinPrice,{a.MinPrice}");
|
||||
sw.WriteLine($"MaxPrice,{a.MaxPrice}");
|
||||
sw.WriteLine($"BidBeforeDeadlineMs,{a.BidBeforeDeadlineMs}");
|
||||
sw.WriteLine($"CheckAuctionOpenBeforeBid,{a.CheckAuctionOpenBeforeBid}");
|
||||
sw.WriteLine($"IsActive,{a.IsActive}");
|
||||
sw.WriteLine($"IsPaused,{a.IsPaused}");
|
||||
sw.WriteLine();
|
||||
sw.WriteLine("--Auction Log--");
|
||||
sw.WriteLine("Message");
|
||||
foreach (var l in a.AuctionLog)
|
||||
{
|
||||
sw.WriteLine($"\"{EscapeCsv(l)}\"");
|
||||
}
|
||||
sw.WriteLine();
|
||||
sw.WriteLine("--Bidders--");
|
||||
sw.WriteLine("Username,BidCount,LastBidTime");
|
||||
foreach (var b in a.BidderStats.Values)
|
||||
{
|
||||
sw.WriteLine($"\"{EscapeCsv(b.Username)}\",{b.BidCount},\"{EscapeCsv(b.LastBidTimeDisplay)}\"");
|
||||
}
|
||||
sw.WriteLine();
|
||||
sw.WriteLine("--BidHistory--");
|
||||
sw.WriteLine("Timestamp,EventType,Bidder,Price,Timer,LatencyMs,Success,Notes");
|
||||
foreach (var bh in a.BidHistory)
|
||||
{
|
||||
sw.WriteLine($"\"{EscapeCsv(bh.Timestamp.ToString("o"))}\",{bh.EventType},\"{EscapeCsv(bh.Bidder)}\",{bh.Price:F2},{bh.Timer:F2},{bh.LatencyMs},{bh.Success},\"{EscapeCsv(bh.Notes)}\"");
|
||||
}
|
||||
}
|
||||
|
||||
exported++;
|
||||
Log($"[EXPORT] Asta esportata -> {path}", LogLevel.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Export asta {a.AuctionId}: {ex.Message}", LogLevel.Error);
|
||||
skipped++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try { ExportPreferences.SaveLastExportExtension(chosenExt); } catch { }
|
||||
|
||||
MessageBox.Show(this, $"Esportazione completata.\n\nEsportate: {exported}\nIgnorate: {skipped}\nPercorso: {folder}", "Esporta Aste", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
Log($"[EXPORT] Completato: {exported} esportate, {skipped} ignorate -> {folder}", LogLevel.Success);
|
||||
|
||||
if ((this.FindName("RemoveAfterExport") as System.Windows.Controls.CheckBox)?.IsChecked == true && selection.Count > 0)
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
foreach (var a in selection)
|
||||
{
|
||||
try
|
||||
{
|
||||
_auctionMonitor.RemoveAuction(a.AuctionId);
|
||||
var vm = _auctionViewModels.FirstOrDefault(x => x.AuctionId == a.AuctionId);
|
||||
if (vm != null)
|
||||
{
|
||||
_auctionViewModels.Remove(vm);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[WARN] Errore rimozione asta {a.AuctionId}: {ex.Message}", LogLevel.Warn);
|
||||
}
|
||||
}
|
||||
|
||||
SaveAuctions();
|
||||
UpdateTotalCount();
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Esportazione toolbar: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show(this, "Errore durante esportazione: " + ex.Message, "Esporta Aste", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExportBrowseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dlg = new Microsoft.Win32.SaveFileDialog() { FileName = "export.csv", Filter = "CSV files|*.csv|All files|*.*" };
|
||||
if (dlg.ShowDialog(this) == true)
|
||||
{
|
||||
ExportPathTextBox.Text = Path.GetDirectoryName(dlg.FileName) ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private string EscapeCsv(string? value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) return string.Empty;
|
||||
return value.Replace("\"", "\"\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using AutoBidder.Utilities;
|
||||
@@ -6,173 +6,161 @@ using AutoBidder.Utilities;
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings and configuration event handlers
|
||||
/// Settings and configuration event handlers - REFACTORED
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// Carica impostazioni predefinite salvate nei controlli UI
|
||||
/// Carica TUTTE le impostazioni salvate nei controlli UI
|
||||
/// </summary>
|
||||
private void LoadDefaultSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = SettingsManager.Load();
|
||||
var settings = Utilities.SettingsManager.Load();
|
||||
|
||||
// Popola i controlli con i valori salvati
|
||||
// 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();
|
||||
|
||||
Log($"[OK] Impostazioni predefinite caricate: Anticipo={settings.DefaultBidBeforeDeadlineMs}ms", LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[WARN] Errore caricamento defaults: {ex.Message}", LogLevel.Warn);
|
||||
// Carica limiti log
|
||||
Settings.MaxLogLinesPerAuctionTextBox.Text = settings.MaxLogLinesPerAuction.ToString();
|
||||
Settings.MaxGlobalLogLinesTextBox.Text = settings.MaxGlobalLogLines.ToString();
|
||||
|
||||
// Valori di fallback se il caricamento fallisce
|
||||
DefaultBidBeforeDeadlineMs.Text = "200";
|
||||
DefaultCheckAuctionOpen.IsChecked = false;
|
||||
DefaultMinPrice.Text = "0.00";
|
||||
DefaultMaxPrice.Text = "0.00";
|
||||
DefaultMaxClicks.Text = "0";
|
||||
}
|
||||
}
|
||||
|
||||
private async void SaveCookieButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var cookie = SettingsCookieTextBox.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(cookie))
|
||||
// ?? 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)
|
||||
{
|
||||
// Silenzioso - nessun MessageBox
|
||||
return;
|
||||
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;
|
||||
}
|
||||
|
||||
// Motore di precisione
|
||||
Settings.PollIntervalFarMsTextBox.Text = settings.PollIntervalFarMs.ToString();
|
||||
Settings.PollIntervalMidMsTextBox.Text = settings.PollIntervalMidMs.ToString();
|
||||
Settings.PollIntervalNearMsTextBox.Text = settings.PollIntervalNearMs.ToString();
|
||||
Settings.PollIntervalCriticalMsTextBox.Text = settings.PollIntervalCriticalMs.ToString();
|
||||
Settings.CriticalWindowMsTextBox.Text = settings.CriticalWindowMs.ToString();
|
||||
Settings.MaxRequestsPerSecondTextBox.Text = settings.MaxRequestsPerSecond.ToString("F0", System.Globalization.CultureInfo.InvariantCulture);
|
||||
Settings.PrecisionTimerCheckBox.IsChecked = settings.PrecisionTimerEnabled;
|
||||
|
||||
_auctionMonitor.InitializeSessionWithCookie(cookie, string.Empty);
|
||||
var success = await _auctionMonitor.UpdateUserInfoAsync();
|
||||
var session = _auctionMonitor.GetSession();
|
||||
RefreshEngineDiagnostics();
|
||||
|
||||
if (success && session != null)
|
||||
// Prodotti seguiti e catalogo
|
||||
Settings.AutoAddEnabledCheckBox.IsChecked = settings.AutoAddProductsEnabled;
|
||||
Settings.AutoAddState = settings.AutoAddNewAuctionState;
|
||||
Settings.AutoAddScanSecondsTextBox.Text = settings.AutoAddScanSeconds.ToString();
|
||||
Settings.AutoAddMaxAuctionsTextBox.Text = settings.AutoAddMaxAuctions.ToString();
|
||||
Settings.AutoAddMaxStartMinutesTextBox.Text = settings.AutoAddMaxStartMinutes.ToString();
|
||||
Settings.AutoAddOnlyNotStartedCheckBox.IsChecked = settings.AutoAddOnlyNotStarted;
|
||||
Settings.SuggestedCoverageTextBox.Text = settings.SuggestedPriceCoveragePercent.ToString("0", System.Globalization.CultureInfo.CurrentCulture);
|
||||
Settings.AverageBidCostTextBox.Text = settings.AverageBidCostEuro.ToString("0.00", System.Globalization.CultureInfo.CurrentCulture);
|
||||
Settings.AutoAddScanDepthTextBox.Text = settings.AutoAddScanMaxAuctions.ToString();
|
||||
Settings.CatalogMaxAuctionsTextBox.Text = settings.CatalogMaxAuctions.ToString();
|
||||
Settings.CatalogAutoRefreshCheckBox.IsChecked = settings.CatalogAutoRefresh;
|
||||
|
||||
// Anticipo, aste programmate, notifiche, cartelle
|
||||
Settings.BidLeadTrackingCheckBox.IsChecked = settings.BidLeadTrackingEnabled;
|
||||
Settings.BidLeadSuggestionsCheckBox.IsChecked = settings.BidLeadSuggestionsEnabled;
|
||||
Settings.BidLeadMinSamplesTextBox.Text = settings.BidLeadMinSamples.ToString();
|
||||
|
||||
Settings.ScheduledBackoffCheckBox.IsChecked = settings.ScheduledAuctionBackoffEnabled;
|
||||
Settings.ScheduledPollFarTextBox.Text = settings.ScheduledPollFarSeconds.ToString();
|
||||
Settings.ScheduledPollMidTextBox.Text = settings.ScheduledPollMidSeconds.ToString();
|
||||
Settings.ScheduledPollWakeTextBox.Text = settings.ScheduledPollWakeSeconds.ToString();
|
||||
|
||||
Settings.NotifyOnWinCheckBox.IsChecked = settings.NotifyOnWin;
|
||||
Settings.NotifyOnLossCheckBox.IsChecked = settings.NotifyOnLoss;
|
||||
|
||||
// I percorsi si mostrano <b>risolti</b>, non come sono salvati: vuoto nel
|
||||
// file significa "predefinito", ma a video il predefinito ha un nome preciso
|
||||
// ed è quello che serve sapere.
|
||||
RefreshDataFolderFields();
|
||||
|
||||
Settings.DetailedStatsCheckBox.IsChecked = settings.DetailedStatsEnabled;
|
||||
Settings.CatalogCacheSecondsTextBox.Text = settings.CatalogCacheSeconds.ToString();
|
||||
|
||||
Settings.WriteAppLogCheckBox.IsChecked = settings.WriteAppLogFile;
|
||||
Settings.WriteFreeBidsLogCheckBox.IsChecked = settings.WriteFreeBidsLogFile;
|
||||
Settings.WriteDossiersCheckBox.IsChecked = settings.WriteAuctionDossiers;
|
||||
Settings.RawPollsCheckBox.IsChecked = settings.DossierIncludeRawPolls;
|
||||
Settings.LogRetentionTextBox.Text = settings.LogRetentionDays.ToString();
|
||||
|
||||
RefreshBidLeadSummary();
|
||||
|
||||
// Aggiorna indicatore visivo
|
||||
UpdateMinBidsIndicator(settings.MinimumRemainingBids);
|
||||
|
||||
// Carica stato iniziale aste
|
||||
// ? NUOVO: Se RememberAuctionStates � attivo, seleziona "Ricorda Stato"
|
||||
if (settings.RememberAuctionStates)
|
||||
{
|
||||
Services.SessionManager.SaveSession(session);
|
||||
SetUserBanner(session.Username ?? string.Empty, session.RemainingBids);
|
||||
StartButton.IsEnabled = true;
|
||||
Log($"[OK] Sessione salvata per: {session.Username}");
|
||||
// Rimosso MessageBox - verrà mostrato dal chiamante
|
||||
Settings.LoadAuctionsRemember.IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[WARN] Cookie non valido o scaduto", LogLevel.Warn);
|
||||
// Rimosso MessageBox - verrà mostrato dal chiamante se necessario
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Salvataggio cookie: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async void ImportCookieFromBrowserButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (EmbeddedWebView?.CoreWebView2 == null)
|
||||
{
|
||||
MessageBox.Show(this, "Browser non inizializzato", "Errore", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var cookies = await EmbeddedWebView.CoreWebView2.CookieManager.GetCookiesAsync("https://it.bidoo.com");
|
||||
var stattrb = cookies.FirstOrDefault(c => c.Name == "__stattrb");
|
||||
|
||||
if (stattrb != null)
|
||||
{
|
||||
SettingsCookieTextBox.Text = stattrb.Value;
|
||||
Log("[OK] Cookie importato dal browser");
|
||||
MessageBox.Show(this, "Cookie importato con successo!\nClicca 'Salva' per confermare.", "Importa Cookie", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("[WARN] Cookie __stattrb non trovato nel browser", LogLevel.Warn);
|
||||
MessageBox.Show(this, "Cookie __stattrb non trovato.\nAssicurati di aver effettuato il login su bidoo.com nella scheda Browser.", "Cookie Non Trovato", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Importazione cookie: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show(this, "Errore durante importazione cookie: " + ex.Message, "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelCookieButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SettingsCookieTextBox.Text = string.Empty;
|
||||
}
|
||||
|
||||
private void SaveSettingsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var lastExt = ExtJson.IsChecked == true ? ".json" : ExtXml.IsChecked == true ? ".xml" : ".csv";
|
||||
var scope = "All";
|
||||
var cbClosed = this.FindName("ExportClosedToolbar") as System.Windows.Controls.CheckBox;
|
||||
var cbUnknown = this.FindName("ExportUnknownToolbar") as System.Windows.Controls.CheckBox;
|
||||
var cbOpen = this.FindName("ExportOpenToolbar") as System.Windows.Controls.CheckBox;
|
||||
|
||||
if (cbClosed != null && cbClosed.IsChecked == true) scope = "Closed";
|
||||
else if (cbUnknown != null && cbUnknown.IsChecked == true) scope = "Unknown";
|
||||
else if (cbOpen != null && cbOpen.IsChecked == true) scope = "Open";
|
||||
|
||||
var s = new AppSettings()
|
||||
{
|
||||
ExportPath = ExportPathTextBox.Text,
|
||||
LastExportExt = lastExt,
|
||||
ExportScope = scope,
|
||||
IncludeOnlyUsedBids = IncludeUsedBids.IsChecked == true,
|
||||
IncludeLogs = IncludeLogs.IsChecked == true,
|
||||
IncludeUserBids = IncludeUserBids.IsChecked == true
|
||||
};
|
||||
|
||||
SettingsManager.Save(s);
|
||||
ExportPreferences.SaveLastExportExtension(s.LastExportExt);
|
||||
Log("[OK] Impostazioni export salvate", LogLevel.Success);
|
||||
// Rimosso MessageBox - verrà mostrato dal chiamante
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Salvataggio impostazioni export: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelSettingsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Ricarica impostazioni export
|
||||
LoadExportSettings();
|
||||
|
||||
// Ricarica cookie salvato
|
||||
var session = Services.SessionManager.LoadSession();
|
||||
if (session != null && !string.IsNullOrEmpty(session.CookieString))
|
||||
{
|
||||
SettingsCookieTextBox.Text = session.CookieString;
|
||||
}
|
||||
else
|
||||
{
|
||||
SettingsCookieTextBox.Text = string.Empty;
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
Log("[INFO] Impostazioni ripristinate", LogLevel.Info);
|
||||
MessageBox.Show(this, "Impostazioni ripristinate alle ultime salvate.", "Annulla", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
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] Ripristino impostazioni: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show(this, "Errore durante ripristino: " + ex.Message, "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Log($"[ERRORE] Caricamento impostazioni predefinite: {ex.Message}", Utilities.LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,58 +168,387 @@ namespace AutoBidder
|
||||
{
|
||||
try
|
||||
{
|
||||
// Salva impostazioni predefinite aste
|
||||
// ? 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)
|
||||
{
|
||||
var settings = Utilities.SettingsManager.Load() ?? new Utilities.AppSettings();
|
||||
settings.DefaultBidBeforeDeadlineMs = bidMs;
|
||||
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;
|
||||
}
|
||||
|
||||
Utilities.SettingsManager.Save(settings);
|
||||
Log($"[OK] Impostazioni predefinite salvate: Anticipo={bidMs}ms, MinPrice=€{settings.DefaultMinPrice:F2}, MaxPrice=€{settings.DefaultMaxPrice:F2}, MaxClicks={maxClicks}", LogLevel.Success);
|
||||
// Rimosso MessageBox - verrà mostrato dal chiamante
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("[WARN] Valore anticipo puntata non valido (deve essere 0-5000)", LogLevel.Warn);
|
||||
Log("[ERRORE] Valore anticipo puntata non valido (deve essere 0-5000ms)", LogLevel.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
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";
|
||||
|
||||
// === SEZIONE: Motore di precisione ===
|
||||
// Ogni cadenza ha un minimo sensato: sotto i 100 ms si spreca banda senza
|
||||
// guadagnare precisione, perché la puntata la decide il cecchino, non il poll.
|
||||
settings.PollIntervalFarMs = ReadBounded(Settings.PollIntervalFarMsTextBox.Text, settings.PollIntervalFarMs, 200, 30000, "polling lontano");
|
||||
settings.PollIntervalMidMs = ReadBounded(Settings.PollIntervalMidMsTextBox.Text, settings.PollIntervalMidMs, 150, 10000, "polling medio");
|
||||
settings.PollIntervalNearMs = ReadBounded(Settings.PollIntervalNearMsTextBox.Text, settings.PollIntervalNearMs, 100, 5000, "polling vicino");
|
||||
settings.PollIntervalCriticalMs = ReadBounded(Settings.PollIntervalCriticalMsTextBox.Text, settings.PollIntervalCriticalMs, 100, 3000, "polling critico");
|
||||
settings.CriticalWindowMs = ReadBounded(Settings.CriticalWindowMsTextBox.Text, settings.CriticalWindowMs, 1000, 60000, "finestra critica");
|
||||
|
||||
if (double.TryParse(Settings.MaxRequestsPerSecondTextBox.Text.Replace(',', '.'),
|
||||
System.Globalization.NumberStyles.Any,
|
||||
System.Globalization.CultureInfo.InvariantCulture, out var rps) && rps >= 1 && rps <= 200)
|
||||
{
|
||||
settings.MaxRequestsPerSecond = rps;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("[ERRORE] Limite richieste al secondo non valido (1-200): valore precedente mantenuto", LogLevel.Error);
|
||||
}
|
||||
|
||||
settings.PrecisionTimerEnabled = Settings.PrecisionTimerCheckBox.IsChecked ?? true;
|
||||
|
||||
// === SEZIONE: Prodotti seguiti ===
|
||||
settings.AutoAddProductsEnabled = Settings.AutoAddEnabledCheckBox.IsChecked ?? true;
|
||||
settings.AutoAddNewAuctionState = Settings.AutoAddState;
|
||||
settings.AutoAddScanSeconds = ReadBounded(Settings.AutoAddScanSecondsTextBox.Text,
|
||||
settings.AutoAddScanSeconds, 30, 3600, "intervallo scansione prodotti seguiti", " s");
|
||||
|
||||
if (int.TryParse(Settings.AutoAddMaxAuctionsTextBox.Text, out var autoMax) && autoMax >= 0)
|
||||
settings.AutoAddMaxAuctions = autoMax;
|
||||
else
|
||||
Log("[ERRORE] Massimo aste aggiunte automaticamente non valido (>= 0)", LogLevel.Error);
|
||||
|
||||
settings.AutoAddScanMaxAuctions = ReadBounded(Settings.AutoAddScanDepthTextBox.Text,
|
||||
settings.AutoAddScanMaxAuctions, 50, 6000, "profondita ricerca prodotti seguiti", " aste");
|
||||
|
||||
// 0 = nessun orizzonte, ed e' una scelta vera: per questo il minimo del
|
||||
// controllo di validita' e' zero e non uno.
|
||||
settings.AutoAddOnlyNotStarted = Settings.AutoAddOnlyNotStartedCheckBox.IsChecked ?? false;
|
||||
|
||||
// Limiti consigliati per prodotto: due valori che entrano nel calcolo del
|
||||
// tetto di prezzo. Si accetta la virgola oltre al punto, come nel resto
|
||||
// dell'applicazione: chi scrive "0,20" non deve vedersi rifiutare il valore.
|
||||
if (TryReadDouble(Settings.SuggestedCoverageTextBox.Text, out var copertura) &&
|
||||
copertura is >= 10 and <= 99)
|
||||
settings.SuggestedPriceCoveragePercent = copertura;
|
||||
else
|
||||
Log("[ERRORE] Copertura delle chiusure non valida (10-99%)", LogLevel.Error);
|
||||
|
||||
if (TryReadDouble(Settings.AverageBidCostTextBox.Text, out var costo) &&
|
||||
costo is > 0 and <= 5)
|
||||
settings.AverageBidCostEuro = costo;
|
||||
else
|
||||
Log("[ERRORE] Costo medio di una puntata non valido (0-5 EUR)", LogLevel.Error);
|
||||
|
||||
if (int.TryParse(Settings.AutoAddMaxStartMinutesTextBox.Text, out var orizzonte) && orizzonte >= 0)
|
||||
settings.AutoAddMaxStartMinutes = orizzonte;
|
||||
else
|
||||
Log("[ERRORE] Orizzonte di aggiunta automatica non valido (>= 0 minuti)", LogLevel.Error);
|
||||
|
||||
if (settings.AutoAddProductsEnabled && settings.AutoAddNewAuctionState == "Active")
|
||||
{
|
||||
Log("[ATTENZIONE] Le aste seguite entreranno in stato Attiva: punteranno da sole, spendendo puntate reali.",
|
||||
LogLevel.Warning);
|
||||
}
|
||||
|
||||
// === SEZIONE: Catalogo ===
|
||||
settings.CatalogMaxAuctions = ReadBounded(Settings.CatalogMaxAuctionsTextBox.Text,
|
||||
settings.CatalogMaxAuctions, 20, 5000, "numero massimo aste catalogo", " aste");
|
||||
settings.CatalogAutoRefresh = Settings.CatalogAutoRefreshCheckBox.IsChecked ?? false;
|
||||
settings.CatalogCacheSeconds = ReadBounded(Settings.CatalogCacheSecondsTextBox.Text,
|
||||
settings.CatalogCacheSeconds, 0, 3600, "cache catalogo", " s");
|
||||
|
||||
// === SEZIONE: Anticipo puntata ===
|
||||
settings.BidLeadTrackingEnabled = Settings.BidLeadTrackingCheckBox.IsChecked ?? true;
|
||||
settings.BidLeadSuggestionsEnabled = Settings.BidLeadSuggestionsCheckBox.IsChecked ?? true;
|
||||
settings.BidLeadMinSamples = ReadBounded(Settings.BidLeadMinSamplesTextBox.Text,
|
||||
settings.BidLeadMinSamples, 5, 500, "puntate minime per il consiglio", "");
|
||||
|
||||
// === SEZIONE: Aste programmate ===
|
||||
settings.ScheduledAuctionBackoffEnabled = Settings.ScheduledBackoffCheckBox.IsChecked ?? true;
|
||||
settings.ScheduledPollFarSeconds = ReadBounded(Settings.ScheduledPollFarTextBox.Text,
|
||||
settings.ScheduledPollFarSeconds, 60, 3600, "polling aste lontane", " s");
|
||||
settings.ScheduledPollMidSeconds = ReadBounded(Settings.ScheduledPollMidTextBox.Text,
|
||||
settings.ScheduledPollMidSeconds, 30, 1800, "polling aste vicine all'apertura", " s");
|
||||
settings.ScheduledPollWakeSeconds = ReadBounded(Settings.ScheduledPollWakeTextBox.Text,
|
||||
settings.ScheduledPollWakeSeconds, 30, 600, "margine di risveglio", " s");
|
||||
|
||||
// === SEZIONE: Notifiche ===
|
||||
settings.NotifyOnWin = Settings.NotifyOnWinCheckBox.IsChecked ?? true;
|
||||
settings.NotifyOnLoss = Settings.NotifyOnLossCheckBox.IsChecked ?? false;
|
||||
|
||||
// === SEZIONE: Cartelle dei dati ===
|
||||
var previousData = AppPaths.DataFolder;
|
||||
var previousStats = AppPaths.StatsFolder;
|
||||
|
||||
// Il campo contiene il percorso risolto: se coincide con il predefinito si
|
||||
// salva vuoto, così spostando la cartella dati i registri la seguono invece
|
||||
// di restare inchiodati a un percorso che nessuno ha mai scelto davvero.
|
||||
settings.DataFolder = NormalizeFolderChoice(Settings.DataFolderTextBox.Text, AppPaths.DataFolder, settings.DataFolder);
|
||||
settings.StatsFolder = NormalizeFolderChoice(Settings.StatsFolderTextBox.Text, AppPaths.StatsFolder, settings.StatsFolder);
|
||||
settings.LogFolder = NormalizeFolderChoice(Settings.LogFolderTextBox.Text, AppPaths.LogFolder, settings.LogFolder);
|
||||
|
||||
settings.DetailedStatsEnabled = Settings.DetailedStatsCheckBox.IsChecked ?? true;
|
||||
|
||||
settings.WriteAppLogFile = Settings.WriteAppLogCheckBox.IsChecked ?? true;
|
||||
settings.WriteFreeBidsLogFile = Settings.WriteFreeBidsLogCheckBox.IsChecked ?? true;
|
||||
settings.WriteAuctionDossiers = Settings.WriteDossiersCheckBox.IsChecked ?? true;
|
||||
settings.DossierIncludeRawPolls = Settings.RawPollsCheckBox.IsChecked ?? true;
|
||||
|
||||
if (int.TryParse(Settings.LogRetentionTextBox.Text?.Trim(), out var retention) && retention >= 0)
|
||||
settings.LogRetentionDays = retention;
|
||||
|
||||
Utilities.SettingsManager.Save(settings);
|
||||
|
||||
ApplyDataFolderSettings(settings, previousData, previousStats);
|
||||
|
||||
// Il limite di ritmo si applica a caldo, senza ricreare il trasporto.
|
||||
_auctionMonitor.ApplyTransportSettings(settings);
|
||||
ApplyProductWatchSettings(settings);
|
||||
|
||||
// L'interruttore in Esplora non deve dissentire dalle impostazioni, e il
|
||||
// ciclo va fermato o riavviato di conseguenza.
|
||||
Browser.SetAutoRefresh(settings.CatalogAutoRefresh);
|
||||
if (settings.CatalogAutoRefresh) StartCatalogAutoRefresh();
|
||||
else StopCatalogAutoRefresh();
|
||||
RefreshEngineDiagnostics();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Salvataggio defaults: {ex.Message}", LogLevel.Error);
|
||||
Log($"[ERRORE] Salvataggio impostazioni: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Legge un intero entro limiti, mantenendo il valore precedente se il testo non è
|
||||
/// utilizzabile: un campo sbagliato non deve far ripartire il motore a caso.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Legge un numero con la virgola o col punto. Le impostazioni si scrivono a mano
|
||||
/// in un'applicazione italiana: rifiutare "0,20" sarebbe un dispetto.
|
||||
/// </summary>
|
||||
private static bool TryReadDouble(string? text, out double value)
|
||||
{
|
||||
value = 0;
|
||||
if (string.IsNullOrWhiteSpace(text)) return false;
|
||||
|
||||
return double.TryParse(text.Trim().Replace(',', '.'),
|
||||
System.Globalization.NumberStyles.Any,
|
||||
System.Globalization.CultureInfo.InvariantCulture, out value);
|
||||
}
|
||||
|
||||
private int ReadBounded(string text, int current, int min, int max, string label, string unit = "ms")
|
||||
{
|
||||
if (int.TryParse(text, out var value) && value >= min && value <= max)
|
||||
return value;
|
||||
|
||||
Log($"[ERRORE] Valore {label} non valido ({min}-{max}{unit}): mantenuto {current}{unit}", LogLevel.Error);
|
||||
return current;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mostra lo stato del motore: aggancio all'orologio del server e traffico prodotto.
|
||||
/// </summary>
|
||||
private void RefreshEngineDiagnostics()
|
||||
{
|
||||
try
|
||||
{
|
||||
var box = Settings.EngineDiagnosticsText;
|
||||
if (box == null) return;
|
||||
|
||||
var clock = _auctionMonitor.Clock;
|
||||
var sent = _auctionMonitor.RequestsSent;
|
||||
var failed = _auctionMonitor.RequestsFailed;
|
||||
|
||||
// Attenzione a come si presenta lo scarto: Bidoo dichiara i secondi interi,
|
||||
// quindi i campioni si distribuiscono per forza su una finestra di circa
|
||||
// 1000 ms. Non è l'errore della stima — la stima usa il minimo, che converge
|
||||
// al confine reale del secondo. Un valore molto oltre i 1000 ms segnala
|
||||
// invece una rete instabile.
|
||||
var clockLine = clock.IsSynced
|
||||
? $"Orologio server agganciato su {clock.SampleCount} campioni: le scadenze seguono il server, non l'orologio locale.\n" +
|
||||
$"Finestra campioni {clock.SpreadMs:F0} ms (intorno a 1000 ms è normale: Bidoo dichiara i secondi interi)."
|
||||
: $"Orologio server in sincronizzazione ({clock.SampleCount}/3 campioni): finché non è agganciato la scadenza è stimata localmente.";
|
||||
|
||||
box.Text = $"{clockLine}\n" +
|
||||
$"Richieste inviate: {sent:N0} — fallite: {failed:N0}.\n" +
|
||||
$"Motori attivi: {_auctionMonitor.ActiveRunners}.";
|
||||
}
|
||||
catch { /* la diagnostica non deve mai far fallire il salvataggio */ }
|
||||
}
|
||||
|
||||
private void CancelDefaultsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Ricarica defaults salvati
|
||||
LoadDefaultSettings();
|
||||
|
||||
Log("[INFO] Impostazioni predefinite ripristinate", LogLevel.Info);
|
||||
MessageBox.Show(this, "Impostazioni predefinite ripristinate.", "Annulla", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Ripristino defaults: {ex.Message}", LogLevel.Error);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,271 +1,214 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Xml.Linq;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.Utilities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Statistics and closed auctions event handlers
|
||||
/// NOTA: Funzionalità statistiche temporaneamente disabilitate - in sviluppo
|
||||
/// Registrazione delle aste concluse.
|
||||
///
|
||||
/// Ne escono due archivi con scopi diversi: un riepilogo compatto che alimenta la
|
||||
/// pagina Statistiche, e una scheda dettagliata per ogni asta destinata alle analisi
|
||||
/// successive. Il secondo esiste perché quei dati, se non raccolti mentre l'asta è in
|
||||
/// corso, non sono più recuperabili: Bidoo non li espone a posteriori.
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private void ExportStatsButton_Click(object sender, RoutedEventArgs e)
|
||||
private void AuctionMonitor_OnAuctionCompleted(AuctionInfo auction, AuctionState state, bool won)
|
||||
{
|
||||
MessageBox.Show(this, "Funzionalità statistiche in sviluppo", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
private async void LoadClosedAuctionsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MessageBox.Show(this, "Funzionalità statistiche in sviluppo", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
/* CODICE TEMPORANEAMENTE DISABILITATO - Statistiche in sviluppo
|
||||
try
|
||||
{
|
||||
StatsStatusText.Text = "Avvio caricamento statistiche...";
|
||||
var settings = Utilities.SettingsManager.Load();
|
||||
if (settings == null || string.IsNullOrWhiteSpace(settings.ExportPath) || !Directory.Exists(settings.ExportPath))
|
||||
var settings = SettingsManager.Load();
|
||||
|
||||
var record = new CompletedAuctionRecord
|
||||
{
|
||||
MessageBox.Show(this, "Percorso export non configurato o non valido. Configuralo nelle impostazioni.", "Carica Statistiche", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
StatsStatusText.Text = "Percorso export non valido";
|
||||
return;
|
||||
AuctionId = auction.AuctionId,
|
||||
Name = string.IsNullOrWhiteSpace(auction.Name) ? auction.AuctionId : auction.Name,
|
||||
ProductKey = ProductKeyHelper.GenerateProductKey(auction.Name),
|
||||
OriginalUrl = auction.OriginalUrl,
|
||||
FinalPrice = state?.Price ?? 0,
|
||||
Winner = state?.LastBidder ?? "",
|
||||
WonByMe = won,
|
||||
Outcome = won ? "Vinta"
|
||||
: (state?.Status == AuctionStatus.EndedLost ? "Persa" : "Chiusa"),
|
||||
MyBidsUsed = auction.BidsUsedOnThisAuction ?? 0,
|
||||
TotalResets = auction.ResetCount,
|
||||
BuyNowPrice = auction.BuyNowPrice,
|
||||
AddedAt = auction.AddedAt,
|
||||
|
||||
// Le puntate spese dal vincitore arrivano dal server insieme allo
|
||||
// stato finale: e' il numero che il sito mostra come "Puntate
|
||||
// utilizzate", e l'unico affidabile (lo storico si ferma a cinquanta).
|
||||
WinnerBidsPaid = state?.WinnerBidsPaid,
|
||||
WinnerBidsFree = state?.WinnerBidsFree,
|
||||
|
||||
// L'ora della fine vera, non quella della registrazione. Un'asta
|
||||
// terminata resta nel monitor finché non la si toglie: prendere
|
||||
// DateTime.Now qui significherebbe datare la chiusura al momento in cui
|
||||
// si è fatto pulizia, magari il giorno dopo.
|
||||
EndedAt = ResolveEndedAt(auction, state)
|
||||
};
|
||||
|
||||
CompletedAuctionsStore.Append(record);
|
||||
|
||||
// Un dato incoerente non va nelle medie: si dice e si scarta, invece di
|
||||
// spostare in silenzio i limiti di prezzo del prodotto.
|
||||
var integrity = AuctionIntegrity.CheckWinnerBids(record);
|
||||
if (record.WinnerBidsUsed.HasValue && !integrity.IsTrustworthy)
|
||||
{
|
||||
Log($"[STATISTICHE] {record.Name}: puntate del vincitore scartate ({integrity.Reason})",
|
||||
LogLevel.Warning);
|
||||
}
|
||||
else if (integrity.IsTrustworthy)
|
||||
{
|
||||
Log($"[STATISTICHE] {record.Name}: vinta con {record.WinnerBidsUsed} puntate " +
|
||||
$"(prezzo {record.FinalPrice:F2} EUR)", LogLevel.Info);
|
||||
}
|
||||
|
||||
ExportProgressBar.Visibility = Visibility.Visible;
|
||||
ExportProgressText.Visibility = Visibility.Visible;
|
||||
ExportProgressText.Text = "Caricamento statistiche...";
|
||||
var detail = BuildDetail(auction, state, record);
|
||||
|
||||
var folder = settings.ExportPath!;
|
||||
var files = Directory.GetFiles(folder, "auction_*.*");
|
||||
if (files.Length == 0)
|
||||
if (settings.DetailedStatsEnabled)
|
||||
{
|
||||
MessageBox.Show(this, "Nessun file di aste trovato nella cartella di export.", "Carica Statistiche", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
StatsStatusText.Text = "Nessun file trovato";
|
||||
ExportProgressBar.Visibility = Visibility.Collapsed;
|
||||
ExportProgressText.Visibility = Visibility.Collapsed;
|
||||
return;
|
||||
AuctionDetailStore.Append(detail);
|
||||
}
|
||||
|
||||
var aggregated = new Dictionary<string, List<ClosedAuctionRecord>>(StringComparer.OrdinalIgnoreCase);
|
||||
// Il dossier si chiude con il riepilogo: da lì in poi quel file è una
|
||||
// storia completa, ed è così che l'analisi sa di poterlo usare.
|
||||
AuctionDossier.Close(auction, detail, state);
|
||||
|
||||
await Task.Run(() =>
|
||||
ProductStatsStore.RecordCompleted(record, detail);
|
||||
|
||||
NotifyOutcome(record, settings);
|
||||
|
||||
Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
foreach (var f in files)
|
||||
Log($"[STORICO] Asta '{record.Name}' salvata ({record.Outcome}, €{record.FinalPrice:F2})",
|
||||
won ? LogLevel.Success : LogLevel.Info);
|
||||
|
||||
// Una vincita è il solo momento in cui il conto delle aste da confermare
|
||||
// cambia: chiederlo subito evita che la barra resti indietro fino al
|
||||
// giro successivo del timer.
|
||||
if (won) _ = RefreshAuctionsToConfirmAsync();
|
||||
|
||||
if (StatisticsPanel != null && StatisticsPanel.Visibility == Visibility.Visible)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ext = Path.GetExtension(f).ToLowerInvariant();
|
||||
if (ext == ".json")
|
||||
{
|
||||
var txt = File.ReadAllText(f, Encoding.UTF8);
|
||||
try
|
||||
{
|
||||
var rec = System.Text.Json.JsonSerializer.Deserialize<ClosedAuctionRecord>(txt);
|
||||
if (rec != null)
|
||||
{
|
||||
var key = (rec.ProductName ?? ExtractProductFromFilename(f) ?? "<unknown>").Trim();
|
||||
if (!aggregated.ContainsKey(key)) aggregated[key] = new List<ClosedAuctionRecord>();
|
||||
aggregated[key].Add(rec);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
try
|
||||
{
|
||||
var arr = System.Text.Json.JsonSerializer.Deserialize<List<ClosedAuctionRecord>>(txt);
|
||||
if (arr != null)
|
||||
{
|
||||
foreach (var r in arr)
|
||||
{
|
||||
var key = (r.ProductName ?? ExtractProductFromFilename(f) ?? "<unknown>").Trim();
|
||||
if (!aggregated.ContainsKey(key)) aggregated[key] = new List<ClosedAuctionRecord>();
|
||||
aggregated[key].Add(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else if (ext == ".xml")
|
||||
{
|
||||
try
|
||||
{
|
||||
var doc = XDocument.Load(f);
|
||||
var auctionElems = doc.Descendants("Auction");
|
||||
if (!auctionElems.Any()) auctionElems = doc.Descendants("AuctionExport");
|
||||
foreach (var n in auctionElems)
|
||||
{
|
||||
var name = n.Descendants("Name").FirstOrDefault()?.Value ?? n.Descendants("ProductName").FirstOrDefault()?.Value;
|
||||
double d = 0; double.TryParse(n.Descendants("FinalPrice").FirstOrDefault()?.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out d);
|
||||
int bids = 0; int.TryParse(n.Descendants("TotalBids").FirstOrDefault()?.Value, out bids);
|
||||
var winner = n.Descendants("Winner").FirstOrDefault()?.Value ?? string.Empty;
|
||||
var url = n.Descendants("OriginalUrl").FirstOrDefault()?.Value ?? string.Empty;
|
||||
var rec = new ClosedAuctionRecord { ProductName = name, FinalPrice = d == 0 ? null : (double?)d, Winner = winner, BidsUsed = bids, AuctionUrl = url };
|
||||
var key = (rec.ProductName ?? ExtractProductFromFilename(f) ?? "<unknown>").Trim();
|
||||
if (!aggregated.ContainsKey(key)) aggregated[key] = new List<ClosedAuctionRecord>();
|
||||
aggregated[key].Add(rec);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else // CSV or text
|
||||
{
|
||||
try
|
||||
{
|
||||
var lines = File.ReadAllLines(f, Encoding.UTF8);
|
||||
string product = ExtractProductFromFilename(f) ?? "<unknown>";
|
||||
double? price = null; int? bids = null; string winner = string.Empty; string url = string.Empty;
|
||||
foreach (var l in lines)
|
||||
{
|
||||
var line = l.Trim();
|
||||
if (line.StartsWith("Name,") || line.StartsWith("ProductName,"))
|
||||
{
|
||||
var parts = line.Split(',', 2);
|
||||
if (parts.Length == 2) product = parts[1].Trim('"');
|
||||
}
|
||||
else if (line.StartsWith("FinalPrice", StringComparison.OrdinalIgnoreCase) || line.StartsWith("Price,"))
|
||||
{
|
||||
var parts = line.Split(',', 2);
|
||||
if (parts.Length == 2 && double.TryParse(parts[1].Trim('"').Replace('€', ' ').Trim(), NumberStyles.Any, CultureInfo.InvariantCulture, out var p)) price = p;
|
||||
}
|
||||
else if (line.StartsWith("TotalBids", StringComparison.OrdinalIgnoreCase) || line.StartsWith("BidsUsed", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var parts = line.Split(',', 2);
|
||||
if (parts.Length == 2 && int.TryParse(parts[1].Trim('"'), out var b)) bids = b;
|
||||
}
|
||||
else if (line.StartsWith("Winner", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var parts = line.Split(',', 2);
|
||||
if (parts.Length == 2) winner = parts[1].Trim('"');
|
||||
}
|
||||
else if (line.StartsWith("OriginalUrl", StringComparison.OrdinalIgnoreCase) || line.StartsWith("AuctionUrl", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var parts = line.Split(',', 2);
|
||||
if (parts.Length == 2) url = parts[1].Trim('"');
|
||||
}
|
||||
}
|
||||
var rec = new ClosedAuctionRecord { ProductName = product, FinalPrice = price, BidsUsed = bids, Winner = winner, AuctionUrl = url };
|
||||
var key = (rec.ProductName ?? ExtractProductFromFilename(f) ?? "<unknown>").Trim();
|
||||
if (!aggregated.ContainsKey(key)) aggregated[key] = new List<ClosedAuctionRecord>();
|
||||
aggregated[key].Add(rec);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
LoadStatistics();
|
||||
}
|
||||
});
|
||||
|
||||
var stats = new List<object>();
|
||||
foreach (var kv in aggregated)
|
||||
{
|
||||
var list = kv.Value.Where(x => x.FinalPrice.HasValue || x.BidsUsed.HasValue).ToList();
|
||||
if (list.Count == 0) continue;
|
||||
var avgPrice = list.Where(x => x.FinalPrice.HasValue).Select(x => x.FinalPrice!.Value).DefaultIfEmpty(0).Average();
|
||||
var avgBids = list.Where(x => x.BidsUsed.HasValue).Select(x => x.BidsUsed!.Value).DefaultIfEmpty(0).Average();
|
||||
var winner = list.Where(x => !string.IsNullOrEmpty(x.Winner)).GroupBy(x => x.Winner).OrderByDescending(g => g.Count()).Select(g => g.Key).FirstOrDefault() ?? string.Empty;
|
||||
var example = list.FirstOrDefault(x => !string.IsNullOrEmpty(x.AuctionUrl))?.AuctionUrl ?? string.Empty;
|
||||
|
||||
stats.Add(new
|
||||
{
|
||||
ProductName = kv.Key,
|
||||
FinalPrice = avgPrice,
|
||||
Winner = winner,
|
||||
BidsUsed = (int)Math.Round(avgBids),
|
||||
AuctionUrl = example,
|
||||
Count = list.Count,
|
||||
AverageFinalPrice = avgPrice,
|
||||
AverageBidsUsed = avgBids
|
||||
});
|
||||
}
|
||||
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
StatsDataGrid.ItemsSource = stats.OrderByDescending(s => (int)s.GetType().GetProperty("Count")!.GetValue(s)).ToList();
|
||||
StatsStatusText.Text = $"Caricati {stats.Count} prodotti ({files.Length} file analizzati)";
|
||||
ExportProgressBar.Visibility = Visibility.Collapsed;
|
||||
ExportProgressText.Visibility = Visibility.Collapsed;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StatsStatusText.Text = "Errore caricamento statistiche";
|
||||
Log($"[ERRORE] Carica statistiche: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show(this, "Errore durante caricamento statistiche: " + ex.Message, "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
ExportProgressBar.Visibility = Visibility.Collapsed;
|
||||
ExportProgressText.Visibility = Visibility.Collapsed;
|
||||
Console.WriteLine($"[STORICO ERROR] {ex.Message}");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private static string? ExtractProductFromFilename(string path)
|
||||
/// <summary>
|
||||
/// Quando l'asta è finita davvero, in ordine di attendibilità: l'istante fissato dal
|
||||
/// monitor quando ha visto la conclusione dal vivo; la scadenza dichiarata dal
|
||||
/// server nell'ultima risposta; l'istante di quella risposta. Solo se non c'è
|
||||
/// nessuna delle tre si ripiega sull'ora corrente.
|
||||
///
|
||||
/// <para>La differenza non è cosmetica: lo storico si legge per capire a che ora del
|
||||
/// giorno chiudono le aste che conviene seguire, e una data presa al momento della
|
||||
/// rimozione rende quel numero privo di significato.</para>
|
||||
/// </summary>
|
||||
private static DateTime ResolveEndedAt(AuctionInfo auction, AuctionState? state)
|
||||
{
|
||||
if (auction.ConcludedAt.HasValue) return auction.ConcludedAt.Value;
|
||||
|
||||
if (state != null && state.ExpiryUnixSeconds > 0)
|
||||
return DateTimeOffset.FromUnixTimeSeconds(state.ExpiryUnixSeconds).ToLocalTime().DateTime;
|
||||
|
||||
if (state != null && state.SnapshotTime != default)
|
||||
return state.SnapshotTime.ToLocalTime();
|
||||
|
||||
return DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Costruisce la scheda dettagliata a partire da ciò che il monitor ha osservato.
|
||||
/// </summary>
|
||||
private AuctionDetailRecord BuildDetail(AuctionInfo auction, AuctionState? state, CompletedAuctionRecord summary)
|
||||
{
|
||||
var bidders = auction.SnapshotBidderStats();
|
||||
var bidsByUser = bidders.ToDictionary(b => b.Username, b => b.BidCount, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var series = auction.SnapshotPriceSeries();
|
||||
var firstSeen = auction.FirstSeenAt ?? auction.AddedAt;
|
||||
var observedMinutes = Math.Max(0, (summary.EndedAt - firstSeen).TotalMinutes);
|
||||
|
||||
return new AuctionDetailRecord
|
||||
{
|
||||
AuctionId = summary.AuctionId,
|
||||
Name = summary.Name,
|
||||
ProductKey = summary.ProductKey,
|
||||
Url = summary.OriginalUrl,
|
||||
|
||||
Outcome = summary.Outcome,
|
||||
WonByMe = summary.WonByMe,
|
||||
Winner = summary.Winner,
|
||||
FinalPrice = summary.FinalPrice,
|
||||
BuyNowPrice = auction.BuyNowPrice,
|
||||
ShippingCost = auction.ShippingCost,
|
||||
|
||||
FirstSeenAt = firstSeen,
|
||||
EndedAt = summary.EndedAt,
|
||||
ObservedMinutes = observedMinutes,
|
||||
|
||||
MyBids = summary.MyBidsUsed,
|
||||
TotalObservedBids = bidsByUser.Values.Sum(),
|
||||
DistinctBidders = bidsByUser.Count,
|
||||
Resets = auction.ResetCount,
|
||||
BidsByUser = bidsByUser,
|
||||
TopBidderShare = AuctionDetailRecord.ComputeTopShare(bidsByUser),
|
||||
|
||||
PriceSeries = series,
|
||||
PriceVelocityPerMinute = observedMinutes > 0.01 ? summary.FinalPrice / observedMinutes : 0,
|
||||
|
||||
AveragePingMs = auction.AverageLatencyMs,
|
||||
PollCount = auction.PollCount,
|
||||
PollErrors = auction.PollErrors,
|
||||
ConfiguredLeadMs = auction.BidBeforeDeadlineMs,
|
||||
TimerExpiredCount = auction.TimerExpiredCount,
|
||||
SuccessfulBids = auction.SuccessfulBidCount,
|
||||
FailedBids = auction.FailedBidCount,
|
||||
BidCostEuro = auction.BidCost,
|
||||
|
||||
ObservedFromStart = auction.ObservedFromStart,
|
||||
ObservedToEnd = auction.ObservedToEnd,
|
||||
DossierPath = AuctionDossier.For(auction.AuctionId)?.Path
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Avvisa con una notifica di sistema. Una vittoria va confermata su Bidoo, e
|
||||
/// accorgersene solo riaprendo la finestra è facile da dimenticare.
|
||||
/// </summary>
|
||||
private static void NotifyOutcome(CompletedAuctionRecord record, AppSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
var name = Path.GetFileNameWithoutExtension(path);
|
||||
var m = Regex.Match(name, @"auction_(.+)");
|
||||
if (m.Success)
|
||||
if (record.WonByMe && settings.NotifyOnWin)
|
||||
{
|
||||
var v = m.Groups[1].Value;
|
||||
if (Regex.IsMatch(v, "^\\d+$")) return null;
|
||||
return v.Replace('_', ' ');
|
||||
WindowsNotifier.Show(
|
||||
"Asta vinta!",
|
||||
$"{record.Name}\nAggiudicata a € {record.FinalPrice:F2} con {record.MyBidsUsed} puntate.\n" +
|
||||
"Ricordati di completare l'acquisto su Bidoo.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch { return null; }
|
||||
}
|
||||
|
||||
private async void ApplyInsightsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MessageBox.Show(this, "Funzionalità statistiche in sviluppo", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
/* CODICE TEMPORANEAMENTE DISABILITATO
|
||||
try
|
||||
{
|
||||
if (_selectedAuction == null)
|
||||
else if (!record.WonByMe && settings.NotifyOnLoss && record.MyBidsUsed > 0)
|
||||
{
|
||||
MessageBox.Show(this, "Seleziona un'asta prima di applicare le raccomandazioni.", "Applica Raccomandazioni", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
// Solo se ci avevamo davvero puntato: le aste solo osservate non
|
||||
// meritano un avviso.
|
||||
WindowsNotifier.Show(
|
||||
"Asta persa",
|
||||
$"{record.Name}\nChiusa a € {record.FinalPrice:F2} da {record.Winner}.",
|
||||
warning: true);
|
||||
}
|
||||
|
||||
var optionsBuilder = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder<Data.StatisticsContext>();
|
||||
var dbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "stats.db");
|
||||
optionsBuilder.UseSqlite($"Data Source={dbPath}");
|
||||
using var ctx = new Data.StatisticsContext(optionsBuilder.Options);
|
||||
var svc = new Services.StatsService(ctx);
|
||||
|
||||
var (recBids, recPrice) = await svc.GetRecommendationAsync(_selectedAuction.AuctionInfo.Name, _selectedAuction.AuctionInfo.OriginalUrl);
|
||||
_selectedAuction.MaxClicks = Math.Max(_selectedAuction.MaxClicks, recBids);
|
||||
_selectedAuction.MaxPrice = Math.Max(_selectedAuction.MaxPrice, recPrice);
|
||||
Log($"[OK] Raccomandazioni: MaxClicks={recBids}, MaxPrice={recPrice:F2} applicate a {_selectedAuction.Name}", LogLevel.Success);
|
||||
UpdateSelectedAuctionDetails(_selectedAuction);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] ApplyInsights: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show(this, "Errore applicazione raccomandazioni: " + ex.Message, "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void FreeBidsStart_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MessageBox.Show(this, "Funzionalità non ancora implementata", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
|
||||
private void FreeBidsStop_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MessageBox.Show(this, "Funzionalità non ancora implementata", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.ViewModels;
|
||||
using AutoBidder.Utilities;
|
||||
using AutoBidder.Services; // HtmlCacheService, HtmlResponse
|
||||
using AutoBidder.Net; // RequestPriority
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
@@ -22,14 +25,14 @@ namespace AutoBidder
|
||||
return;
|
||||
}
|
||||
|
||||
string auctionId;
|
||||
string? productName;
|
||||
string? auctionId;
|
||||
string? productName = null;
|
||||
string originalUrl;
|
||||
|
||||
// Verifica se è un URL o solo un ID
|
||||
// Verifica se � un URL o solo un ID
|
||||
if (input.Contains("bidoo.com") || input.Contains("http"))
|
||||
{
|
||||
// È un URL - estrai ID e nome prodotto
|
||||
// � un URL - estrai ID e nome prodotto dall'URL stesso
|
||||
originalUrl = input.Trim();
|
||||
auctionId = ExtractAuctionId(originalUrl);
|
||||
if (string.IsNullOrEmpty(auctionId))
|
||||
@@ -38,60 +41,98 @@ namespace AutoBidder
|
||||
return;
|
||||
}
|
||||
|
||||
productName = ExtractProductName(originalUrl) ?? string.Empty;
|
||||
productName = ExtractProductName(originalUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
// È solo un ID numerico - costruisci URL generico
|
||||
// � solo un ID numerico - costruisci URL generico
|
||||
auctionId = input.Trim();
|
||||
productName = string.Empty;
|
||||
originalUrl = $"https://it.bidoo.com/auction.php?a=asta_{auctionId}";
|
||||
}
|
||||
|
||||
// Verifica duplicati
|
||||
if (_auctionViewModels.Any(a => a.AuctionId == auctionId))
|
||||
{
|
||||
MessageBox.Show("Asta già monitorata!", "Duplicato", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
MessageBox.Show("Asta gi� monitorata!", "Duplicato", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
// Crea nome visualizzazione
|
||||
// ? MODIFICATO: Nome senza ID (gi� nella colonna separata)
|
||||
var displayName = string.IsNullOrEmpty(productName)
|
||||
? $"Asta {auctionId}"
|
||||
: $"{System.Net.WebUtility.HtmlDecode(productName)} ({auctionId})";
|
||||
: DecodeAllHtmlEntities(productName);
|
||||
|
||||
// CARICA IMPOSTAZIONI PREDEFINITE SALVATE
|
||||
var settings = Utilities.SettingsManager.Load();
|
||||
|
||||
// Crea model con valori dalle impostazioni salvate - ASTA STOPPATA ALL'INIZIO
|
||||
// ? Determina stato iniziale dalla configurazione
|
||||
bool isActive = false;
|
||||
bool isPaused = false;
|
||||
|
||||
switch (settings.DefaultNewAuctionState)
|
||||
{
|
||||
case "Active":
|
||||
isActive = true;
|
||||
isPaused = false;
|
||||
break;
|
||||
case "Paused":
|
||||
isActive = true;
|
||||
isPaused = true;
|
||||
break;
|
||||
case "Stopped":
|
||||
default:
|
||||
isActive = false;
|
||||
isPaused = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Crea model con valori dalle impostazioni salvate e stato configurato
|
||||
var auction = new AuctionInfo
|
||||
{
|
||||
AuctionId = auctionId,
|
||||
Name = System.Net.WebUtility.HtmlDecode(displayName),
|
||||
Name = DecodeAllHtmlEntities(displayName),
|
||||
OriginalUrl = originalUrl,
|
||||
BidBeforeDeadlineMs = settings.DefaultBidBeforeDeadlineMs,
|
||||
CheckAuctionOpenBeforeBid = settings.DefaultCheckAuctionOpenBeforeBid,
|
||||
IsActive = false, // STOPPATA
|
||||
IsPaused = false
|
||||
IsActive = isActive,
|
||||
IsPaused = isPaused
|
||||
};
|
||||
|
||||
// Aggiungi al monitor
|
||||
_auctionMonitor.AddAuction(auction);
|
||||
|
||||
// Crea ViewModel con valori dalle impostazioni
|
||||
// Limiti del prodotto se ne ha di suoi, altrimenti i predefiniti. Lo stato
|
||||
// non si tocca: qui l'ha scelto l'utente nella finestra di aggiunta, mentre
|
||||
// lo stato del prodotto vale per le aste che entrano da sole.
|
||||
var limits = ProductRuleResolver.ResolveByName(auction.Name, settings);
|
||||
|
||||
var vm = new AuctionViewModel(auction)
|
||||
{
|
||||
MinPrice = settings.DefaultMinPrice,
|
||||
MaxPrice = settings.DefaultMaxPrice,
|
||||
MaxClicks = settings.DefaultMaxClicks
|
||||
MinPrice = limits.MinPrice,
|
||||
MaxPrice = limits.MaxPrice,
|
||||
MaxClicks = limits.MaxClicks
|
||||
};
|
||||
_auctionViewModels.Add(vm);
|
||||
|
||||
// ? Auto-start del monitoraggio se l'asta � attiva e il monitoraggio � fermo
|
||||
if (isActive && !_isAutomationActive)
|
||||
{
|
||||
_auctionMonitor.Start();
|
||||
_isAutomationActive = true;
|
||||
Log($"[AUTO-START] Monitoraggio avviato automaticamente per nuova asta: {vm.Name}", LogLevel.Info);
|
||||
}
|
||||
|
||||
SaveAuctions();
|
||||
UpdateTotalCount();
|
||||
UpdateGlobalControlButtons(); // Aggiorna stato pulsanti globali
|
||||
UpdateGlobalControlButtons();
|
||||
|
||||
Log($"[ADD] Asta aggiunta con defaults: Anticipo={settings.DefaultBidBeforeDeadlineMs}ms, MinPrice=€{settings.DefaultMinPrice:F2}, MaxPrice=€{settings.DefaultMaxPrice:F2}, MaxClicks={settings.DefaultMaxClicks}", Utilities.LogLevel.Info);
|
||||
var stateText = isActive ? (isPaused ? "Paused" : "Active") : "Stopped";
|
||||
Log($"[ADD] Asta aggiunta con stato={stateText}, Anticipo={settings.DefaultBidBeforeDeadlineMs}ms", Utilities.LogLevel.Info);
|
||||
|
||||
// ? NUOVO: Se il nome non � stato estratto, recuperalo in background DOPO l'aggiunta
|
||||
if (string.IsNullOrEmpty(productName))
|
||||
{
|
||||
_ = FetchAuctionNameInBackgroundAsync(auction, vm);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -100,6 +141,85 @@ namespace AutoBidder
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera il nome dell'asta in background e aggiorna l'UI quando completa
|
||||
/// </summary>
|
||||
private async Task FetchAuctionNameInBackgroundAsync(AuctionInfo auction, AuctionViewModel vm)
|
||||
{
|
||||
try
|
||||
{
|
||||
// ? USA IL SERVIZIO CENTRALIZZATO invece di HttpClient diretto
|
||||
var response = await _htmlCacheService.GetHtmlAsync(
|
||||
auction.OriginalUrl,
|
||||
RequestPriority.Normal,
|
||||
bypassCache: false // Usa cache se disponibile
|
||||
);
|
||||
|
||||
if (!response.Success)
|
||||
{
|
||||
Log($"[WARN] Impossibile recuperare nome per asta {auction.AuctionId}: {response.Error}", LogLevel.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
// Estrai nome dal <title>
|
||||
var match = System.Text.RegularExpressions.Regex.Match(response.Html, @"<title>([^<]+)</title>");
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
var productName = match.Groups[1].Value.Trim().Replace(" - Bidoo", "");
|
||||
// ? Decodifica entity HTML (incluse quelle non standard)
|
||||
productName = DecodeAllHtmlEntities(productName);
|
||||
// ? MODIFICATO: Nome senza ID
|
||||
var newName = productName;
|
||||
|
||||
// Aggiorna il nome su thread UI
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
auction.Name = newName;
|
||||
// Forza refresh della griglia per mostrare il nuovo nome
|
||||
var tempSource = MultiAuctionsGrid.ItemsSource;
|
||||
MultiAuctionsGrid.ItemsSource = null;
|
||||
MultiAuctionsGrid.ItemsSource = tempSource;
|
||||
SaveAuctions(); // Salva il nome aggiornato
|
||||
Log($"[NAME] Nome recuperato per asta {auction.AuctionId}: {productName}{(response.FromCache ? " (cached)" : "")}", LogLevel.Info);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[WARN] Nome non trovato nell'HTML per asta {auction.AuctionId}", LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[WARN] Errore recupero nome per asta {auction.AuctionId}: {ex.Message}", LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodifica tutte le entity HTML, incluse quelle non standard come +
|
||||
/// </summary>
|
||||
private string DecodeAllHtmlEntities(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return text;
|
||||
|
||||
// Prima decodifica entity standard
|
||||
var decoded = System.Net.WebUtility.HtmlDecode(text);
|
||||
|
||||
// ? Poi sostituisci entity non standard che WebUtility.HtmlDecode non gestisce
|
||||
decoded = decoded.Replace("+", "+");
|
||||
decoded = decoded.Replace("=", "=");
|
||||
decoded = decoded.Replace("−", "-");
|
||||
decoded = decoded.Replace("×", "�");
|
||||
decoded = decoded.Replace("÷", "�");
|
||||
decoded = decoded.Replace("%", "%");
|
||||
decoded = decoded.Replace("$", "$");
|
||||
decoded = decoded.Replace("€", "�");
|
||||
decoded = decoded.Replace("£", "�");
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
private async Task AddAuctionFromUrl(string url)
|
||||
{
|
||||
try
|
||||
@@ -120,7 +240,7 @@ namespace AutoBidder
|
||||
// Verifica duplicati
|
||||
if (_auctionViewModels.Any(a => a.AuctionId == auctionId))
|
||||
{
|
||||
MessageBox.Show("Asta già monitorata!", "Duplicato", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
MessageBox.Show("Asta gi� monitorata!", "Duplicato", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -128,12 +248,16 @@ namespace AutoBidder
|
||||
var name = $"Asta {auctionId}";
|
||||
try
|
||||
{
|
||||
using var httpClient = new System.Net.Http.HttpClient();
|
||||
var html = await httpClient.GetStringAsync(url);
|
||||
var match = System.Text.RegularExpressions.Regex.Match(html, @"<title>([^<]+)</title>");
|
||||
if (match.Success)
|
||||
// ? USA IL SERVIZIO CENTRALIZZATO
|
||||
var response = await _htmlCacheService.GetHtmlAsync(url, RequestPriority.Normal);
|
||||
|
||||
if (response.Success)
|
||||
{
|
||||
name = System.Net.WebUtility.HtmlDecode(match.Groups[1].Value.Trim().Replace(" - Bidoo", ""));
|
||||
var match2 = System.Text.RegularExpressions.Regex.Match(response.Html, @"<title>([^<]+)</title>");
|
||||
if (match2.Success)
|
||||
{
|
||||
name = DecodeAllHtmlEntities(match2.Groups[1].Value.Trim().Replace(" - Bidoo", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
@@ -141,35 +265,68 @@ namespace AutoBidder
|
||||
// CARICA IMPOSTAZIONI PREDEFINITE SALVATE
|
||||
var settings = Utilities.SettingsManager.Load();
|
||||
|
||||
// Crea model con valori dalle impostazioni salvate - ASTA STOPPATA ALL'INIZIO
|
||||
// ? Determina stato iniziale dalla configurazione
|
||||
bool isActive = false;
|
||||
bool isPaused = false;
|
||||
|
||||
switch (settings.DefaultNewAuctionState)
|
||||
{
|
||||
case "Active":
|
||||
isActive = true;
|
||||
isPaused = false;
|
||||
break;
|
||||
case "Paused":
|
||||
isActive = true;
|
||||
isPaused = true;
|
||||
break;
|
||||
case "Stopped":
|
||||
default:
|
||||
isActive = false;
|
||||
isPaused = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Crea model con valori dalle impostazioni salvate e stato configurato
|
||||
var auction = new AuctionInfo
|
||||
{
|
||||
AuctionId = auctionId,
|
||||
Name = System.Net.WebUtility.HtmlDecode(name),
|
||||
Name = DecodeAllHtmlEntities(name),
|
||||
OriginalUrl = url,
|
||||
BidBeforeDeadlineMs = settings.DefaultBidBeforeDeadlineMs,
|
||||
CheckAuctionOpenBeforeBid = settings.DefaultCheckAuctionOpenBeforeBid,
|
||||
IsActive = false, // STOPPATA
|
||||
IsPaused = false
|
||||
IsActive = isActive,
|
||||
IsPaused = isPaused
|
||||
};
|
||||
|
||||
// Aggiungi al monitor
|
||||
_auctionMonitor.AddAuction(auction);
|
||||
|
||||
// Crea ViewModel con valori dalle impostazioni
|
||||
// Limiti del prodotto se ne ha di suoi, altrimenti i predefiniti. Lo stato
|
||||
// non si tocca: qui l'ha scelto l'utente nella finestra di aggiunta, mentre
|
||||
// lo stato del prodotto vale per le aste che entrano da sole.
|
||||
var limits = ProductRuleResolver.ResolveByName(auction.Name, settings);
|
||||
|
||||
var vm = new AuctionViewModel(auction)
|
||||
{
|
||||
MinPrice = settings.DefaultMinPrice,
|
||||
MaxPrice = settings.DefaultMaxPrice,
|
||||
MaxClicks = settings.DefaultMaxClicks
|
||||
MinPrice = limits.MinPrice,
|
||||
MaxPrice = limits.MaxPrice,
|
||||
MaxClicks = limits.MaxClicks
|
||||
};
|
||||
_auctionViewModels.Add(vm);
|
||||
|
||||
// ? Auto-start del monitoraggio se l'asta � attiva e il monitoraggio � fermo
|
||||
if (isActive && !_isAutomationActive)
|
||||
{
|
||||
_auctionMonitor.Start();
|
||||
_isAutomationActive = true;
|
||||
Log($"[AUTO-START] Monitoraggio avviato automaticamente per nuova asta: {vm.Name}", LogLevel.Info);
|
||||
}
|
||||
|
||||
SaveAuctions();
|
||||
UpdateTotalCount();
|
||||
UpdateGlobalControlButtons(); // Aggiorna stato pulsanti globali
|
||||
UpdateGlobalControlButtons();
|
||||
|
||||
Log($"[ADD] Asta aggiunta con defaults: Anticipo={settings.DefaultBidBeforeDeadlineMs}ms", Utilities.LogLevel.Info);
|
||||
var stateText = isActive ? (isPaused ? "Paused" : "Active") : "Stopped";
|
||||
Log($"[ADD] Asta aggiunta con stato={stateText}, Anticipo={settings.DefaultBidBeforeDeadlineMs}ms", Utilities.LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -178,6 +335,57 @@ namespace AutoBidder
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna manualmente il nome di un'asta recuperandolo dall'HTML
|
||||
/// </summary>
|
||||
public async Task RefreshAuctionNameAsync(AuctionViewModel vm)
|
||||
{
|
||||
if (vm == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
Log($"[NAME REFRESH] Aggiornamento nome per: {vm.Name}", LogLevel.Info);
|
||||
await FetchAuctionNameInBackgroundAsync(vm.AuctionInfo, vm);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Refresh nome asta: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Controlla se ci sono aste con nomi generici e prova a recuperarli dopo un delay
|
||||
/// </summary>
|
||||
private async Task RetryFailedAuctionNamesAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Aspetta 30 secondi prima di ritentare (d� tempo alle altre richieste di completare)
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(30));
|
||||
|
||||
// Trova aste con nomi generici "Asta XXXX"
|
||||
var auctionsWithGenericNames = _auctionViewModels
|
||||
.Where(vm => vm.Name.StartsWith("Asta ") && !vm.Name.Contains("Shop") && !vm.Name.Contains("�"))
|
||||
.ToList();
|
||||
|
||||
if (auctionsWithGenericNames.Count > 0)
|
||||
{
|
||||
Log($"[NAME RETRY] Trovate {auctionsWithGenericNames.Count} aste con nomi generici. Ritento recupero...", LogLevel.Info);
|
||||
|
||||
// Ritenta il recupero per ognuna (con delay tra una e l'altra per non sovraccaricare)
|
||||
foreach (var vm in auctionsWithGenericNames)
|
||||
{
|
||||
await FetchAuctionNameInBackgroundAsync(vm.AuctionInfo, vm);
|
||||
await System.Threading.Tasks.Task.Delay(2000); // 2 secondi tra una richiesta e l'altra
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[WARN] Errore retry nomi aste: {ex.Message}", LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveAuctions()
|
||||
{
|
||||
try
|
||||
@@ -195,40 +403,266 @@ namespace AutoBidder
|
||||
{
|
||||
try
|
||||
{
|
||||
// ? Carica impostazioni
|
||||
var settings = Utilities.SettingsManager.Load();
|
||||
|
||||
// Ottieni username corrente dalla sessione per ripristinare IsMyBid
|
||||
var session = _auctionMonitor.GetSession();
|
||||
var currentUsername = session?.Username ?? string.Empty;
|
||||
|
||||
var auctions = Utilities.PersistenceManager.LoadAuctions();
|
||||
foreach (var auction in auctions)
|
||||
{
|
||||
// Protezione: rimuovi eventuali BidHistory null
|
||||
auction.BidHistory = auction.BidHistory?.Where(b => b != null).ToList() ?? new System.Collections.Generic.List<BidHistory>();
|
||||
|
||||
// Decode HTML entities
|
||||
try { auction.Name = System.Net.WebUtility.HtmlDecode(auction.Name ?? string.Empty); } catch { }
|
||||
// ? Decode HTML entities (incluse quelle non standard)
|
||||
try { auction.Name = DecodeAllHtmlEntities(auction.Name ?? string.Empty); } catch { }
|
||||
|
||||
// ? Ripristina IsMyBid per tutte le puntate in RecentBids
|
||||
if (auction.RecentBids != null && auction.RecentBids.Count > 0 && !string.IsNullOrEmpty(currentUsername))
|
||||
{
|
||||
foreach (var bid in auction.RecentBids)
|
||||
{
|
||||
bid.IsMyBid = bid.Username.Equals(currentUsername, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ? NUOVO: Gestione stato in base a RememberAuctionStates
|
||||
if (settings.RememberAuctionStates)
|
||||
{
|
||||
// MODO 1: Ripristina lo stato salvato di ogni asta (IsActive e IsPaused vengono dal file salvato)
|
||||
// Non serve fare nulla, lo stato � gi� quello salvato nel file
|
||||
}
|
||||
else
|
||||
{
|
||||
// MODO 2: Applica DefaultStartAuctionsOnLoad a tutte le aste
|
||||
var loadState = settings.DefaultStartAuctionsOnLoad;
|
||||
switch (loadState)
|
||||
{
|
||||
case "Active":
|
||||
auction.IsActive = true;
|
||||
auction.IsPaused = false;
|
||||
break;
|
||||
case "Paused":
|
||||
auction.IsActive = true;
|
||||
auction.IsPaused = true;
|
||||
break;
|
||||
case "Stopped":
|
||||
default:
|
||||
auction.IsActive = false;
|
||||
auction.IsPaused = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_auctionMonitor.AddAuction(auction);
|
||||
var vm = new AuctionViewModel(auction);
|
||||
_auctionViewModels.Add(vm);
|
||||
}
|
||||
|
||||
// ? Avvia monitoraggio se ci sono aste in stato Active O Paused
|
||||
bool hasActiveOrPausedAuctions = auctions.Any(a => a.IsActive);
|
||||
|
||||
// On startup treat persisted auctions as stopped
|
||||
foreach (var vm in _auctionViewModels)
|
||||
if (hasActiveOrPausedAuctions && auctions.Count > 0)
|
||||
{
|
||||
vm.IsActive = false;
|
||||
vm.IsPaused = false;
|
||||
_auctionMonitor.Start();
|
||||
_isAutomationActive = true;
|
||||
|
||||
if (settings.RememberAuctionStates)
|
||||
{
|
||||
var activeCount = auctions.Count(a => a.IsActive && !a.IsPaused);
|
||||
var pausedCount = auctions.Count(a => a.IsActive && a.IsPaused);
|
||||
Log($"[AUTO-START] Monitoraggio avviato: {activeCount} attive, {pausedCount} in pausa (stati ripristinati)", LogLevel.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
var loadState = settings.DefaultStartAuctionsOnLoad;
|
||||
if (loadState == "Active")
|
||||
{
|
||||
Log($"[AUTO-START] Monitoraggio avviato automaticamente per {auctions.Count} aste caricate in stato attivo", LogLevel.Info);
|
||||
}
|
||||
else if (loadState == "Paused")
|
||||
{
|
||||
Log($"[AUTO-START] Monitoraggio avviato automaticamente per {auctions.Count} aste caricate in pausa", LogLevel.Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UpdateTotalCount();
|
||||
UpdateGlobalControlButtons(); // Aggiorna stato pulsanti dopo caricamento
|
||||
UpdateGlobalControlButtons();
|
||||
|
||||
// Log sempre mostrato (anche con 0 aste)
|
||||
if (auctions.Count > 0)
|
||||
{
|
||||
Log($"[OK] Caricate {auctions.Count} aste salvate");
|
||||
if (settings.RememberAuctionStates)
|
||||
{
|
||||
Log($"[LOAD] {auctions.Count} aste caricate con stati individuali ripristinati", LogLevel.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[LOAD] {auctions.Count} aste caricate con stato iniziale: {settings.DefaultStartAuctionsOnLoad}", LogLevel.Info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("[LOAD] Nessuna asta salvata", LogLevel.Info);
|
||||
}
|
||||
|
||||
LoadSavedSession();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Errore caricamento aste: {ex.Message}");
|
||||
Log($"[ERRORE] Caricamento aste: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna i dettagli dell'asta selezionata nel pannello Info Prodotto
|
||||
/// </summary>
|
||||
private void UpdateSelectedAuctionDetails(AuctionViewModel? vm)
|
||||
{
|
||||
if (vm == null || vm.AuctionInfo == null)
|
||||
{
|
||||
// Resetta campi se nessuna asta selezionata
|
||||
AuctionMonitor.ProductBuyNowPriceText.Text = "�";
|
||||
AuctionMonitor.ProductShippingCostText.Text = "�";
|
||||
AuctionMonitor.ProductWinLimitText.Text = "";
|
||||
RefreshProductVerdict(null);
|
||||
return;
|
||||
}
|
||||
|
||||
var auction = vm.AuctionInfo;
|
||||
|
||||
// CARICA AUTOMATICAMENTE INFO PRODOTTO SE NON PRESENTI
|
||||
if (!auction.BuyNowPrice.HasValue && !auction.ShippingCost.HasValue)
|
||||
{
|
||||
// Carica in background senza bloccare l'UI
|
||||
_ = LoadProductInfoInBackgroundAsync(auction);
|
||||
}
|
||||
|
||||
// Aggiorna i campi delle impostazioni
|
||||
UpdateAuctionSettingsDisplay(vm);
|
||||
|
||||
// Aggiorna Valore (Compra Subito)
|
||||
if (auction.BuyNowPrice.HasValue)
|
||||
{
|
||||
AuctionMonitor.ProductBuyNowPriceText.Text = $"{auction.BuyNowPrice.Value:F2}�";
|
||||
}
|
||||
else
|
||||
{
|
||||
AuctionMonitor.ProductBuyNowPriceText.Text = "�";
|
||||
}
|
||||
|
||||
// Aggiorna Spese di Spedizione
|
||||
if (auction.ShippingCost.HasValue)
|
||||
{
|
||||
AuctionMonitor.ProductShippingCostText.Text = $"{auction.ShippingCost.Value:F2}�";
|
||||
}
|
||||
else
|
||||
{
|
||||
AuctionMonitor.ProductShippingCostText.Text = "�";
|
||||
}
|
||||
|
||||
// Aggiorna Limiti di Vincita
|
||||
if (auction.HasWinLimit && !string.IsNullOrWhiteSpace(auction.WinLimitDescription))
|
||||
{
|
||||
AuctionMonitor.ProductWinLimitText.Text = auction.WinLimitDescription;
|
||||
}
|
||||
else if (!auction.HasWinLimit)
|
||||
{
|
||||
AuctionMonitor.ProductWinLimitText.Text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
AuctionMonitor.ProductWinLimitText.Text = "";
|
||||
}
|
||||
|
||||
// Verdetto di convenienza: costo totale se vinci contro valore del prodotto.
|
||||
RefreshProductVerdict(vm);
|
||||
RefreshSelectedStats(vm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Carica le informazioni del prodotto (e nome se generico) in background quando selezioni un'asta
|
||||
/// </summary>
|
||||
private async System.Threading.Tasks.Task LoadProductInfoInBackgroundAsync(AuctionInfo auction)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool hasGenericName = auction.Name.StartsWith("Asta ") &&
|
||||
!auction.Name.Contains("Shop") &&
|
||||
!auction.Name.Contains("�") &&
|
||||
!auction.Name.Contains("Buono") &&
|
||||
!auction.Name.Contains("Carburante");
|
||||
|
||||
Log($"[PRODUCT INFO] Caricamento automatico per: {auction.Name}{(hasGenericName ? " (+ nome generico)" : "")}", Utilities.LogLevel.Info);
|
||||
|
||||
// ? USA IL SERVIZIO CENTRALIZZATO
|
||||
var response = await _htmlCacheService.GetHtmlAsync(
|
||||
auction.OriginalUrl,
|
||||
RequestPriority.Normal, // Priorit� alta per info prodotto
|
||||
bypassCache: false
|
||||
);
|
||||
|
||||
if (!response.Success)
|
||||
{
|
||||
Log($"[PRODUCT INFO] Errore caricamento: {response.Error}", Utilities.LogLevel.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
bool updated = false;
|
||||
|
||||
// 1. ? Se nome generico, estrai nome reale dal <title>
|
||||
if (hasGenericName)
|
||||
{
|
||||
var matchTitle = System.Text.RegularExpressions.Regex.Match(response.Html, @"<title>([^<]+)</title>");
|
||||
if (matchTitle.Success)
|
||||
{
|
||||
var productName = matchTitle.Groups[1].Value.Trim().Replace(" - Bidoo", "");
|
||||
productName = DecodeAllHtmlEntities(productName);
|
||||
// ? MODIFICATO: Nome senza ID
|
||||
var newName = productName;
|
||||
|
||||
auction.Name = newName;
|
||||
updated = true;
|
||||
Log($"[NAME] Nome recuperato: {productName}{(response.FromCache ? " (cached)" : "")}", LogLevel.Info);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. ? Estrai informazioni prodotto (prezzo, spedizione, limiti)
|
||||
var extracted = Utilities.ProductValueCalculator.ExtractProductInfo(response.Html, auction);
|
||||
if (extracted)
|
||||
{
|
||||
updated = true;
|
||||
Log($"[PRODUCT INFO] Valore={auction.BuyNowPrice:F2}�, Spedizione={auction.ShippingCost:F2}�{(response.FromCache ? " (cached)" : "")}", Utilities.LogLevel.Success);
|
||||
}
|
||||
|
||||
// 3. ? Salva e aggiorna UI solo se qualcosa � cambiato
|
||||
if (updated)
|
||||
{
|
||||
SaveAuctions();
|
||||
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
// Refresh griglia per mostrare nome aggiornato
|
||||
if (hasGenericName)
|
||||
{
|
||||
var tempSource = MultiAuctionsGrid.ItemsSource;
|
||||
MultiAuctionsGrid.ItemsSource = null;
|
||||
MultiAuctionsGrid.ItemsSource = tempSource;
|
||||
}
|
||||
|
||||
// Refresh dettagli se ancora selezionata
|
||||
if (_selectedAuction != null && _selectedAuction.AuctionId == auction.AuctionId)
|
||||
{
|
||||
UpdateSelectedAuctionDetails(_selectedAuction);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PRODUCT INFO] Errore caricamento: {ex.Message}", Utilities.LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
@@ -14,7 +14,8 @@ namespace AutoBidder
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private void StartButton_Click(object sender, RoutedEventArgs e)
|
||||
// sender null = azione interna (non richiesta dall'utente): si evita di loggarla.
|
||||
private void StartButton_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -41,6 +42,8 @@ namespace AutoBidder
|
||||
Log("[START ALL] Tutte le aste avviate/riprese", LogLevel.Info);
|
||||
}
|
||||
|
||||
// ? Salva gli stati aggiornati su disco
|
||||
SaveAuctions();
|
||||
UpdateGlobalControlButtons();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -50,7 +53,7 @@ namespace AutoBidder
|
||||
}
|
||||
}
|
||||
|
||||
private void StopButton_Click(object sender, RoutedEventArgs e)
|
||||
private void StopButton_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -67,11 +70,13 @@ namespace AutoBidder
|
||||
_isAutomationActive = false;
|
||||
}
|
||||
|
||||
// ? Salva gli stati aggiornati su disco
|
||||
SaveAuctions();
|
||||
UpdateGlobalControlButtons();
|
||||
|
||||
if (sender != null) // Solo se chiamato dall'utente
|
||||
{
|
||||
Log("[STOP ALL] Monitoraggio fermato e tutte le aste arrestate", LogLevel.Warn);
|
||||
Log("[STOP ALL] Monitoraggio fermato e tutte le aste arrestate", LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -80,19 +85,31 @@ namespace AutoBidder
|
||||
}
|
||||
}
|
||||
|
||||
private async void PauseAllButton_Click(object sender, RoutedEventArgs e)
|
||||
private async void PauseAllButton_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var vm in _auctionViewModels.Where(a => a.IsActive))
|
||||
// Osserva vale anche per le aste ferme: servono comunque i motori accesi
|
||||
// per seguirle, semplicemente non punteranno.
|
||||
foreach (var vm in _auctionViewModels)
|
||||
{
|
||||
vm.IsActive = true;
|
||||
vm.IsPaused = true;
|
||||
}
|
||||
|
||||
if (_auctionViewModels.Count > 0 && !_isAutomationActive)
|
||||
{
|
||||
_auctionMonitor.Start();
|
||||
_isAutomationActive = true;
|
||||
}
|
||||
|
||||
// ? Salva gli stati aggiornati su disco
|
||||
SaveAuctions();
|
||||
UpdateGlobalControlButtons();
|
||||
|
||||
|
||||
if (sender != null) // Solo se chiamato dall'utente
|
||||
{
|
||||
Log("[PAUSE ALL] Tutte le aste in pausa", LogLevel.Warn);
|
||||
Log("[OSSERVA] Tutte le aste seguite senza puntare", LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -158,6 +175,9 @@ namespace AutoBidder
|
||||
summary += "\nDettagli: " + string.Join("; ", skipped.Take(10));
|
||||
|
||||
MessageBox.Show(summary, "Aggiunta aste", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
// ? RIMOSSO: Retry automatico ora avviene alla selezione on-demand
|
||||
// Le aste con nome generico vengono aggiornate automaticamente quando l'utente le seleziona
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,10 +191,13 @@ namespace AutoBidder
|
||||
|
||||
var auctionName = _selectedAuction.Name;
|
||||
var auctionId = _selectedAuction.AuctionId;
|
||||
|
||||
// Salva l'indice corrente prima di rimuovere
|
||||
var currentIndex = _auctionViewModels.IndexOf(_selectedAuction);
|
||||
|
||||
// Conferma rimozione
|
||||
var result = MessageBox.Show(
|
||||
$"Rimuovere l'asta dal monitoraggio?\n\n{auctionName}\n(ID: {auctionId})\n\nL'asta verrà eliminata dalla lista e non sarà più monitorata.",
|
||||
$"Rimuovere l'asta dal monitoraggio?\n\n{auctionName}\n(ID: {auctionId})\n\nL'asta verr� eliminata dalla lista e non sar� pi� monitorata.",
|
||||
"Conferma Rimozione",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
@@ -193,15 +216,58 @@ namespace AutoBidder
|
||||
// Rimuove dal ViewModel
|
||||
_auctionViewModels.Remove(_selectedAuction);
|
||||
|
||||
// Reset selezione
|
||||
_selectedAuction = null;
|
||||
|
||||
// Salva modifiche
|
||||
SaveAuctions();
|
||||
UpdateTotalCount();
|
||||
UpdateGlobalControlButtons();
|
||||
|
||||
Log($"[REMOVE] Asta rimossa: {auctionName} (ID: {auctionId})", LogLevel.Success);
|
||||
|
||||
// ? NUOVO: Sposta il focus sulla riga successiva
|
||||
if (_auctionViewModels.Count > 0)
|
||||
{
|
||||
// Se c'� ancora almeno un'asta nella lista
|
||||
int newIndex;
|
||||
|
||||
if (currentIndex >= _auctionViewModels.Count)
|
||||
{
|
||||
// L'asta rimossa era l'ultima, seleziona la nuova ultima
|
||||
newIndex = _auctionViewModels.Count - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Seleziona l'asta che ora si trova nella stessa posizione
|
||||
newIndex = currentIndex;
|
||||
}
|
||||
|
||||
// Seleziona l'asta
|
||||
MultiAuctionsGrid.SelectedIndex = newIndex;
|
||||
_selectedAuction = _auctionViewModels[newIndex];
|
||||
|
||||
// ? FIX: Salva il nome della NUOVA asta selezionata per il log
|
||||
var newAuctionName = _selectedAuction?.Name ?? "Sconosciuta";
|
||||
|
||||
// Forza il focus sulla griglia dopo un breve delay per permettere alla UI di aggiornarsi
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
MultiAuctionsGrid.Focus();
|
||||
|
||||
// Scroll fino alla riga selezionata per assicurarsi che sia visibile
|
||||
if (MultiAuctionsGrid.SelectedItem != null)
|
||||
{
|
||||
MultiAuctionsGrid.ScrollIntoView(MultiAuctionsGrid.SelectedItem);
|
||||
}
|
||||
|
||||
// ? FIX: Usa la variabile locale invece di _selectedAuction.Name
|
||||
Log($"[FOCUS] Focus spostato su: {newAuctionName}", LogLevel.Info);
|
||||
}), System.Windows.Threading.DispatcherPriority.Background);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nessuna asta rimasta, reset selezione
|
||||
_selectedAuction = null;
|
||||
Log($"[REMOVE] Nessuna asta rimasta nella lista", LogLevel.Info);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -209,213 +275,378 @@ namespace AutoBidder
|
||||
MessageBox.Show($"Errore durante la rimozione:\n{ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetSettingsButton_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
private void RemoveAllButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
var result = MessageBox.Show(
|
||||
"Ripristinare le impostazioni ai valori predefiniti?",
|
||||
"Conferma Reset",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
if (_auctionViewModels.Count == 0)
|
||||
{
|
||||
_selectedAuction.AuctionInfo.BidBeforeDeadlineMs = 200;
|
||||
_selectedAuction.AuctionInfo.CheckAuctionOpenBeforeBid = false;
|
||||
_selectedAuction.MinPrice = 0;
|
||||
_selectedAuction.MaxPrice = 0;
|
||||
_selectedAuction.MaxClicks = 0;
|
||||
MessageBox.Show("Non ci sono aste da rimuovere", "Lista Vuota", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateSelectedAuctionDetails(_selectedAuction);
|
||||
Log($"Reset impostazioni: {_selectedAuction.Name}", LogLevel.Success);
|
||||
var count = _auctionViewModels.Count;
|
||||
|
||||
// Conferma rimozione
|
||||
var result = MessageBox.Show(
|
||||
$"Rimuovere TUTTE le aste dal monitoraggio?\n\nSono presenti {count} aste monitorate.\n\nTutte le aste verranno eliminate dalla lista e non saranno pi� monitorate.",
|
||||
"Conferma Rimozione Totale",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
if (result != MessageBoxResult.Yes)
|
||||
{
|
||||
Log($"[REMOVE ALL] Rimozione annullata", LogLevel.Info);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Ferma il monitoraggio se attivo
|
||||
if (_isAutomationActive)
|
||||
{
|
||||
_auctionMonitor.Stop();
|
||||
_isAutomationActive = false;
|
||||
Log("[STOP] Monitoraggio fermato prima della rimozione totale", LogLevel.Info);
|
||||
}
|
||||
|
||||
// Rimuove tutte le aste dal monitor e dal ViewModel
|
||||
var auctionsToRemove = _auctionViewModels.ToList(); // Copia per evitare modifiche durante iterazione
|
||||
|
||||
foreach (var auction in auctionsToRemove)
|
||||
{
|
||||
_auctionMonitor.RemoveAuction(auction.AuctionId);
|
||||
}
|
||||
|
||||
// Pulisci la lista ViewModel
|
||||
_auctionViewModels.Clear();
|
||||
|
||||
// Resetta selezione
|
||||
_selectedAuction = null;
|
||||
|
||||
// Salva modifiche
|
||||
SaveAuctions();
|
||||
UpdateTotalCount();
|
||||
UpdateGlobalControlButtons();
|
||||
|
||||
Log($"[REMOVE ALL] Tutte le aste rimosse: {count} aste eliminate", LogLevel.Success);
|
||||
|
||||
MessageBox.Show($"Tutte le {count} aste sono state rimosse dal monitoraggio.", "Rimozione Completata", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERROR] Errore rimozione totale: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore durante la rimozione delle aste: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearBiddersButton_Click(object sender, RoutedEventArgs e)
|
||||
private async void CopyAuctionUrlButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
var result = MessageBox.Show(
|
||||
"Cancellare la lista degli utenti?",
|
||||
"Conferma Pulizia",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
if (_selectedAuction == null)
|
||||
{
|
||||
_selectedAuction.AuctionInfo.BidderStats.Clear();
|
||||
SelectedAuctionBiddersGrid.ItemsSource = null;
|
||||
SelectedAuctionBiddersCount.Text = "Utenti: 0";
|
||||
Log($"[CLEAR] Lista utenti pulita: {_selectedAuction.Name}", LogLevel.Info);
|
||||
MessageBox.Show(
|
||||
"Seleziona un'asta dalla griglia prima di copiare l'URL.",
|
||||
"Nessuna Asta Selezionata",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
Log("[INFO] Tentativo di copia URL senza asta selezionata", LogLevel.Info);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearLogButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
var result = MessageBox.Show(
|
||||
"Cancellare il log dell'asta?",
|
||||
"Conferma Pulizia",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
_selectedAuction.AuctionInfo.AuctionLog.Clear();
|
||||
SelectedAuctionLog.Document.Blocks.Clear();
|
||||
Log($"Log pulito: {_selectedAuction.Name}", LogLevel.Success);
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyAuctionUrlButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
var url = _selectedAuction.AuctionInfo.OriginalUrl;
|
||||
if (string.IsNullOrEmpty(url))
|
||||
url = $"https://it.bidoo.com/auction.php?a=asta_{_selectedAuction.AuctionId}";
|
||||
|
||||
// Tenta di copiare con retry mechanism
|
||||
const int maxAttempts = 3;
|
||||
const int delayMs = 50;
|
||||
|
||||
for (int attempt = 1; attempt <= maxAttempts; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(url);
|
||||
Log("URL copiato negli appunti", LogLevel.Success);
|
||||
return; // Successo, esci
|
||||
}
|
||||
catch (System.Runtime.InteropServices.COMException ex) when (ex.ErrorCode == unchecked((int)0x800401D0)) // CLIPBRD_E_CANT_OPEN
|
||||
{
|
||||
if (attempt < maxAttempts)
|
||||
{
|
||||
// Clipboard occupato, riprova dopo un breve delay
|
||||
System.Threading.Thread.Sleep(delayMs);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ultimo tentativo fallito
|
||||
Log($"[WARN] Clipboard temporaneamente occupato. Il testo potrebbe essere stato copiato.", LogLevel.Warning);
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Altri errori
|
||||
Log($"[ERRORE] Impossibile copiare URL: {ex.Message}", LogLevel.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenAuctionInternalButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null)
|
||||
{
|
||||
MessageBox.Show("Seleziona un'asta dalla griglia", "Nessuna Selezione", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(url);
|
||||
Log("URL copiato negli appunti", LogLevel.Success);
|
||||
var url = _selectedAuction.AuctionInfo.OriginalUrl;
|
||||
if (string.IsNullOrEmpty(url))
|
||||
url = $"https://it.bidoo.com/auction.php?a=asta_{_selectedAuction.AuctionId}";
|
||||
|
||||
// Naviga alla scheda Browser, in modalita' browser (non catalogo)
|
||||
TabBrowser.IsChecked = true;
|
||||
Browser.ShowBrowser();
|
||||
|
||||
// Naviga all'URL
|
||||
if (EmbeddedWebView?.CoreWebView2 != null)
|
||||
{
|
||||
EmbeddedWebView.CoreWebView2.Navigate(url);
|
||||
Log($"[BROWSER] Apertura asta nel browser interno: {_selectedAuction.Name}", LogLevel.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[WARN] Browser interno non ancora inizializzato", LogLevel.Warning);
|
||||
MessageBox.Show("Il browser interno non � ancora pronto.\nRiprova tra qualche secondo.", "Browser", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Copia link: {ex.Message}", LogLevel.Error);
|
||||
Log($"[ERRORE] Apertura nel browser interno: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore durante l'apertura: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectedBidBeforeDeadlineMs_TextChanged(object sender, TextChangedEventArgs e)
|
||||
|
||||
private void OpenAuctionExternalButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
if (sender is TextBox tb && int.TryParse(tb.Text, out var value) && value >= 0 && value <= 5000)
|
||||
if (_selectedAuction == null)
|
||||
{
|
||||
var oldValue = _selectedAuction.AuctionInfo.BidBeforeDeadlineMs;
|
||||
_selectedAuction.AuctionInfo.BidBeforeDeadlineMs = value;
|
||||
|
||||
// Log solo se non stiamo caricando E il valore è cambiato
|
||||
if (!_isUpdatingSelection && oldValue != value)
|
||||
MessageBox.Show("Seleziona un'asta dalla griglia", "Nessuna Selezione", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var url = _selectedAuction.AuctionInfo.OriginalUrl;
|
||||
if (string.IsNullOrEmpty(url))
|
||||
url = $"https://it.bidoo.com/auction.php?a=asta_{_selectedAuction.AuctionId}";
|
||||
|
||||
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
_selectedAuction.AuctionInfo.AddLog($"[SETTINGS] Anticipo puntata: {oldValue}ms → {value}ms");
|
||||
}
|
||||
FileName = url,
|
||||
UseShellExecute = true
|
||||
});
|
||||
|
||||
// Salva sempre (anche durante caricamento iniziale non fa male)
|
||||
SaveAuctions();
|
||||
Log($"[BROWSER] Apertura asta nel browser esterno: {_selectedAuction.Name}", LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Apertura nel browser esterno: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore durante l'apertura: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectedCheckAuctionOpen_Changed(object sender, RoutedEventArgs e)
|
||||
|
||||
private void ExportAuctionButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
if (sender is System.Windows.Controls.Primitives.ToggleButton cb)
|
||||
if (_selectedAuction == null)
|
||||
{
|
||||
var oldValue = _selectedAuction.AuctionInfo.CheckAuctionOpenBeforeBid;
|
||||
var newValue = cb.IsChecked ?? false;
|
||||
_selectedAuction.AuctionInfo.CheckAuctionOpenBeforeBid = newValue;
|
||||
|
||||
// Log solo se non stiamo caricando E il valore è cambiato
|
||||
if (!_isUpdatingSelection && oldValue != newValue)
|
||||
{
|
||||
_selectedAuction.AuctionInfo.AddLog($"[SETTINGS] Verifica stato asta: {(newValue ? "ON" : "OFF")}");
|
||||
}
|
||||
|
||||
SaveAuctions();
|
||||
MessageBox.Show("Seleziona un'asta dalla griglia", "Nessuna Selezione", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectedMinPrice_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
if (sender is TextBox tb)
|
||||
try
|
||||
{
|
||||
if (double.TryParse(tb.Text.Replace(',', '.'), System.Globalization.NumberStyles.Any,
|
||||
System.Globalization.CultureInfo.InvariantCulture, out var value))
|
||||
{
|
||||
var oldValue = _selectedAuction.MinPrice;
|
||||
_selectedAuction.MinPrice = value;
|
||||
MessageBox.Show(
|
||||
$"Esportazione singola asta:\n\n{_selectedAuction.Name}\n(ID: {_selectedAuction.AuctionId})\n\nFunzionalit� in sviluppo.\nUsa 'Esporta' dalla toolbar per esportare tutte le aste.",
|
||||
"Export Asta",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
|
||||
// Log solo se non stiamo caricando E il valore è cambiato
|
||||
if (!_isUpdatingSelection && Math.Abs(oldValue - value) > 0.01)
|
||||
{
|
||||
_selectedAuction.AuctionInfo.AddLog($"[SETTINGS] Prezzo minimo: €{oldValue:F2} → €{value:F2}");
|
||||
}
|
||||
|
||||
SaveAuctions();
|
||||
}
|
||||
Log($"[INFO] Richiesto export singolo per asta: {_selectedAuction.Name} (funzionalit� in sviluppo)", LogLevel.Info);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectedMaxPrice_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
if (sender is TextBox tb)
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (double.TryParse(tb.Text.Replace(',', '.'), System.Globalization.NumberStyles.Any,
|
||||
System.Globalization.CultureInfo.InvariantCulture, out var value))
|
||||
{
|
||||
var oldValue = _selectedAuction.MaxPrice;
|
||||
_selectedAuction.MaxPrice = value;
|
||||
|
||||
// Log solo se non stiamo caricando E il valore è cambiato
|
||||
if (!_isUpdatingSelection && Math.Abs(oldValue - value) > 0.01)
|
||||
{
|
||||
_selectedAuction.AuctionInfo.AddLog($"[SETTINGS] Prezzo massimo: €{oldValue:F2} → €{value:F2}");
|
||||
}
|
||||
|
||||
SaveAuctions();
|
||||
}
|
||||
Log($"[ERRORE] Export asta: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectedMaxClicks_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
if (sender is TextBox tb && int.TryParse(tb.Text, out var value) && value >= 0)
|
||||
{
|
||||
var oldValue = _selectedAuction.MaxClicks;
|
||||
_selectedAuction.MaxClicks = value;
|
||||
|
||||
// Log solo se non stiamo caricando E il valore è cambiato
|
||||
if (!_isUpdatingSelection && oldValue != value)
|
||||
{
|
||||
_selectedAuction.AuctionInfo.AddLog($"[SETTINGS] Max clicks: {oldValue} → {value}");
|
||||
}
|
||||
|
||||
SaveAuctions();
|
||||
}
|
||||
}
|
||||
|
||||
private void ExportMultipleAuctions_Click(object sender, RoutedEventArgs e)
|
||||
private async void RefreshProductInfoButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_auctionViewModels.Count == 0)
|
||||
if (_selectedAuction == null)
|
||||
{
|
||||
MessageBox.Show("Nessuna asta da esportare.", "Export", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
MessageBox.Show("Seleziona un'asta dalla griglia", "Nessuna Selezione", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
MessageBox.Show(
|
||||
$"Export Massivo di {_auctionViewModels.Count} aste.\n\n" +
|
||||
"Per configurare le opzioni di export, vai nella scheda Impostazioni.\n\n" +
|
||||
"Nota: Questa funzionalità verrà completata nelle prossime versioni.",
|
||||
"Export Aste",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
|
||||
Log($"[EXPORT] Richiesto export per {_auctionViewModels.Count} aste (funzionalità in sviluppo)", LogLevel.Info);
|
||||
var auction = _selectedAuction.AuctionInfo;
|
||||
|
||||
// Verifica che ci siano le info prodotto caricate
|
||||
if (!auction.BuyNowPrice.HasValue)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Informazioni prodotto non disponibili.\n\n" +
|
||||
"Il sistema le sta caricando automaticamente.\n" +
|
||||
"Riprova tra qualche secondo.",
|
||||
"Info Prodotto Mancanti",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
// Feedback visivo
|
||||
AuctionMonitor.RefreshProductInfoButton.IsEnabled = false;
|
||||
|
||||
// CALCOLA LIMITI SUGGERITI (CONSERVATIVI)
|
||||
double buyNowPrice = auction.BuyNowPrice.Value;
|
||||
double shippingCost = auction.ShippingCost ?? 0;
|
||||
double totalValue = buyNowPrice + shippingCost;
|
||||
|
||||
// Max EUR = 40% del valore TOTALE (pi� conservativo del 50%)
|
||||
double suggestedMaxPrice = totalValue * 0.40;
|
||||
suggestedMaxPrice = Math.Round(suggestedMaxPrice, 2);
|
||||
|
||||
// CALCOLA MAX CLICKS (numero massimo puntate conservativo)
|
||||
// Formula: (Valore Totale - Max EUR) / 0.20� per puntata
|
||||
// Poi riduciamo del 20% per maggiore margine di sicurezza
|
||||
int maxClicksTheoretical = (int)Math.Floor((totalValue - suggestedMaxPrice) / 0.20);
|
||||
int suggestedMaxClicks = (int)Math.Floor(maxClicksTheoretical * 0.80); // 80% del teorico
|
||||
|
||||
// Minimo 10 puntate per dare comunque una chance
|
||||
if (suggestedMaxClicks < 10) suggestedMaxClicks = 10;
|
||||
|
||||
Log($"[LIMITI] Valore={buyNowPrice:F2}� + Extra={shippingCost:F2}� = Tot={totalValue:F2}� ? MaxEUR={suggestedMaxPrice:F2}� (40%), MaxClicks={suggestedMaxClicks}", LogLevel.Info);
|
||||
|
||||
// CHIEDI CONFERMA
|
||||
var result = MessageBox.Show(
|
||||
$"Limiti suggeriti (conservativi):\n\n" +
|
||||
$"Max EUR: {suggestedMaxPrice:F2}�\n" +
|
||||
$"Max Clicks: {suggestedMaxClicks}\n\n" +
|
||||
$"Applicare questi valori?",
|
||||
"Conferma Limiti",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result != MessageBoxResult.Yes)
|
||||
{
|
||||
Log($"[LIMITI] Annullato dall'utente", LogLevel.Info);
|
||||
return;
|
||||
}
|
||||
|
||||
// APPLICA I LIMITI
|
||||
_selectedAuction.MaxPrice = suggestedMaxPrice;
|
||||
_selectedAuction.MaxClicks = suggestedMaxClicks;
|
||||
|
||||
// AGGIORNA UI
|
||||
UpdateAuctionSettingsDisplay(_selectedAuction);
|
||||
|
||||
// SALVA
|
||||
SaveAuctions();
|
||||
|
||||
Log($"[LIMITI] Applicati: MaxEUR={suggestedMaxPrice:F2}�, MaxClicks={suggestedMaxClicks}", LogLevel.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Export massivo: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore durante l'export: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Log($"[ERRORE] Calcolo limiti: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore durante il calcolo dei limiti:\n\n{ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
AuctionMonitor.RefreshProductInfoButton.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sposta l'asta selezionata verso l'alto nell'elenco
|
||||
/// </summary>
|
||||
private void MoveUpButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null)
|
||||
{
|
||||
MessageBox.Show("Seleziona un'asta dalla griglia", "Nessuna Selezione", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var currentIndex = _auctionViewModels.IndexOf(_selectedAuction);
|
||||
|
||||
if (currentIndex <= 0)
|
||||
{
|
||||
// Gi� in cima o non trovata
|
||||
Log($"[MOVE] L'asta � gi� in cima alla lista", LogLevel.Info);
|
||||
return;
|
||||
}
|
||||
|
||||
// Sposta l'elemento verso l'alto
|
||||
_auctionViewModels.Move(currentIndex, currentIndex - 1);
|
||||
|
||||
// Mantieni la selezione
|
||||
MultiAuctionsGrid.SelectedItem = _selectedAuction;
|
||||
MultiAuctionsGrid.ScrollIntoView(_selectedAuction);
|
||||
|
||||
// Salva il nuovo ordine
|
||||
SaveAuctions();
|
||||
|
||||
Log($"[MOVE UP] Asta spostata verso l'alto: {_selectedAuction.Name}", LogLevel.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Spostamento asta verso l'alto: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore durante lo spostamento: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sposta l'asta selezionata verso il basso nell'elenco
|
||||
/// </summary>
|
||||
private void MoveDownButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selectedAuction == null)
|
||||
{
|
||||
MessageBox.Show("Seleziona un'asta dalla griglia", "Nessuna Selezione", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var currentIndex = _auctionViewModels.IndexOf(_selectedAuction);
|
||||
|
||||
if (currentIndex < 0 || currentIndex >= _auctionViewModels.Count - 1)
|
||||
{
|
||||
// Gi� in fondo o non trovata
|
||||
Log($"[MOVE] L'asta � gi� in fondo alla lista", LogLevel.Info);
|
||||
return;
|
||||
}
|
||||
|
||||
// Sposta l'elemento verso il basso
|
||||
_auctionViewModels.Move(currentIndex, currentIndex + 1);
|
||||
|
||||
// Mantieni la selezione
|
||||
MultiAuctionsGrid.SelectedItem = _selectedAuction;
|
||||
MultiAuctionsGrid.ScrollIntoView(_selectedAuction);
|
||||
|
||||
// Salva il nuovo ordine
|
||||
SaveAuctions();
|
||||
|
||||
Log($"[MOVE DOWN] Asta spostata verso il basso: {_selectedAuction.Name}", LogLevel.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Spostamento asta verso il basso: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore durante lo spostamento: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,405 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.Services;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Catalogo nativo della scheda Esplora.
|
||||
///
|
||||
/// Affianca il browser integrato senza sostituirlo: il browser resta l'unico modo per
|
||||
/// fare il login (da cui il cookie viene importato da solo), questa e' la via veloce
|
||||
/// per confrontare molte aste senza caricare pagine.
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private BidooCatalogClient? _catalogClient;
|
||||
|
||||
private readonly List<CatalogCategory> _catalogCategories = new();
|
||||
|
||||
/// <summary>Aste della categoria corrente, prima dei filtri.</summary>
|
||||
private List<CatalogAuction> _catalogAuctions = new();
|
||||
|
||||
/// <summary>
|
||||
/// Le aste effettivamente mostrate, nell'ordine in cui compaiono. È su queste che
|
||||
/// lavora l'aggiornamento prezzi: aggiornare anche quelle nascoste dai filtri
|
||||
/// costerebbe richieste per numeri che nessuno sta guardando.
|
||||
/// </summary>
|
||||
private List<CatalogAuction> _catalogVisible = new();
|
||||
|
||||
private CatalogCategory? _catalogCategory;
|
||||
private CancellationTokenSource? _catalogCts;
|
||||
private CancellationTokenSource? _catalogRefreshCts;
|
||||
|
||||
/// <summary>Comandi usati dai pulsanti sulle singole schede prodotto.</summary>
|
||||
public RelayCommand? CatalogAddCommand { get; private set; }
|
||||
public RelayCommand? CatalogOpenCommand { get; private set; }
|
||||
public RelayCommand? CatalogWatchCommand { get; private set; }
|
||||
public RelayCommand? CatalogConfigureCommand { get; private set; }
|
||||
|
||||
private BidooCatalogClient CatalogClient
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_catalogClient == null)
|
||||
{
|
||||
_catalogClient = new BidooCatalogClient(_auctionMonitor.GetApiClient().Transport)
|
||||
{
|
||||
Diagnostic = msg => Dispatcher.Invoke(() => Log(msg, LogLevel.Info))
|
||||
};
|
||||
}
|
||||
return _catalogClient;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeCatalogCommands()
|
||||
{
|
||||
CatalogAddCommand = new RelayCommand(async p => await AddFromCatalogAsync(p as CatalogAuction));
|
||||
CatalogOpenCommand = new RelayCommand(p => OpenCatalogAuction(p as CatalogAuction));
|
||||
CatalogWatchCommand = new RelayCommand(p => ToggleWatchedProduct(p as CatalogAuction));
|
||||
CatalogConfigureCommand = new RelayCommand(p => ConfigureCatalogProduct(p as CatalogAuction));
|
||||
}
|
||||
|
||||
/// <summary>Carica l'elenco categorie la prima volta che si apre la scheda Esplora.</summary>
|
||||
private async Task EnsureCatalogLoadedAsync()
|
||||
{
|
||||
if (_catalogCategories.Count > 0) return;
|
||||
|
||||
// L'interruttore riflette l'impostazione salvata.
|
||||
Browser.SetAutoRefresh(SettingsManager.Load().CatalogAutoRefresh);
|
||||
|
||||
try
|
||||
{
|
||||
Browser.SetCatalogMessage("Caricamento categorie…");
|
||||
|
||||
var categories = await CatalogClient.GetCategoriesAsync(false, CancellationToken.None);
|
||||
|
||||
_catalogCategories.Clear();
|
||||
_catalogCategories.AddRange(categories);
|
||||
Browser.SetCategories(_catalogCategories);
|
||||
|
||||
var first = _catalogCategories.FirstOrDefault();
|
||||
if (first != null)
|
||||
{
|
||||
// Prima si registra la categoria corrente, poi si spunta il pulsante:
|
||||
// spuntarlo scatena CategoryChanged, e senza questo ordine partirebbero
|
||||
// due caricamenti concorrenti che si annullano a vicenda.
|
||||
_catalogCategory = first;
|
||||
first.IsSelected = true;
|
||||
|
||||
await LoadCategoryAsync(first);
|
||||
}
|
||||
else
|
||||
{
|
||||
Browser.SetCatalogMessage("Nessuna categoria disponibile.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Browser.SetCatalogMessage($"Impossibile caricare le categorie: {ex.Message}");
|
||||
Log($"[CATALOGO] Errore categorie: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadCategoryAsync(CatalogCategory category)
|
||||
{
|
||||
// Una richiesta per volta: cambiare categoria durante un caricamento deve
|
||||
// annullare il precedente, non accodarne un altro.
|
||||
var previous = _catalogCts;
|
||||
var cts = new CancellationTokenSource();
|
||||
_catalogCts = cts;
|
||||
previous?.Cancel();
|
||||
previous?.Dispose();
|
||||
|
||||
_catalogCategory = category;
|
||||
StopCatalogAutoRefresh();
|
||||
|
||||
try
|
||||
{
|
||||
Browser.SetCatalogMessage($"Carico \"{category.DisplayName}\"…");
|
||||
|
||||
var settings = SettingsManager.Load();
|
||||
var max = Math.Max(20, settings.CatalogMaxAuctions);
|
||||
var auctions = await CatalogClient.GetAllAuctionsAsync(
|
||||
category, max, cts.Token, settings.CatalogCacheSeconds);
|
||||
if (cts.Token.IsCancellationRequested) return;
|
||||
|
||||
// La pagina HTML da sola darebbe sempre 0,01 € e il timer di partenza:
|
||||
// un secondo giro su data.php porta prezzi e scadenze reali.
|
||||
if (auctions.Count > 0)
|
||||
await CatalogClient.UpdateStatesAsync(auctions, cts.Token);
|
||||
|
||||
if (cts.Token.IsCancellationRequested) return;
|
||||
|
||||
MarkWatchedProducts(auctions);
|
||||
|
||||
_catalogAuctions = auctions;
|
||||
RebuildCatalogView();
|
||||
StartCatalogAutoRefresh();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Sostituita da una richiesta piu' recente: nessun messaggio, e' normale.
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Browser.SetCatalogMessage($"Errore: {ex.Message}");
|
||||
Log($"[CATALOGO] {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ReferenceEquals(_catalogCts, cts))
|
||||
{
|
||||
_catalogCts = null;
|
||||
cts.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Segna quali schede appartengono a un prodotto gia' in elenco, distinguendo
|
||||
/// "seguito" (stellina) da "solo configurato" (ingranaggio acceso).
|
||||
/// </summary>
|
||||
private static void MarkWatchedProducts(IEnumerable<CatalogAuction> auctions)
|
||||
{
|
||||
var products = WatchedProductsStore.GetAll();
|
||||
|
||||
foreach (var auction in auctions)
|
||||
{
|
||||
var rule = products.FirstOrDefault(p => p.Matches(auction));
|
||||
auction.IsWatched = rule?.IsWatched == true;
|
||||
auction.IsListed = rule != null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ricostruisce (e riordina) l'elenco mostrato. Si chiama SOLO al caricamento o
|
||||
/// quando cambiano i filtri: riordinare mentre si legge farebbe saltare le schede
|
||||
/// da una posizione all'altra sotto il cursore.
|
||||
/// </summary>
|
||||
private void RebuildCatalogView()
|
||||
{
|
||||
var filter = Browser.SearchText;
|
||||
var hideManual = Browser.HideManualAuctions;
|
||||
|
||||
var view = _catalogAuctions
|
||||
.Where(a => !hideManual || !a.IsManualOnly)
|
||||
.Where(a => filter.Length == 0 || a.Name.Contains(filter, StringComparison.OrdinalIgnoreCase))
|
||||
// Le aste che stanno per chiudere sono quelle su cui si decide: prima.
|
||||
.OrderBy(a => a.RemainingSeconds <= 0 ? int.MaxValue : a.RemainingSeconds)
|
||||
.ToList();
|
||||
|
||||
_catalogVisible = view;
|
||||
Browser.SetCatalogItems(view, _catalogAuctions.Count);
|
||||
}
|
||||
|
||||
// ── Aggiornamento prezzi sul posto ───────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Quante aste tenere aggiornate mentre si guarda la griglia. Il listato si sfoglia
|
||||
/// ormai a migliaia, e <c>data.php</c> ne accetta una sessantina per chiamata: senza
|
||||
/// un tetto, un catalogo grande significherebbe decine di richieste ogni due secondi
|
||||
/// per aggiornare aste che chiudono fra ore.
|
||||
/// </summary>
|
||||
private const int CatalogRefreshBudget = 300;
|
||||
|
||||
private void StartCatalogAutoRefresh()
|
||||
{
|
||||
StopCatalogAutoRefresh();
|
||||
|
||||
if (!Browser.AutoRefreshEnabled || _catalogAuctions.Count == 0) return;
|
||||
|
||||
var cts = new CancellationTokenSource();
|
||||
_catalogRefreshCts = cts;
|
||||
_ = CatalogRefreshLoopAsync(cts.Token);
|
||||
}
|
||||
|
||||
private void StopCatalogAutoRefresh()
|
||||
{
|
||||
var cts = _catalogRefreshCts;
|
||||
_catalogRefreshCts = null;
|
||||
|
||||
cts?.Cancel();
|
||||
cts?.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna prezzi e timer delle aste in vista. I valori cambiano <i>sul posto</i>:
|
||||
/// nessun riordino e nessuna ricostruzione della lista, altrimenti le schede
|
||||
/// ballerebbero mentre le si guarda.
|
||||
///
|
||||
/// <para>Si aggiornano le prime <see cref="CatalogRefreshBudget"/> della griglia,
|
||||
/// che essendo ordinata per scadenza sono quelle che stanno per chiudere: sono le
|
||||
/// uniche i cui numeri cambiano da un momento all'altro.</para>
|
||||
/// </summary>
|
||||
private async Task CatalogRefreshLoopAsync(CancellationToken ct)
|
||||
{
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
if (!await Wait.DelayAsync(2000, ct).ConfigureAwait(false)) return;
|
||||
|
||||
var visible = _catalogVisible;
|
||||
if (visible.Count == 0) continue;
|
||||
|
||||
var snapshot = visible.Count > CatalogRefreshBudget
|
||||
? visible.GetRange(0, CatalogRefreshBudget)
|
||||
: visible;
|
||||
|
||||
try
|
||||
{
|
||||
await CatalogClient.UpdateStatesAsync(snapshot, ct).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Un aggiornamento saltato non compromette la pagina.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ct.IsCancellationRequested) return;
|
||||
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
foreach (var auction in snapshot) auction.NotifyStateChanged();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ── Azioni sulle schede ──────────────────────────────────────────
|
||||
|
||||
private async Task AddFromCatalogAsync(CatalogAuction? auction)
|
||||
{
|
||||
if (auction == null) return;
|
||||
|
||||
if (_auctionViewModels.Any(a => a.AuctionId == auction.AuctionId))
|
||||
{
|
||||
Log($"[CATALOGO] {auction.Name} è già nel monitor", LogLevel.Info);
|
||||
return;
|
||||
}
|
||||
|
||||
await AddAuctionById(auction.Url);
|
||||
WatchedProductsStore.MarkHandled(auction.AuctionId);
|
||||
Log($"[CATALOGO] Aggiunta al monitor: {auction.Name}", LogLevel.Info);
|
||||
}
|
||||
|
||||
private void OpenCatalogAuction(CatalogAuction? auction)
|
||||
{
|
||||
if (auction == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
// Passa alla scheda Browser: TabBrowser_Checked mostra il pannello e il
|
||||
// browser integrato, poi si naviga all'asta.
|
||||
TabBrowser.IsChecked = true;
|
||||
Browser.ShowBrowser();
|
||||
Browser.EmbeddedWebView?.CoreWebView2?.Navigate(auction.Url);
|
||||
Browser.BrowserAddress.Text = auction.Url;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[CATALOGO] Apertura nel browser fallita: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attiva o disattiva la sorveglianza del prodotto (stellina). Da qui in poi le aste
|
||||
/// nuove dello stesso articolo entrano nel monitor da sole.
|
||||
/// </summary>
|
||||
private void ToggleWatchedProduct(CatalogAuction? auction)
|
||||
{
|
||||
if (auction == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
if (auction.IsWatched)
|
||||
{
|
||||
// Spegnere la stellina non butta via i limiti scritti a mano: la scheda
|
||||
// resta fra i Prodotti, solo senza aggiunta automatica.
|
||||
WatchedProductsStore.SetWatched(auction, false);
|
||||
Log($"[SEGUITI] Non seguo più: {auction.Name}", LogLevel.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
WatchedProductsStore.SetWatched(auction, true);
|
||||
|
||||
var settings = SettingsManager.Load();
|
||||
if (settings.AutoAddProductsEnabled)
|
||||
{
|
||||
Log($"[SEGUITI] Ora seguo: {auction.Name} — le aste nuove entreranno in stato {StateLabel(settings.AutoAddNewAuctionState)}",
|
||||
LogLevel.Success);
|
||||
_ = _productWatcher?.ScanNowAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[SEGUITI] Ora seguo: {auction.Name} — l'aggiunta automatica è però disattivata in Impostazioni",
|
||||
LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
// Tutte le schede dello stesso prodotto cambiano stella insieme.
|
||||
MarkWatchedProducts(_catalogAuctions);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[SEGUITI] Errore: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static string StateLabel(string state) => state switch
|
||||
{
|
||||
"Active" => "Attiva",
|
||||
"Stopped" => "Ferma",
|
||||
_ => "Osserva"
|
||||
};
|
||||
|
||||
// ── Handler degli eventi del controllo ───────────────────────────
|
||||
|
||||
private async void Browser_CatalogCategoryChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selected = _catalogCategories.FirstOrDefault(c => c.IsSelected);
|
||||
if (selected == null || ReferenceEquals(selected, _catalogCategory)) return;
|
||||
|
||||
await LoadCategoryAsync(selected);
|
||||
}
|
||||
|
||||
private async void Browser_CatalogRefreshClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Chi preme "Aggiorna" vuole i dati dal server, non quelli in cache.
|
||||
CatalogClient.InvalidateCache();
|
||||
|
||||
if (_catalogCategory == null)
|
||||
{
|
||||
_catalogCategories.Clear();
|
||||
await EnsureCatalogLoadedAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await LoadCategoryAsync(_catalogCategory);
|
||||
}
|
||||
|
||||
private void Browser_CatalogSearchChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Filtri cambiati: qui il riordino ci sta, è l'utente ad averlo chiesto.
|
||||
RebuildCatalogView();
|
||||
}
|
||||
|
||||
private void Browser_CatalogAutoRefreshChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var settings = SettingsManager.Load();
|
||||
settings.CatalogAutoRefresh = Browser.AutoRefreshEnabled;
|
||||
SettingsManager.Save(settings);
|
||||
|
||||
if (Browser.AutoRefreshEnabled) StartCatalogAutoRefresh();
|
||||
else StopCatalogAutoRefresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using AutoBidder.Utilities;
|
||||
@@ -21,21 +21,24 @@ namespace AutoBidder
|
||||
GridPauseCommand = new RelayCommand(param => ExecuteGridPause(param as AuctionViewModel));
|
||||
GridStopCommand = new RelayCommand(param => ExecuteGridStop(param as AuctionViewModel));
|
||||
GridBidCommand = new RelayCommand(async param => await ExecuteGridBidAsync(param as AuctionViewModel));
|
||||
|
||||
InitializeCatalogCommands();
|
||||
InitializeProductCommands();
|
||||
}
|
||||
|
||||
private void ExecuteStartAll()
|
||||
{
|
||||
StartButton_Click(null, null);
|
||||
StartButton_Click(null, new RoutedEventArgs());
|
||||
}
|
||||
|
||||
private void ExecuteStopAll()
|
||||
{
|
||||
StopButton_Click(null, null);
|
||||
StopButton_Click(null, new RoutedEventArgs());
|
||||
}
|
||||
|
||||
private void ExecutePauseAll()
|
||||
{
|
||||
PauseAllButton_Click(null, null);
|
||||
PauseAllButton_Click(null, new RoutedEventArgs());
|
||||
}
|
||||
|
||||
private void ExecuteGridStart(AuctionViewModel? vm)
|
||||
@@ -46,7 +49,7 @@ namespace AutoBidder
|
||||
vm.IsActive = true;
|
||||
vm.IsPaused = false;
|
||||
|
||||
// Se il monitoraggio globale non è attivo, avvialo automaticamente
|
||||
// Se il monitoraggio globale non � attivo, avvialo automaticamente
|
||||
if (!_isAutomationActive)
|
||||
{
|
||||
_auctionMonitor.Start();
|
||||
@@ -58,14 +61,30 @@ namespace AutoBidder
|
||||
Log($"[START] Asta avviata: {vm.Name}", LogLevel.Info);
|
||||
}
|
||||
|
||||
// ? Salva gli stati aggiornati su disco
|
||||
SaveAuctions();
|
||||
UpdateGlobalControlButtons();
|
||||
}
|
||||
|
||||
private void ExecuteGridPause(AuctionViewModel? vm)
|
||||
{
|
||||
if (vm == null) return;
|
||||
|
||||
// Osserva significa "segui ma non puntare": serve comunque un motore acceso,
|
||||
// quindi l'asta va resa attiva anche se partiva da ferma.
|
||||
vm.IsActive = true;
|
||||
vm.IsPaused = true;
|
||||
Log($"[PAUSA] Asta in pausa: {vm.Name}", LogLevel.Info);
|
||||
|
||||
if (!_isAutomationActive)
|
||||
{
|
||||
_auctionMonitor.Start();
|
||||
_isAutomationActive = true;
|
||||
}
|
||||
|
||||
Log($"[OSSERVA] Asta seguita senza puntare: {vm.Name}", LogLevel.Info);
|
||||
|
||||
// ? Salva gli stati aggiornati su disco
|
||||
SaveAuctions();
|
||||
UpdateGlobalControlButtons();
|
||||
}
|
||||
|
||||
@@ -87,6 +106,8 @@ namespace AutoBidder
|
||||
Log($"[STOP] Asta fermata: {vm.Name}", LogLevel.Info);
|
||||
}
|
||||
|
||||
// ? Salva gli stati aggiornati su disco
|
||||
SaveAuctions();
|
||||
UpdateGlobalControlButtons();
|
||||
}
|
||||
|
||||
@@ -97,10 +118,31 @@ namespace AutoBidder
|
||||
{
|
||||
Log($"[BID] Puntata manuale richiesta su: {vm.Name}", LogLevel.Info);
|
||||
var result = await _auctionMonitor.PlaceManualBidAsync(vm.AuctionInfo);
|
||||
|
||||
// Aggiorna dati puntate da risposta server per puntata manuale
|
||||
if (result.Success)
|
||||
{
|
||||
if (result.RemainingBids.HasValue)
|
||||
{
|
||||
vm.AuctionInfo.RemainingBids = result.RemainingBids.Value;
|
||||
|
||||
// Aggiorna immediatamente il banner in alto
|
||||
Dispatcher.Invoke(() => UpdateRemainingBidsDisplay());
|
||||
}
|
||||
if (result.BidsUsedOnThisAuction.HasValue)
|
||||
{
|
||||
vm.AuctionInfo.BidsUsedOnThisAuction = result.BidsUsedOnThisAuction.Value;
|
||||
}
|
||||
|
||||
// Notifica aggiornamento contatori per aggiornare la UI - SUL THREAD UI
|
||||
Dispatcher.Invoke(() => vm.RefreshCounters());
|
||||
|
||||
Log($"[OK] Puntata manuale su {vm.Name}: {result.LatencyMs}ms", LogLevel.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[FAIL] Puntata manuale su {vm.Name}: {result.Error}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Event handlers per il nuovo sistema di connessione automatica
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// Handler per il click sul nome utente nella sidebar
|
||||
/// </summary>
|
||||
private void SidebarUsername_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
// Riusa la stessa logica del pulsante connessione (se fosse ancora presente)
|
||||
ConnectionStatusButton_Click(sender, new RoutedEventArgs());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handler per il pulsante stato connessione nel banner
|
||||
/// Se non connesso: apre tab Browser per login
|
||||
/// Se connesso: mostra opzioni (disconnetti, riconnetti)
|
||||
/// </summary>
|
||||
private void ConnectionStatusButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = _sessionService?.GetCurrentSession();
|
||||
|
||||
if (session != null && !string.IsNullOrEmpty(session.Username))
|
||||
{
|
||||
// Gi� connesso - Mostra opzioni
|
||||
var result = MessageBox.Show(
|
||||
this,
|
||||
$"Connesso come: {session.Username}\n" +
|
||||
$"Puntate residue: {session.RemainingBids}\n" +
|
||||
$"Credito Shop: EUR {session.ShopCredit:F2}\n\n" +
|
||||
"Vuoi disconnettere e accedere con un altro account?",
|
||||
"Gestione Connessione",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
// Disconnetti
|
||||
DisconnectSession();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non connesso - Apri browser per login
|
||||
MessageBox.Show(
|
||||
this,
|
||||
"Per accedere:\n\n" +
|
||||
"1. Fai login su Bidoo nella scheda Browser\n" +
|
||||
"2. La connessione sar� automatica\n\n" +
|
||||
"Apertura scheda Browser...",
|
||||
"Accedi a Bidoo",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
|
||||
// Apri tab Browser, in modalita' browser: il login passa da li'
|
||||
TabBrowser.IsChecked = true;
|
||||
Browser.ShowBrowser();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Gestione connessione: {ex.Message}", Utilities.LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== SEZIONE SESSIONE NELLE IMPOSTAZIONI =====
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna il riquadro di stato sessione nelle Impostazioni.
|
||||
/// </summary>
|
||||
private void RefreshSettingsSessionStatus()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = _sessionService?.GetCurrentSession();
|
||||
bool connected = session != null && !string.IsNullOrEmpty(session.Username);
|
||||
|
||||
Settings.SetSessionStatus(
|
||||
connected,
|
||||
session?.Username,
|
||||
session?.RemainingBids ?? 0,
|
||||
session?.ShopCredit ?? 0);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "Verifica connessione": ricontrolla contro il sito la sessione già in uso.
|
||||
///
|
||||
/// <para>Non chiede più un cookie da incollare: l'accesso si fa una volta dal
|
||||
/// browser integrato e vale per tutta l'applicazione. Questo pulsante serve a
|
||||
/// rispondere alla domanda che ci si fa davvero — "sono ancora connesso?" — che
|
||||
/// prima si poteva solo dedurre da un'asta che smetteva di funzionare.</para>
|
||||
/// </summary>
|
||||
private async void Settings_ConnectSessionClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var cookie = _auctionMonitor.GetApiClient().Transport.Cookie;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(cookie))
|
||||
{
|
||||
MessageBox.Show(this,
|
||||
"Nessuna sessione da verificare.\n\n" +
|
||||
"Accedi a Bidoo dalla scheda Browser: il cookie viene rilevato e importato da solo.",
|
||||
"Non connesso", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Log("[SESSION] Verifica della sessione in corso...", Utilities.LogLevel.Info);
|
||||
|
||||
var result = await _sessionService.ValidateAndActivateSessionAsync(cookie);
|
||||
|
||||
if (result.Success && result.Session != null)
|
||||
{
|
||||
_sessionService.SaveSession(result.Session);
|
||||
SetUserBanner(result.Session.Username, result.Session.RemainingBids);
|
||||
RefreshSettingsSessionStatus();
|
||||
|
||||
Log($"[SESSION] Connesso come {result.Session.Username} " +
|
||||
$"({result.Session.RemainingBids} puntate)", Utilities.LogLevel.Success);
|
||||
|
||||
MessageBox.Show(this,
|
||||
$"Connesso come: {result.Session.Username}\n" +
|
||||
$"Puntate residue: {result.Session.RemainingBids}\n" +
|
||||
$"Credito Shop: EUR {result.Session.ShopCredit:F2}",
|
||||
"Sessione attiva", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[SESSION] Sessione non più valida: {result.ErrorMessage}", Utilities.LogLevel.Error);
|
||||
RefreshSettingsSessionStatus();
|
||||
|
||||
MessageBox.Show(this,
|
||||
"La sessione non è più valida.\n\n" +
|
||||
(result.ErrorMessage ?? "Cookie scaduto.") +
|
||||
"\n\nRiaccedi a Bidoo dalla scheda Browser.",
|
||||
"Sessione scaduta", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Verifica sessione: {ex.Message}", Utilities.LogLevel.Error);
|
||||
MessageBox.Show(this, "Errore durante la verifica: " + ex.Message,
|
||||
"Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>"Disconnetti" dalla sezione Impostazioni.</summary>
|
||||
private void Settings_DisconnectSessionClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DisconnectSession();
|
||||
RefreshSettingsSessionStatus();
|
||||
}
|
||||
|
||||
/// <summary>"Apri Browser per il login": passa alla scheda Browser.</summary>
|
||||
private void Settings_OpenBrowserLoginClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TabBrowser.IsChecked = true;
|
||||
Browser.ShowBrowser();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnette la sessione corrente
|
||||
/// </summary>
|
||||
private void DisconnectSession()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log("[SESSION] Disconnessione in corso...", Utilities.LogLevel.Info);
|
||||
|
||||
// Clear session tramite SessionService
|
||||
_sessionService?.ClearSession();
|
||||
|
||||
// Aggiorna UI
|
||||
SetUserBanner(string.Empty, 0);
|
||||
|
||||
// Ferma monitoraggio se attivo
|
||||
if (_isAutomationActive)
|
||||
{
|
||||
_auctionMonitor?.Stop();
|
||||
_isAutomationActive = false;
|
||||
UpdateGlobalControlButtons();
|
||||
}
|
||||
|
||||
Log("[SESSION] Disconnesso con successo", Utilities.LogLevel.Success);
|
||||
|
||||
MessageBox.Show(
|
||||
this,
|
||||
"Disconnesso con successo.\n\n" +
|
||||
"Per riconnetterti, fai login nella scheda Browser.",
|
||||
"Disconnesso",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Disconnessione: {ex.Message}", Utilities.LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
@@ -17,34 +17,73 @@ namespace AutoBidder
|
||||
private void TabBrowser_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ShowPanel(Browser);
|
||||
Browser.ShowBrowser();
|
||||
}
|
||||
|
||||
private async void TabCerca_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ShowPanel(Browser);
|
||||
Browser.ShowCatalog();
|
||||
await EnsureCatalogLoadedAsync();
|
||||
}
|
||||
|
||||
private void TabProdotti_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ShowPanel(Products);
|
||||
LoadProducts();
|
||||
}
|
||||
|
||||
private void TabPuntateGratis_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ShowPanel(PuntateGratisPanel);
|
||||
ShowPanel(FreeBids);
|
||||
RefreshFreeBidsPanel();
|
||||
}
|
||||
|
||||
private void TabEsporta_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ShowPanel(Export);
|
||||
|
||||
// Il conteggio si rifà all'apertura: nel frattempo possono essersi concluse
|
||||
// altre aste, e un numero vecchio farebbe scegliere i filtri al buio.
|
||||
Export.RefreshPreview();
|
||||
}
|
||||
|
||||
private void TabDatiStatistici_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ShowPanel(StatisticsPanel);
|
||||
LoadStatistics();
|
||||
}
|
||||
|
||||
private void TabImpostazioni_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ShowPanel(Settings);
|
||||
try
|
||||
{
|
||||
// Mostra il pannello Impostazioni
|
||||
ShowPanel(Settings);
|
||||
|
||||
// Carica impostazioni quando si apre la tab
|
||||
LoadDefaultSettings();
|
||||
|
||||
// Aggiorna il riquadro di stato della sezione Sessione
|
||||
RefreshSettingsSessionStatus();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void ShowPanel(System.Windows.UIElement? panelToShow)
|
||||
{
|
||||
// Prevent NullReferenceException during initialization
|
||||
if (AuctionMonitor == null || Browser == null || StatisticsPanel == null || Settings == null || PuntateGratisPanel == null)
|
||||
if (AuctionMonitor == null || Browser == null || StatisticsPanel == null ||
|
||||
Settings == null || FreeBids == null || Products == null || Export == null)
|
||||
return;
|
||||
|
||||
// Hide all panels
|
||||
AuctionMonitor.Visibility = Visibility.Collapsed;
|
||||
Browser.Visibility = Visibility.Collapsed;
|
||||
PuntateGratisPanel.Visibility = Visibility.Collapsed;
|
||||
Products.Visibility = Visibility.Collapsed;
|
||||
FreeBids.Visibility = Visibility.Collapsed;
|
||||
StatisticsPanel.Visibility = Visibility.Collapsed;
|
||||
Export.Visibility = Visibility.Collapsed;
|
||||
Settings.Visibility = Visibility.Collapsed;
|
||||
|
||||
// Show selected panel
|
||||
@@ -71,7 +110,25 @@ namespace AutoBidder
|
||||
|
||||
private void AuctionMonitor_ExportClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ExportMultipleAuctions_Click(sender, e);
|
||||
// Chiama il metodo di export esistente
|
||||
try
|
||||
{
|
||||
// Esporta tutte le aste monitorate
|
||||
var auctions = _auctionMonitor.GetAuctions();
|
||||
if (auctions.Count == 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Nessuna asta da esportare", "Export", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Implementare dialog export con scelta formato
|
||||
System.Windows.MessageBox.Show($"Export di {auctions.Count} aste.\n\nFunzionalit� in sviluppo.\nUsa le impostazioni nella scheda Impostazioni per configurare l'export.", "Export Aste", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
|
||||
Log($"[INFO] Richiesto export di {auctions.Count} aste (funzionalit� in sviluppo)", Utilities.LogLevel.Info);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Export: {ex.Message}", Utilities.LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AuctionMonitor_AddUrlClicked(object sender, RoutedEventArgs e)
|
||||
@@ -83,6 +140,21 @@ namespace AutoBidder
|
||||
{
|
||||
RemoveUrlButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void AuctionMonitor_RemoveAllClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RemoveAllButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void AuctionMonitor_MoveUpClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MoveUpButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void AuctionMonitor_MoveDownClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MoveDownButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void AuctionMonitor_AuctionSelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@@ -90,6 +162,25 @@ namespace AutoBidder
|
||||
{
|
||||
_selectedAuction = selected;
|
||||
UpdateSelectedAuctionDetails(selected);
|
||||
|
||||
// ? NUOVO: Rileva nome generico O info prodotto mancanti e recupera automaticamente
|
||||
var auction = selected.AuctionInfo;
|
||||
bool hasGenericName = auction.Name.StartsWith("Asta ") &&
|
||||
!auction.Name.Contains("Shop") &&
|
||||
!auction.Name.Contains("�") &&
|
||||
!auction.Name.Contains("Buono") &&
|
||||
!auction.Name.Contains("Carburante");
|
||||
|
||||
bool needsProductInfo = !auction.BuyNowPrice.HasValue && !auction.ShippingCost.HasValue;
|
||||
|
||||
// Se ha nome generico O mancano info prodotto ? recupera in background
|
||||
if (hasGenericName || needsProductInfo)
|
||||
{
|
||||
Log($"[AUTO-FETCH] Recupero automatico per: {auction.Name} (nome generico={hasGenericName}, info mancanti={needsProductInfo})", Utilities.LogLevel.Info);
|
||||
|
||||
// Avvia fetch in background senza bloccare UI
|
||||
_ = LoadProductInfoInBackgroundAsync(auction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +188,21 @@ namespace AutoBidder
|
||||
{
|
||||
CopyAuctionUrlButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void AuctionMonitor_OpenAuctionInternalClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenAuctionInternalButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void AuctionMonitor_OpenAuctionExternalClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenAuctionExternalButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void AuctionMonitor_ExportAuctionClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ExportAuctionButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void AuctionMonitor_ResetSettingsClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@@ -115,34 +221,104 @@ namespace AutoBidder
|
||||
|
||||
private void AuctionMonitor_ClearGlobalLogClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ClearGlobalLogButton_Click(sender, e);
|
||||
ClearLogButton_Click(sender, e); // Clear Log invece di ClearGlobalLog
|
||||
}
|
||||
|
||||
// ===== AUCTION SETTINGS EVENTS =====
|
||||
|
||||
private void AuctionMonitor_RefreshProductInfoClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RefreshProductInfoButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void AuctionMonitor_ConnectionStatusClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ConnectionStatusButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void AuctionMonitor_BidBeforeDeadlineMsChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SelectedBidBeforeDeadlineMs_TextChanged(AuctionMonitor.SelectedBidBeforeDeadlineMs, new System.Windows.Controls.TextChangedEventArgs(e.RoutedEvent, System.Windows.Controls.UndoAction.None));
|
||||
}
|
||||
// Riempire i campi alla selezione di un'asta scatena i TextChanged:
|
||||
// senza questa guardia ogni selezione riscriveva auctions.json quattro volte
|
||||
// con gli stessi valori appena letti.
|
||||
if (_isUpdatingSelection) return;
|
||||
|
||||
private void AuctionMonitor_CheckAuctionOpenChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SelectedCheckAuctionOpen_Changed(AuctionMonitor.SelectedCheckAuctionOpen, e);
|
||||
if (_selectedAuction != null && int.TryParse(AuctionMonitor.SelectedBidBeforeDeadlineMs.Text, out int ms))
|
||||
{
|
||||
_selectedAuction.AuctionInfo.BidBeforeDeadlineMs = ms;
|
||||
SaveAuctions();
|
||||
}
|
||||
}
|
||||
|
||||
private void AuctionMonitor_MinPriceChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SelectedMinPrice_TextChanged(AuctionMonitor.SelectedMinPrice, new System.Windows.Controls.TextChangedEventArgs(e.RoutedEvent, System.Windows.Controls.UndoAction.None));
|
||||
// Riempire i campi alla selezione di un'asta scatena i TextChanged:
|
||||
// senza questa guardia ogni selezione riscriveva auctions.json quattro volte
|
||||
// con gli stessi valori appena letti.
|
||||
if (_isUpdatingSelection) return;
|
||||
|
||||
if (_selectedAuction != null && double.TryParse(AuctionMonitor.SelectedMinPrice.Text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out double price))
|
||||
{
|
||||
_selectedAuction.MinPrice = price;
|
||||
SaveAuctions();
|
||||
}
|
||||
}
|
||||
|
||||
private void AuctionMonitor_MaxPriceChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SelectedMaxPrice_TextChanged(AuctionMonitor.SelectedMaxPrice, new System.Windows.Controls.TextChangedEventArgs(e.RoutedEvent, System.Windows.Controls.UndoAction.None));
|
||||
// Riempire i campi alla selezione di un'asta scatena i TextChanged:
|
||||
// senza questa guardia ogni selezione riscriveva auctions.json quattro volte
|
||||
// con gli stessi valori appena letti.
|
||||
if (_isUpdatingSelection) return;
|
||||
|
||||
if (_selectedAuction != null && double.TryParse(AuctionMonitor.SelectedMaxPrice.Text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out double price))
|
||||
{
|
||||
_selectedAuction.MaxPrice = price;
|
||||
SaveAuctions();
|
||||
}
|
||||
}
|
||||
|
||||
private void AuctionMonitor_MaxClicksChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SelectedMaxClicks_TextChanged(AuctionMonitor.SelectedMaxClicks, new System.Windows.Controls.TextChangedEventArgs(e.RoutedEvent, System.Windows.Controls.UndoAction.None));
|
||||
// Riempire i campi alla selezione di un'asta scatena i TextChanged:
|
||||
// senza questa guardia ogni selezione riscriveva auctions.json quattro volte
|
||||
// con gli stessi valori appena letti.
|
||||
if (_isUpdatingSelection) return;
|
||||
|
||||
if (_selectedAuction != null && int.TryParse(AuctionMonitor.SelectedMaxClicks.Text, out int clicks))
|
||||
{
|
||||
_selectedAuction.MaxClicks = clicks;
|
||||
SaveAuctions();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tetto di spesa in euro per l'asta selezionata. E' il fratello di MaxClicks detto
|
||||
/// in denaro: chi ragiona in euro non deve fare la divisione a mente.
|
||||
/// </summary>
|
||||
private void AuctionMonitor_MaxSpendChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isUpdatingSelection) return;
|
||||
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
var testo = AuctionMonitor.SelectedMaxSpend.Text.Trim().Replace(',', '.');
|
||||
if (double.TryParse(testo, System.Globalization.NumberStyles.Any,
|
||||
System.Globalization.CultureInfo.InvariantCulture, out var spesa) && spesa >= 0)
|
||||
{
|
||||
_selectedAuction.AuctionInfo.MaxTotalSpendEuro = spesa;
|
||||
SaveAuctions();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Interruttore del controllo di pareggio sull'asta selezionata.</summary>
|
||||
private void AuctionMonitor_BreakEvenChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isUpdatingSelection) return;
|
||||
if (_selectedAuction == null) return;
|
||||
|
||||
_selectedAuction.AuctionInfo.StopAtBreakEven = AuctionMonitor.SelectedStopAtBreakEven.IsChecked == true;
|
||||
SaveAuctions();
|
||||
}
|
||||
|
||||
// ===== BROWSER CONTROL EVENTS =====
|
||||
@@ -211,37 +387,7 @@ namespace AutoBidder
|
||||
}
|
||||
|
||||
// ===== SETTINGS CONTROL EVENTS =====
|
||||
|
||||
private void Settings_SaveCookieClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SaveCookieButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void Settings_ImportCookieClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ImportCookieFromBrowserButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void Settings_CancelCookieClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CancelCookieButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void Settings_ExportBrowseClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ExportBrowseButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void Settings_SaveSettingsClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SaveSettingsButton_Click(sender, e);
|
||||
}
|
||||
|
||||
private void Settings_CancelSettingsClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CancelSettingsButton_Click(sender, e);
|
||||
}
|
||||
|
||||
|
||||
private void Settings_SaveDefaultsClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SaveDefaultsButton_Click(sender, e);
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Cartelle dei dati, misura dell'anticipo ed esportazione dello storico.
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
// ── Anticipo: misura e consiglio ─────────────────────────────────
|
||||
|
||||
private void RefreshBidLeadSummary()
|
||||
{
|
||||
try
|
||||
{
|
||||
var s = BidLeadStats.Summarize();
|
||||
|
||||
if (!s.HasData)
|
||||
{
|
||||
Settings.SetBidLeadSummary(
|
||||
"Nessuna puntata registrata finora. Le misure si raccolgono da sole a ogni puntata.");
|
||||
return;
|
||||
}
|
||||
|
||||
Settings.SetBidLeadSummary(
|
||||
$"{s.Count} puntate misurate — {s.Successes} riuscite ({s.SuccessRate:F0}%), {s.TooLate} tardive.\n" +
|
||||
$"Arrivano in media {s.AverageActualMs:F0} ms prima della scadenza " +
|
||||
$"(mediana {s.MedianActualMs:F0} ms, caso peggiore {s.MinActualMs:F0} ms).\n" +
|
||||
$"Ping medio {s.AveragePingMs:F0} ms, anticipo impostato di norma {s.TypicalConfiguredMs} ms.");
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void Settings_ComputeBidLeadAdviceClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = SettingsManager.Load();
|
||||
var current = settings.DefaultBidBeforeDeadlineMs;
|
||||
var advice = BidLeadStats.Suggest(current, settings.BidLeadMinSamples);
|
||||
|
||||
RefreshBidLeadSummary();
|
||||
|
||||
if (!advice.HasAdvice)
|
||||
{
|
||||
MessageBox.Show(this, advice.Reason, "Anticipo puntata",
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
// Il consiglio non si applica mai da solo: cambia il parametro che decide
|
||||
// se una puntata arriva o no, e la decisione resta dell'utente.
|
||||
var answer = MessageBox.Show(this,
|
||||
$"{advice.Reason}\n\nVuoi impostare l'anticipo predefinito a {advice.SuggestedLeadMs} ms?\n\n" +
|
||||
"Le aste già nel monitor mantengono il proprio valore.",
|
||||
"Anticipo puntata", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
settings.DefaultBidBeforeDeadlineMs = advice.SuggestedLeadMs;
|
||||
SettingsManager.Save(settings);
|
||||
|
||||
DefaultBidBeforeDeadlineMs.Text = advice.SuggestedLeadMs.ToString();
|
||||
Log($"[ANTICIPO] Anticipo predefinito portato a {advice.SuggestedLeadMs} ms", LogLevel.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ANTICIPO] {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void Settings_ClearBidLeadStatsClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var answer = MessageBox.Show(this,
|
||||
"Vuoi azzerare tutte le misure sull'anticipo?\n\n" +
|
||||
"Serviranno di nuovo diverse puntate prima di poter dare un consiglio.",
|
||||
"Misure anticipo", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
BidLeadStats.Clear();
|
||||
RefreshBidLeadSummary();
|
||||
Log("[ANTICIPO] Misure azzerate", LogLevel.Info);
|
||||
}
|
||||
|
||||
// ── Cartelle dei dati ────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Riempie i campi dei percorsi con quelli davvero in uso.
|
||||
///
|
||||
/// <para>I campi non restano mai vuoti: un campo vuoto costringeva a cercare altrove
|
||||
/// dove finiscono i file, ed è il motivo per cui sotto c'era una riga che ripeteva i
|
||||
/// percorsi. Scriverli direttamente nel campo toglie la ripetizione e rende il valore
|
||||
/// selezionabile e copiabile. Chi vuole tornare al predefinito lo svuota: al
|
||||
/// salvataggio si ricompila da sé.</para>
|
||||
/// </summary>
|
||||
private void RefreshDataFolderFields()
|
||||
{
|
||||
try
|
||||
{
|
||||
Settings.DataFolderTextBox.Text = AppPaths.DataFolder;
|
||||
Settings.StatsFolderTextBox.Text = AppPaths.StatsFolder;
|
||||
Settings.LogFolderTextBox.Text = AppPaths.LogFolder;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Traduce quello che c'è nel campo in ciò che va salvato.
|
||||
///
|
||||
/// <para>Il campo mostra sempre un percorso pieno, ma nelle impostazioni "vuoto"
|
||||
/// ha un significato che non si vuole perdere: <i>usa il predefinito</i>. Se il
|
||||
/// testo coincide con il predefinito corrente si salva vuoto — così spostando la
|
||||
/// cartella dati le sottocartelle la seguono — e se il campo è stato svuotato a mano
|
||||
/// si torna al predefinito. Solo un percorso davvero diverso viene registrato.</para>
|
||||
/// </summary>
|
||||
private static string NormalizeFolderChoice(string? typed, string resolvedDefault, string previouslySaved)
|
||||
{
|
||||
var text = typed?.Trim() ?? "";
|
||||
|
||||
if (text.Length == 0) return "";
|
||||
|
||||
// Uguale a ciò che è in uso, e in uso c'era il predefinito: resta predefinito.
|
||||
if (string.Equals(text, resolvedDefault, StringComparison.OrdinalIgnoreCase) &&
|
||||
string.IsNullOrWhiteSpace(previouslySaved))
|
||||
return "";
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
private void Settings_BrowseDataFolderClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var chosen = PickFolder("Scegli la cartella dei dati d'esercizio", AppPaths.DataFolder);
|
||||
if (chosen != null) Settings.DataFolderTextBox.Text = chosen;
|
||||
}
|
||||
|
||||
private void Settings_BrowseStatsFolderClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var chosen = PickFolder("Scegli la cartella delle statistiche", AppPaths.StatsFolder);
|
||||
if (chosen != null) Settings.StatsFolderTextBox.Text = chosen;
|
||||
}
|
||||
|
||||
private void Settings_BrowseLogFolderClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var chosen = PickFolder("Scegli la cartella dei registri", AppPaths.LogFolder);
|
||||
if (chosen != null) Settings.LogFolderTextBox.Text = chosen;
|
||||
}
|
||||
|
||||
private void Settings_OpenDataFolderClicked(object sender, RoutedEventArgs e)
|
||||
=> OpenFolder(AppPaths.DataFolder);
|
||||
|
||||
private void Settings_OpenStatsFolderClicked(object sender, RoutedEventArgs e)
|
||||
=> OpenFolder(AppPaths.StatsFolder);
|
||||
|
||||
private void Settings_OpenLogFolderClicked(object sender, RoutedEventArgs e)
|
||||
=> OpenFolder(AppPaths.LogFolder);
|
||||
|
||||
/// <summary>
|
||||
/// Selettore di cartella. Usa quello di WinForms perché WPF non ne offre uno:
|
||||
/// l'alternativa sarebbe una finestra scritta a mano, molto peggio.
|
||||
/// </summary>
|
||||
private static string? PickFolder(string description, string startFrom)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var dialog = new System.Windows.Forms.FolderBrowserDialog
|
||||
{
|
||||
Description = description,
|
||||
UseDescriptionForTitle = true,
|
||||
SelectedPath = Directory.Exists(startFrom) ? startFrom : "",
|
||||
ShowNewFolderButton = true
|
||||
};
|
||||
|
||||
return dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK
|
||||
? dialog.SelectedPath
|
||||
: null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenFolder(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
Process.Start(new ProcessStartInfo { FileName = path, UseShellExecute = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[DATI] Impossibile aprire {path}: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applica i percorsi dopo un salvataggio. Se sono cambiati serve un riavvio: gli
|
||||
/// archivi hanno già in memoria i dati letti dalla posizione precedente, e
|
||||
/// spostarli a caldo rischierebbe di mescolarli.
|
||||
/// </summary>
|
||||
private void ApplyDataFolderSettings(AppSettings settings, string previousData, string previousStats)
|
||||
{
|
||||
AppPaths.Configure(settings.DataFolder, settings.StatsFolder, settings.LogFolder);
|
||||
AppPaths.EnsureFolders();
|
||||
|
||||
// I campi tornano a mostrare i percorsi effettivi: chi ne ha svuotato uno deve
|
||||
// vedere subito qual è il predefinito che ha appena scelto.
|
||||
RefreshDataFolderFields();
|
||||
|
||||
if (previousData == AppPaths.DataFolder && previousStats == AppPaths.StatsFolder) return;
|
||||
|
||||
MessageBox.Show(this,
|
||||
"Le cartelle dei dati sono cambiate.\n\n" +
|
||||
$"Dati: {AppPaths.DataFolder}\nStatistiche: {AppPaths.StatsFolder}\n\n" +
|
||||
"Riavvia l'applicazione perché vengano usate davvero. I file già scritti " +
|
||||
"restano dove sono: puoi spostarli a mano nella nuova posizione.",
|
||||
"Cartelle dei dati", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
Log($"[DATI] Nuovi percorsi impostati (riavvio necessario)", LogLevel.Warning);
|
||||
}
|
||||
|
||||
// ── Esportazione dello storico ───────────────────────────────────
|
||||
|
||||
private void ExportStatsCsvButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RunExport(StatsExporter.ExportCsv(), "CSV");
|
||||
|
||||
private void ExportStatsJsonButton_Click(object sender, RoutedEventArgs e)
|
||||
=> RunExport(StatsExporter.ExportJson(), "JSON");
|
||||
|
||||
private void RunExport(StatsExporter.Result result, string format)
|
||||
{
|
||||
if (!result.Success)
|
||||
{
|
||||
MessageBox.Show(this, result.Error ?? "Esportazione non riuscita.",
|
||||
$"Esporta {format}", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
Log($"[EXPORT] {result.Records} aste esportate in {result.Path}", LogLevel.Success);
|
||||
|
||||
var answer = MessageBox.Show(this,
|
||||
$"Esportate {result.Records} aste in formato {format}.\n\n{result.Path}\n\n" +
|
||||
"Vuoi aprire la cartella?",
|
||||
$"Esporta {format}", MessageBoxButton.YesNo, MessageBoxImage.Information);
|
||||
|
||||
if (answer == MessageBoxResult.Yes)
|
||||
{
|
||||
OpenFolder(Path.GetDirectoryName(result.Path) ?? AppPaths.ExportFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Scheda Esporta: raccoglie in un unico file le aste che rispondono ai filtri.
|
||||
///
|
||||
/// <para>Qui c'è solo il collegamento fra il pannello e
|
||||
/// <see cref="AuctionExporter"/>. La scrittura può durare qualche secondo — con gli
|
||||
/// eventi inclusi si leggono decine di dossier — quindi gira su un thread di lavoro:
|
||||
/// bloccare l'interfaccia mentre il motore sta seguendo un'asta non è accettabile.</para>
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private async void Export_ExportRequested(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = Export.BuildFilter();
|
||||
|
||||
Log("[ESPORTA] Esportazione in corso…", LogLevel.Info);
|
||||
|
||||
var result = await System.Threading.Tasks.Task
|
||||
.Run(() => AuctionExporter.Export(filter))
|
||||
.ConfigureAwait(true);
|
||||
|
||||
Export.ShowResult(result);
|
||||
|
||||
Log(result.Success
|
||||
? $"[ESPORTA] {result.Message} → {result.Path}"
|
||||
: $"[ESPORTA] {result.Message}",
|
||||
result.Success ? LogLevel.Success : LogLevel.Warning);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ESPORTA] Esportazione non riuscita: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void Export_OpenFolderClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(AppPaths.ExportFolder);
|
||||
OpenInExplorer(AppPaths.ExportFolder);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ESPORTA] Apertura cartella non riuscita: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void Export_OpenLastFileClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var path = Export.LastExportPath;
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path)) return;
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(path) { UseShellExecute = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ESPORTA] Apertura file non riuscita: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apre una cartella in Esplora risorse. Sta qui perché la usano più schede: i
|
||||
/// pulsanti "apri" dei percorsi, le esportazioni e i registri.
|
||||
/// </summary>
|
||||
internal void OpenInExplorer(string folder)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(folder)) return;
|
||||
|
||||
Directory.CreateDirectory(folder);
|
||||
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = folder,
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[CARTELLE] Impossibile aprire {folder}: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.Services;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Scheda "Puntate": riscatto automatico delle ricompense, contatori e registro.
|
||||
///
|
||||
/// <para>Il lavoro vero sta in <see cref="FreeBidsAutoClaimService"/> e
|
||||
/// <see cref="BidooFreeBidsClaimer"/>: qui c'è solo il collegamento fra quei servizi e
|
||||
/// l'interfaccia, compreso il passaggio sul thread dell'interfaccia — il ciclo gira su
|
||||
/// un thread di lavoro e non deve toccare i controlli.</para>
|
||||
///
|
||||
/// <para>Resta invece manuale la parte consegnata per notifica push (OneSignal) e per
|
||||
/// email: quei premi sono agganciati all'abbonamento del browser, non all'account, e
|
||||
/// non esiste una chiamata da fare con il cookie di sessione.</para>
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private FreeBidsAutoClaimService? _freeBidsService;
|
||||
private BidooFreeBidsClaimer? _freeBidsClaimer;
|
||||
private BidooPromoRedeemer? _promoRedeemer;
|
||||
|
||||
/// <summary>Esito dell'ultima raccolta, da mostrare nella riga di stato.</summary>
|
||||
private string? _lastHarvestOutcome;
|
||||
|
||||
/// <summary>
|
||||
/// Indirizzi presi dai riferimenti configurati, non scritti qui: sono gli stessi che
|
||||
/// usa il riscatto automatico, e devono restare gli stessi anche quando cambiano —
|
||||
/// altrimenti «Apri su Bidoo» porterebbe a una pagina diversa da quella che
|
||||
/// l'applicazione sta davvero interrogando.
|
||||
/// </summary>
|
||||
private static FreeBidsSiteConfig FreeBidsConfig => FreeBidsConfigStore.Current;
|
||||
|
||||
private static string ChestsUrl => FreeBidsConfig.Url(FreeBidsConfig.Endpoints.Rewards);
|
||||
|
||||
private void StartFreeBidsService()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Alla prima esecuzione il file dei riferimenti non c'è: crearlo subito è il
|
||||
// modo per farne sapere l'esistenza a chi dovrà correggerlo.
|
||||
if (FreeBidsConfigStore.EnsureFileExists())
|
||||
Log($"[PUNTATE] Riferimenti del riscatto creati in {FreeBidsConfigStore.FilePath}", LogLevel.Info);
|
||||
|
||||
// Il file va letto davvero prima di poter dire se ha qualcosa che non va:
|
||||
// un problema non ancora incontrato non è un problema che si può segnalare.
|
||||
FreeBidsConfigStore.Reload();
|
||||
|
||||
if (FreeBidsConfigStore.LastProblem is { } problem)
|
||||
Log($"[PUNTATE] {problem}", LogLevel.Warning);
|
||||
|
||||
var transport = _auctionMonitor.GetApiClient().Transport;
|
||||
|
||||
_freeBidsClaimer = new BidooFreeBidsClaimer(transport)
|
||||
{
|
||||
Diagnostic = msg => Dispatcher.BeginInvoke(() => Log($"[PUNTATE] {msg}", LogLevel.Info))
|
||||
};
|
||||
|
||||
_promoRedeemer = new BidooPromoRedeemer(transport)
|
||||
{
|
||||
Diagnostic = msg => Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
Log($"[PUNTATE] {msg}", LogLevel.Info);
|
||||
FreeBids.AppendActivity(msg);
|
||||
})
|
||||
};
|
||||
|
||||
_freeBidsService = new FreeBidsAutoClaimService(_freeBidsClaimer, ReadBalanceAsync, _promoRedeemer);
|
||||
|
||||
_freeBidsService.OnLog += (message, isProblem) => Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
Log($"[PUNTATE] {message}", isProblem ? LogLevel.Warning : LogLevel.Success);
|
||||
FreeBids.AppendActivity(message, isProblem);
|
||||
});
|
||||
|
||||
_freeBidsService.OnCycleCompleted += _ => Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
if (_freeBidsService?.LastHarvest is { } harvest) _lastHarvestOutcome = harvest.Message;
|
||||
RefreshFreeBidsPanel();
|
||||
});
|
||||
|
||||
var settings = SettingsManager.Load();
|
||||
FreeBids.SetOptions(settings.FreeBidsAutoClaimEnabled, settings.FreeBidsCheckMinutes);
|
||||
|
||||
if (settings.FreeBidsAutoClaimEnabled) _freeBidsService.Start();
|
||||
|
||||
RefreshFreeBidsPanel();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Il riscatto è un accessorio: se non parte, il resto dell'applicazione
|
||||
// deve continuare a funzionare senza accorgersene.
|
||||
Log($"[PUNTATE] Riscatto automatico non avviato: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rilegge il saldo dal sito. Serve al servizio per misurare quante puntate ha
|
||||
/// portato davvero un riscatto, invece di fidarsi del messaggio di risposta.
|
||||
/// </summary>
|
||||
private async Task<int?> ReadBalanceAsync(CancellationToken ct)
|
||||
{
|
||||
await _auctionMonitor.UpdateUserInfoAsync().ConfigureAwait(false);
|
||||
return _auctionMonitor.GetSession()?.RemainingBids;
|
||||
}
|
||||
|
||||
private void RefreshFreeBidsPanel()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = _auctionMonitor.GetSession();
|
||||
FreeBids.SetBalance(session?.RemainingBids);
|
||||
|
||||
FreeBids.SetSchedule(
|
||||
running: _freeBidsService?.IsRunning == true,
|
||||
lastCheck: _freeBidsService?.LastCheckAt,
|
||||
nextCheck: _freeBidsService?.NextCheckAt);
|
||||
|
||||
FreeBids.SetCounters(FreeBidsStats.Read());
|
||||
FreeBids.SetConfigPath(FreeBidsConfigStore.FilePath, FreeBidsConfigStore.LastProblem);
|
||||
|
||||
FreeBids.SetHarvestStatus(
|
||||
FreeBidsConfig.PromoHarvest.SourceUrl,
|
||||
ClaimedPromoStore.ClaimedCount,
|
||||
_lastHarvestOutcome);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// ── Eventi della scheda ──────────────────────────────────────────
|
||||
|
||||
private async void FreeBids_RefreshBalanceClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _auctionMonitor.UpdateUserInfoAsync();
|
||||
RefreshFreeBidsPanel();
|
||||
UpdateRemainingBidsDisplay();
|
||||
|
||||
Log("[PUNTATE] Saldo aggiornato", LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PUNTATE] Aggiornamento saldo non riuscito: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async void FreeBids_CheckNowClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_freeBidsService == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
FreeBids.AppendActivity("Controllo richiesto a mano…");
|
||||
|
||||
var result = await _freeBidsService.CheckNowAsync();
|
||||
|
||||
if (result.IsSuccess && result.ClaimedCount == 0)
|
||||
FreeBids.AppendActivity(result.Message);
|
||||
|
||||
RefreshFreeBidsPanel();
|
||||
UpdateRemainingBidsDisplay();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PUNTATE] Controllo non riuscito: {ex.Message}", LogLevel.Error);
|
||||
FreeBids.AppendActivity($"controllo non riuscito: {ex.Message}", isProblem: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Apre la pagina nel browser predefinito di Windows, fuori dall'applicazione.</summary>
|
||||
private void FreeBids_OpenExternalClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(ChestsUrl) { UseShellExecute = true });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PUNTATE] Apertura nel browser esterno non riuscita: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FreeBids_OpenInternalClicked(object sender, RoutedEventArgs e)
|
||||
=> OpenInEmbeddedBrowser(ChestsUrl);
|
||||
|
||||
private void FreeBids_OpenVouchersClicked(object sender, RoutedEventArgs e)
|
||||
=> OpenInEmbeddedBrowser(FreeBidsConfig.Url(FreeBidsConfig.Endpoints.Vouchers));
|
||||
|
||||
private void FreeBids_OpenBuyBidsClicked(object sender, RoutedEventArgs e)
|
||||
=> OpenInEmbeddedBrowser(FreeBidsConfig.Url(FreeBidsConfig.Endpoints.BuyBids));
|
||||
|
||||
/// <summary>
|
||||
/// Riscatta il codice o il collegamento incollato dall'utente.
|
||||
///
|
||||
/// <para>Il saldo viene riletto in ogni caso: il messaggio del sito dice quello che
|
||||
/// vuole, la differenza di puntate sul conto no.</para>
|
||||
/// </summary>
|
||||
private async void FreeBids_ClaimPromoClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_freeBidsClaimer == null) return;
|
||||
|
||||
var code = FreeBids.PromoCode;
|
||||
|
||||
if (code.Length == 0)
|
||||
{
|
||||
FreeBids.AppendActivity("manca il codice o il collegamento da riscattare", isProblem: true);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
FreeBids.AppendActivity("Riscatto del codice richiesto a mano…");
|
||||
|
||||
var before = _auctionMonitor.GetSession()?.RemainingBids;
|
||||
var result = await _freeBidsClaimer.ClaimPromoAsync(code);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
FreeBids.AppendActivity(result.Message, isProblem: true);
|
||||
Log($"[PUNTATE] Riscatto codice non riuscito: {result.Message}", LogLevel.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
await _auctionMonitor.UpdateUserInfoAsync();
|
||||
|
||||
var after = _auctionMonitor.GetSession()?.RemainingBids;
|
||||
var gained = before.HasValue && after.HasValue ? Math.Max(0, after.Value - before.Value) : 0;
|
||||
|
||||
if (gained > 0) FreeBidsStats.RecordClaim(claimedCount: 1, bidsGained: gained);
|
||||
|
||||
FreeBids.AppendActivity(gained > 0
|
||||
? $"codice riscattato: +{gained} puntate"
|
||||
: $"codice accettato ({result.Message}), saldo invariato");
|
||||
|
||||
FreeBids.ClearPromoCode();
|
||||
RefreshFreeBidsPanel();
|
||||
UpdateRemainingBidsDisplay();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PUNTATE] Riscatto codice non riuscito: {ex.Message}", LogLevel.Error);
|
||||
FreeBids.AppendActivity($"riscatto non riuscito: {ex.Message}", isProblem: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Esegue subito una raccolta dei collegamenti pubblicati, senza aspettare il giro.
|
||||
///
|
||||
/// <para>Le puntate ottenute si misurano sul saldo prima e dopo: la pagina di Bidoo
|
||||
/// risponde allo stesso modo per un codice appena riscosso e per uno già usato.</para>
|
||||
/// </summary>
|
||||
private async void FreeBids_HarvestClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_promoRedeemer == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
FreeBids.AppendActivity("Raccolta dei collegamenti richiesta a mano…");
|
||||
|
||||
var before = _auctionMonitor.GetSession()?.RemainingBids;
|
||||
var report = await _promoRedeemer.HarvestAndRedeemAsync();
|
||||
|
||||
_lastHarvestOutcome = report.Message;
|
||||
|
||||
if (!report.SourceReadable)
|
||||
{
|
||||
FreeBids.AppendActivity(report.Message, isProblem: true);
|
||||
Log($"[PUNTATE] Raccolta non riuscita: {report.Message}", LogLevel.Warning);
|
||||
RefreshFreeBidsPanel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (report.Claimed > 0)
|
||||
{
|
||||
await _auctionMonitor.UpdateUserInfoAsync();
|
||||
|
||||
var after = _auctionMonitor.GetSession()?.RemainingBids;
|
||||
var gained = before.HasValue && after.HasValue ? Math.Max(0, after.Value - before.Value) : 0;
|
||||
|
||||
FreeBidsStats.RecordClaim(report.Claimed, gained);
|
||||
|
||||
FreeBids.AppendActivity(gained > 0
|
||||
? $"{report.Message}: +{gained} puntate"
|
||||
: $"{report.Message} (saldo invariato)");
|
||||
|
||||
UpdateRemainingBidsDisplay();
|
||||
}
|
||||
else
|
||||
{
|
||||
FreeBids.AppendActivity(report.Message);
|
||||
}
|
||||
|
||||
RefreshFreeBidsPanel();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PUNTATE] Raccolta non riuscita: {ex.Message}", LogLevel.Error);
|
||||
FreeBids.AppendActivity($"raccolta non riuscita: {ex.Message}", isProblem: true);
|
||||
}
|
||||
}
|
||||
|
||||
private void FreeBids_OpenPromoSourceClicked(object sender, RoutedEventArgs e)
|
||||
=> OpenInEmbeddedBrowser(FreeBidsConfig.PromoHarvest.SourceUrl);
|
||||
|
||||
/// <summary>
|
||||
/// Azzera la memoria dei collegamenti già aperti. Serve dopo un cambio di account:
|
||||
/// i codici presi da un utente non dicono nulla su quelli disponibili per un altro.
|
||||
/// </summary>
|
||||
private void FreeBids_ForgetPromosClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var answer = MessageBox.Show(this,
|
||||
$"Vuoi dimenticare i {ClaimedPromoStore.ClaimedCount} codici già presi?\n\n" +
|
||||
"Alla raccolta successiva verranno riaperti tutti i collegamenti pubblicati, " +
|
||||
"compresi quelli già usati: serve dopo un cambio di account, non nell'uso normale.",
|
||||
"Puntate", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
ClaimedPromoStore.Clear();
|
||||
_lastHarvestOutcome = null;
|
||||
RefreshFreeBidsPanel();
|
||||
|
||||
Log("[PUNTATE] Memoria dei collegamenti azzerata", LogLevel.Info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apre <c>site-config.json</c> con l'editor predefinito. Il file viene creato se
|
||||
/// manca: aprire il vuoto non direbbe a nessuno quali valori si possono cambiare.
|
||||
/// </summary>
|
||||
private void FreeBids_OpenConfigClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
FreeBidsConfigStore.EnsureFileExists();
|
||||
|
||||
Process.Start(new ProcessStartInfo(FreeBidsConfigStore.FilePath) { UseShellExecute = true });
|
||||
|
||||
FreeBids.AppendActivity(
|
||||
"Riferimenti aperti: salva il file e premi «Controlla adesso», " +
|
||||
"le modifiche valgono subito.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PUNTATE] Apertura dei riferimenti non riuscita: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FreeBids_ResetCountersClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var answer = MessageBox.Show(this,
|
||||
"Vuoi azzerare i contatori dei riscatti?\n\n" +
|
||||
"Si perde il totale storico delle puntate raccolte. Le puntate sul conto non vengono toccate.",
|
||||
"Puntate", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
FreeBidsStats.Clear();
|
||||
RefreshFreeBidsPanel();
|
||||
Log("[PUNTATE] Contatori azzerati", LogLevel.Info);
|
||||
}
|
||||
|
||||
private void FreeBids_OptionsChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = SettingsManager.Load();
|
||||
settings.FreeBidsAutoClaimEnabled = FreeBids.AutoClaimEnabled;
|
||||
settings.FreeBidsCheckMinutes = FreeBids.CheckMinutes;
|
||||
SettingsManager.Save(settings);
|
||||
|
||||
if (_freeBidsService != null)
|
||||
{
|
||||
if (settings.FreeBidsAutoClaimEnabled && !_freeBidsService.IsRunning)
|
||||
{
|
||||
_freeBidsService.Start();
|
||||
Log($"[PUNTATE] Riscatto automatico attivo, ogni {settings.FreeBidsCheckMinutes} minuti", LogLevel.Success);
|
||||
}
|
||||
else if (!settings.FreeBidsAutoClaimEnabled && _freeBidsService.IsRunning)
|
||||
{
|
||||
_freeBidsService.Stop();
|
||||
Log("[PUNTATE] Riscatto automatico spento", LogLevel.Info);
|
||||
}
|
||||
}
|
||||
|
||||
RefreshFreeBidsPanel();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PUNTATE] Impostazioni non salvate: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apre una pagina nel browser integrato. Deve essere quello, non il browser di
|
||||
/// sistema: è lì che la sessione è attiva ed è lì che vanno concesse le notifiche.
|
||||
/// </summary>
|
||||
private void OpenInEmbeddedBrowser(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
TabBrowser.IsChecked = true;
|
||||
Browser.ShowBrowser();
|
||||
Browser.EmbeddedWebView?.CoreWebView2?.Navigate(url);
|
||||
Browser.BrowserAddress.Text = url;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PUNTATE] Apertura pagina non riuscita: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,33 +6,79 @@ using AutoBidder.Utilities;
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Logging functionality with color-coded severity levels
|
||||
/// Logging functionality with color-coded severity levels and configurable minimum level filtering
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// Scrive un messaggio nel log globale con filtraggio basato sul livello minimo configurato
|
||||
/// </summary>
|
||||
/// <param name="message">Messaggio da loggare</param>
|
||||
/// <param name="level">Livello di severit� del messaggio</param>
|
||||
private void Log(string message, LogLevel level = LogLevel.Info)
|
||||
{
|
||||
// Il file si scrive subito, fuori dal Dispatcher e senza filtro di livello:
|
||||
// il registro serve proprio quando qualcosa è andato storto, e in quel momento
|
||||
// il messaggio utile è spesso uno di quelli che a video sono nascosti. La
|
||||
// scrittura è accodata, quindi non costa nulla al chiamante.
|
||||
TextLogService.App(LevelTag(level), message);
|
||||
|
||||
Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// Carica impostazioni per ottenere livello minimo e limite righe
|
||||
var settings = SettingsManager.Load();
|
||||
|
||||
// Filtra messaggi in base al livello minimo configurato
|
||||
MinimumLogLevel minLevel = MinimumLogLevel.Normal; // Default
|
||||
if (Enum.TryParse<MinimumLogLevel>(settings.MinLogLevel, out var parsedLevel))
|
||||
{
|
||||
minLevel = parsedLevel;
|
||||
}
|
||||
|
||||
// Se il livello del messaggio � maggiore del minimo configurato, ignora
|
||||
if ((int)level > (int)minLevel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var timestamp = DateTime.Now.ToString("HH:mm:ss");
|
||||
var logEntry = $"[{timestamp}] {message}";
|
||||
|
||||
var logEntry = $"[{timestamp}] [{LevelTag(level)}] {message}";
|
||||
|
||||
// Color coding based on severity for dark theme
|
||||
var color = level switch
|
||||
{
|
||||
LogLevel.Error => new SolidColorBrush(Color.FromRgb(232, 17, 35)), // #E81123 (Red)
|
||||
LogLevel.Warn => new SolidColorBrush(Color.FromRgb(255, 183, 0)), // #FFB700 (Yellow/Orange)
|
||||
LogLevel.Success => new SolidColorBrush(Color.FromRgb(0, 216, 0)), // #00D800 (Green)
|
||||
LogLevel.Info => new SolidColorBrush(Color.FromRgb(0, 122, 204)), // #007ACC (Blue)
|
||||
_ => new SolidColorBrush(Color.FromRgb(204, 204, 204)) // #CCCCCC (Light Gray)
|
||||
LogLevel.Error => new SolidColorBrush(Color.FromRgb(232, 17, 35)), // #E81123 (Red)
|
||||
LogLevel.Warning => new SolidColorBrush(Color.FromRgb(255, 191, 0)), // #FFBF00 (Yellow)
|
||||
LogLevel.Success => new SolidColorBrush(Color.FromRgb(0, 216, 0)), // #00D800 (Green)
|
||||
LogLevel.Info => new SolidColorBrush(Color.FromRgb(100, 180, 255)), // #64B4FF (Light Blue)
|
||||
LogLevel.Debug => new SolidColorBrush(Color.FromRgb(255, 140, 255)), // #FF8CFF (Magenta)
|
||||
LogLevel.Trace => new SolidColorBrush(Color.FromRgb(160, 160, 160)), // #A0A0A0 (Gray)
|
||||
_ => new SolidColorBrush(Color.FromRgb(204, 204, 204)) // #CCCCCC (Light Gray)
|
||||
};
|
||||
|
||||
var p = new System.Windows.Documents.Paragraph { Margin = new Thickness(0, 2, 0, 2) };
|
||||
var r = new System.Windows.Documents.Run(logEntry) { Foreground = color };
|
||||
p.Inlines.Add(r);
|
||||
LogBox.Document.Blocks.Add(p);
|
||||
|
||||
// Mantieni solo gli ultimi N paragrafi (configurabile dalle impostazioni)
|
||||
int maxLogLines = settings.MaxGlobalLogLines;
|
||||
|
||||
if (LogBox.Document.Blocks.Count > maxLogLines)
|
||||
{
|
||||
// Rimuovi i paragrafi pi� vecchi (primi inseriti)
|
||||
int excessCount = LogBox.Document.Blocks.Count - maxLogLines;
|
||||
for (int i = 0; i < excessCount; i++)
|
||||
{
|
||||
if (LogBox.Document.Blocks.FirstBlock != null)
|
||||
{
|
||||
LogBox.Document.Blocks.Remove(LogBox.Document.Blocks.FirstBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-scroll if near bottom
|
||||
if (LogBox.VerticalOffset >= LogBox.ExtentHeight - LogBox.ViewportHeight - 40)
|
||||
@@ -44,23 +90,19 @@ namespace AutoBidder
|
||||
});
|
||||
}
|
||||
|
||||
private void ClearGlobalLogButton_Click(object sender, RoutedEventArgs e)
|
||||
/// <summary>
|
||||
/// Sigla del livello, uguale a video e su file: due formati diversi renderebbero
|
||||
/// impossibile ritrovare nel file la riga che si è vista nella finestra.
|
||||
/// </summary>
|
||||
private static string LevelTag(LogLevel level) => level switch
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = MessageBox.Show(
|
||||
"Cancellare il log globale?",
|
||||
"Conferma Pulizia",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
LogBox.Document.Blocks.Clear();
|
||||
Log("[OK] Log globale pulito", LogLevel.Success);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
LogLevel.Error => "ERROR",
|
||||
LogLevel.Warning => "WARN",
|
||||
LogLevel.Info => "INFO",
|
||||
LogLevel.Success => "OK",
|
||||
LogLevel.Debug => "DEBUG",
|
||||
LogLevel.Trace => "TRACE",
|
||||
_ => "LOG"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.Utilities;
|
||||
using AutoBidder.ViewModels;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Barra strumenti del Monitor: contatori delle aste e stato del motore.
|
||||
///
|
||||
/// Sono informazioni che cambiano di continuo ma non a ogni singolo poll: un
|
||||
/// battito fisso di un secondo le tiene aggiornate senza far ridisegnare la
|
||||
/// barra decine di volte al secondo.
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private DispatcherTimer? _headerTimer;
|
||||
|
||||
private void StartMonitorHeaderTimer()
|
||||
{
|
||||
_headerTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };
|
||||
_headerTimer.Tick += (_, _) => RefreshMonitorHeader();
|
||||
_headerTimer.Start();
|
||||
|
||||
RefreshMonitorHeader();
|
||||
}
|
||||
|
||||
private void RefreshMonitorHeader()
|
||||
{
|
||||
try
|
||||
{
|
||||
var vms = _auctionViewModels;
|
||||
|
||||
var active = 0;
|
||||
var watch = 0;
|
||||
var stopped = 0;
|
||||
var won = 0;
|
||||
var lost = 0;
|
||||
|
||||
foreach (var vm in vms)
|
||||
{
|
||||
switch (vm.StatusKind)
|
||||
{
|
||||
case "won": won++; break;
|
||||
case "lost": lost++; break;
|
||||
case "leading":
|
||||
case "active": active++; break;
|
||||
case "watch": watch++; break;
|
||||
default: stopped++; break;
|
||||
}
|
||||
}
|
||||
|
||||
AuctionMonitor.UpdateCounters(vms.Count, active, watch, stopped, won, lost);
|
||||
|
||||
var clock = _auctionMonitor.Clock;
|
||||
AuctionMonitor.UpdateEngineStatus(
|
||||
_auctionMonitor.RequestsSent, clock.IsSynced, clock.SampleCount, clock.AverageLatencyMs);
|
||||
|
||||
RefreshAccountPills();
|
||||
|
||||
// Lo stato dei pulsanti globali dipende da tutte le aste: ricalcolarlo a
|
||||
// ogni risposta di ogni asta era uno scorrimento completo dell'elenco
|
||||
// decine di volte al secondo. Una volta al secondo è più che sufficiente.
|
||||
UpdateGlobalControlButtons();
|
||||
|
||||
if (_selectedAuction != null) RefreshSelectedStats(_selectedAuction);
|
||||
}
|
||||
catch { /* la barra informativa non deve mai disturbare il resto */ }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Puntate, credito e vincite da confermare, riletti dalla sessione viva a ogni
|
||||
/// battito.
|
||||
///
|
||||
/// <para>Prima ciascuno di questi numeri veniva scritto da chi lo aggiornava —
|
||||
/// il ripristino della sessione, il timer di rinfresco, il codice dopo la puntata —
|
||||
/// e bastava che uno dei tre non passasse perché la barra restasse su un valore
|
||||
/// vecchio. Rileggerli qui costa una lettura di campo al secondo e toglie di mezzo
|
||||
/// tutta quella categoria di errori.</para>
|
||||
/// </summary>
|
||||
private void RefreshAccountPills()
|
||||
{
|
||||
var session = _auctionMonitor.GetSession();
|
||||
|
||||
var connected = session != null && !string.IsNullOrEmpty(session.Username);
|
||||
|
||||
AuctionMonitor.UpdateAccountStatus(
|
||||
connected ? session!.RemainingBids : null,
|
||||
connected ? (decimal)session!.ShopCredit : null,
|
||||
AuctionsToConfirm);
|
||||
|
||||
UpdateMinBidsIndicator(SettingsManager.Load().MinimumRemainingBids);
|
||||
}
|
||||
|
||||
/// <summary>Contatori del motore relativi alla sola asta selezionata.</summary>
|
||||
private void RefreshSelectedStats(AuctionViewModel vm)
|
||||
{
|
||||
try
|
||||
{
|
||||
var info = vm.AuctionInfo;
|
||||
AuctionMonitor.UpdateSelectedStats(
|
||||
info.ResetCount,
|
||||
info.BidsUsedOnThisAuction ?? vm.MyClicks,
|
||||
info.AverageLatencyMs,
|
||||
info.PollCount,
|
||||
info.PollErrors);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scheda Prodotto: costo totale se si vince e verdetto di convenienza.
|
||||
/// </summary>
|
||||
private void RefreshProductVerdict(AuctionViewModel? vm)
|
||||
{
|
||||
try
|
||||
{
|
||||
var totalBox = AuctionMonitor.FindName("ProductTotalCostText") as System.Windows.Controls.TextBlock;
|
||||
var value = vm?.AuctionInfo.CalculatedValue;
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
if (totalBox != null) totalBox.Text = "—";
|
||||
AuctionMonitor.SetVerdict("Convenienza", "non calcolabile", "neutral");
|
||||
return;
|
||||
}
|
||||
|
||||
if (totalBox != null) totalBox.Text = $"{value.TotalCostIfWin:F2} €";
|
||||
|
||||
if (value.Savings is not { } savings)
|
||||
{
|
||||
AuctionMonitor.SetVerdict("Convenienza", "valore prodotto ignoto", "neutral");
|
||||
return;
|
||||
}
|
||||
|
||||
var pct = Math.Abs(value.SavingsPercentage ?? 0);
|
||||
AuctionMonitor.SetVerdict(
|
||||
savings > 0 ? "Risparmio" : "Sovrapprezzo",
|
||||
$"{Math.Abs(savings):F2} € ({pct:F1}%)",
|
||||
savings > 0 ? "ok" : "danger");
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "Rimuovi le aste concluse": ripulisce l'elenco da ciò che non serve più
|
||||
/// senza toccare quelle ancora in corso.
|
||||
/// </summary>
|
||||
private void AuctionMonitor_RemoveFinishedClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var finished = _auctionViewModels
|
||||
.Where(a => a.StatusKind is "won" or "lost")
|
||||
.ToList();
|
||||
|
||||
if (finished.Count == 0)
|
||||
{
|
||||
MessageBox.Show(this, "Nessuna asta conclusa da rimuovere.", "Aste concluse",
|
||||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var vm in finished)
|
||||
{
|
||||
_auctionMonitor.RemoveAuction(vm.AuctionId);
|
||||
_auctionViewModels.Remove(vm);
|
||||
}
|
||||
|
||||
if (_selectedAuction != null && !_auctionViewModels.Contains(_selectedAuction))
|
||||
_selectedAuction = null;
|
||||
|
||||
SaveAuctions();
|
||||
UpdateTotalCount();
|
||||
UpdateGlobalControlButtons();
|
||||
RefreshMonitorHeader();
|
||||
|
||||
Log($"[REMOVE] Rimosse {finished.Count} aste concluse", LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Rimozione aste concluse: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.Services;
|
||||
using AutoBidder.Utilities;
|
||||
using AutoBidder.ViewModels;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Prodotti seguiti: le aste nuove dello stesso articolo entrano nel monitor da sole.
|
||||
///
|
||||
/// L'aggiunta qui deve essere silenziosa — succede mentre l'utente sta facendo altro,
|
||||
/// quindi niente finestre di dialogo: solo righe di log.
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private ProductWatchService? _productWatcher;
|
||||
|
||||
/// <summary>Aste presenti nel monitor perché aggiunte automaticamente.</summary>
|
||||
private readonly HashSet<string> _autoAddedAuctionIds = new(StringComparer.Ordinal);
|
||||
|
||||
private void StartProductWatcher()
|
||||
{
|
||||
try
|
||||
{
|
||||
_productWatcher = new ProductWatchService(CatalogClient)
|
||||
{
|
||||
CountAutoAdded = () => _autoAddedAuctionIds.Count(id =>
|
||||
_auctionViewModels.Any(a => a.AuctionId == id))
|
||||
};
|
||||
|
||||
_productWatcher.OnLog += msg => Dispatcher.BeginInvoke(() => Log(msg, LogLevel.Info));
|
||||
_productWatcher.OnAuctionFound += (auction, product) =>
|
||||
Dispatcher.BeginInvoke(() => AutoAddAuction(auction, product));
|
||||
|
||||
_productWatcher.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[SEGUITI] Impossibile avviare la sorveglianza: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunge al monitor un'asta trovata dalla sorveglianza. Volutamente separata da
|
||||
/// AddAuctionById: quella mostra finestre di dialogo, qui inaccettabili.
|
||||
/// </summary>
|
||||
private void AutoAddAuction(CatalogAuction auction, WatchedProduct product)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Marcala comunque: anche se la scartiamo, non va riproposta a ogni giro.
|
||||
WatchedProductsStore.MarkHandled(auction.AuctionId);
|
||||
|
||||
if (_auctionViewModels.Any(a => a.AuctionId == auction.AuctionId)) return;
|
||||
|
||||
var settings = SettingsManager.Load();
|
||||
|
||||
// I limiti del prodotto, dove ci sono, hanno la precedenza sui predefiniti:
|
||||
// è il senso della scheda Prodotti.
|
||||
var limits = ProductRuleResolver.Resolve(product, settings);
|
||||
|
||||
var info = new AuctionInfo
|
||||
{
|
||||
AuctionId = auction.AuctionId,
|
||||
Name = DecodeAllHtmlEntities(auction.Name),
|
||||
OriginalUrl = auction.Url,
|
||||
BidBeforeDeadlineMs = settings.DefaultBidBeforeDeadlineMs,
|
||||
BuyNowPrice = auction.BuyNowPrice.HasValue ? (double)auction.BuyNowPrice.Value : null,
|
||||
State = limits.State
|
||||
};
|
||||
|
||||
_auctionMonitor.AddAuction(info);
|
||||
|
||||
var vm = new AuctionViewModel(info)
|
||||
{
|
||||
MinPrice = limits.MinPrice,
|
||||
MaxPrice = limits.MaxPrice,
|
||||
MaxClicks = limits.MaxClicks
|
||||
};
|
||||
_auctionViewModels.Add(vm);
|
||||
_autoAddedAuctionIds.Add(auction.AuctionId);
|
||||
|
||||
// Un'asta che entra in Osserva o Attiva ha bisogno del motore acceso.
|
||||
if (info.State != RunState.Stopped && !_isAutomationActive)
|
||||
{
|
||||
_auctionMonitor.Start();
|
||||
_isAutomationActive = true;
|
||||
}
|
||||
|
||||
WatchedProductsStore.CountAutoAdd(product);
|
||||
|
||||
SaveAuctions();
|
||||
UpdateTotalCount();
|
||||
UpdateGlobalControlButtons();
|
||||
RefreshMonitorHeader();
|
||||
|
||||
var origine = limits.FromProduct ? " — limiti del prodotto" : "";
|
||||
Log($"[SEGUITI] Aggiunta automaticamente: {info.Name} ({StateLabel(product.AutoAddState ?? settings.AutoAddNewAuctionState)}){origine}",
|
||||
LogLevel.Success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[SEGUITI] Aggiunta automatica non riuscita: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Applica a caldo le impostazioni della sorveglianza dopo un salvataggio.</summary>
|
||||
private void ApplyProductWatchSettings(AppSettings settings)
|
||||
{
|
||||
if (_productWatcher == null) return;
|
||||
|
||||
if (settings.AutoAddProductsEnabled && !_productWatcher.IsRunning) _productWatcher.Start();
|
||||
else if (!settings.AutoAddProductsEnabled && _productWatcher.IsRunning) _productWatcher.Stop();
|
||||
}
|
||||
|
||||
// L'elenco dei prodotti, con stellina e limiti, vive ora nella scheda Prodotti:
|
||||
// vedi MainWindow.Products.cs. Qui restano solo l'avvio della sorveglianza e
|
||||
// l'aggiunta automatica delle aste che trova.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.Utilities;
|
||||
using AutoBidder.ViewModels;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Scheda Prodotti: l'elenco degli articoli con la stellina e i limiti su misura.
|
||||
///
|
||||
/// <para>Raccoglie in un posto solo ciò che prima stava diviso fra le Impostazioni
|
||||
/// (l'elenco dei prodotti seguiti) e i valori predefiniti delle aste. Ragionare per
|
||||
/// prodotto è il modo naturale di usare Bidoo, che rimette all'asta lo stesso articolo
|
||||
/// di continuo: i limiti giusti per un buono da 50 € non sono quelli di un telefono.</para>
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private readonly ObservableCollection<ProductViewModel> _productViewModels = new();
|
||||
|
||||
/// <summary>Stellina di una riga della scheda Prodotti.</summary>
|
||||
public RelayCommand? ProductWatchCommand { get; private set; }
|
||||
|
||||
/// <summary>Applica i limiti consigliati alla singola riga.</summary>
|
||||
public RelayCommand? ProductApplyAdviceCommand { get; private set; }
|
||||
|
||||
private void InitializeProductCommands()
|
||||
{
|
||||
ProductWatchCommand = new RelayCommand(p => ToggleProductWatch(p as ProductViewModel));
|
||||
ProductApplyAdviceCommand = new RelayCommand(p => ApplyAdviceToProduct(p as ProductViewModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ricostruisce l'elenco unendo le schede prodotto e lo storico. Le statistiche
|
||||
/// arrivano dallo stesso aggregato che alimenta la scheda Statistiche: un solo modo
|
||||
/// di calcolarle, così i due pannelli non possono raccontare numeri diversi.
|
||||
/// </summary>
|
||||
private void LoadProducts()
|
||||
{
|
||||
try
|
||||
{
|
||||
var selectedIdentity = Products.SelectedProduct?.Identity;
|
||||
|
||||
var stats = CompletedAuctionsStore.AggregateByProduct()
|
||||
.GroupBy(s => s.ProductKey, StringComparer.Ordinal)
|
||||
.ToDictionary(g => g.Key, g => g.First(), StringComparer.Ordinal);
|
||||
|
||||
_productViewModels.Clear();
|
||||
|
||||
foreach (var rule in WatchedProductsStore.GetAll()
|
||||
.OrderByDescending(r => r.IsWatched)
|
||||
.ThenBy(r => r.DisplayName, StringComparer.CurrentCultureIgnoreCase))
|
||||
{
|
||||
stats.TryGetValue(StatsKeyFor(rule), out var summary);
|
||||
_productViewModels.Add(new ProductViewModel(rule, summary));
|
||||
}
|
||||
|
||||
Products.SetProducts(_productViewModels);
|
||||
|
||||
// Ricaricare non deve far perdere il posto in cui si stava lavorando.
|
||||
if (selectedIdentity != null) Products.SelectProduct(selectedIdentity);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PRODOTTI] Caricamento non riuscito: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiave con cui il prodotto compare nello storico. Le schede salvate senza chiave
|
||||
/// (le più vecchie) la ricavano dal nome, com'è per le aste concluse.
|
||||
/// </summary>
|
||||
private static string StatsKeyFor(WatchedProduct rule) =>
|
||||
string.IsNullOrEmpty(rule.ProductKey)
|
||||
? ProductKeyHelper.GenerateProductKey(rule.DisplayName)
|
||||
: rule.ProductKey;
|
||||
|
||||
private void ToggleProductWatch(ProductViewModel? product)
|
||||
{
|
||||
if (product == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
product.IsWatched = !product.IsWatched;
|
||||
WatchedProductsStore.Persist();
|
||||
|
||||
Products.RefreshCounters();
|
||||
MarkWatchedProducts(_catalogAuctions);
|
||||
|
||||
Log(product.IsWatched
|
||||
? $"[PRODOTTI] Ora seguo: {product.DisplayName}"
|
||||
: $"[PRODOTTI] Non seguo più: {product.DisplayName} (i limiti restano)",
|
||||
LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PRODOTTI] {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mette il prodotto in elenco e apre la scheda Prodotti su quella riga. È la strada
|
||||
/// dell'ingranaggio sulle schede del catalogo: serve a dare limiti a un articolo
|
||||
/// anche senza volerlo seguire.
|
||||
/// </summary>
|
||||
private void ConfigureCatalogProduct(CatalogAuction? auction)
|
||||
{
|
||||
if (auction == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
var existing = WatchedProductsStore.FindFor(auction);
|
||||
|
||||
if (existing == null)
|
||||
{
|
||||
// Senza stellina: chi arriva da qui vuole i limiti, non l'aggiunta automatica.
|
||||
WatchedProductsStore.Add(auction, watched: false);
|
||||
Log($"[PRODOTTI] Aggiunto all'elenco: {auction.Name}", LogLevel.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[PRODOTTI] {auction.Name} era già in elenco: apro la sua riga", LogLevel.Info);
|
||||
}
|
||||
|
||||
MarkWatchedProducts(_catalogAuctions);
|
||||
|
||||
// Il cambio scheda ricarica già l'elenco, ma solo se la scheda cambia
|
||||
// davvero: ricaricare qui rende la riga nuova visibile in ogni caso.
|
||||
TabProdotti.IsChecked = true;
|
||||
LoadProducts();
|
||||
|
||||
var identity = WatchedProductsStore.FindFor(auction)?.Identity;
|
||||
if (identity != null) Products.SelectProduct(identity);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PRODOTTI] Aggiunta non riuscita: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Eventi della scheda ──────────────────────────────────────────
|
||||
|
||||
private void Products_RefreshClicked(object sender, RoutedEventArgs e) => LoadProducts();
|
||||
|
||||
private void Products_ProductLimitsEdited(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
PersistProductLimits();
|
||||
|
||||
// Il tetto consigliato dipende dalle puntate massime: se è quella che è
|
||||
// appena cambiata, la colonna accanto deve rifarsi il conto.
|
||||
Products.SelectedProduct?.RefreshAdvice();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[PRODOTTI] Salvataggio non riuscito: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void Products_ProductSelectionChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Il riquadro statistiche si aggiorna da solo: è legato alla riga selezionata.
|
||||
}
|
||||
|
||||
private async void Products_ScanNowClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_productWatcher == null) return;
|
||||
|
||||
Log("[PRODOTTI] Cerco aste dei prodotti seguiti…", LogLevel.Info);
|
||||
await _productWatcher.ScanNowAsync();
|
||||
LoadProducts();
|
||||
}
|
||||
|
||||
private void Products_RemoveClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var product = Products.SelectedProduct;
|
||||
if (product == null)
|
||||
{
|
||||
MessageBox.Show(this, "Seleziona prima un prodotto dall'elenco.",
|
||||
"Prodotti", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
var answer = MessageBox.Show(this,
|
||||
$"Vuoi togliere \"{product.DisplayName}\" dall'elenco?\n\n" +
|
||||
"Si perdono i limiti impostati per questo prodotto. Le aste già nel monitor restano dove sono.",
|
||||
"Prodotti", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
WatchedProductsStore.RemoveByIdentity(product.Identity);
|
||||
LoadProducts();
|
||||
MarkWatchedProducts(_catalogAuctions);
|
||||
|
||||
Log($"[PRODOTTI] Tolto dall'elenco: {product.DisplayName}", LogLevel.Info);
|
||||
}
|
||||
|
||||
private void Products_ClearClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_productViewModels.Count == 0) return;
|
||||
|
||||
var answer = MessageBox.Show(this,
|
||||
$"Vuoi svuotare l'elenco dei {_productViewModels.Count} prodotti?\n\n" +
|
||||
"Si perdono tutti i limiti impostati. Le aste già nel monitor restano dove sono.",
|
||||
"Prodotti", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
WatchedProductsStore.Clear();
|
||||
LoadProducts();
|
||||
MarkWatchedProducts(_catalogAuctions);
|
||||
|
||||
Log("[PRODOTTI] Elenco svuotato", LogLevel.Info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scrive nei limiti del prodotto i valori consigliati dallo storico — minimo e
|
||||
/// massimo insieme, perché è la coppia a definire la finestra in cui ha senso
|
||||
/// puntare: un tetto senza pavimento lascia sprecare puntate su aste ancora lontane
|
||||
/// dalla chiusura, un pavimento senza tetto non protegge da niente.
|
||||
/// </summary>
|
||||
private void ApplyAdviceToProduct(ProductViewModel? product)
|
||||
{
|
||||
if (product == null) return;
|
||||
|
||||
if (!product.ApplyAdvice())
|
||||
{
|
||||
MessageBox.Show(this,
|
||||
$"Per \"{product.DisplayName}\" non ci sono abbastanza aste concluse " +
|
||||
$"(ne servono almeno {PriceAdvisor.MinimumSample}) per ricavare un consiglio.",
|
||||
"Limiti consigliati", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
PersistProductLimits();
|
||||
|
||||
Log($"[PRODOTTI] {product.DisplayName}: limiti consigliati applicati " +
|
||||
$"({product.SuggestedMinPrice:F2} € – {product.SuggestedMaxPrice:F2} €)",
|
||||
LogLevel.Success);
|
||||
|
||||
if (product.AdviceWarns)
|
||||
{
|
||||
Log($"[PRODOTTI] {product.DisplayName}: il tetto è sotto il prezzo tipico di " +
|
||||
"aggiudicazione — con questo numero di puntate l'articolo non conviene.",
|
||||
LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void Products_ApplySuggestedClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var product = Products.SelectedProduct;
|
||||
if (product == null)
|
||||
{
|
||||
MessageBox.Show(this, "Seleziona prima un prodotto dall'elenco.",
|
||||
"Limiti consigliati", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyAdviceToProduct(product);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applica i limiti consigliati a tutto l'elenco.
|
||||
///
|
||||
/// <para>Chiede conferma dicendo <b>quante righe cambierebbe davvero</b>, non quante
|
||||
/// ce ne sono: su un elenco dove la metà è già a posto, "applico a 40 prodotti"
|
||||
/// sarebbe una risposta a una domanda che nessuno ha fatto. I prodotti senza abbastanza
|
||||
/// storico restano intoccati, e quelli su cui il consiglio avverte vengono contati a
|
||||
/// parte: sono i casi da guardare a mano.</para>
|
||||
/// </summary>
|
||||
private void Products_ApplyAllSuggestedClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var candidates = _productViewModels.Where(p => p.HasAdvice && !p.MatchesAdvice).ToList();
|
||||
var senzaStorico = _productViewModels.Count(p => !p.HasAdvice);
|
||||
|
||||
if (candidates.Count == 0)
|
||||
{
|
||||
MessageBox.Show(this,
|
||||
senzaStorico == _productViewModels.Count
|
||||
? $"Nessun prodotto ha abbastanza aste concluse (ne servono almeno " +
|
||||
$"{PriceAdvisor.MinimumSample}) per ricavare un consiglio."
|
||||
: "I limiti consigliati sono già scritti su tutti i prodotti che ne hanno uno.",
|
||||
"Limiti consigliati", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
var avvisi = candidates.Count(p => p.AdviceWarns);
|
||||
|
||||
var messaggio =
|
||||
$"Scrivo i limiti consigliati su {candidates.Count} " +
|
||||
(candidates.Count == 1 ? "prodotto" : "prodotti") + ".\n\n" +
|
||||
"I valori scritti a mano su quei prodotti verranno sostituiti.";
|
||||
|
||||
if (senzaStorico > 0)
|
||||
messaggio += $"\n\n{senzaStorico} prodotti restano invariati: non hanno abbastanza aste concluse.";
|
||||
|
||||
if (avvisi > 0)
|
||||
messaggio += $"\n\nAttenzione: su {avvisi} il tetto resta sotto il prezzo tipico di " +
|
||||
"aggiudicazione — con le puntate impostate quegli articoli non convengono.";
|
||||
|
||||
messaggio += "\n\nProcedo?";
|
||||
|
||||
var answer = MessageBox.Show(this, messaggio, "Limiti consigliati",
|
||||
MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
var applicati = candidates.Count(p => p.ApplyAdvice());
|
||||
|
||||
PersistProductLimits();
|
||||
|
||||
Log($"[PRODOTTI] Limiti consigliati applicati a {applicati} prodotti" +
|
||||
(avvisi > 0 ? $" ({avvisi} con avviso di convenienza)" : ""),
|
||||
LogLevel.Success);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rende durevoli i limiti e li rispecchia nella scheda prodotto. Le due scritture
|
||||
/// vanno sempre insieme: <c>watched-products.json</c> è la fonte di verità,
|
||||
/// <c>products.json</c> è il file che si apre per capire com'è impostato un articolo,
|
||||
/// e disallinearli vuol dire avere due risposte alla stessa domanda.
|
||||
/// </summary>
|
||||
private void PersistProductLimits()
|
||||
{
|
||||
WatchedProductsStore.Persist();
|
||||
ProductStatsStore.SyncOptionsFromWatchList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Riscrive i limiti del prodotto sulle aste di quell'articolo già presenti nel
|
||||
/// monitor. Serve la conferma perché sovrascrive anche i ritocchi fatti a mano su
|
||||
/// una singola asta, che è esattamente ciò che qualcuno potrebbe non volere.
|
||||
/// </summary>
|
||||
private void Products_ReapplyClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var product = Products.SelectedProduct;
|
||||
if (product == null)
|
||||
{
|
||||
MessageBox.Show(this, "Seleziona prima un prodotto dall'elenco.",
|
||||
"Riapplica limiti", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
var targets = _auctionViewModels
|
||||
.Where(a => product.Rule.MatchesName(a.AuctionInfo.Name))
|
||||
.ToList();
|
||||
|
||||
if (targets.Count == 0)
|
||||
{
|
||||
MessageBox.Show(this,
|
||||
$"Nel monitor non ci sono aste di \"{product.DisplayName}\".",
|
||||
"Riapplica limiti", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
var answer = MessageBox.Show(this,
|
||||
$"Riscrivo i limiti di \"{product.DisplayName}\" su {targets.Count} " +
|
||||
(targets.Count == 1 ? "asta" : "aste") + " già nel monitor.\n\n" +
|
||||
"Le modifiche fatte a mano su quelle aste verranno sostituite. Procedo?",
|
||||
"Riapplica limiti", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
var limits = ProductRuleResolver.Resolve(product.Rule, SettingsManager.Load());
|
||||
|
||||
foreach (var auction in targets)
|
||||
{
|
||||
auction.MinPrice = limits.MinPrice;
|
||||
auction.MaxPrice = limits.MaxPrice;
|
||||
auction.MaxClicks = limits.MaxClicks;
|
||||
}
|
||||
|
||||
SaveAuctions();
|
||||
|
||||
// Il pannello dei dettagli mostra i valori dell'asta selezionata: se è fra
|
||||
// quelle toccate, i campi devono cambiare sotto gli occhi.
|
||||
if (_selectedAuction != null && targets.Contains(_selectedAuction))
|
||||
UpdateAuctionSettingsDisplay(_selectedAuction);
|
||||
|
||||
Log($"[PRODOTTI] Limiti di {product.DisplayName} riapplicati a {targets.Count} aste",
|
||||
LogLevel.Success);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Chiusura ordinata dell'applicazione.
|
||||
///
|
||||
/// Senza, alla chiusura restavano in volo i motori delle aste, la sorveglianza dei
|
||||
/// prodotti e il cerchio di aggiornamento del catalogo: il processo moriva e Windows
|
||||
/// recuperava tutto, ma una puntata in corso veniva troncata a metà senza che nulla
|
||||
/// lo registrasse, e la richiesta di timer a 1 ms non veniva mai restituita al sistema.
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private bool _shutdownDone;
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
base.OnClosing(e);
|
||||
ShutdownServices();
|
||||
}
|
||||
|
||||
private void ShutdownServices()
|
||||
{
|
||||
if (_shutdownDone) return;
|
||||
_shutdownDone = true;
|
||||
|
||||
// Ogni pezzo va spento separatamente: se uno fallisce, gli altri devono
|
||||
// comunque avere la loro occasione di chiudersi bene.
|
||||
TryShutdown("timer interfaccia", () =>
|
||||
{
|
||||
_headerTimer?.Stop();
|
||||
_userBannerTimer?.Stop();
|
||||
_userHtmlTimer?.Stop();
|
||||
});
|
||||
|
||||
TryShutdown("catalogo", StopCatalogAutoRefresh);
|
||||
|
||||
TryShutdown("sorveglianza prodotti", () => _productWatcher?.Stop());
|
||||
|
||||
TryShutdown("riscatto puntate", () => _freeBidsService?.Stop());
|
||||
|
||||
// Salva prima di spegnere il motore: fermare le aste ne cambia lo stato.
|
||||
TryShutdown("salvataggio aste", SaveAuctions);
|
||||
|
||||
// Ferma i motori per asta e rilascia rete e risoluzione del timer di sistema.
|
||||
TryShutdown("motore aste", () => _auctionMonitor?.Dispose());
|
||||
|
||||
TryShutdown("browser integrato", () => Browser?.EmbeddedWebView?.Dispose());
|
||||
}
|
||||
|
||||
private static void TryShutdown(string what, Action action)
|
||||
{
|
||||
try { action(); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
// In chiusura non c'è più un'interfaccia a cui riportarlo.
|
||||
Console.WriteLine($"[SHUTDOWN] {what}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Sezione Statistiche: legge lo storico delle aste concluse
|
||||
/// (CompletedAuctionsStore) e popola la griglia asta per asta.
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// Carica lo storico asta per asta.
|
||||
///
|
||||
/// <para>La lettura aggregata per prodotto non sta più qui: vive nella scheda
|
||||
/// Prodotti, accanto ai limiti che quelle stesse cifre servono a decidere.</para>
|
||||
/// </summary>
|
||||
private void LoadStatistics()
|
||||
{
|
||||
try
|
||||
{
|
||||
var records = CompletedAuctionsStore.LoadAll();
|
||||
|
||||
StatsDetailGrid.ItemsSource = records;
|
||||
|
||||
StatsPillRecords.Text = records.Count == 1 ? "1 asta" : $"{records.Count} aste";
|
||||
StatsPillWon.Text = $"{records.Count(r => r.WonByMe)} vinte";
|
||||
|
||||
// Con lo storico vuoto la griglia mostrerebbe solo intestazioni:
|
||||
// meglio spiegare che si popola da sola.
|
||||
var empty = records.Count == 0;
|
||||
StatsEmptyState.Visibility = empty ? Visibility.Visible : Visibility.Collapsed;
|
||||
StatsAuctionsPane.Visibility = empty ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[STATISTICHE] Errore caricamento: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Ricarica manuale delle statistiche (pulsante).</summary>
|
||||
private void ReloadStatisticsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
LoadStatistics();
|
||||
}
|
||||
|
||||
/// <summary>Apre la cartella contenente il file storico JSON.</summary>
|
||||
private void OpenStatsFolderButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var folder = AppPaths.StatsFolder;
|
||||
if (!string.IsNullOrEmpty(folder) && System.IO.Directory.Exists(folder))
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = folder,
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[STATISTICHE] Impossibile aprire la cartella: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Svuota lo storico delle aste concluse (con conferma).</summary>
|
||||
private void ClearStatsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var res = MessageBox.Show(this,
|
||||
"Vuoi eliminare tutto lo storico delle aste concluse? L'operazione non è reversibile.",
|
||||
"Svuota storico",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
if (res == MessageBoxResult.Yes)
|
||||
{
|
||||
CompletedAuctionsStore.Clear();
|
||||
LoadStatistics();
|
||||
Log("[STATISTICHE] Storico svuotato", LogLevel.Info);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Analizza lo storico e toglie le aste incomplete secondo le regole scelte
|
||||
/// dall'utente. Il dialogo mostra il conto prima di toccare qualunque cosa.
|
||||
/// </summary>
|
||||
private void CleanupStatsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var records = CompletedAuctionsStore.LoadAll();
|
||||
|
||||
if (records.Count == 0)
|
||||
{
|
||||
MessageBox.Show(this, "Lo storico e' vuoto: non c'e' nulla da pulire.",
|
||||
"Pulizia", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
var dialog = new Dialogs.StatsCleanupDialog(records) { Owner = this };
|
||||
|
||||
if (dialog.ShowDialog() != true) return;
|
||||
|
||||
LoadStatistics();
|
||||
LoadProducts();
|
||||
|
||||
Log($"[STORICO] Pulizia: tolte {dialog.RemovedCount} aste. " +
|
||||
$"Copia di sicurezza in {dialog.BackupPath}", LogLevel.Success);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chiede al server quante puntate ha speso il vincitore delle aste gia' concluse.
|
||||
///
|
||||
/// <para>Il dato non scade: le aste registrate prima che l'applicazione sapesse
|
||||
/// leggerlo non sono perse, basta richiederle. Senza questo recupero le statistiche
|
||||
/// sulle puntate ripartirebbero da zero e servirebbero mesi per averne abbastanza.</para>
|
||||
/// </summary>
|
||||
private async void BackfillWinnerBidsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var missing = Services.WinnerBidsBackfill.FindMissing();
|
||||
|
||||
if (missing.Count == 0)
|
||||
{
|
||||
MessageBox.Show(this,
|
||||
"Tutte le aste concluse hanno gia' il conteggio delle puntate del vincitore.",
|
||||
"Recupero", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
var answer = MessageBox.Show(this,
|
||||
$"Chiedo al server le puntate del vincitore per {missing.Count} aste concluse.\n\n" +
|
||||
"Serve una richiesta per asta, e viaggia in corsia di fondo dietro alle aste " +
|
||||
"in corso: misurato sul campo, circa un'asta e mezza al secondo, quindi " +
|
||||
$"{Math.Max(1, (int)(missing.Count * 1.6 / 60))} minuti circa.\n\n" +
|
||||
"Puoi continuare a usare l'applicazione: le aste in corso hanno la precedenza " +
|
||||
"e non ne risentono.\n\nProcedo?",
|
||||
"Recupera puntate dei vincitori", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
var transport = _auctionMonitor?.GetApiClient()?.Transport;
|
||||
if (transport == null)
|
||||
{
|
||||
Log("[RECUPERO] Trasporto HTTP non disponibile", LogLevel.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var button = sender as System.Windows.Controls.Button;
|
||||
if (button != null) button.IsEnabled = false;
|
||||
|
||||
try
|
||||
{
|
||||
var backfill = new Services.WinnerBidsBackfill(transport);
|
||||
backfill.OnLog += m => Dispatcher.Invoke(() => Log(m, LogLevel.Warning));
|
||||
|
||||
var lastReported = 0;
|
||||
backfill.OnProgress += (done, total, updated) =>
|
||||
{
|
||||
// Una riga di registro ogni cinquanta: una per asta seppellirebbe
|
||||
// tutto il resto sotto migliaia di righe.
|
||||
if (done - lastReported < 50 && done != total) return;
|
||||
lastReported = done;
|
||||
Dispatcher.Invoke(() =>
|
||||
Log($"[RECUPERO] {done}/{total} aste esaminate, {updated} aggiornate", LogLevel.Info));
|
||||
};
|
||||
|
||||
Log($"[RECUPERO] Avvio: {missing.Count} aste da completare", LogLevel.Info);
|
||||
|
||||
var result = await backfill.RunAsync(0, System.Threading.CancellationToken.None);
|
||||
|
||||
LoadStatistics();
|
||||
LoadProducts();
|
||||
|
||||
Log($"[RECUPERO] Fatto: {result.Updated} aggiornate, {result.Skipped} senza dato utilizzabile, " +
|
||||
$"{result.Failed} non riuscite", LogLevel.Success);
|
||||
|
||||
MessageBox.Show(this,
|
||||
$"Aggiornate {result.Updated} aste su {result.Examined}.\n\n" +
|
||||
(result.Skipped > 0
|
||||
? $"{result.Skipped} senza un conteggio utilizzabile: il server non l'ha dato, " +
|
||||
"oppure non superava il controllo di coerenza col prezzo finale.\n"
|
||||
: "") +
|
||||
(result.Failed > 0 ? $"{result.Failed} non riuscite per errori di rete.\n" : "") +
|
||||
"\nLe statistiche per prodotto sono gia' aggiornate.",
|
||||
"Recupero completato", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[RECUPERO] Interrotto: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (button != null) button.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -13,66 +13,54 @@ namespace AutoBidder
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private void UpdateSelectedAuctionDetails(AuctionViewModel auction)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Blocca temporaneamente i TextChanged per evitare loop di aggiornamento
|
||||
_isUpdatingSelection = true;
|
||||
/// <summary>Firma dell'ultimo log disegnato: asta, righe e ultima voce.</summary>
|
||||
private (string Id, int Count, DateTime Last, int Repeat) _lastLogSignature;
|
||||
|
||||
SelectedAuctionName.Text = auction.Name;
|
||||
SelectedBidBeforeDeadlineMs.Text = auction.AuctionInfo.BidBeforeDeadlineMs.ToString();
|
||||
SelectedCheckAuctionOpen.IsChecked = auction.AuctionInfo.CheckAuctionOpenBeforeBid;
|
||||
SelectedMinPrice.Text = auction.MinPrice.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
|
||||
SelectedMaxPrice.Text = auction.MaxPrice.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
|
||||
SelectedMaxClicks.Text = auction.MaxClicks.ToString();
|
||||
|
||||
var url = auction.AuctionInfo.OriginalUrl;
|
||||
if (string.IsNullOrEmpty(url))
|
||||
url = $"https://it.bidoo.com/auction.php?a=asta_{auction.AuctionId}";
|
||||
SelectedAuctionUrl.Text = url;
|
||||
|
||||
ResetSettingsButton.IsEnabled = true;
|
||||
ClearBiddersButton.IsEnabled = true;
|
||||
ClearLogButton.IsEnabled = true;
|
||||
|
||||
UpdateAuctionLog(auction);
|
||||
RefreshBiddersGrid(auction);
|
||||
|
||||
_isUpdatingSelection = false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_isUpdatingSelection = false;
|
||||
}
|
||||
}
|
||||
/// <summary>Firma dell'ultima griglia puntatori disegnata.</summary>
|
||||
private (string Id, int Count, int TotalBids) _lastBiddersSignature;
|
||||
|
||||
private void UpdateAuctionLog(AuctionViewModel auction)
|
||||
{
|
||||
try
|
||||
{
|
||||
var auctionInfo = auction.AuctionInfo;
|
||||
var log = auctionInfo.AuctionLog;
|
||||
if (log == null) return;
|
||||
|
||||
// Ricostruire il documento significa creare un Paragraph e un Run per ogni
|
||||
// riga, fino a duecento, a ogni risposta del server. Se il log non è
|
||||
// cambiato non c'è nulla da ridisegnare.
|
||||
var last = log.Count > 0 ? log[^1] : null;
|
||||
var signature = (auction.AuctionId, log.Count,
|
||||
last?.Timestamp ?? DateTime.MinValue, last?.RepeatCount ?? 0);
|
||||
|
||||
if (signature == _lastLogSignature) return;
|
||||
_lastLogSignature = signature;
|
||||
|
||||
var logBox = SelectedAuctionLog;
|
||||
var doc = logBox.Document;
|
||||
doc.Blocks.Clear();
|
||||
|
||||
foreach (var entry in auctionInfo.AuctionLog)
|
||||
|
||||
foreach (var entry in log)
|
||||
{
|
||||
var upper = entry.ToUpperInvariant();
|
||||
|
||||
// Color coding based on log content
|
||||
Brush color;
|
||||
if (upper.Contains("[ERRORE]") || upper.Contains("[FAIL]") || upper.Contains("EXCEPTION"))
|
||||
color = new SolidColorBrush(Color.FromRgb(232, 17, 35)); // Red
|
||||
else if (upper.Contains("[WARN]") || upper.Contains("ATTENZIONE"))
|
||||
color = new SolidColorBrush(Color.FromRgb(255, 183, 0)); // Yellow/Orange
|
||||
else if (upper.Contains("[OK]") || upper.Contains("SUCCESS"))
|
||||
color = new SolidColorBrush(Color.FromRgb(0, 216, 0)); // Green
|
||||
else
|
||||
color = new SolidColorBrush(Color.FromRgb(0, 122, 204)); // Blue (info)
|
||||
// Color coding based on structured log level
|
||||
Brush color = entry.Level switch
|
||||
{
|
||||
Models.AuctionLogLevel.Error => new SolidColorBrush(Color.FromRgb(232, 17, 35)), // Red
|
||||
Models.AuctionLogLevel.Warning => new SolidColorBrush(Color.FromRgb(255, 183, 0)), // Yellow/Orange
|
||||
Models.AuctionLogLevel.Success => new SolidColorBrush(Color.FromRgb(0, 216, 0)), // Green
|
||||
Models.AuctionLogLevel.Bid => new SolidColorBrush(Color.FromRgb(0, 216, 0)), // Green
|
||||
Models.AuctionLogLevel.Strategy => new SolidColorBrush(Color.FromRgb(200, 160, 255)),// Purple
|
||||
Models.AuctionLogLevel.Timing => new SolidColorBrush(Color.FromRgb(150, 150, 150)), // Gray
|
||||
Models.AuctionLogLevel.Debug => new SolidColorBrush(Color.FromRgb(120, 120, 120)), // Dark gray
|
||||
_ => new SolidColorBrush(Color.FromRgb(100, 180, 255)) // Light Blue
|
||||
};
|
||||
|
||||
var repeatSuffix = entry.RepeatCount > 1 ? $" (x{entry.RepeatCount})" : "";
|
||||
var line = $"[{entry.TimeDisplay}] [{entry.LevelLabel}] {entry.Message}{repeatSuffix}";
|
||||
|
||||
var p = new System.Windows.Documents.Paragraph { Margin = new Thickness(0, 2, 0, 2) };
|
||||
var r = new System.Windows.Documents.Run(entry) { Foreground = color };
|
||||
var r = new System.Windows.Documents.Run(line) { Foreground = color };
|
||||
p.Inlines.Add(r);
|
||||
doc.Blocks.Add(p);
|
||||
}
|
||||
@@ -93,17 +81,88 @@ namespace AutoBidder
|
||||
{
|
||||
try
|
||||
{
|
||||
var bidders = auction.AuctionInfo.BidderStats.Values
|
||||
.OrderByDescending(b => b.BidCount)
|
||||
.ToList();
|
||||
// Copia sotto lucchetto: il motore riscrive il dizionario dal proprio thread.
|
||||
var bidders = auction.AuctionInfo.SnapshotBidderStats();
|
||||
|
||||
SelectedAuctionBiddersGrid.ItemsSource = null;
|
||||
SelectedAuctionBiddersGrid.ItemsSource = bidders;
|
||||
SelectedAuctionBiddersCount.Text = $"Utenti: {bidders?.Count ?? 0}";
|
||||
// La quota si calcola qui: il singolo puntatore non conosce il totale dell'asta.
|
||||
var totalBids = bidders.Sum(b => b.BidCount);
|
||||
foreach (var bidder in bidders)
|
||||
{
|
||||
bidder.SharePercent = totalBids > 0 ? bidder.BidCount * 100.0 / totalBids : 0;
|
||||
}
|
||||
|
||||
// Riassegnare ItemsSource ricostruisce l'intera griglia e la fa lampeggiare:
|
||||
// si rifà solo quando i numeri sono davvero cambiati.
|
||||
var signature = (auction.AuctionId, bidders.Count, totalBids);
|
||||
if (signature != _lastBiddersSignature)
|
||||
{
|
||||
_lastBiddersSignature = signature;
|
||||
|
||||
SelectedAuctionBiddersGrid.ItemsSource = null;
|
||||
SelectedAuctionBiddersGrid.ItemsSource = bidders;
|
||||
SelectedAuctionBiddersCount.Text = bidders.Count == 0
|
||||
? "Nessun dato sui puntatori."
|
||||
: $"{bidders.Count} puntatori · {totalBids} puntate osservate";
|
||||
}
|
||||
|
||||
// ?? NUOVO: Aggiorna il contatore della storia puntate con limite configurato
|
||||
var settings = SettingsManager.Load();
|
||||
var maxEntries = settings?.MaxBidHistoryEntries ?? 20;
|
||||
var historyCount = auction.BidHistoryEntries?.Count ?? 0;
|
||||
|
||||
var bidHistoryCountTextBlock = AuctionMonitor.FindName("BidHistoryCount") as TextBlock;
|
||||
if (bidHistoryCountTextBlock != null)
|
||||
{
|
||||
// Mostra "Ultime 20 puntate" se il limite � attivo
|
||||
if (maxEntries > 0)
|
||||
{
|
||||
bidHistoryCountTextBlock.Text = $"Ultime {maxEntries} puntate";
|
||||
}
|
||||
else
|
||||
{
|
||||
bidHistoryCountTextBlock.Text = $"Ultime puntate: {historyCount}";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void UpdateAuctionSettingsDisplay(AuctionViewModel auction)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Blocca temporaneamente i TextChanged per evitare loop di aggiornamento
|
||||
_isUpdatingSelection = true;
|
||||
|
||||
SelectedAuctionName.Text = auction.Name;
|
||||
SelectedBidBeforeDeadlineMs.Text = auction.AuctionInfo.BidBeforeDeadlineMs.ToString();
|
||||
SelectedMinPrice.Text = auction.MinPrice.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
|
||||
SelectedMaxPrice.Text = auction.MaxPrice.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
|
||||
SelectedMaxClicks.Text = auction.MaxClicks.ToString();
|
||||
AuctionMonitor.SelectedMaxSpend.Text = auction.AuctionInfo.MaxTotalSpendEuro
|
||||
.ToString("F2", System.Globalization.CultureInfo.InvariantCulture);
|
||||
AuctionMonitor.SelectedStopAtBreakEven.IsChecked = auction.AuctionInfo.StopAtBreakEven;
|
||||
|
||||
var url = auction.AuctionInfo.OriginalUrl;
|
||||
if (string.IsNullOrEmpty(url))
|
||||
url = $"https://it.bidoo.com/auction.php?a=asta_{auction.AuctionId}";
|
||||
SelectedAuctionUrl.Text = url;
|
||||
|
||||
ResetSettingsButton.IsEnabled = true;
|
||||
ClearBiddersButton.IsEnabled = true;
|
||||
ClearLogButton.IsEnabled = true;
|
||||
|
||||
UpdateAuctionLog(auction);
|
||||
RefreshBiddersGrid(auction);
|
||||
|
||||
_isUpdatingSelection = false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_isUpdatingSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTotalCount()
|
||||
{
|
||||
MonitorateTitle.Text = $"Aste monitorate: {_auctionViewModels.Count}";
|
||||
@@ -132,18 +191,17 @@ namespace AutoBidder
|
||||
int canPauseCount = _auctionViewModels.Count(a => a.CanPause);
|
||||
int canStopCount = _auctionViewModels.Count(a => a.CanStop);
|
||||
|
||||
// AVVIA TUTTI: abilitato se ALMENO UNA asta può essere avviata
|
||||
// Scuro se NESSUNA asta può essere avviata (tutte già avviate)
|
||||
// AVVIA TUTTI: abilitato se ALMENO UNA asta pu� essere avviata
|
||||
// Scuro se NESSUNA asta pu� essere avviata (tutte gi� avviate)
|
||||
StartButton.IsEnabled = canStartCount > 0;
|
||||
StartButton.Opacity = canStartCount > 0 ? 1.0 : 0.4;
|
||||
|
||||
// PAUSA TUTTI: abilitato se ALMENO UNA asta può essere messa in pausa
|
||||
// Scuro se NESSUNA asta può essere messa in pausa (tutte già in pausa o ferme)
|
||||
// OSSERVA TUTTE: abilitato se ALMENO UNA asta non e' gia' in sola osservazione
|
||||
PauseAllButton.IsEnabled = canPauseCount > 0;
|
||||
PauseAllButton.Opacity = canPauseCount > 0 ? 1.0 : 0.4;
|
||||
|
||||
// FERMA TUTTI: abilitato se ALMENO UNA asta può essere fermata
|
||||
// Scuro se NESSUNA asta può essere fermata (tutte già ferme)
|
||||
// FERMA TUTTI: abilitato se ALMENO UNA asta pu� essere fermata
|
||||
// Scuro se NESSUNA asta pu� essere fermata (tutte gi� ferme)
|
||||
StopButton.IsEnabled = canStopCount > 0;
|
||||
StopButton.Opacity = canStopCount > 0 ? 1.0 : 0.4;
|
||||
}
|
||||
@@ -196,5 +254,106 @@ namespace AutoBidder
|
||||
Log($"[ERRORE] Esportazione asta: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resetta le impostazioni dell'asta selezionata ai valori predefiniti
|
||||
/// </summary>
|
||||
private void ResetSettingsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_selectedAuction == null)
|
||||
{
|
||||
MessageBox.Show("Seleziona un'asta dalla griglia", "Nessuna Selezione", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
var settings = SettingsManager.Load();
|
||||
|
||||
// Resetta ai valori predefiniti dalle impostazioni
|
||||
_selectedAuction.AuctionInfo.BidBeforeDeadlineMs = settings.DefaultBidBeforeDeadlineMs;
|
||||
_selectedAuction.MinPrice = settings.DefaultMinPrice;
|
||||
_selectedAuction.MaxPrice = settings.DefaultMaxPrice;
|
||||
_selectedAuction.MaxClicks = settings.DefaultMaxClicks;
|
||||
|
||||
// Aggiorna UI
|
||||
UpdateAuctionSettingsDisplay(_selectedAuction);
|
||||
|
||||
// Salva
|
||||
SaveAuctions();
|
||||
|
||||
Log($"[RESET] Impostazioni ripristinate ai valori predefiniti per: {_selectedAuction.Name}", LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Reset impostazioni: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore durante il reset: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pulisce la lista degli utenti che hanno puntato sull'asta selezionata
|
||||
/// </summary>
|
||||
private void ClearBiddersButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_selectedAuction == null)
|
||||
{
|
||||
MessageBox.Show("Seleziona un'asta dalla griglia", "Nessuna Selezione", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(
|
||||
$"Pulire la lista degli utenti per questa asta?\n\n{_selectedAuction.Name}\n\nLa lista degli utenti che hanno puntato verr� svuotata.",
|
||||
"Conferma Pulizia",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
// Pulisci la lista bidders
|
||||
_selectedAuction.AuctionInfo.BidderStats.Clear();
|
||||
|
||||
// Aggiorna UI
|
||||
RefreshBiddersGrid(_selectedAuction);
|
||||
|
||||
Log($"[CLEAR] Lista utenti pulita per: {_selectedAuction.Name}", LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Pulizia lista utenti: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore durante la pulizia: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pulisce il log dell'asta selezionata
|
||||
/// </summary>
|
||||
private void ClearLogButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_selectedAuction == null)
|
||||
{
|
||||
MessageBox.Show("Seleziona un'asta dalla griglia", "Nessuna Selezione", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pulisci il log dell'asta
|
||||
_selectedAuction.AuctionInfo.AuctionLog.Clear();
|
||||
|
||||
// Aggiorna UI
|
||||
UpdateAuctionLog(_selectedAuction);
|
||||
|
||||
Log($"[CLEAR] Log pulito per: {_selectedAuction.Name}", LogLevel.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Pulizia log asta: {ex.Message}", LogLevel.Error);
|
||||
MessageBox.Show($"Errore durante la pulizia: {ex.Message}", "Errore", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,35 @@ using AutoBidder.Utilities;
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// User info and banner management
|
||||
/// User info and banner management - REFACTORED con SessionService
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private System.Windows.Threading.DispatcherTimer _userBannerTimer;
|
||||
private System.Windows.Threading.DispatcherTimer _userHtmlTimer;
|
||||
// Creati in InitializeUserInfo(), non nel costruttore.
|
||||
private System.Windows.Threading.DispatcherTimer? _userBannerTimer;
|
||||
private System.Windows.Threading.DispatcherTimer? _userHtmlTimer;
|
||||
private System.Windows.Threading.DispatcherTimer? _toConfirmTimer;
|
||||
private SessionService _sessionService = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Aste vinte in attesa di conferma su Bidoo, o <c>-1</c> finché non è arrivata una
|
||||
/// risposta utilizzabile. È un <c>int</c> e non un <c>int?</c> perché lo scrive la
|
||||
/// rete e lo legge il battito dell'interfaccia: un annullabile sono due campi, e
|
||||
/// due campi si possono leggere a metà aggiornamento.
|
||||
/// </summary>
|
||||
private int _auctionsToConfirmRaw = Unknown;
|
||||
|
||||
private const int Unknown = -1;
|
||||
|
||||
/// <summary>Aste da confermare, o <c>null</c> se ancora non si sa.</summary>
|
||||
private int? AuctionsToConfirm
|
||||
{
|
||||
get
|
||||
{
|
||||
var value = System.Threading.Volatile.Read(ref _auctionsToConfirmRaw);
|
||||
return value < 0 ? null : value;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeUserInfoTimers()
|
||||
{
|
||||
@@ -29,38 +52,137 @@ namespace AutoBidder
|
||||
_userBannerTimer.Tick += UserBannerTimer_Tick;
|
||||
_userBannerTimer.Start();
|
||||
|
||||
Log("[INFO] Timer info utente avviati (5min HTML principale, 10min API fallback)", LogLevel.Info);
|
||||
// Aste da confermare: una richiesta da un byte, quindi si può chiedere spesso.
|
||||
// Un minuto è il compromesso fra "il numero compare subito dopo una vincita"
|
||||
// e "non si tempesta il server per un dato che cambia di rado".
|
||||
_toConfirmTimer = new System.Windows.Threading.DispatcherTimer();
|
||||
_toConfirmTimer.Interval = TimeSpan.FromSeconds(60);
|
||||
_toConfirmTimer.Tick += (_, _) => _ = RefreshAuctionsToConfirmAsync();
|
||||
_toConfirmTimer.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rilegge da Bidoo quante aste vinte aspettano conferma.
|
||||
///
|
||||
/// <para>Una risposta non utilizzabile <b>non</b> azzera il valore noto: se la rete
|
||||
/// cade, la barra continua a mostrare l'ultimo numero certo invece di far sparire
|
||||
/// una vincita che esiste.</para>
|
||||
/// </summary>
|
||||
private async Task RefreshAuctionsToConfirmAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = _auctionMonitor.GetSession();
|
||||
if (session == null || string.IsNullOrEmpty(session.Username))
|
||||
{
|
||||
System.Threading.Volatile.Write(ref _auctionsToConfirmRaw, Unknown);
|
||||
return;
|
||||
}
|
||||
|
||||
var count = await _auctionMonitor.GetAuctionsWonToConfirmAsync().ConfigureAwait(false);
|
||||
if (count.HasValue) System.Threading.Volatile.Write(ref _auctionsToConfirmRaw, count.Value);
|
||||
}
|
||||
catch { /* la barra non deve mai disturbare il resto */ }
|
||||
}
|
||||
|
||||
private void InitializeSessionService()
|
||||
{
|
||||
// NUOVO: Inizializza SessionService
|
||||
_sessionService = new SessionService(_auctionMonitor.GetApiClient());
|
||||
|
||||
// Event handlers
|
||||
_sessionService.OnLog += (msg) => Log(msg, LogLevel.Info);
|
||||
_sessionService.OnSessionChanged += (session) =>
|
||||
{
|
||||
Dispatcher.Invoke(() => SetUserBanner(session.Username, session.RemainingBids));
|
||||
};
|
||||
|
||||
// La sessione salvata va ripresa, altrimenti salvarla non serve a niente.
|
||||
_ = RestoreSavedSessionAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Riprende la sessione salvata su disco e la riattiva verso Bidoo.
|
||||
///
|
||||
/// Senza questo passaggio il cookie veniva scritto in session.dat e mai più letto:
|
||||
/// a ogni avvio l'applicazione risultava "Non connesso" e bisognava reincollarlo,
|
||||
/// pur avendone una copia valida sul disco.
|
||||
///
|
||||
/// Non blocca l'avvio: la validazione richiede un giro di rete, quindi la finestra
|
||||
/// si apre subito e il banner si aggiorna quando la risposta arriva.
|
||||
/// </summary>
|
||||
private async Task RestoreSavedSessionAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var saved = _sessionService.LoadSession();
|
||||
if (saved == null || string.IsNullOrWhiteSpace(saved.CookieString)) return;
|
||||
|
||||
Log("[SESSION] Sessione salvata trovata: verifica in corso…", LogLevel.Info);
|
||||
|
||||
// Il cookie potrebbe essere scaduto da giorni: si riattiva contro il server
|
||||
// invece di fidarsi del file.
|
||||
var result = await _sessionService.ValidateAndActivateSessionAsync(
|
||||
saved.CookieString, saved.Username);
|
||||
|
||||
if (result.Success && result.Session != null)
|
||||
{
|
||||
// Il motore deve conoscere il cookie per poter interrogare e puntare.
|
||||
_auctionMonitor.InitializeSessionWithCookie(
|
||||
saved.CookieString, result.Session.Username);
|
||||
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
SetUserBanner(result.Session.Username, result.Session.RemainingBids);
|
||||
RefreshSettingsSessionStatus();
|
||||
});
|
||||
|
||||
Log($"[SESSION] Riconnesso come {result.Session.Username}", LogLevel.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si lascia il cookie sul disco: l'utente lo vede in Impostazioni e
|
||||
// decide se rinnovarlo dal browser.
|
||||
Log($"[SESSION] Sessione salvata non più valida: {result.ErrorMessage}", LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[SESSION] Ripristino non riuscito: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetUserBanner(string username, int? remainingBids)
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = _auctionMonitor.GetSession();
|
||||
var session = _sessionService?.GetCurrentSession();
|
||||
|
||||
if (!string.IsNullOrEmpty(username))
|
||||
{
|
||||
// === HEADER - 2 RIGHE ===
|
||||
// Riga 1: Puntate + Credito
|
||||
RemainingBidsText.Text = remainingBids?.ToString() ?? "0";
|
||||
|
||||
if (session?.ShopCredit > 0)
|
||||
{
|
||||
AuctionMonitor.ShopCreditText.Text = $"EUR {session.ShopCredit:F2}";
|
||||
}
|
||||
else
|
||||
{
|
||||
AuctionMonitor.ShopCreditText.Text = "EUR 0.00";
|
||||
}
|
||||
|
||||
// Riga 2: Aste vinte (TODO: implementare)
|
||||
BannerAsteDaRiscattare.Text = "0";
|
||||
|
||||
// === SIDEBAR - Pannello Utente ===
|
||||
// Username
|
||||
// === CONNESSO ===
|
||||
|
||||
// Puntate, credito e aste da confermare li ridisegna il battito da un
|
||||
// secondo (RefreshAccountPills) leggendo la sessione viva: scriverli
|
||||
// anche qui non aggiungerebbe nulla e riporterebbe il rischio di due
|
||||
// fonti che si contraddicono.
|
||||
AuctionMonitor.UpdateAccountStatus(
|
||||
remainingBids ?? session?.RemainingBids,
|
||||
session is null ? null : (decimal)session.ShopCredit,
|
||||
AuctionsToConfirm);
|
||||
|
||||
// Appena la sessione è viva si può finalmente chiedere quante vincite
|
||||
// aspettano conferma: prima non si poteva sapere.
|
||||
_ = RefreshAuctionsToConfirmAsync();
|
||||
|
||||
// === SIDEBAR - Mostra dati utente ===
|
||||
SidebarUsernameText.Text = username;
|
||||
SidebarUsernameText.Foreground = new System.Windows.Media.SolidColorBrush(
|
||||
System.Windows.Media.Color.FromRgb(0, 216, 0)); // Verde
|
||||
SidebarUsernameText.FontWeight = System.Windows.FontWeights.Bold;
|
||||
SidebarUsernameText.ToolTip = $"Connesso come {username} - Click per disconnettere";
|
||||
|
||||
// ID Utente
|
||||
// Solo l'ID: l'indirizzo di posta non aggiungeva nulla di utile qui.
|
||||
if (session?.UserId > 0)
|
||||
{
|
||||
SidebarUserIdText.Text = $"ID: {session.UserId}";
|
||||
@@ -70,30 +192,30 @@ namespace AutoBidder
|
||||
{
|
||||
SidebarUserIdText.Visibility = System.Windows.Visibility.Collapsed;
|
||||
}
|
||||
|
||||
// Email
|
||||
if (!string.IsNullOrEmpty(session?.Email))
|
||||
{
|
||||
SidebarUserEmailText.Text = session.Email;
|
||||
SidebarUserEmailText.Visibility = System.Windows.Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
SidebarUserEmailText.Visibility = System.Windows.Visibility.Collapsed;
|
||||
}
|
||||
|
||||
// Mostra il pannello sidebar
|
||||
SidebarUserInfoPanel.Visibility = System.Windows.Visibility.Visible;
|
||||
|
||||
SidebarUserDetailsPanel.Visibility = System.Windows.Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nascondi pannello sidebar
|
||||
SidebarUserInfoPanel.Visibility = System.Windows.Visibility.Collapsed;
|
||||
// === NON CONNESSO ===
|
||||
|
||||
// Senza sessione questi numeri non esistono: un trattino lo dice,
|
||||
// uno zero mentirebbe.
|
||||
System.Threading.Volatile.Write(ref _auctionsToConfirmRaw, Unknown);
|
||||
AuctionMonitor.UpdateAccountStatus(null, null, null);
|
||||
|
||||
// Nascondi indicatore limite
|
||||
MinBidsLimitIndicator.Visibility = Visibility.Collapsed;
|
||||
|
||||
// === SIDEBAR - Mostra "Non connesso" ===
|
||||
SidebarUsernameText.Text = "Non connesso";
|
||||
SidebarUsernameText.Foreground = new System.Windows.Media.SolidColorBrush(
|
||||
System.Windows.Media.Color.FromRgb(255, 82, 82)); // Rosso chiaro (#FF5252)
|
||||
SidebarUsernameText.FontWeight = System.Windows.FontWeights.Bold;
|
||||
SidebarUsernameText.ToolTip = "Non connesso - Click per accedere tramite browser";
|
||||
|
||||
// Reset header
|
||||
RemainingBidsText.Text = "0";
|
||||
AuctionMonitor.ShopCreditText.Text = "EUR 0.00";
|
||||
BannerAsteDaRiscattare.Text = "0";
|
||||
// Nascondi dettagli (ID + Email)
|
||||
SidebarUserDetailsPanel.Visibility = System.Windows.Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
@@ -101,156 +223,46 @@ namespace AutoBidder
|
||||
|
||||
private async void UserBannerTimer_Tick(object? sender, EventArgs e)
|
||||
{
|
||||
// Questo è ora il fallback secondario
|
||||
await UpdateUserBannerInfoAsync();
|
||||
// Usa SessionService per refresh
|
||||
if (_sessionService != null)
|
||||
{
|
||||
await _sessionService.RefreshUserInfoAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async void UserHtmlTimer_Tick(object? sender, EventArgs e)
|
||||
{
|
||||
// Questo è ora il metodo principale
|
||||
await UpdateUserHtmlInfoAsync();
|
||||
}
|
||||
|
||||
private async Task UpdateUserBannerInfoAsync()
|
||||
{
|
||||
try
|
||||
// Usa SessionService per refresh
|
||||
if (_sessionService != null)
|
||||
{
|
||||
Log("[INFO] Tentativo recupero info utente da API...", LogLevel.Info);
|
||||
|
||||
// Prova prima l'endpoint API
|
||||
var success = await _auctionMonitor.UpdateUserInfoAsync();
|
||||
|
||||
if (success)
|
||||
{
|
||||
var session = _auctionMonitor.GetSession();
|
||||
if (session != null && !string.IsNullOrEmpty(session.Username))
|
||||
{
|
||||
SetUserBanner(session.Username, session.RemainingBids);
|
||||
Log($"[OK] Info utente API: {session.Username}, {session.RemainingBids} puntate", LogLevel.Info);
|
||||
return; // Successo con API
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[WARN] API ha risposto ma senza dati validi", LogLevel.Warn);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[WARN] API non ha risposto correttamente", LogLevel.Warn);
|
||||
}
|
||||
|
||||
// Se API fallisce o non ha dati, usa HTML scraping come fallback
|
||||
Log("[INFO] Tentativo fallback con HTML scraping...", LogLevel.Info);
|
||||
var userData = await _auctionMonitor.GetUserDataFromHtmlAsync();
|
||||
|
||||
if (userData != null && !string.IsNullOrEmpty(userData.Username))
|
||||
{
|
||||
SetUserBanner(userData.Username, userData.RemainingBids);
|
||||
Log($"[OK] Info utente HTML (fallback): {userData.Username}, {userData.RemainingBids} puntate", LogLevel.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[ERROR] Impossibile aggiornare info utente - verifica cookie nelle Impostazioni", LogLevel.Warn);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERROR] Errore aggiornamento banner utente: {ex.Message}", LogLevel.Warn);
|
||||
Log($"[ERROR] StackTrace: {ex.StackTrace}", LogLevel.Warn);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateUserHtmlInfoAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log("[INFO] Tentativo recupero dati utente da HTML...", LogLevel.Info);
|
||||
|
||||
// HTML scraping è il metodo PRINCIPALE (più affidabile)
|
||||
var userData = await _auctionMonitor.GetUserDataFromHtmlAsync();
|
||||
|
||||
if (userData != null && !string.IsNullOrEmpty(userData.Username))
|
||||
{
|
||||
SetUserBanner(userData.Username, userData.RemainingBids);
|
||||
Log($"[OK] Dati utente aggiornati via HTML: {userData.Username}, {userData.RemainingBids} puntate", LogLevel.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Se HTML fallisce, non fare nulla - il timer API proverà tra poco
|
||||
Log($"[WARN] HTML scraping non ha restituito dati validi - verifica cookie nelle Impostazioni", LogLevel.Warn);
|
||||
Log($"[WARN] Possibili cause: cookie scaduto, non autenticato, sito modificato", LogLevel.Warn);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERROR] Errore aggiornamento dati HTML: {ex.Message}", LogLevel.Warn);
|
||||
Log($"[ERROR] StackTrace: {ex.StackTrace}", LogLevel.Warn);
|
||||
await _sessionService.RefreshUserInfoAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Carica sessione salvata
|
||||
/// </summary>
|
||||
private void LoadSavedSession()
|
||||
{
|
||||
try
|
||||
{
|
||||
var session = SessionManager.LoadSession();
|
||||
var session = _sessionService?.GetCurrentSession();
|
||||
|
||||
if (session != null && session.IsValid)
|
||||
{
|
||||
// Ripristina sessione nel monitor
|
||||
if (!string.IsNullOrEmpty(session.CookieString))
|
||||
{
|
||||
_auctionMonitor.InitializeSessionWithCookie(session.CookieString, session.Username);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(session.AuthToken))
|
||||
{
|
||||
var cookieString = $"__stattrb={session.AuthToken}";
|
||||
_auctionMonitor.InitializeSessionWithCookie(cookieString, session.Username);
|
||||
}
|
||||
|
||||
// Show saved cookie in settings textbox
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(session.CookieString))
|
||||
{
|
||||
var m = System.Text.RegularExpressions.Regex.Match(session.CookieString, "__stattrb=([^;]+)");
|
||||
if (m.Success && !session.CookieString.Contains(";"))
|
||||
{
|
||||
SettingsCookieTextBox.Text = m.Groups[1].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
SettingsCookieTextBox.Text = session.CookieString;
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(session.AuthToken))
|
||||
{
|
||||
SettingsCookieTextBox.Text = session.AuthToken;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
StartButton.IsEnabled = true;
|
||||
|
||||
Log($"[OK] Sessione ripristinata per: {session.Username}");
|
||||
Log($"[SESSION] Ripristino sessione per: {session.Username}", LogLevel.Info);
|
||||
|
||||
// Aggiorna UI con stato connesso (ottimistico)
|
||||
SetUserBanner(session.Username, session.RemainingBids);
|
||||
|
||||
// Verifica validità cookie (background) - USA HTML come metodo principale
|
||||
Task.Run(async () =>
|
||||
// Verifica validit� cookie in background
|
||||
System.Threading.Tasks.Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// Prova prima HTML scraping (più affidabile)
|
||||
var htmlUser = await _auctionMonitor.GetUserDataFromHtmlAsync();
|
||||
if (htmlUser != null && !string.IsNullOrEmpty(htmlUser.Username))
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
SetUserBanner(htmlUser.Username, htmlUser.RemainingBids);
|
||||
Log($"[OK] Dati utente rilevati via HTML - Utente: {htmlUser.Username}, Puntate residue: {htmlUser.RemainingBids}");
|
||||
});
|
||||
return; // Successo con HTML
|
||||
}
|
||||
|
||||
// Fallback: prova API
|
||||
Log("[SESSION] Verifica validit� sessione...", LogLevel.Info);
|
||||
var success = await _auctionMonitor.UpdateUserInfoAsync();
|
||||
var updatedSession = _auctionMonitor.GetSession();
|
||||
|
||||
@@ -259,11 +271,13 @@ namespace AutoBidder
|
||||
if (success && updatedSession != null && !string.IsNullOrEmpty(updatedSession.Username))
|
||||
{
|
||||
SetUserBanner(updatedSession.Username, updatedSession.RemainingBids);
|
||||
Log($"[OK] Cookie valido - Crediti disponibili: {updatedSession.RemainingBids}");
|
||||
Log($"[SESSION] Sessione valida - {updatedSession.Username} ({updatedSession.RemainingBids} puntate)", LogLevel.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[WARN] Impossibile verificare sessione: verifica cookie nelle Impostazioni");
|
||||
SetUserBanner(string.Empty, 0);
|
||||
Log("[SESSION] Sessione scaduta", LogLevel.Warning);
|
||||
CheckBrowserCookieAfterWebViewReady();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -271,21 +285,138 @@ namespace AutoBidder
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
Log($"[WARN] Errore verifica sessione: {ex.Message}");
|
||||
SetUserBanner(string.Empty, 0);
|
||||
Log($"[SESSION] Errore verifica sessione: {ex.Message}", LogLevel.Warning);
|
||||
CheckBrowserCookieAfterWebViewReady();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("[INFO] Nessuna sessione salvata trovata");
|
||||
Log("[INFO] Usa 'Configura Sessione' per inserire il cookie");
|
||||
Log("[SESSION] Nessuna sessione salvata", LogLevel.Info);
|
||||
CheckBrowserCookieAfterWebViewReady();
|
||||
SetUserBanner(string.Empty, 0);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[WARN] Errore caricamento sessione: {ex.Message}");
|
||||
Log($"[ERRORE] Caricamento sessione: {ex.Message}", LogLevel.Error);
|
||||
CheckBrowserCookieAfterWebViewReady();
|
||||
SetUserBanner(string.Empty, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attende che WebView sia pronta, poi verifica presenza cookie
|
||||
/// </summary>
|
||||
private void CheckBrowserCookieAfterWebViewReady()
|
||||
{
|
||||
System.Threading.Tasks.Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// Aspetta che WebView sia inizializzata (max 60 secondi)
|
||||
var webViewReady = await WaitForWebViewInitAsync(60);
|
||||
|
||||
if (!webViewReady)
|
||||
{
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
Log("[WARN] WebView non inizializzata dopo 60 secondi", LogLevel.Warning);
|
||||
Log("[INFO] Per accedere:", LogLevel.Info);
|
||||
Log("[INFO] 1. Click su 'Non connesso' nella sidebar", LogLevel.Info);
|
||||
Log("[INFO] 2. Si aprir� la scheda Browser", LogLevel.Info);
|
||||
Log("[INFO] 3. Fai login su Bidoo", LogLevel.Info);
|
||||
Log("[INFO] 4. La connessione sar� automatica", LogLevel.Info);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// WebView pronta - verifica cookie
|
||||
await Dispatcher.InvokeAsync(async () =>
|
||||
{
|
||||
var browserCookie = await GetCookieFromWebView();
|
||||
|
||||
if (string.IsNullOrEmpty(browserCookie))
|
||||
{
|
||||
Log("[INFO] Nessun cookie nel browser", LogLevel.Info);
|
||||
Log("[INFO] Per accedere:", LogLevel.Info);
|
||||
Log("[INFO] 1. Click su 'Non connesso' nella sidebar", LogLevel.Info);
|
||||
Log("[INFO] 2. Si aprir� la scheda Browser", LogLevel.Info);
|
||||
Log("[INFO] 3. Fai login su Bidoo", LogLevel.Info);
|
||||
Log("[INFO] 4. La connessione sar� automatica", LogLevel.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("[INFO] Cookie rilevato nel browser - importazione in corso...", LogLevel.Info);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[WARN] Errore verifica cookie: {ex.Message}", LogLevel.Warning);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ridisegna subito la barra del conto dopo una puntata, senza aspettare il battito.
|
||||
///
|
||||
/// <para>Prima aggiornava il numero solo se era maggiore di zero: finite le puntate,
|
||||
/// la barra restava sull'ultimo valore positivo — cioè mentiva proprio nel momento
|
||||
/// in cui contava di più.</para>
|
||||
/// </summary>
|
||||
public void UpdateRemainingBidsDisplay()
|
||||
{
|
||||
try
|
||||
{
|
||||
RefreshAccountPills();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERROR] Errore aggiornamento banner: {ex.Message}", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicatore del limite minimo puntate, accanto al saldo.
|
||||
///
|
||||
/// <para>Il colore va ricalcolato anche a zero puntate: era proprio il caso in cui
|
||||
/// prima restava dell'ultimo colore utile, cioè verde, mentre il conto era vuoto.</para>
|
||||
/// </summary>
|
||||
private void UpdateMinBidsIndicator(int minBidsLimit)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (minBidsLimit <= 0)
|
||||
{
|
||||
MinBidsLimitIndicator.Visibility = Visibility.Collapsed;
|
||||
return;
|
||||
}
|
||||
|
||||
MinBidsLimitIndicator.Visibility = Visibility.Visible;
|
||||
MinBidsLimitIndicator.Text = $"({minBidsLimit})";
|
||||
MinBidsLimitIndicator.ToolTip =
|
||||
$"Limite minimo puntate attivo: il bot non scende sotto {minBidsLimit} puntate";
|
||||
|
||||
var session = _auctionMonitor.GetSession();
|
||||
if (session == null || string.IsNullOrEmpty(session.Username))
|
||||
{
|
||||
MinBidsLimitIndicator.SetResourceReference(
|
||||
System.Windows.Controls.TextBlock.ForegroundProperty, "Brush.TextFaint");
|
||||
return;
|
||||
}
|
||||
|
||||
var key =
|
||||
session.RemainingBids <= minBidsLimit ? "Brush.Danger" :
|
||||
session.RemainingBids <= minBidsLimit + 10 ? "Brush.Warning" :
|
||||
"Brush.Success";
|
||||
|
||||
MinBidsLimitIndicator.SetResourceReference(
|
||||
System.Windows.Controls.TextBlock.ForegroundProperty, key);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder
|
||||
{
|
||||
/// <summary>
|
||||
/// Gestione WebView2: pre-caricamento e estrazione cookie
|
||||
/// </summary>
|
||||
public partial class MainWindow
|
||||
{
|
||||
private bool _isWebViewInitialized = false;
|
||||
private TaskCompletionSource<bool>? _webViewInitCompletionSource;
|
||||
|
||||
/// <summary>
|
||||
/// Inizializza WebView2 in background all'avvio per pre-caricare il browser
|
||||
/// </summary>
|
||||
private async void InitializeWebView2()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (EmbeddedWebView == null)
|
||||
{
|
||||
Log("[WARN] WebView2 non disponibile", LogLevel.Warning);
|
||||
_webViewInitCompletionSource?.TrySetResult(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Log("[BROWSER] Inizializzazione WebView2 in background...", LogLevel.Info);
|
||||
|
||||
// Aspetta un attimo che l'UI sia completamente caricata
|
||||
await System.Threading.Tasks.Task.Delay(500);
|
||||
|
||||
// ? FIX: WebView2 si inizializza SOLO se visibile
|
||||
// Salva tab corrente e switcha temporaneamente a Browser
|
||||
var wasVisible = Browser.Visibility == Visibility.Visible;
|
||||
var currentTab = TabAsteAttive.IsChecked == true ? "AsteAttive" :
|
||||
TabCerca.IsChecked == true ? "Cerca" :
|
||||
TabProdotti.IsChecked == true ? "Prodotti" :
|
||||
TabBrowser.IsChecked == true ? "Browser" :
|
||||
TabPuntateGratis.IsChecked == true ? "PuntateGratis" :
|
||||
TabDatiStatistici.IsChecked == true ? "DatiStatistici" :
|
||||
TabImpostazioni.IsChecked == true ? "Impostazioni" : "AsteAttive";
|
||||
|
||||
if (!wasVisible)
|
||||
{
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
Browser.Visibility = Visibility.Visible;
|
||||
});
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
// Specifica UserDataFolder esplicito
|
||||
var userDataFolder = System.IO.Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"AutoBidder",
|
||||
"WebView2"
|
||||
);
|
||||
|
||||
// Crea directory se non esiste
|
||||
System.IO.Directory.CreateDirectory(userDataFolder);
|
||||
|
||||
// Crea environment con UserDataFolder esplicito
|
||||
var env = await Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync(
|
||||
browserExecutableFolder: null,
|
||||
userDataFolder: userDataFolder
|
||||
);
|
||||
|
||||
// Inizializza WebView con environment
|
||||
await EmbeddedWebView.EnsureCoreWebView2Async(env);
|
||||
|
||||
// Ripristina tab originale se necessario
|
||||
if (!wasVisible)
|
||||
{
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
Browser.Visibility = Visibility.Collapsed;
|
||||
|
||||
// Ripristina tab originale
|
||||
switch (currentTab)
|
||||
{
|
||||
case "AsteAttive":
|
||||
TabAsteAttive.IsChecked = true;
|
||||
AuctionMonitor.Visibility = Visibility.Visible;
|
||||
break;
|
||||
case "Cerca":
|
||||
// "Cerca" mostra lo stesso controllo Browser, in modalità catalogo.
|
||||
TabCerca.IsChecked = true;
|
||||
Browser.Visibility = Visibility.Visible;
|
||||
break;
|
||||
case "Prodotti":
|
||||
TabProdotti.IsChecked = true;
|
||||
Products.Visibility = Visibility.Visible;
|
||||
break;
|
||||
case "PuntateGratis":
|
||||
TabPuntateGratis.IsChecked = true;
|
||||
FreeBids.Visibility = Visibility.Visible;
|
||||
break;
|
||||
case "DatiStatistici":
|
||||
TabDatiStatistici.IsChecked = true;
|
||||
StatisticsPanel.Visibility = Visibility.Visible;
|
||||
break;
|
||||
case "Impostazioni":
|
||||
TabImpostazioni.IsChecked = true;
|
||||
Settings.Visibility = Visibility.Visible;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (EmbeddedWebView.CoreWebView2 != null)
|
||||
{
|
||||
_isWebViewInitialized = true;
|
||||
|
||||
// Pre-carica la pagina di Bidoo in background
|
||||
EmbeddedWebView.CoreWebView2.Navigate("https://it.bidoo.com");
|
||||
|
||||
Log("[BROWSER] WebView2 inizializzato e pre-caricato", LogLevel.Success);
|
||||
|
||||
// Registra evento per rilevare login automatico
|
||||
EmbeddedWebView.CoreWebView2.NavigationCompleted += OnWebViewNavigationCompleted;
|
||||
|
||||
// Notifica che WebView � pronta
|
||||
_webViewInitCompletionSource?.TrySetResult(true);
|
||||
|
||||
// Verifica immediata se c'� gi� un cookie
|
||||
await CheckAndImportCookieIfAvailable();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("[ERROR] CoreWebView2 � null dopo init", LogLevel.Error);
|
||||
_webViewInitCompletionSource?.TrySetResult(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERROR] Inizializzazione WebView2 fallita: {ex.Message}", LogLevel.Error);
|
||||
_webViewInitCompletionSource?.TrySetResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica e importa cookie se disponibile
|
||||
/// </summary>
|
||||
private async Task CheckAndImportCookieIfAvailable()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Aspetta che la pagina sia completamente caricata
|
||||
await Task.Delay(1000);
|
||||
|
||||
var cookie = await GetCookieFromWebView();
|
||||
|
||||
if (!string.IsNullOrEmpty(cookie))
|
||||
{
|
||||
var currentSession = _sessionService?.GetCurrentSession();
|
||||
|
||||
// Importa solo se diverso da quello salvato
|
||||
if (currentSession == null ||
|
||||
string.IsNullOrEmpty(currentSession.CookieString) ||
|
||||
!currentSession.CookieString.Contains(cookie))
|
||||
{
|
||||
Log("[BROWSER] Cookie rilevato nel browser - importazione automatica...", LogLevel.Info);
|
||||
await AutoImportCookieFromWebView(cookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[WARN] Verifica cookie fallita: {ex.Message}", LogLevel.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aspetta che WebView sia inizializzata (con timeout)
|
||||
/// </summary>
|
||||
private async Task<bool> WaitForWebViewInitAsync(int timeoutSeconds = 60)
|
||||
{
|
||||
if (_isWebViewInitialized)
|
||||
return true;
|
||||
|
||||
_webViewInitCompletionSource = new TaskCompletionSource<bool>();
|
||||
|
||||
// Timeout
|
||||
var timeoutTask = Task.Delay(TimeSpan.FromSeconds(timeoutSeconds));
|
||||
var completedTask = await Task.WhenAny(_webViewInitCompletionSource.Task, timeoutTask);
|
||||
|
||||
if (completedTask == timeoutTask)
|
||||
{
|
||||
Log("[WARN] Timeout attesa inizializzazione WebView2", LogLevel.Warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
return await _webViewInitCompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Evento chiamato quando la navigazione nella WebView � completata
|
||||
/// Rileva automaticamente se l'utente ha effettuato il login
|
||||
/// </summary>
|
||||
private async void OnWebViewNavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!e.IsSuccess || EmbeddedWebView?.CoreWebView2 == null)
|
||||
return;
|
||||
|
||||
var url = EmbeddedWebView.CoreWebView2.Source;
|
||||
|
||||
// Se l'utente � sulla homepage di Bidoo (dopo login), verifica cookie
|
||||
if (url.Contains("bidoo.com") && !url.Contains("login"))
|
||||
{
|
||||
// ? REFACTORED: Delega a CheckAndImportCookieIfAvailable
|
||||
await CheckAndImportCookieIfAvailable();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Importa automaticamente il cookie dalla WebView senza conferma utente
|
||||
/// </summary>
|
||||
private async Task<bool> AutoImportCookieFromWebView(string cookieString)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Valida e attiva il cookie usando SessionService
|
||||
var result = await _sessionService.ValidateAndActivateSessionAsync(cookieString);
|
||||
|
||||
if (result.Success && result.Session != null)
|
||||
{
|
||||
// Salva automaticamente la sessione
|
||||
_sessionService.SaveSession(result.Session);
|
||||
|
||||
// Aggiorna il banner
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
SetUserBanner(result.Session.Username, result.Session.RemainingBids);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Estrae il cookie __stattrb dalla WebView2
|
||||
/// </summary>
|
||||
/// <returns>Cookie completo o null se non trovato</returns>
|
||||
private async Task<string?> GetCookieFromWebView()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (EmbeddedWebView?.CoreWebView2 == null)
|
||||
return null;
|
||||
|
||||
// Ottieni tutti i cookie di bidoo.com
|
||||
var cookies = await EmbeddedWebView.CoreWebView2.CookieManager.GetCookiesAsync("https://it.bidoo.com");
|
||||
|
||||
if (cookies == null || cookies.Count == 0)
|
||||
return null;
|
||||
|
||||
// Cerca il cookie __stattrb (cookie di sessione principale)
|
||||
var stattrb = cookies.FirstOrDefault(c => c.Name == "__stattrb");
|
||||
|
||||
if (stattrb == null)
|
||||
return null;
|
||||
|
||||
// Costruisci la stringa cookie completa con tutti i cookie necessari
|
||||
var cookieStrings = cookies
|
||||
.Where(c => !string.IsNullOrEmpty(c.Value))
|
||||
.Select(c => $"{c.Name}={c.Value}")
|
||||
.ToList();
|
||||
|
||||
return string.Join("; ", cookieStrings);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[WARN] Impossibile estrarre cookie da WebView: {ex.Message}", LogLevel.Warning);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Importa il cookie dalla WebView e lo salva per l'uso nelle API
|
||||
/// </summary>
|
||||
public async Task<bool> ImportCookieFromWebView()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_isWebViewInitialized || EmbeddedWebView?.CoreWebView2 == null)
|
||||
{
|
||||
Log("[WARN] Browser non inizializzato - attendi qualche secondo e riprova", LogLevel.Warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
Log("[BROWSER] Estrazione cookie dal browser...", LogLevel.Info);
|
||||
|
||||
var cookieString = await GetCookieFromWebView();
|
||||
|
||||
if (string.IsNullOrEmpty(cookieString))
|
||||
{
|
||||
Log("[WARN] Nessun cookie trovato nel browser - assicurati di aver effettuato il login su bidoo.com", LogLevel.Warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
// ? NOTA: Non aggiorna pi� TextBox (rimossa) - direttamente alla validazione
|
||||
|
||||
// Valida e attiva il cookie usando SessionService
|
||||
var result = await _sessionService.ValidateAndActivateSessionAsync(cookieString);
|
||||
|
||||
if (result.Success && result.Session != null)
|
||||
{
|
||||
// Salva automaticamente la sessione
|
||||
_sessionService.SaveSession(result.Session);
|
||||
|
||||
// Aggiorna il banner
|
||||
SetUserBanner(result.Session.Username, result.Session.RemainingBids);
|
||||
|
||||
Log($"[OK] Cookie importato e validato - Utente: {result.Session.Username}, Puntate: {result.Session.RemainingBids}", LogLevel.Success);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[ERRORE] Cookie importato ma non valido: {result.ErrorMessage}", LogLevel.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Importazione cookie: {ex.Message}", LogLevel.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se WebView2 � pronta per l'uso
|
||||
/// </summary>
|
||||
public bool IsWebViewReady()
|
||||
{
|
||||
return _isWebViewInitialized && EmbeddedWebView?.CoreWebView2 != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AutoBidder.Models;
|
||||
|
||||
namespace AutoBidder.Data
|
||||
{
|
||||
public class StatisticsContext : DbContext
|
||||
{
|
||||
public DbSet<ProductStat> ProductStats { get; set; }
|
||||
|
||||
public StatisticsContext(DbContextOptions<StatisticsContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<ProductStat>()
|
||||
.HasIndex(p => p.ProductKey)
|
||||
.IsUnique(false);
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,10 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:AutoBidder.Controls"
|
||||
Title="Aggiungi Asta" Height="320" Width="700"
|
||||
Background="#0a0a0a" Foreground="#FFFFFF"
|
||||
Background="{DynamicResource Brush.Bg}" Foreground="{DynamicResource Brush.Text}"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
Icon="pack://application:,,,/Icon/favicon.ico"
|
||||
ResizeMode="NoResize">
|
||||
<Border Background="#1a1a1a" CornerRadius="8" Padding="16" Margin="8">
|
||||
<Border Background="{DynamicResource Brush.Bg}" CornerRadius="8" Padding="16" Margin="8">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -17,11 +16,11 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Text="Inserire URL dell'asta (uno o più)" Foreground="#CCCCCC" FontSize="14" Margin="0,0,0,6" />
|
||||
<TextBlock Grid.Row="1" Text="Puoi aggiungere più link separandoli con 'a capo', 'spazio' o ';'" Foreground="#999999" FontSize="12" Margin="0,0,0,10" />
|
||||
<TextBlock Text="Inserire URL dell'asta (uno o più)" Foreground="{DynamicResource Brush.Text}" FontSize="14" Margin="0,0,0,6" />
|
||||
<TextBlock Grid.Row="1" Text="Puoi aggiungere più link separandoli con 'a capo', 'spazio' o ';'" Foreground="{DynamicResource Brush.TextMuted}" FontSize="12" Margin="0,0,0,10" />
|
||||
|
||||
<TextBox x:Name="AuctionUrlBox" Grid.Row="2" MinWidth="560" Margin="0,0,0,8"
|
||||
Background="#181818" Foreground="#00CCFF" BorderBrush="#444" BorderThickness="1"
|
||||
Background="{DynamicResource Brush.Bg}" Foreground="{DynamicResource Brush.Info}" BorderBrush="{DynamicResource Brush.Border}" BorderThickness="1"
|
||||
Padding="8" FontSize="13" ToolTip="Inserisci uno o più URL/ID dell'asta. Separali con a capo, spazio o ';'"
|
||||
AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Height="160" />
|
||||
|
||||
@@ -29,9 +28,9 @@
|
||||
<controls:SimpleToolbar.RightContent>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Content="OK" Width="110" Margin="6" Padding="10,8"
|
||||
Style="{StaticResource SmallButtonStyle}" Background="#00CC66" Foreground="White" Click="OkButton_Click" />
|
||||
Style="{StaticResource SmallButtonStyle}" Background="{DynamicResource Brush.Success}" Foreground="{DynamicResource Brush.TextOnAccent}" Click="OkButton_Click" />
|
||||
<Button Content="Annulla" Width="110" Margin="6" Padding="10,8"
|
||||
Style="{StaticResource SmallButtonStyle}" Background="#666" Foreground="White" Click="CancelButton_Click" />
|
||||
Style="{StaticResource SmallButtonStyle}" Background="{DynamicResource Brush.SurfaceAlt}" Foreground="{DynamicResource Brush.Text}" Click="CancelButton_Click" />
|
||||
</StackPanel>
|
||||
</controls:SimpleToolbar.RightContent>
|
||||
</controls:SimpleToolbar>
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
<Window x:Class="AutoBidder.Dialogs.ClosedAuctionsWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Aste Chiuse - Estrazione" Height="600" Width="1000"
|
||||
Background="#0a0a0a" Foreground="#FFFFFF" WindowStartupLocation="CenterOwner">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="8" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Border Background="#1a1a1a" Padding="10" CornerRadius="6" Grid.Row="0" BorderBrush="#333333" BorderThickness="1">
|
||||
<DockPanel>
|
||||
<TextBlock Text="Estrazione Aste Chiuse" FontSize="16" FontWeight="Bold" Foreground="#00CC66" VerticalAlignment="Center" DockPanel.Dock="Left" />
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Right">
|
||||
<Button x:Name="StartExtractButton" Content="Avvia Estrazione" Click="StartExtractButton_Click" Width="140" Height="36" Margin="8,0,0,0" Background="#00CC66" Style="{StaticResource SmallButtonStyle}"/>
|
||||
<Button x:Name="ExportStatsButton" Content="Esporta Statistiche" Click="ExportStatsButton_Click" Width="160" Height="36" Margin="8,0,0,0" Background="#8B5CF6" Style="{StaticResource SmallButtonStyle}"/>
|
||||
<Button x:Name="CloseButton" Content="Chiudi" Click="CloseButton_Click" Width="80" Height="36" Margin="8,0,0,0" Background="#666" Style="{StaticResource SmallButtonStyle}"/>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<Border Grid.Row="2" Background="#1a1a1a" Padding="8" CornerRadius="6" BorderBrush="#333333" BorderThickness="1">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*" />
|
||||
<ColumnDefinition Width="8" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Products grid: styled like MainWindow -->
|
||||
<DataGrid x:Name="ProductsGrid" AutoGenerateColumns="False" Grid.Column="0" Background="#1a1a1a" Foreground="#FFFFFF" BorderBrush="#333333" BorderThickness="1"
|
||||
RowBackground="#1a1a1a" AlternatingRowBackground="#222222" GridLinesVisibility="Horizontal" HorizontalGridLinesBrush="#333333"
|
||||
IsReadOnly="True" SelectionUnit="CellOrRowHeader" SelectionMode="Extended" ClipboardCopyMode="IncludeHeader" CanUserAddRows="False" CanUserDeleteRows="False">
|
||||
<DataGrid.Resources>
|
||||
<Style TargetType="DataGridColumnHeader">
|
||||
<Setter Property="Background" Value="#2a2a2a" />
|
||||
<Setter Property="Foreground" Value="#FFFFFF" />
|
||||
<Setter Property="FontWeight" Value="Bold" />
|
||||
<Setter Property="Padding" Value="10,8" />
|
||||
<Setter Property="BorderThickness" Value="0,0,0,2" />
|
||||
<Setter Property="BorderBrush" Value="#00CC66" />
|
||||
</Style>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Setter Property="Height" Value="36" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#0099FF" />
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Padding" Value="10,6" />
|
||||
</Style>
|
||||
</DataGrid.Resources>
|
||||
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Command="ApplicationCommands.Copy" Header="Copia" />
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Asta URL" Binding="{Binding AuctionUrl}" Width="2*" />
|
||||
<DataGridTextColumn Header="Nome" Binding="{Binding ProductName}" Width="3*"/>
|
||||
<DataGridTextColumn Header="Prezzo" Binding="{Binding FinalPrice}" Width="80"/>
|
||||
<DataGridTextColumn Header="Vincitore" Binding="{Binding Winner}" Width="120"/>
|
||||
<DataGridTextColumn Header="Puntate Usate" Binding="{Binding BidsUsed}" Width="100"/>
|
||||
<DataGridTextColumn Header="Scraped At" Binding="{Binding ScrapedAt}" Width="140"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<GridSplitter Grid.Column="1" Width="8" />
|
||||
|
||||
<!-- Log area styled like main window log -->
|
||||
<Border Grid.Column="2" Background="#0f0f0f" Padding="8" CornerRadius="6" BorderBrush="#333333" BorderThickness="1">
|
||||
<DockPanel>
|
||||
<TextBlock Text="Log Operazioni" FontWeight="Bold" Foreground="#00CC66" DockPanel.Dock="Top" Margin="0,0,0,8" />
|
||||
<RichTextBox x:Name="ExtractLogBox" IsReadOnly="True" VerticalScrollBarVisibility="Auto" FontFamily="Consolas" FontSize="11" Background="#0f0f0f" Foreground="#CCC" BorderBrush="#333333" BorderThickness="1" />
|
||||
</DockPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -1,140 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using Microsoft.Win32;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.Services;
|
||||
using AutoBidder.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AutoBidder.Dialogs
|
||||
{
|
||||
public partial class ClosedAuctionsWindow : Window
|
||||
{
|
||||
private ObservableCollection<ClosedAuctionRecord> _products = new();
|
||||
|
||||
private bool _isRunning = false;
|
||||
|
||||
// StatsService using local DB. Create context with default sqlite file in app folder
|
||||
private readonly StatsService _statsService;
|
||||
|
||||
public ClosedAuctionsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
ProductsGrid.ItemsSource = _products;
|
||||
|
||||
var optionsBuilder = new DbContextOptionsBuilder<StatisticsContext>();
|
||||
var dbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "stats.db");
|
||||
optionsBuilder.UseSqlite($"Data Source={dbPath}");
|
||||
var ctx = new StatisticsContext(optionsBuilder.Options);
|
||||
_statsService = new StatsService(ctx);
|
||||
|
||||
Log("Finestra pronta");
|
||||
}
|
||||
|
||||
private void Log(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
var para = new Paragraph(new Run($"{DateTime.Now:HH:mm} - {message}"));
|
||||
ExtractLogBox.Document.Blocks.Add(para);
|
||||
// keep size manageable
|
||||
while (ExtractLogBox.Document.Blocks.Count > 500)
|
||||
ExtractLogBox.Document.Blocks.Remove(ExtractLogBox.Document.Blocks.FirstBlock);
|
||||
ExtractLogBox.ScrollToEnd();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private async void StartExtractButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_isRunning)
|
||||
{
|
||||
Log("Estrazione già in corso");
|
||||
return;
|
||||
}
|
||||
|
||||
_isRunning = true;
|
||||
StartExtractButton.IsEnabled = false;
|
||||
Log("Avvio procedura di estrazione da closed_auctions.php...");
|
||||
|
||||
try
|
||||
{
|
||||
var scraper = new ClosedAuctionsScraper(null, _statsService, Log);
|
||||
var closedUrl = "https://it.bidoo.com/closed_auctions.php";
|
||||
|
||||
Log($"Scarico: {closedUrl}");
|
||||
|
||||
int count = 0;
|
||||
await foreach (var rec in scraper.ScrapeYieldAsync(closedUrl))
|
||||
{
|
||||
// Filter out records without bids info (user requested)
|
||||
if (!rec.BidsUsed.HasValue)
|
||||
{
|
||||
Log($"Scartata asta (mancano puntate): {rec.AuctionUrl} - '{rec.ProductName ?? "?"}'");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add and log incrementally so user sees progress
|
||||
_products.Add(rec);
|
||||
count++;
|
||||
Log($"[{count}] {rec.ProductName} | Prezzo: {(rec.FinalPrice.HasValue?rec.FinalPrice.Value.ToString("F2")+"€":"--")} | Vincitore: {rec.Winner ?? "--"} | Puntate: {rec.BidsUsed.Value} | URL: {rec.AuctionUrl}");
|
||||
}
|
||||
|
||||
Log($"Estrazione completata: {count} record aggiunti.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Estrattore: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRunning = false;
|
||||
StartExtractButton.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private async void ExportStatsButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log("Preparazione esportazione statistiche...");
|
||||
var stats = await _statsService.GetAllStatsAsync();
|
||||
if (stats == null || stats.Count == 0)
|
||||
{
|
||||
Log("Nessuna statistica disponibile da esportare.");
|
||||
MessageBox.Show(this, "Nessuna statistica disponibile.", "Esporta Statistiche", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
var dlg = new SaveFileDialog() { Filter = "CSV files|*.csv|All files|*.*", FileName = "auction_stats.csv" };
|
||||
if (dlg.ShowDialog(this) != true) return;
|
||||
|
||||
using var sw = new StreamWriter(dlg.FileName, false, System.Text.Encoding.UTF8);
|
||||
sw.WriteLine("ProductKey,ProductName,TotalAuctions,AverageBidsUsed,AverageFinalPrice,LastSeen");
|
||||
foreach (var s in stats)
|
||||
{
|
||||
var line = $"\"{s.ProductKey}\",\"{s.ProductName}\",{s.TotalAuctions},{s.AverageBidsUsed:F2},{s.AverageFinalPrice:F2},{s.LastSeen:O}";
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
|
||||
Log($"Statistiche esportate su: {dlg.FileName}");
|
||||
MessageBox.Show(this, "Statistiche esportate con successo.", "Esporta Statistiche", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ERRORE] Esporta: {ex.Message}");
|
||||
MessageBox.Show(this, "Errore durante esportazione: " + ex.Message, "Esporta Statistiche", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,10 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Configura Sessione" Height="440" Width="700"
|
||||
Background="#0a0a0a" Foreground="#FFFFFF"
|
||||
Background="{DynamicResource Brush.Bg}" Foreground="{DynamicResource Brush.Text}"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
Icon="pack://application:,,,/Icon/favicon.ico"
|
||||
ResizeMode="NoResize">
|
||||
<Border Background="#1a1a1a" CornerRadius="8" Padding="16" Margin="8">
|
||||
<Border Background="{DynamicResource Brush.Bg}" CornerRadius="8" Padding="16" Margin="8">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -15,9 +14,9 @@
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Inserisci Cookie di sessione" FontSize="16" FontWeight="SemiBold" Foreground="#00CC66" Margin="0,0,0,12" />
|
||||
<TextBlock Grid.Row="1" Text="Cookie di sessione (copia dal menu delle Impostazioni/Applicazioni di Chrome)" Foreground="#CCCCCC" FontSize="13" />
|
||||
<TextBlock Grid.Row="2" Foreground="#888" FontSize="12" TextWrapping="Wrap" Margin="0,4,0,10">
|
||||
<TextBlock Text="Inserisci Cookie di sessione" FontSize="16" FontWeight="SemiBold" Foreground="{DynamicResource Brush.Success}" Margin="0,0,0,12" />
|
||||
<TextBlock Grid.Row="1" Text="Cookie di sessione (copia dal menu delle Impostazioni/Applicazioni di Chrome)" Foreground="{DynamicResource Brush.Text}" FontSize="13" />
|
||||
<TextBlock Grid.Row="2" Foreground="{DynamicResource Brush.TextMuted}" FontSize="12" TextWrapping="Wrap" Margin="0,4,0,10">
|
||||
<Run Text="Come trovare i cookie di sessione in Chrome:" />
|
||||
<LineBreak/>
|
||||
<Run Text="1. Apri Chrome e premi F12 (Windows) o Cmd+Option+I (Mac) per aprire gli Strumenti per sviluppatori." />
|
||||
@@ -29,12 +28,12 @@
|
||||
<Run Text="4. Scegli il sito desiderato e copia il valore del cookie di sessione." />
|
||||
</TextBlock>
|
||||
<TextBox x:Name="CookieBox" Grid.Row="3" MinWidth="320" MinHeight="120" MaxHeight="220" VerticalScrollBarVisibility="Auto"
|
||||
Background="#181818" Foreground="#00CCFF" BorderBrush="#444" BorderThickness="1" Padding="8" FontSize="14" AcceptsReturn="True" TextWrapping="Wrap" />
|
||||
Background="{DynamicResource Brush.Bg}" Foreground="{DynamicResource Brush.Info}" BorderBrush="{DynamicResource Brush.Border}" BorderThickness="1" Padding="8" FontSize="14" AcceptsReturn="True" TextWrapping="Wrap" />
|
||||
<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,12,0,0">
|
||||
<Button x:Name="OkButton" Content="OK" Width="110" Margin="6" Padding="10,8"
|
||||
Style="{StaticResource SmallButtonStyle}" Background="#00CC66" Foreground="White" Click="OkButton_Click" />
|
||||
Style="{StaticResource SmallButtonStyle}" Background="{DynamicResource Brush.Success}" Foreground="{DynamicResource Brush.TextOnAccent}" Click="OkButton_Click" />
|
||||
<Button x:Name="CancelButton" Content="Annulla" Width="110" Margin="6" Padding="10,8"
|
||||
Style="{StaticResource SmallButtonStyle}" Background="#666" Foreground="White" Click="CancelButton_Click" />
|
||||
Style="{StaticResource SmallButtonStyle}" Background="{DynamicResource Brush.SurfaceAlt}" Foreground="{DynamicResource Brush.Text}" Click="CancelButton_Click" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<Window x:Class="AutoBidder.Dialogs.StatsCleanupDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Pulizia dello storico"
|
||||
Width="620" SizeToContent="Height"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
ShowInTaskbar="False"
|
||||
Background="{DynamicResource Brush.Bg}">
|
||||
|
||||
<StackPanel Margin="22,18">
|
||||
|
||||
<TextBlock Text="Cosa considerare incompleto"
|
||||
FontSize="{StaticResource Font.Size.Lg}" FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource Brush.Text}"/>
|
||||
|
||||
<TextBlock Style="{StaticResource Hint}" Margin="0,6,0,14"
|
||||
Text="Il conto si aggiorna mentre scegli. Niente viene toccato finché non premi Pulisci, e viene salvata una copia dello storico prima di procedere."/>
|
||||
|
||||
<CheckBox x:Name="ChkNoPrice" Margin="0,4" IsChecked="True"
|
||||
Content="Aste senza prezzo finale"
|
||||
ToolTip="Non dicono nulla e sporcano ogni media: il prezzo è il dato su cui si regge tutto il resto."
|
||||
Checked="Option_Changed" Unchecked="Option_Changed"/>
|
||||
|
||||
<CheckBox x:Name="ChkBadBids" Margin="0,4" IsChecked="True"
|
||||
Content="Aste con puntate del vincitore incoerenti col prezzo"
|
||||
ToolTip="Ogni puntata alza il prezzo di un centesimo, quindi il prezzo in centesimi è il totale delle puntate dell'asta. Un vincitore che ne dichiara di più — o zero — porta un dato che non può essere vero."
|
||||
Checked="Option_Changed" Unchecked="Option_Changed"/>
|
||||
|
||||
<CheckBox x:Name="ChkDuplicates" Margin="0,4" IsChecked="True"
|
||||
Content="Doppioni con lo stesso identificativo (tiene il più recente)"
|
||||
ToolTip="La stessa asta può essere registrata due volte: quando il motore ne vede la fine e quando viene tolta dal monitor. Si tiene la versione più recente."
|
||||
Checked="Option_Changed" Unchecked="Option_Changed"/>
|
||||
|
||||
<CheckBox x:Name="ChkNoWinnerBids" Margin="0,4"
|
||||
Content="Aste di cui non si conoscono le puntate del vincitore"
|
||||
ToolTip="Severo: toglie tutte le aste su cui non si può calcolare il costo reale. Prima di usarlo, prova «Recupera puntate dei vincitori» nella scheda Storico — il dato si può quasi sempre riprendere dal server."
|
||||
Checked="Option_Changed" Unchecked="Option_Changed"/>
|
||||
|
||||
<CheckBox x:Name="ChkNoWinner" Margin="0,4"
|
||||
Content="Aste senza vincitore"
|
||||
ToolTip="Aste scadute senza offerte, oppure registrate a metà."
|
||||
Checked="Option_Changed" Unchecked="Option_Changed"/>
|
||||
|
||||
<CheckBox x:Name="ChkNoValue" Margin="0,4"
|
||||
Content="Aste senza valore del prodotto"
|
||||
ToolTip="Senza il «Compra Subito» non si può calcolare il risparmio, ma il prezzo e le puntate restano validi."
|
||||
Checked="Option_Changed" Unchecked="Option_Changed"/>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
|
||||
<CheckBox x:Name="ChkCoverage" VerticalAlignment="Center"
|
||||
Content="Aste seguite per meno del"
|
||||
ToolTip="Toglie le aste agganciate a metà. Sono il caso peggiore: i numeri sono veri ma parziali, quindi sembrano buone e abbassano le medie senza dare segnali. Quanta asta si è vista si ricava dal prezzo finale, senza bisogno di alcun dato in più: ogni puntata vale un centesimo, quindi il prezzo in centesimi è il totale delle puntate dell'asta, e i reset osservati dicono quanti se ne sono visti. Sul tuo storico, su 5876 aste: al 75% ne resterebbero circa 78 su 100, al 90% circa 64, al 95% circa 54, al 99% circa 34."
|
||||
Checked="Option_Changed" Unchecked="Option_Changed"/>
|
||||
<TextBox x:Name="CoverageBox" Text="90" Width="50" Margin="8,0"
|
||||
VerticalAlignment="Center" TextChanged="Option_Changed"/>
|
||||
<TextBlock Text="% della loro durata" VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.Text}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
|
||||
<CheckBox x:Name="ChkOlderThan" VerticalAlignment="Center"
|
||||
Content="Aste chiuse da più di"
|
||||
ToolTip="Le aste vecchie descrivono un mercato che può essere cambiato."
|
||||
Checked="Option_Changed" Unchecked="Option_Changed"/>
|
||||
<TextBox x:Name="DaysBox" Text="180" Width="60" Margin="8,0"
|
||||
VerticalAlignment="Center" TextChanged="Option_Changed"/>
|
||||
<TextBlock Text="giorni" VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.Text}"/>
|
||||
</StackPanel>
|
||||
|
||||
<Border Style="{StaticResource InfoBox}" Margin="0,16,0,0">
|
||||
<StackPanel>
|
||||
<TextBlock x:Name="SummaryText" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource Brush.Text}"
|
||||
FontSize="{StaticResource Font.Size.Sm}" LineHeight="18"
|
||||
Text="Calcolo…"/>
|
||||
<TextBlock x:Name="DetailText" TextWrapping="Wrap" Margin="0,8,0,0"
|
||||
Foreground="{DynamicResource Brush.TextMuted}"
|
||||
FontSize="{StaticResource Font.Size.Sm}" LineHeight="17"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,18,0,0">
|
||||
<Button x:Name="CleanButton" Content="Pulisci" Padding="26,7" Margin="0,0,10,0"
|
||||
Style="{StaticResource ModernButton}"
|
||||
Background="{DynamicResource Brush.Danger}"
|
||||
Foreground="{DynamicResource Brush.TextOnAccent}"
|
||||
Click="Clean_Click"/>
|
||||
<Button Content="Annulla" Padding="26,7"
|
||||
Style="{StaticResource ModernButton}"
|
||||
Background="{DynamicResource Brush.SurfaceAlt}"
|
||||
IsCancel="True"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Window>
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// Sceglie cosa considerare incompleto nello storico e lo toglie.
|
||||
///
|
||||
/// <para>Il conto si aggiorna a ogni spunta, <b>prima</b> di toccare qualunque cosa: una
|
||||
/// pulizia è irreversibile, e l'unico modo di renderla una decisione informata è mostrare
|
||||
/// quante righe cadrebbero e per quale motivo mentre si sceglie. La copia di sicurezza
|
||||
/// prima di scrivere è la seconda rete: le statistiche sono mesi di raccolta che nessun
|
||||
/// pulsante ha il diritto di far sparire per un clic distratto.</para>
|
||||
/// </summary>
|
||||
public partial class StatsCleanupDialog : Window
|
||||
{
|
||||
private readonly List<CompletedAuctionRecord> _records;
|
||||
|
||||
public StatsCleanupDialog(List<CompletedAuctionRecord> records)
|
||||
{
|
||||
InitializeComponent();
|
||||
_records = records ?? new List<CompletedAuctionRecord>();
|
||||
Loaded += (_, _) => Refresh();
|
||||
}
|
||||
|
||||
/// <summary>Righe rimosse, dopo la conferma. 0 se l'utente ha annullato.</summary>
|
||||
public int RemovedCount { get; private set; }
|
||||
|
||||
/// <summary>Dove è finita la copia di sicurezza.</summary>
|
||||
public string? BackupPath { get; private set; }
|
||||
|
||||
private StatsMaintenance.CleanupOptions ReadOptions()
|
||||
{
|
||||
var options = new StatsMaintenance.CleanupOptions
|
||||
{
|
||||
RemoveWithoutPrice = ChkNoPrice.IsChecked == true,
|
||||
RemoveInconsistentBids = ChkBadBids.IsChecked == true,
|
||||
RemoveDuplicates = ChkDuplicates.IsChecked == true,
|
||||
RemoveWithoutWinnerBids = ChkNoWinnerBids.IsChecked == true,
|
||||
RemoveWithoutWinner = ChkNoWinner.IsChecked == true,
|
||||
RemoveWithoutValue = ChkNoValue.IsChecked == true
|
||||
};
|
||||
|
||||
// Una soglia illeggibile o fuori scala non deve diventare "togli tutto":
|
||||
// il filtro resta spento finché il numero non ha senso.
|
||||
if (ChkCoverage.IsChecked == true &&
|
||||
double.TryParse(CoverageBox.Text.Trim().Replace(',', '.'),
|
||||
System.Globalization.NumberStyles.Float,
|
||||
System.Globalization.CultureInfo.InvariantCulture, out var percento) &&
|
||||
percento is > 0 and <= 100)
|
||||
{
|
||||
options.MinObservedCoverage = percento / 100.0;
|
||||
}
|
||||
|
||||
if (ChkOlderThan.IsChecked == true &&
|
||||
int.TryParse(DaysBox.Text.Trim(), out var days) && days > 0)
|
||||
{
|
||||
options.OlderThan = DateTime.Now.AddDays(-days);
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
private void Option_Changed(object sender, RoutedEventArgs e) => Refresh();
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
if (SummaryText == null) return;
|
||||
|
||||
var report = StatsMaintenance.Preview(_records, ReadOptions());
|
||||
|
||||
SummaryText.Text = report.Removed == 0
|
||||
? $"Nessuna delle {report.Total} aste verrebbe tolta."
|
||||
: $"Verrebbero tolte {report.Removed} aste su {report.Total}. " +
|
||||
$"Ne resterebbero {report.Kept}.";
|
||||
|
||||
DetailText.Text = report.ByReason.Count == 0
|
||||
? ""
|
||||
: string.Join("\n", report.ByReason
|
||||
.OrderByDescending(kv => kv.Value)
|
||||
.Select(kv => $"• {kv.Value} {kv.Key}"));
|
||||
|
||||
CleanButton.IsEnabled = report.Removed > 0;
|
||||
}
|
||||
|
||||
private void Clean_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var options = ReadOptions();
|
||||
var report = StatsMaintenance.Preview(_records, options);
|
||||
|
||||
if (report.Removed == 0) return;
|
||||
|
||||
var answer = MessageBox.Show(this,
|
||||
$"Tolgo {report.Removed} aste su {report.Total}.\n\n" +
|
||||
"L'operazione non è reversibile, ma prima viene salvata una copia " +
|
||||
"dello storico nella cartella dei backup.\n\nProcedo?",
|
||||
"Pulizia dello storico", MessageBoxButton.YesNo, MessageBoxImage.Warning);
|
||||
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
try
|
||||
{
|
||||
BackupPath = CompletedAuctionsStore.BackupNow();
|
||||
|
||||
// La stessa risposta usata per il conto: contare con una regola e
|
||||
// cancellare con un'altra è il modo classico di far sparire dati che
|
||||
// nessuno voleva perdere.
|
||||
var kept = StatsMaintenance.Apply(_records, options);
|
||||
CompletedAuctionsStore.ReplaceAll(kept);
|
||||
|
||||
RemovedCount = report.Removed;
|
||||
DialogResult = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(this, $"Pulizia non riuscita: {ex.Message}",
|
||||
"Pulizia dello storico", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,357 +0,0 @@
|
||||
# AutoBidder v4.0 - Architettura Completa
|
||||
|
||||
## ?? Diagramma Architettura
|
||||
|
||||
```
|
||||
???????????????????????????????????????????????????????????????????????
|
||||
? MainWindow.xaml ?
|
||||
? (TabControl Principale) ?
|
||||
???????????????????????????????????????????????????????????????????????
|
||||
? ?
|
||||
? ????????????? ????????????? ???????????????? ???????????????? ?
|
||||
? ? ?? Monitor? ? ?? Browser? ? ?? Statistiche? ? ?? Impostazioni? ?
|
||||
? ? Aste ? ? ? ? ? ? ? ?
|
||||
? ????????????? ????????????? ???????????????? ???????????????? ?
|
||||
? ? ? ? ? ?
|
||||
? ? ? ? ? ?
|
||||
? ??????????????????????????????????????????????????????????????? ?
|
||||
? ? UserControls (4 controlli modulari) ? ?
|
||||
? ??????????????????????????????????????????????????????????????? ?
|
||||
? ?
|
||||
?????????????????????????????????????????????????????????????????????
|
||||
?
|
||||
? Events & Data Binding
|
||||
?
|
||||
?
|
||||
???????????????????????????????????????????????????????????????????????
|
||||
? MainWindow Code-Behind ?
|
||||
? (Partial Classes - 13 file) ?
|
||||
???????????????????????????????????????????????????????????????????????
|
||||
? ?
|
||||
? MainWindow.xaml.cs ? Core & Initialization ?
|
||||
? MainWindow.ControlEvents.cs ? NEW: Event Routing ?
|
||||
? MainWindow.Commands.cs ? Command Pattern ?
|
||||
? MainWindow.AuctionManagement.cs ? CRUD Aste ?
|
||||
? MainWindow.EventHandlers.Browser.cs ? Browser Logic ?
|
||||
? MainWindow.EventHandlers.Export.cs ? Export Features ?
|
||||
? MainWindow.EventHandlers.Settings.cs ? Settings Management ?
|
||||
? MainWindow.EventHandlers.Stats.cs ? Statistics Analysis ?
|
||||
? MainWindow.Logging.cs ? Logging System ?
|
||||
? MainWindow.UIUpdates.cs ? UI Refresh ?
|
||||
? MainWindow.UrlParsing.cs ? URL Utilities ?
|
||||
? MainWindow.UserInfo.cs ? User Session ?
|
||||
? MainWindow.ButtonHandlers.cs ? Button Events ?
|
||||
? ?
|
||||
?????????????????????????????????????????????????????????????????????
|
||||
?
|
||||
? Service Layer
|
||||
?
|
||||
?
|
||||
???????????????????????????????????????????????????????????????????????
|
||||
? Services Layer ?
|
||||
???????????????????????????????????????????????????????????????????????
|
||||
? ?
|
||||
? AuctionMonitor ? Core monitoring service ?
|
||||
? BidooApiClient ? HTTP API client ?
|
||||
? SessionManager ? Session persistence ?
|
||||
? StatsService ? Statistics engine ?
|
||||
? ClosedAuctionsScraper ? Data scraping ?
|
||||
? ?
|
||||
?????????????????????????????????????????????????????????????????????
|
||||
?
|
||||
? Data Access
|
||||
?
|
||||
?
|
||||
???????????????????????????????????????????????????????????????????????
|
||||
? Models & Data Layer ?
|
||||
???????????????????????????????????????????????????????????????????????
|
||||
? ?
|
||||
? Models/ ?
|
||||
? ??? AuctionInfo ? Dati asta ?
|
||||
? ??? AuctionState ? Stato runtime ?
|
||||
? ??? BidResult ? Risultato puntata ?
|
||||
? ??? BidHistory ? Storico ?
|
||||
? ??? BidderInfo ? Info utenti ?
|
||||
? ??? ... ?
|
||||
? ?
|
||||
? ViewModels/ ?
|
||||
? ??? AuctionViewModel ? MVVM pattern ?
|
||||
? ?
|
||||
? Data/ ?
|
||||
? ??? StatisticsContext ? EF Core DbContext ?
|
||||
? ?
|
||||
? Utilities/ ?
|
||||
? ??? PersistenceManager ? Salvataggio JSON ?
|
||||
? ??? SettingsManager ? App settings ?
|
||||
? ??? CsvExporter ? Export utilities ?
|
||||
? ??? ... ?
|
||||
? ?
|
||||
???????????????????????????????????????????????????????????????????????
|
||||
```
|
||||
|
||||
## ?? Flusso Dati
|
||||
|
||||
### 1. User Interaction Flow
|
||||
```
|
||||
User Click
|
||||
?
|
||||
UserControl (XAML)
|
||||
?
|
||||
UserControl.xaml.cs (Routed Event)
|
||||
?
|
||||
MainWindow.ControlEvents.cs (Event Router)
|
||||
?
|
||||
MainWindow.[Feature].cs (Business Logic)
|
||||
?
|
||||
Service Layer (AuctionMonitor, ApiClient, etc.)
|
||||
?
|
||||
Models/Data Update
|
||||
?
|
||||
Property Change Notification
|
||||
?
|
||||
UI Update (Data Binding)
|
||||
```
|
||||
|
||||
### 2. Auction Monitoring Flow
|
||||
```
|
||||
AuctionMonitor.Start()
|
||||
?
|
||||
Polling Loop (async)
|
||||
?
|
||||
BidooApiClient.PollAuctionStateAsync()
|
||||
?
|
||||
HTTP Request to Bidoo API
|
||||
?
|
||||
Parse JSON Response
|
||||
?
|
||||
Update AuctionState
|
||||
?
|
||||
Fire OnAuctionUpdated Event
|
||||
?
|
||||
MainWindow.AuctionMonitor_OnAuctionUpdated()
|
||||
?
|
||||
Update AuctionViewModel
|
||||
?
|
||||
DataGrid Auto-Refresh (INotifyPropertyChanged)
|
||||
```
|
||||
|
||||
### 3. Export Flow
|
||||
```
|
||||
User Click "Esporta"
|
||||
?
|
||||
MainWindow.EventHandlers.Export.cs
|
||||
?
|
||||
Load Export Settings
|
||||
?
|
||||
Filter Auctions (Open/Closed/Unknown)
|
||||
?
|
||||
For Each Auction:
|
||||
?? Generate File (CSV/JSON/XML)
|
||||
?? CsvExporter / JsonSerializer / XDocument
|
||||
?? Save to Disk
|
||||
?
|
||||
Optional: Remove Exported Auctions
|
||||
?
|
||||
Show Completion Message
|
||||
```
|
||||
|
||||
## ?? Componenti Chiave
|
||||
|
||||
### UserControls
|
||||
```
|
||||
Controls/
|
||||
??? AuctionMonitorControl [430 lines XAML]
|
||||
? ??? Header (Toolbar)
|
||||
? ??? MainContent (Grid + Details)
|
||||
? ??? Footer (Global Log)
|
||||
?
|
||||
??? BrowserControl [120 lines XAML]
|
||||
? ??? Navigation Toolbar
|
||||
? ??? WebView2 Embedded
|
||||
?
|
||||
??? StatisticsControl [80 lines XAML]
|
||||
? ??? Header (Load Button)
|
||||
? ??? DataGrid (Stats)
|
||||
? ??? Footer (Progress)
|
||||
?
|
||||
??? SettingsControl [200 lines XAML]
|
||||
??? Session Config
|
||||
??? Export Settings
|
||||
??? Auction Defaults
|
||||
```
|
||||
|
||||
### Partial Classes
|
||||
```
|
||||
MainWindow/
|
||||
??? xaml.cs [150 lines] Core
|
||||
??? ControlEvents.cs [150 lines] NEW: Event routing
|
||||
??? Commands.cs [80 lines] Commands
|
||||
??? AuctionManagement.cs [200 lines] CRUD
|
||||
??? EventHandlers.*.cs [600 lines] Events (4 files)
|
||||
??? Logging.cs [50 lines] Log system
|
||||
??? UIUpdates.cs [120 lines] UI refresh
|
||||
??? UrlParsing.cs [80 lines] URL utils
|
||||
??? UserInfo.cs [140 lines] Session
|
||||
??? ButtonHandlers.cs [200 lines] Buttons
|
||||
```
|
||||
|
||||
## ?? Design Patterns Utilizzati
|
||||
|
||||
### 1. **MVVM (Model-View-ViewModel)**
|
||||
- `Model`: AuctionInfo, BidHistory, etc.
|
||||
- `View`: XAML files (MainWindow, UserControls)
|
||||
- `ViewModel`: AuctionViewModel (INotifyPropertyChanged)
|
||||
|
||||
### 2. **Service Layer**
|
||||
- `AuctionMonitor`: Orchestrazione monitoring
|
||||
- `BidooApiClient`: HTTP communication
|
||||
- `SessionManager`: Persistenza sessione
|
||||
|
||||
### 3. **Repository Pattern**
|
||||
- `PersistenceManager`: Load/Save aste
|
||||
- `SettingsManager`: Load/Save settings
|
||||
|
||||
### 4. **Observer Pattern**
|
||||
- Events: `OnAuctionUpdated`, `OnBidExecuted`, `OnLog`
|
||||
- Data Binding: `INotifyPropertyChanged`
|
||||
|
||||
### 5. **Command Pattern**
|
||||
- `RelayCommand`: WPF ICommand implementation
|
||||
- Grid commands: Start, Pause, Stop, Bid
|
||||
|
||||
### 6. **Composite Pattern**
|
||||
- UserControls compongono il MainWindow
|
||||
- Ogni controllo è autonomo ma collabora
|
||||
|
||||
### 7. **Strategy Pattern**
|
||||
- Export formats: CSV, JSON, XML
|
||||
- Diversi scraper per HTML parsing
|
||||
|
||||
## ?? Sicurezza & Best Practices
|
||||
|
||||
### ? Implementate
|
||||
- [x] Cookie encryption (future enhancement)
|
||||
- [x] Input validation (URL, prezzi, etc.)
|
||||
- [x] Error handling robusto
|
||||
- [x] Logging strutturato
|
||||
- [x] Thread safety (lock su collections)
|
||||
|
||||
### ?? Raccomandazioni Future
|
||||
- [ ] Secure credential storage (Windows Credential Manager)
|
||||
- [ ] Rate limiting per API calls
|
||||
- [ ] Retry policy con exponential backoff
|
||||
- [ ] Circuit breaker pattern per resilienza
|
||||
- [ ] Telemetry & monitoring
|
||||
|
||||
## ?? Metriche Codebase
|
||||
|
||||
| Metrica | Prima | Dopo | Delta |
|
||||
|---------|-------|------|-------|
|
||||
| File XAML | 1 (1000 lines) | 5 (100+4×150) | +4 files |
|
||||
| File C# (MainWindow) | 2 | 14 | +12 files |
|
||||
| Dimensione media file | 500 lines | 120 lines | -76% |
|
||||
| Linee per classe | 1000+ | 50-200 | -80% |
|
||||
| Complessità ciclomatica | Alta | Bassa | ?? |
|
||||
| Testabilità | 30% | 85% | +55% |
|
||||
| Riutilizzabilità | 10% | 90% | +80% |
|
||||
|
||||
## ?? Performance
|
||||
|
||||
### Ottimizzazioni
|
||||
1. **Lazy Loading**: Tab caricati on-demand
|
||||
2. **Virtual Scrolling**: DataGrid virtualizzato
|
||||
3. **Async Operations**: Tutte le IO sono async
|
||||
4. **Caching**: Stati asta cachati in memoria
|
||||
5. **Debouncing**: TextBox changes debounced
|
||||
|
||||
### Benchmarks Stimati
|
||||
- Startup time: ~2s (cold), ~0.5s (warm)
|
||||
- UI responsiveness: <16ms per frame (60fps)
|
||||
- Memory footprint: ~100MB base + 10MB per 100 aste
|
||||
- API polling: ~50-200ms latency media
|
||||
|
||||
## ?? Documentazione
|
||||
|
||||
### File Documentazione Creati
|
||||
1. `REFACTORING_SUMMARY.md` - Code-behind refactoring
|
||||
2. `XAML_REFACTORING_SUMMARY.md` - XAML refactoring
|
||||
3. `ARCHITECTURE_OVERVIEW.md` - Questo file
|
||||
|
||||
### XML Comments
|
||||
Tutte le classi public hanno XML documentation:
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Descrizione classe
|
||||
/// </summary>
|
||||
/// <param name="param">Descrizione parametro</param>
|
||||
/// <returns>Descrizione return</returns>
|
||||
```
|
||||
|
||||
## ?? Getting Started
|
||||
|
||||
### Per Sviluppatori
|
||||
|
||||
1. **Clona il repository**
|
||||
```bash
|
||||
git clone https://192.168.30.23/Alby96/Mimante
|
||||
cd Mimante/Mimante
|
||||
```
|
||||
|
||||
2. **Apri in Visual Studio 2022**
|
||||
- Apri `AutoBidder.csproj`
|
||||
- Restore NuGet packages
|
||||
- Build Solution
|
||||
|
||||
3. **Struttura Progetto**
|
||||
- `/Controls/` - UserControls modulari
|
||||
- `/Services/` - Business logic
|
||||
- `/Models/` - Data models
|
||||
- `/ViewModels/` - MVVM ViewModels
|
||||
- `/Utilities/` - Helper utilities
|
||||
|
||||
4. **Workflow Sviluppo**
|
||||
- Modifica UI ? Edit UserControl XAML
|
||||
- Modifica logic ? Edit MainWindow partial classes
|
||||
- Aggiungi feature ? Create new service/model
|
||||
- Test ? Build & Run
|
||||
|
||||
### Per Utenti Finali
|
||||
|
||||
1. **Primo Avvio**
|
||||
- Tab "Impostazioni" ? Configura sessione (cookie)
|
||||
- Tab "Impostazioni" ? Imposta percorso export
|
||||
|
||||
2. **Monitoraggio Aste**
|
||||
- Tab "Monitor Aste" ? Aggiungi URL/ID asta
|
||||
- Clicca "Avvia" per iniziare il monitoring
|
||||
- Configura parametri asta nel pannello dettagli
|
||||
|
||||
3. **Statistiche**
|
||||
- Tab "Statistiche" ? Carica aste chiuse
|
||||
- Analizza medie prezzi e click
|
||||
|
||||
## ?? Troubleshooting
|
||||
|
||||
### Problemi Comuni
|
||||
|
||||
**Problema**: Cookie non valido
|
||||
- **Soluzione**: Vai su bidoo.com, F12 > Application > Cookies > Copia __stattrb
|
||||
|
||||
**Problema**: WebView2 non si carica
|
||||
- **Soluzione**: Installa WebView2 Runtime da microsoft.com
|
||||
|
||||
**Problema**: Export fallisce
|
||||
- **Soluzione**: Verifica permessi cartella e spazio disco
|
||||
|
||||
**Problema**: Asta non viene monitorata
|
||||
- **Soluzione**: Verifica che sia attiva (checkbox) e non in pausa
|
||||
|
||||
## ?? Support
|
||||
|
||||
- **Issues**: GitHub Issues
|
||||
- **Docs**: `/docs` folder
|
||||
- **Wiki**: Project Wiki
|
||||
|
||||
---
|
||||
|
||||
**AutoBidder v4.0** - Architettura modulare e scalabile per il monitoraggio automatizzato delle aste Bidoo.com ??
|
||||
@@ -1,309 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
Tutte le modifiche importanti a questo progetto saranno documentate in questo file.
|
||||
|
||||
Il formato è basato su [Keep a Changelog](https://keepachangelog.com/it/1.0.0/),
|
||||
e questo progetto aderisce a [Semantic Versioning](https://semver.org/lang/it/).
|
||||
|
||||
## [4.0.0] - 2024
|
||||
|
||||
### 🎉 Maggiori Cambiamenti
|
||||
|
||||
#### Refactoring Architettura
|
||||
- **Partial Classes**: MainWindow diviso in 13 file partial per responsabilità specifiche
|
||||
- **UserControls Modulari**: Creati 5 UserControls riutilizzabili (AuctionMonitor, Browser, Settings, Statistics, SimpleToolbar)
|
||||
- **Struttura a Cartelle**: Riorganizzazione completa del progetto in cartelle logiche
|
||||
|
||||
#### Nuovo Layout UI
|
||||
- **Dashboard Moderna**: Layout a griglia con panel ridimensionabili
|
||||
- **GridSplitters**: 4 splitter per personalizzazione completa del workspace
|
||||
- **Design Dark Theme**: Palette colori consistente (#1E1E1E, #252526, #2D2D30)
|
||||
- **Card-Style Panels**: Tutti i pannelli con bordi arrotondati e ombre
|
||||
|
||||
### ✨ Nuove Funzionalità
|
||||
|
||||
#### Sistema di Logging Avanzato
|
||||
- Log colorati per severity (Info, Success, Warn, Error)
|
||||
- Timestamp automatici
|
||||
- Auto-scroll intelligente
|
||||
- Log globale + log per singola asta
|
||||
|
||||
#### Monitoraggio Aste
|
||||
- Monitoraggio simultaneo di più aste
|
||||
- Polling HTTP API-based (no Selenium)
|
||||
- Tracking real-time timer, prezzo, offerenti
|
||||
- Statistiche dettagliate per asta
|
||||
|
||||
#### Browser Integrato
|
||||
- WebView2 Microsoft Edge
|
||||
- Navigazione completa su Bidoo
|
||||
- Aggiunta rapida aste da URL
|
||||
- Context menu personalizzato
|
||||
|
||||
#### Export Dati
|
||||
- Supporto formati: CSV, JSON, XML
|
||||
- Export massivo o per singola asta
|
||||
- Opzioni configurabili (logs, bidders, metadata)
|
||||
- Auto-rimozione dopo export
|
||||
|
||||
### 🔧 Miglioramenti
|
||||
|
||||
#### Performance
|
||||
- Ridotto uso memoria con lazy loading UserControls
|
||||
- Ottimizzazione rendering DataGrid con virtualizzazione
|
||||
- Async/await per tutte le operazioni I/O
|
||||
- Throttling polling API
|
||||
|
||||
#### UX/UI
|
||||
- Icone emoji per maggiore leggibilità
|
||||
- Tooltip informativi su bottoni disabilitati
|
||||
- Feedback visivo per azioni utente
|
||||
- Messaggi di errore user-friendly
|
||||
|
||||
#### Code Quality
|
||||
- Riduzione complessità ciclomatica
|
||||
- Separazione concerns (SoC)
|
||||
- Eliminazione codice duplicato
|
||||
- XML documentation per API pubbliche
|
||||
|
||||
### 📦 Dipendenze
|
||||
|
||||
#### Aggiunte
|
||||
- `Microsoft.EntityFrameworkCore.Sqlite` v8.0.0
|
||||
- `Microsoft.Web.WebView2` v1.0.1343.22
|
||||
- `Microsoft.Windows.SDK.BuildTools` v10.0.26100.6584
|
||||
|
||||
#### Rimosse
|
||||
- ~~Selenium.WebDriver~~ (sostituito con HTTP API)
|
||||
- ~~Selenium.WebDriver.ChromeDriver~~ (non più necessario)
|
||||
|
||||
### 🐛 Bug Fix
|
||||
|
||||
#### Critici
|
||||
- Fix memory leak in AuctionMonitor polling loop
|
||||
- Fix race condition in bid execution
|
||||
- Fix crash quando WebView2 non inizializzato
|
||||
- Fix parsing URL con caratteri speciali
|
||||
|
||||
#### Minori
|
||||
- Fix auto-scroll log quando raggiunge bottom
|
||||
- Fix selezione asta dopo rimozione
|
||||
- Fix salvataggio impostazioni con valori nulli
|
||||
- Fix export XML con caratteri escape
|
||||
|
||||
### 🔒 Sicurezza
|
||||
|
||||
- Cookie session storage cifrato
|
||||
- Validazione input URL
|
||||
- Sanitizzazione dati prima di export
|
||||
- Protezione contro injection in log
|
||||
|
||||
### 📝 Documentazione
|
||||
|
||||
#### Nuovi File
|
||||
- `README.md` - Panoramica progetto e setup
|
||||
- `REFACTORING_SUMMARY.md` - Dettagli refactoring code-behind
|
||||
- `XAML_REFACTORING_SUMMARY.md` - Dettagli refactoring XAML
|
||||
- `ARCHITECTURE_OVERVIEW.md` - Overview architettura software
|
||||
- `XAML_REFACTORING_CHECKLIST.md` - Checklist implementazione
|
||||
- `CHANGELOG.md` - Questo file
|
||||
|
||||
#### Guide
|
||||
- Guida importazione cookie da browser
|
||||
- Best practices per configurazione aste
|
||||
- FAQ troubleshooting comuni
|
||||
|
||||
### 🗂️ Struttura Progetto
|
||||
|
||||
```
|
||||
Prima:
|
||||
AutoBidder/
|
||||
├── MainWindow.xaml/cs (2000+ righe)
|
||||
├── Models/
|
||||
├── Services/
|
||||
└── Utilities/
|
||||
|
||||
Dopo:
|
||||
AutoBidder/
|
||||
├── Core/
|
||||
│ ├── MainWindow files (13 partial classes)
|
||||
│ └── EventHandlers/
|
||||
├── Controls/ (5 UserControls)
|
||||
├── Dialogs/
|
||||
├── Models/
|
||||
├── Services/
|
||||
├── ViewModels/
|
||||
├── Utilities/
|
||||
├── Data/
|
||||
└── Documentation/
|
||||
```
|
||||
|
||||
### 📊 Metriche
|
||||
|
||||
| Metrica | Prima | Dopo | Miglioramento |
|
||||
|---------|-------|------|---------------|
|
||||
| LOC MainWindow.xaml | 1000+ | 100 | -90% |
|
||||
| LOC MainWindow.xaml.cs | 2000+ | 180 | -91% |
|
||||
| File partial classes | 1 | 13 | +1200% |
|
||||
| Complessità ciclomatica | 85 | 12 | -86% |
|
||||
| Test coverage | 0% | 45% | +45% |
|
||||
| Manutenibilità | 35 | 82 | +134% |
|
||||
|
||||
### ⚠️ Breaking Changes
|
||||
|
||||
- **Namespace Changes**: Alcuni namespace sono stati riorganizzati
|
||||
- **API Changes**: `AuctionMonitor` ha nuova signature per eventi
|
||||
- **Config Format**: Formato file `app_settings.json` modificato
|
||||
- **Database Schema**: Aggiunto campo `PollingLatencyMs` a statistiche
|
||||
|
||||
### 🔄 Migrazioni
|
||||
|
||||
#### Da v3.x a v4.0
|
||||
|
||||
1. **Cookie Session**:
|
||||
```json
|
||||
// Vecchio formato
|
||||
{ "cookie": "..." }
|
||||
|
||||
// Nuovo formato
|
||||
{ "authCookie": "...", "userId": "...", "expiryDate": "..." }
|
||||
```
|
||||
|
||||
2. **Aste Salvate**:
|
||||
- Percorso spostato da `auctions.json` → `saved_auctions.json`
|
||||
- Eseguire script migrazione: `dotnet run --migrate`
|
||||
|
||||
3. **Database SQLite**:
|
||||
- Nuova tabella `AuctionStatistics`
|
||||
- Eseguire: `dotnet ef database update`
|
||||
|
||||
### 🎯 Roadmap Futura
|
||||
|
||||
#### v4.1 (Q1 2025)
|
||||
- [ ] Sistema notifiche desktop
|
||||
- [ ] Multi-account support
|
||||
- [ ] Temi personalizzabili
|
||||
- [ ] Backup cloud automatico
|
||||
|
||||
#### v4.2 (Q2 2025)
|
||||
- [ ] Machine Learning per bid prediction
|
||||
- [ ] Analytics dashboard avanzato
|
||||
- [ ] Plugin system
|
||||
- [ ] REST API per integrazioni
|
||||
|
||||
#### v5.0 (Q3 2025)
|
||||
- [ ] Architettura microservizi
|
||||
- [ ] Web version (Blazor)
|
||||
- [ ] Mobile app (MAUI)
|
||||
- [ ] Multi-piattaforma (Linux, macOS)
|
||||
|
||||
### 🙏 Ringraziamenti
|
||||
|
||||
- **Microsoft**: Per .NET 8 e WPF
|
||||
- **WebView2 Team**: Per il fantastico browser embedded
|
||||
- **EF Core Team**: Per l'ORM potente e leggero
|
||||
- **Bidoo**: Per la piattaforma aste (non ufficialmente affiliati)
|
||||
|
||||
---
|
||||
|
||||
**Legenda Emoji**:
|
||||
- 🎉 Maggiori cambiamenti
|
||||
- ✨ Nuove funzionalità
|
||||
- 🔧 Miglioramenti
|
||||
- 🐛 Bug fix
|
||||
- 🔒 Sicurezza
|
||||
- 📝 Documentazione
|
||||
- 🗂️ Struttura
|
||||
- 📊 Metriche
|
||||
- ⚠️ Breaking changes
|
||||
- 🔄 Migrazioni
|
||||
- 🎯 Roadmap
|
||||
- 🙏 Ringraziamenti
|
||||
|
||||
## v4.1 - UI Modernizzata (2024-01-XX)
|
||||
|
||||
### 🎨 Miglioramenti UI
|
||||
- ✅ **Header semplificato**: Info utente spostate in basso a sinistra
|
||||
- ✅ **Pannello utente** elegante con:
|
||||
- Username + ID utente
|
||||
- Email
|
||||
- Design card moderno con bordi arrotondati
|
||||
- Visibilità automatica (appare solo quando loggato)
|
||||
- ✅ **Header compatto** con statistiche chiave:
|
||||
- Puntate residue (verde #00D800)
|
||||
- Credito Shop (verde #00D800)
|
||||
- Aste vinte (giallo #FFB700)
|
||||
- ✅ **Layout pulito** stile moderno con separatori verticali
|
||||
|
||||
### ⚙️ Performance
|
||||
- ✅ **Aggiornamento ogni 5 minuti** (era 1 minuto)
|
||||
- Timer HTML principale: 5 minuti
|
||||
- Timer API fallback: 10 minuti
|
||||
- Ridotto carico rete del 80%
|
||||
- ✅ Pannello utente nascosto di default (meno distrazione)
|
||||
|
||||
### 📊 Posizionamento Info
|
||||
```
|
||||
┌─────────────────────────────────────────────┐
|
||||
│ Puntate: 199 | Credito: EUR 15.00 | Aste: 0│ [Pulsanti]
|
||||
├─────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ GRIGLIA ASTE + LOG │
|
||||
│ │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ IMPOSTAZIONI | UTENTI | LOG │
|
||||
│ │
|
||||
└─────────────────────────────────────────────┘
|
||||
┌────────────────────┐
|
||||
│ sirbietole23 │ ← Pannello utente
|
||||
│ (ID: 6707664) │ in basso a sx
|
||||
│ email@email.com │
|
||||
└────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## v4.0 - Sistema di Timing Avanzato
|
||||
|
||||
### ⚡ Nuovo Sistema di Timing
|
||||
- ✅ Sostituito "Timer Click (secondi)" con "Anticipo (ms)"
|
||||
- ✅ Precisione al millisecondo invece dei secondi
|
||||
- ✅ Polling adattivo 10-1000ms basato su timer rimanente
|
||||
- ✅ Cooldown 800ms tra puntate consecutive
|
||||
- ✅ Rilevamento puntate recenti altri utenti (500ms)
|
||||
- ✅ Checkbox opzionale "Verifica stato asta prima di puntare"
|
||||
|
||||
### 🐛 Bug Fix
|
||||
- ✅ Fix persistenza valori modificati per singola asta
|
||||
- ✅ Fix visualizzazione username e puntate rimanenti
|
||||
- ✅ Conferma richiesta prima di cancellare asta (pulsante + tasto Canc)
|
||||
- ✅ Ottimizzazione logging per miglior performance
|
||||
- ✅ Fix stato pulsanti globali all'avvio
|
||||
- ✅ **Fix tasto Canc**: Ora elimina correttamente l'asta selezionata
|
||||
- Cambiato da `KeyDown` a `PreviewKeyDown` (priorità più alta)
|
||||
- Migliorata gestione focus keyboard sul DataGrid
|
||||
- Aggiunto messaggio di conferma migliorato
|
||||
- Aggiunto logging dettagliato per debug
|
||||
- **Fix messaggio duplicato**: Rimosso secondo messaggio di conferma (ora ne appare solo uno)
|
||||
- ✅ **Fix avvio singola asta**: Ora il pulsante "Avvia" sulla griglia funziona senza "Avvia Tutti"
|
||||
- Auto-start del monitoraggio quando si avvia la prima asta
|
||||
- Auto-stop del monitoraggio quando si ferma l'ultima asta
|
||||
- Logging dettagliato con `[AUTO-START]` e `[AUTO-STOP]`
|
||||
- Comportamento più intuitivo e flessibile
|
||||
- ✅ **Fix persistenza impostazioni predefinite**: Le impostazioni ora vengono applicate e persistono correttamente
|
||||
- Nuove aste usano valori dalle impostazioni salvate invece di hardcoded
|
||||
- Impostazioni predefinite vengono caricate all'avvio
|
||||
- Logging dettagliato quando si salvano/applicano defaults
|
||||
- File settings.json in %LocalAppData%\AutoBidder
|
||||
- ✅ **Fix puntata se già vincitore**: Sistema ora evita di puntare quando l'utente è già il vincitore corrente
|
||||
- Controllo `IsMyBid` in `ShouldBid()` come prima condizione
|
||||
- Logging chiaro: `[STRATEGIA] SKIP: Sono già il vincitore corrente`
|
||||
- Elimina errori "Asta chiusa" quando già vincitore
|
||||
- Risparmia puntate e chiamate API inutili
|
||||
- Punta solo quando serve riprendersi l'asta
|
||||
- ✅ **Fix campo URL browser**: URL sempre visibile e campo non editabile
|
||||
- Campo URL ora `IsReadOnly="True"` (non modificabile)
|
||||
- URL si aggiorna automaticamente ad ogni navigazione
|
||||
- Rimosso pulsante "Vai" non funzionale
|
||||
- Cursore freccia + tooltip esplicativo
|
||||
- UX più chiara e coerente
|
||||
@@ -1,148 +0,0 @@
|
||||
# ?? Diagnostica Recupero Dati Utente
|
||||
|
||||
## Cosa è cambiato
|
||||
|
||||
**NON ho modificato** la procedura di recupero dati utente nelle ultime modifiche.
|
||||
|
||||
Il codice esistente è lo stesso di prima, ma ho aggiunto **logging dettagliato** per capire cosa sta andando storto.
|
||||
|
||||
## Come funziona il recupero dati
|
||||
|
||||
Il sistema usa **2 strategie parallele** (ridondanza per affidabilità):
|
||||
|
||||
### 1?? **METODO PRINCIPALE**: HTML Scraping (Timer 5 minuti)
|
||||
- **URL**: `https://it.bidoo.com/bids_history.php`
|
||||
- **Estrae**: Username, Puntate residue
|
||||
- **Pattern cercati**:
|
||||
```regex
|
||||
<a class="pers_lnk"[^>]*>([^<]+)</a> # Username
|
||||
<span id="divSaldoBidBottom"[^>]*>(\d+)</span> # Puntate
|
||||
```
|
||||
|
||||
### 2?? **METODO FALLBACK**: API (Timer 10 minuti)
|
||||
- **URL**: `https://it.bidoo.com/buy_bids.php`
|
||||
- **Estrae**: Username, Email, ID, Telefono, Puntate, Credito Shop
|
||||
- **Pattern cercati**:
|
||||
```regex
|
||||
BidooCnf.userObj.username = 'username';
|
||||
BidooCnf.userObj.email = 'email@example.com';
|
||||
BidooCnf.userObj.id = '123456';
|
||||
<span id="divSaldoBidMobile">206</span>
|
||||
<span class="cbstotal">15.00</span>
|
||||
```
|
||||
|
||||
## ?? Possibili Cause dell'Errore
|
||||
|
||||
### 1. **Cookie Scaduto o Non Valido**
|
||||
Il cookie `__stattrb` potrebbe essere scaduto o non più valido.
|
||||
|
||||
**Come verificare**:
|
||||
1. Apri il browser e vai su `https://it.bidoo.com`
|
||||
2. Apri DevTools (F12) ? Applicazione ? Cookie
|
||||
3. Controlla se il cookie `__stattrb` esiste
|
||||
4. Copia il nuovo valore e inseriscilo nelle Impostazioni
|
||||
|
||||
### 2. **Sito Bidoo ha Cambiato Struttura HTML**
|
||||
Bidoo potrebbe aver modificato la struttura delle pagine.
|
||||
|
||||
**Come verificare**:
|
||||
1. Guarda i log dettagliati (ora disponibili dopo le modifiche)
|
||||
2. Cerca messaggi tipo:
|
||||
- `[USER HTML ERROR] Username NON trovato nell'HTML`
|
||||
- `[USER HTML DEBUG] Snippet HTML: ...`
|
||||
3. Confronta lo snippet con i pattern regex
|
||||
|
||||
### 3. **Problema di Rete o Firewall**
|
||||
Il server potrebbe bloccare le richieste.
|
||||
|
||||
**Come verificare**:
|
||||
1. Cerca nei log:
|
||||
- `[USER HTML ERROR] HTTP 403` ? Bloccato
|
||||
- `[USER HTML ERROR] HTTP 401` ? Non autorizzato
|
||||
- `[USER HTML ERROR] HTTP 500` ? Errore server
|
||||
|
||||
### 4. **Redirect o Risposta Non HTML**
|
||||
Il server potrebbe fare redirect o rispondere con JSON/testo.
|
||||
|
||||
**Come verificare**:
|
||||
1. Cerca nei log:
|
||||
- `[USER HTML ERROR] Risposta non contiene HTML valido`
|
||||
- `Body length: <100` ? Risposta troppo corta
|
||||
|
||||
## ?? Nuovo Logging Disponibile
|
||||
|
||||
Ho aggiunto logging **molto dettagliato** per diagnosticare:
|
||||
|
||||
### Log nel Console Output
|
||||
```
|
||||
[INFO] Tentativo recupero dati utente da HTML...
|
||||
[USER HTML REQUEST] GET https://it.bidoo.com/bids_history.php
|
||||
[USER HTML RESPONSE] Status: 200 OK
|
||||
[USER HTML RESPONSE] Body length: 45233 chars
|
||||
[USER HTML PARSED] Username trovato: sirbietole23
|
||||
[USER HTML PARSED] Puntate residue trovate: 206
|
||||
[USER HTML SUCCESS] Dati estratti: sirbietole23, 206 puntate
|
||||
[OK] Dati utente aggiornati via HTML: sirbietole23, 206 puntate
|
||||
```
|
||||
|
||||
### Se Fallisce
|
||||
```
|
||||
[USER HTML RESPONSE] Status: 200 OK
|
||||
[USER HTML RESPONSE] Body length: 45233 chars
|
||||
[USER HTML ERROR] Username NON trovato nell'HTML
|
||||
[USER HTML DEBUG] Snippet HTML: <!DOCTYPE html><html lang="it">...
|
||||
[USER HTML ERROR] Puntate residue NON trovate nell'HTML
|
||||
[USER HTML FAILED] Impossibile estrarre dati utente dall'HTML
|
||||
[WARN] HTML scraping non ha restituito dati validi - verifica cookie nelle Impostazioni
|
||||
```
|
||||
|
||||
## ?? Come Risolvere
|
||||
|
||||
### Soluzione 1: Aggiorna Cookie
|
||||
1. Vai su **Impostazioni**
|
||||
2. Clicca **Configura Sessione**
|
||||
3. Inserisci il cookie `__stattrb` aggiornato dal browser
|
||||
4. Clicca **Salva**
|
||||
5. Controlla i log
|
||||
|
||||
### Soluzione 2: Verifica Log Dettagliati
|
||||
1. **Riavvia l'applicazione**
|
||||
2. Aspetta 5-10 secondi (timer automatico parte)
|
||||
3. Guarda il **Log Principale** in basso
|
||||
4. Cerca i messaggi `[USER HTML...]` e `[USER INFO...]`
|
||||
5. Inviami lo snippet HTML se vedi errori
|
||||
|
||||
### Soluzione 3: Test Manuale
|
||||
1. Apri browser e vai su `https://it.bidoo.com/bids_history.php`
|
||||
2. Verifica se sei loggato (vedi username in alto)
|
||||
3. Se non sei loggato ? Cookie scaduto
|
||||
4. Se sei loggato ? Mandami screenshot della pagina
|
||||
|
||||
## ?? Test di Verifica
|
||||
|
||||
Dopo aver seguito le soluzioni, verifica che nei log appaia:
|
||||
|
||||
? **SUCCESSO**:
|
||||
```
|
||||
[OK] Dati utente aggiornati via HTML: tuousername, X puntate
|
||||
```
|
||||
|
||||
? **ANCORA ERRORE**:
|
||||
```
|
||||
[ERROR] Impossibile aggiornare info utente - verifica cookie nelle Impostazioni
|
||||
```
|
||||
|
||||
Se ancora non funziona, **inviami i log completi** dal primo avvio fino all'errore.
|
||||
|
||||
## ?? Supporto
|
||||
|
||||
Se il problema persiste:
|
||||
1. Copia **tutti i log** dal pannello principale
|
||||
2. Invia screenshot della **scheda Impostazioni** (censura cookie se vuoi)
|
||||
3. Dimmi se hai aggiornato il cookie recentemente
|
||||
4. Dimmi se funzionava prima (quando?)
|
||||
|
||||
---
|
||||
|
||||
**Data**: 2025
|
||||
**Versione**: 4.0+
|
||||
@@ -1,288 +0,0 @@
|
||||
# ?? Fix URL Browser - Campo Non Editabile
|
||||
|
||||
## Problema Rilevato
|
||||
|
||||
Nella scheda **Browser**:
|
||||
|
||||
1. ? L'**indirizzo URL** della pagina corrente **non era sempre visibile** nel campo in alto
|
||||
2. ? Il campo era **editabile**, permettendo di inserire URL personalizzati (funzionalità non ancora implementata)
|
||||
3. ? Il pulsante **"Vai"** era presente ma non funzionale
|
||||
|
||||
## Causa del Problema
|
||||
|
||||
Il `TextBox` `BrowserAddress` era configurato come campo editabile standard:
|
||||
|
||||
```xaml
|
||||
<!-- ? PRIMA -->
|
||||
<TextBox x:Name="BrowserAddress"
|
||||
VerticalAlignment="Center"
|
||||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
Foreground="#CCCCCC"
|
||||
Padding="10,0"
|
||||
FontSize="13"/>
|
||||
<!-- Mancava IsReadOnly="True" -->
|
||||
```
|
||||
|
||||
L'URL veniva aggiornato correttamente negli eventi `NavigationStarting` e `NavigationCompleted`, ma:
|
||||
- Il campo era modificabile dall'utente
|
||||
- Il pulsante "Vai" suggeriva una funzionalità non implementata
|
||||
|
||||
## Soluzione Implementata
|
||||
|
||||
### ? 1. Campo URL Non Editabile
|
||||
|
||||
Aggiunto `IsReadOnly="True"` al TextBox:
|
||||
|
||||
```xaml
|
||||
<!-- ? DOPO -->
|
||||
<TextBox x:Name="BrowserAddress"
|
||||
VerticalAlignment="Center"
|
||||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
Foreground="#CCCCCC"
|
||||
Padding="10,0"
|
||||
FontSize="13"
|
||||
IsReadOnly="True"
|
||||
Cursor="Arrow"
|
||||
ToolTip="Indirizzo della pagina corrente (non editabile)"/>
|
||||
```
|
||||
|
||||
**Caratteristiche**:
|
||||
- ? `IsReadOnly="True"` - Non modificabile
|
||||
- ? `Cursor="Arrow"` - Mostra cursore normale (non testo)
|
||||
- ? `ToolTip` - Spiega che il campo è solo visualizzazione
|
||||
|
||||
### ? 2. Rimosso Pulsante "Vai"
|
||||
|
||||
Eliminato il pulsante "Vai" non necessario:
|
||||
|
||||
**Prima**:
|
||||
```xaml
|
||||
<Button x:Name="BrowserGoButton"
|
||||
Content="Vai"
|
||||
Click="BrowserGoButton_Click"/>
|
||||
```
|
||||
|
||||
**Dopo**: Pulsante rimosso ?
|
||||
|
||||
### ? 3. Mantenuto Aggiornamento Automatico
|
||||
|
||||
L'URL viene ancora aggiornato automaticamente in `MainWindow.EventHandlers.Browser.cs`:
|
||||
|
||||
```csharp
|
||||
private void EmbeddedWebView_NavigationStarting(...)
|
||||
{
|
||||
BrowserAddress.Text = e.Uri ?? string.Empty;
|
||||
// ...
|
||||
}
|
||||
|
||||
private void EmbeddedWebView_NavigationCompleted(...)
|
||||
{
|
||||
var uri = EmbeddedWebView?.Source?.ToString() ?? BrowserAddress.Text;
|
||||
BrowserAddress.Text = uri;
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
## Comportamento Atteso
|
||||
|
||||
### ? Scenario 1: Navigazione Normale
|
||||
|
||||
1. Apri scheda **Browser**
|
||||
2. Vai su `https://it.bidoo.com`
|
||||
3. ? URL appare nel campo in alto: `https://it.bidoo.com/`
|
||||
4. Clicca link in pagina ? Vai a `https://it.bidoo.com/auction.php?a=asta_12345`
|
||||
5. ? URL si aggiorna automaticamente nel campo
|
||||
|
||||
### ? Scenario 2: Campo Non Editabile
|
||||
|
||||
1. Apri scheda **Browser**
|
||||
2. Prova a cliccare nel campo URL
|
||||
3. ? **Non puoi modificare** il testo
|
||||
4. ? Cursore rimane freccia (non diventa testo)
|
||||
5. ? Tooltip mostra: "Indirizzo della pagina corrente (non editabile)"
|
||||
|
||||
### ? Scenario 3: Navigazione con Pulsanti
|
||||
|
||||
1. Usa **"Indietro"** / **"Avanti"** / **"Ricarica"** / **"Home"**
|
||||
2. ? URL si aggiorna automaticamente
|
||||
3. ? Campo mostra sempre l'indirizzo corrente
|
||||
|
||||
### ? Scenario 4: Aggiunta Asta
|
||||
|
||||
1. Naviga su un'asta: `https://it.bidoo.com/auction.php?a=asta_12345`
|
||||
2. ? URL visibile nel campo
|
||||
3. Clicca **"Aggiungi Asta"**
|
||||
4. ? L'URL dal campo viene usato per aggiungere l'asta
|
||||
|
||||
## Vantaggi della Soluzione
|
||||
|
||||
### ?? 1. UX Chiara
|
||||
- ? **Prima**: Campo editabile ma funzionalità non implementata
|
||||
- ? **Dopo**: Campo read-only, comportamento chiaro
|
||||
|
||||
### ?? 2. Nessuna Confusione
|
||||
- ? **Prima**: Pulsante "Vai" che non faceva nulla
|
||||
- ? **Dopo**: Solo funzionalità implementate visibili
|
||||
|
||||
### ?? 3. Visualizzazione Sempre Aggiornata
|
||||
- ? URL aggiornato automaticamente ad ogni navigazione
|
||||
- ? Sincronizzato con WebView2
|
||||
|
||||
### ?? 4. Preparato per Futuro
|
||||
Se in futuro si implementa la navigazione manuale:
|
||||
- Basta rimuovere `IsReadOnly="True"`
|
||||
- Ri-aggiungere pulsante "Vai"
|
||||
- Tutto il resto già funziona
|
||||
|
||||
## File Modificati
|
||||
|
||||
### 1. ? `Controls\BrowserControl.xaml`
|
||||
|
||||
**Modifiche**:
|
||||
- Aggiunto `IsReadOnly="True"` a `BrowserAddress`
|
||||
- Aggiunto `Cursor="Arrow"` per UX migliore
|
||||
- Aggiunto `ToolTip` esplicativo
|
||||
- Rimosso pulsante "Vai" (BrowserGoButton)
|
||||
|
||||
**Prima**:
|
||||
```xaml
|
||||
<TextBox x:Name="BrowserAddress" ... />
|
||||
<Button x:Name="BrowserGoButton" Content="Vai" Click="BrowserGoButton_Click"/>
|
||||
<Button x:Name="BrowserAddAuctionButton" Content="Aggiungi Asta" .../>
|
||||
```
|
||||
|
||||
**Dopo**:
|
||||
```xaml
|
||||
<TextBox x:Name="BrowserAddress" IsReadOnly="True" Cursor="Arrow" ToolTip="..." />
|
||||
<Button x:Name="BrowserAddAuctionButton" Content="Aggiungi Asta" .../>
|
||||
```
|
||||
|
||||
### 2. ? `Controls\BrowserControl.xaml.cs`
|
||||
|
||||
**Modifiche**:
|
||||
- Rimosso metodo `BrowserGoButton_Click`
|
||||
- Evento `BrowserGoClickedEvent` lasciato per compatibilità (non usato)
|
||||
|
||||
### 3. ? `Core\EventHandlers\MainWindow.EventHandlers.Browser.cs`
|
||||
|
||||
**Modifiche**:
|
||||
- Rimosso gestore `BrowserGoButton_Click`
|
||||
- Mantenuti gestori `NavigationStarting` e `NavigationCompleted`
|
||||
|
||||
### 4. ? `MainWindow.xaml`
|
||||
|
||||
**Modifiche**:
|
||||
- Rimosso binding `BrowserGoClicked="Browser_BrowserGoClicked"`
|
||||
|
||||
## Layout Browser
|
||||
|
||||
### Toolbar Nuovo
|
||||
|
||||
```
|
||||
??????????????????????????????????????????????????????????????
|
||||
? [Indietro] [Avanti] [Ricarica] [Home] ?URL? [Aggiungi] ?
|
||||
??????????????????????????????????????????????????????????????
|
||||
```
|
||||
|
||||
**Prima**:
|
||||
```
|
||||
[Indietro] [Avanti] [Ricarica] [Home] [URL editabile] [Vai] [Aggiungi]
|
||||
```
|
||||
|
||||
**Dopo**:
|
||||
```
|
||||
[Indietro] [Avanti] [Ricarica] [Home] [URL read-only] [Aggiungi Asta]
|
||||
```
|
||||
|
||||
## Note Tecniche
|
||||
|
||||
### Perché `IsReadOnly` invece di Disabilitato?
|
||||
|
||||
| Proprietà | Effetto | Pro | Contro |
|
||||
|-----------|---------|-----|--------|
|
||||
| `IsEnabled="False"` | ? Disabilitato | Chiaro che non è usabile | Testo grigio, difficile da leggere |
|
||||
| `IsReadOnly="True"` | ? Read-only | Testo leggibile, copiabile | Potrebbe sembrare editabile |
|
||||
|
||||
**Scelta**: `IsReadOnly="True"` + `Cursor="Arrow"` + `ToolTip`
|
||||
- ? Testo leggibile e copiabile
|
||||
- ? Cursore chiarisce che non è editabile
|
||||
- ? Tooltip spiega il comportamento
|
||||
|
||||
### Aggiornamento URL
|
||||
|
||||
L'URL viene aggiornato in **2 eventi**:
|
||||
|
||||
1. **`NavigationStarting`**: Quando inizia la navigazione
|
||||
```csharp
|
||||
BrowserAddress.Text = e.Uri ?? string.Empty;
|
||||
```
|
||||
|
||||
2. **`NavigationCompleted`**: Quando la navigazione finisce
|
||||
```csharp
|
||||
BrowserAddress.Text = EmbeddedWebView?.Source?.ToString() ?? BrowserAddress.Text;
|
||||
```
|
||||
|
||||
**Perché entrambi?**
|
||||
- `NavigationStarting`: Mostra subito dove stai andando
|
||||
- `NavigationCompleted`: Aggiorna con URL finale (dopo redirect)
|
||||
|
||||
## Funzionalità Future
|
||||
|
||||
### Se si vuole Navigazione Manuale
|
||||
|
||||
1. Rimuovi `IsReadOnly="True"` da BrowserAddress
|
||||
2. Ri-aggiungi pulsante "Vai":
|
||||
```xaml
|
||||
<Button Content="Vai" Click="BrowserGoButton_Click"/>
|
||||
```
|
||||
3. Implementa gestore:
|
||||
```csharp
|
||||
private void BrowserGoButton_Click(...)
|
||||
{
|
||||
var url = BrowserAddress.Text?.Trim();
|
||||
if (!url.StartsWith("http")) url = "https://" + url;
|
||||
EmbeddedWebView?.CoreWebView2?.Navigate(url);
|
||||
}
|
||||
```
|
||||
|
||||
### Se si vuole Autocompletamento
|
||||
|
||||
1. Sostituisci `TextBox` con `ComboBox` editabile
|
||||
2. Popola con cronologia navigazione
|
||||
3. Usa `IsEditable="True"` + suggerimenti
|
||||
|
||||
---
|
||||
|
||||
## ? Test di Verifica
|
||||
|
||||
- [x] URL visibile nel campo in alto
|
||||
- [x] URL si aggiorna automaticamente
|
||||
- [x] Campo non editabile (IsReadOnly)
|
||||
- [x] Cursore freccia (non testo)
|
||||
- [x] Tooltip informativo
|
||||
- [x] Pulsante "Vai" rimosso
|
||||
- [x] Pulsante "Aggiungi Asta" funziona
|
||||
- [x] Navigazione con Indietro/Avanti funziona
|
||||
- [x] URL copiabile con Ctrl+C
|
||||
|
||||
---
|
||||
|
||||
**Data Fix**: 2025
|
||||
**Versione**: 4.0+
|
||||
**Issue**: URL Browser non visibile e editabile
|
||||
**Status**: ? RISOLTO
|
||||
|
||||
## Riepilogo
|
||||
|
||||
**Prima**:
|
||||
- ? URL non sempre visibile
|
||||
- ? Campo editabile (ma non funzionante)
|
||||
- ? Pulsante "Vai" non implementato
|
||||
|
||||
**Dopo**:
|
||||
- ? URL **sempre visibile** e aggiornato
|
||||
- ? Campo **read-only** (chiaro e leggibile)
|
||||
- ? Solo funzionalità **implementate** disponibili
|
||||
- ? UX pulita e coerente
|
||||
@@ -1,327 +0,0 @@
|
||||
# ?? Fix Persistenza Impostazioni Predefinite Aste
|
||||
|
||||
## Problema Rilevato
|
||||
|
||||
Quando si modificavano le **impostazioni predefinite** per le nuove aste (es. Anticipo ms da 200 a 300):
|
||||
|
||||
1. ? Le nuove aste aggiunte usavano **sempre 200ms** (valore hardcoded) invece del valore salvato (300ms)
|
||||
2. ? Riaprendo l'applicazione, le impostazioni predefinite mostravano **200ms** invece di 300ms salvati
|
||||
|
||||
## Causa del Problema
|
||||
|
||||
### 1. Valori Hardcoded nella Creazione Aste
|
||||
Nel metodo `AddAuctionById` e `AddAuctionFromUrl`, i valori erano **hardcoded**:
|
||||
|
||||
```csharp
|
||||
// ? PRIMA - Valori hardcoded
|
||||
var auction = new AuctionInfo
|
||||
{
|
||||
BidBeforeDeadlineMs = 200, // Sempre 200!
|
||||
CheckAuctionOpenBeforeBid = false,
|
||||
// ...
|
||||
};
|
||||
```
|
||||
|
||||
### 2. Impostazioni Non Caricate all'Avvio
|
||||
Non esisteva un metodo `LoadDefaultSettings()` che caricasse i valori salvati nei controlli UI all'avvio dell'applicazione.
|
||||
|
||||
## Soluzione Implementata
|
||||
|
||||
### ? 1. Lettura Impostazioni Salvate alla Creazione Asta
|
||||
|
||||
Ora quando si aggiunge una nuova asta, vengono **letti i valori dalle impostazioni salvate**:
|
||||
|
||||
```csharp
|
||||
// ? DOPO - Legge da settings.json
|
||||
var settings = Utilities.SettingsManager.Load();
|
||||
|
||||
var auction = new AuctionInfo
|
||||
{
|
||||
BidBeforeDeadlineMs = settings.DefaultBidBeforeDeadlineMs, // Dal file!
|
||||
CheckAuctionOpenBeforeBid = settings.DefaultCheckAuctionOpenBeforeBid,
|
||||
// ...
|
||||
};
|
||||
|
||||
var vm = new AuctionViewModel(auction)
|
||||
{
|
||||
MinPrice = settings.DefaultMinPrice,
|
||||
MaxPrice = settings.DefaultMaxPrice,
|
||||
MaxClicks = settings.DefaultMaxClicks
|
||||
};
|
||||
```
|
||||
|
||||
### ? 2. Caricamento Impostazioni all'Avvio
|
||||
|
||||
Aggiunto metodo `LoadDefaultSettings()` chiamato nel costruttore di `MainWindow`:
|
||||
|
||||
```csharp
|
||||
public MainWindow()
|
||||
{
|
||||
// ... altre inizializzazioni ...
|
||||
|
||||
LoadExportSettings();
|
||||
LoadDefaultSettings(); // ? NUOVO
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Il metodo popola i controlli UI con i valori salvati:
|
||||
|
||||
```csharp
|
||||
private void LoadDefaultSettings()
|
||||
{
|
||||
var settings = SettingsManager.Load();
|
||||
|
||||
DefaultBidBeforeDeadlineMs.Text = settings.DefaultBidBeforeDeadlineMs.ToString();
|
||||
DefaultCheckAuctionOpen.IsChecked = settings.DefaultCheckAuctionOpenBeforeBid;
|
||||
DefaultMinPrice.Text = settings.DefaultMinPrice.ToString("F2");
|
||||
DefaultMaxPrice.Text = settings.DefaultMaxPrice.ToString("F2");
|
||||
DefaultMaxClicks.Text = settings.DefaultMaxClicks.ToString();
|
||||
|
||||
Log($"[OK] Impostazioni predefinite caricate: Anticipo={settings.DefaultBidBeforeDeadlineMs}ms", LogLevel.Info);
|
||||
}
|
||||
```
|
||||
|
||||
### ? 3. Logging Dettagliato
|
||||
|
||||
Aggiunto logging quando si salvano/caricano le impostazioni:
|
||||
|
||||
**Salvataggio**:
|
||||
```
|
||||
[OK] Impostazioni predefinite salvate: Anticipo=300ms, MinPrice=€0.00, MaxPrice=€0.00, MaxClicks=0
|
||||
```
|
||||
|
||||
**Caricamento all'avvio**:
|
||||
```
|
||||
[OK] Impostazioni predefinite caricate: Anticipo=300ms
|
||||
```
|
||||
|
||||
**Aggiunta asta con defaults**:
|
||||
```
|
||||
[ADD] Asta aggiunta con defaults: Anticipo=300ms, MinPrice=€0.00, MaxPrice=€0.00, MaxClicks=0
|
||||
```
|
||||
|
||||
## Comportamento Atteso
|
||||
|
||||
### ? Scenario 1: Modifica Defaults e Aggiungi Asta
|
||||
|
||||
1. Vai su **Impostazioni**
|
||||
2. Modifica "Anticipo puntata (ms)" da **200** a **300**
|
||||
3. Clicca **"Salva Defaults"**
|
||||
4. Log: `[OK] Impostazioni predefinite salvate: Anticipo=300ms`
|
||||
5. Aggiungi una nuova asta
|
||||
6. Log: `[ADD] Asta aggiunta con defaults: Anticipo=300ms`
|
||||
7. ? La nuova asta ha **Anticipo = 300ms**
|
||||
|
||||
### ? Scenario 2: Riavvio Applicazione
|
||||
|
||||
1. Modifica defaults (es. Anticipo = 300ms)
|
||||
2. Clicca **"Salva Defaults"**
|
||||
3. **Chiudi** l'applicazione
|
||||
4. **Riapri** l'applicazione
|
||||
5. Vai su **Impostazioni**
|
||||
6. ? Il campo mostra **300ms** (non 200ms!)
|
||||
7. Log: `[OK] Impostazioni predefinite caricate: Anticipo=300ms`
|
||||
|
||||
### ? Scenario 3: Aste Esistenti Non Modificate
|
||||
|
||||
1. Hai già aste con Anticipo = 200ms
|
||||
2. Modifichi defaults a 300ms
|
||||
3. ? Le aste **esistenti** mantengono 200ms
|
||||
4. ? Le **nuove** aste avranno 300ms
|
||||
|
||||
### ? Scenario 4: Ripristino Defaults
|
||||
|
||||
1. Vai su **Impostazioni**
|
||||
2. Clicca **"Annulla"** (senza salvare)
|
||||
3. ? I valori tornano a quelli salvati in precedenza
|
||||
4. Log: `[INFO] Impostazioni predefinite ripristinate`
|
||||
|
||||
## File Modificati
|
||||
|
||||
### 1. ? `Core\MainWindow.AuctionManagement.cs`
|
||||
|
||||
**Modifiche**:
|
||||
- `AddAuctionById`: Legge `settings.DefaultBidBeforeDeadlineMs` invece di hardcoded `200`
|
||||
- `AddAuctionFromUrl`: Stessa modifica
|
||||
- Aggiunto logging quando si aggiunge asta con defaults
|
||||
|
||||
**Prima**:
|
||||
```csharp
|
||||
BidBeforeDeadlineMs = 200, // ? Hardcoded
|
||||
```
|
||||
|
||||
**Dopo**:
|
||||
```csharp
|
||||
var settings = Utilities.SettingsManager.Load();
|
||||
BidBeforeDeadlineMs = settings.DefaultBidBeforeDeadlineMs, // ? Da file
|
||||
```
|
||||
|
||||
### 2. ? `MainWindow.xaml.cs`
|
||||
|
||||
**Modifiche**:
|
||||
- Aggiunto `LoadDefaultSettings()` nel costruttore
|
||||
|
||||
**Prima**:
|
||||
```csharp
|
||||
LoadExportSettings();
|
||||
UpdateGlobalControlButtons();
|
||||
```
|
||||
|
||||
**Dopo**:
|
||||
```csharp
|
||||
LoadExportSettings();
|
||||
LoadDefaultSettings(); // ? NUOVO
|
||||
UpdateGlobalControlButtons();
|
||||
```
|
||||
|
||||
### 3. ? `Core\EventHandlers\MainWindow.EventHandlers.Settings.cs`
|
||||
|
||||
**Modifiche**:
|
||||
- Aggiunto metodo `LoadDefaultSettings()`
|
||||
- Migliorato `SaveDefaultsButton_Click` con logging dettagliato
|
||||
- Modificato `CancelDefaultsButton_Click` per usare `LoadDefaultSettings()`
|
||||
|
||||
**Nuovo metodo**:
|
||||
```csharp
|
||||
private void LoadDefaultSettings()
|
||||
{
|
||||
var settings = SettingsManager.Load();
|
||||
DefaultBidBeforeDeadlineMs.Text = settings.DefaultBidBeforeDeadlineMs.ToString();
|
||||
// ... altri campi ...
|
||||
}
|
||||
```
|
||||
|
||||
## Struttura File settings.json
|
||||
|
||||
Le impostazioni vengono salvate in:
|
||||
```
|
||||
%LocalAppData%\AutoBidder\settings.json
|
||||
```
|
||||
|
||||
Contenuto esempio:
|
||||
```json
|
||||
{
|
||||
"ExportPath": "C:\\Exports",
|
||||
"LastExportExt": ".csv",
|
||||
"ExportScope": "All",
|
||||
"IncludeOnlyUsedBids": true,
|
||||
"IncludeLogs": false,
|
||||
"IncludeUserBids": false,
|
||||
"ExportOpen": true,
|
||||
"ExportClosed": true,
|
||||
"ExportUnknown": true,
|
||||
"IncludeMetadata": true,
|
||||
"RemoveAfterExport": false,
|
||||
"OverwriteExisting": false,
|
||||
"DefaultBidBeforeDeadlineMs": 300,
|
||||
"DefaultCheckAuctionOpenBeforeBid": false,
|
||||
"DefaultMinPrice": 0,
|
||||
"DefaultMaxPrice": 0,
|
||||
"DefaultMaxClicks": 0
|
||||
}
|
||||
```
|
||||
|
||||
## Test di Verifica
|
||||
|
||||
### Test 1: Salvataggio e Applicazione Defaults
|
||||
|
||||
- [x] Modifica Anticipo da 200 a 300
|
||||
- [x] Clicca "Salva Defaults"
|
||||
- [x] Aggiungi nuova asta
|
||||
- [x] Verifica che abbia Anticipo = 300ms
|
||||
- [x] Log mostra salvataggio e applicazione
|
||||
|
||||
### Test 2: Persistenza tra Riavvii
|
||||
|
||||
- [x] Modifica Anticipo a 300
|
||||
- [x] Salva Defaults
|
||||
- [x] Chiudi applicazione
|
||||
- [x] Riapri applicazione
|
||||
- [x] Vai su Impostazioni
|
||||
- [x] Verifica che mostri 300ms
|
||||
|
||||
### Test 3: Ripristino Defaults
|
||||
|
||||
- [x] Modifica Anticipo senza salvare
|
||||
- [x] Clicca "Annulla"
|
||||
- [x] Verifica che torni al valore salvato
|
||||
- [x] Log mostra ripristino
|
||||
|
||||
### Test 4: Aste Esistenti Non Toccate
|
||||
|
||||
- [x] Crea asta con Anticipo = 200
|
||||
- [x] Cambia defaults a 300
|
||||
- [x] Prima asta mantiene 200
|
||||
- [x] Nuova asta ha 300
|
||||
|
||||
## Vantaggi della Soluzione
|
||||
|
||||
### ?? 1. Coerenza
|
||||
- Le impostazioni salvate vengono **sempre** applicate
|
||||
- Non più sorprese con valori hardcoded
|
||||
|
||||
### ?? 2. Persistenza
|
||||
- Le impostazioni **sopravvivono** ai riavvii
|
||||
- File JSON in `%LocalAppData%`
|
||||
|
||||
### ?? 3. Flessibilità
|
||||
- Ogni utente può avere i propri defaults
|
||||
- Facile modificare defaults senza toccare codice
|
||||
|
||||
### ?? 4. Trasparenza
|
||||
- Logging dettagliato di ogni operazione
|
||||
- Si vede esattamente cosa viene salvato/caricato
|
||||
|
||||
## Note Tecniche
|
||||
|
||||
### Perché SettingsManager.Load() invece di Cache?
|
||||
|
||||
`SettingsManager.Load()` legge sempre da file, garantendo:
|
||||
- ? **Aggiornamenti in tempo reale** se il file viene modificato manualmente
|
||||
- ? **Thread-safe** (ogni lettura è isolata)
|
||||
- ? **Nessun problema di sincronizzazione** tra diverse istanze
|
||||
|
||||
### Ordine di Caricamento
|
||||
|
||||
```
|
||||
1. InitializeComponent()
|
||||
2. _auctionMonitor = new AuctionMonitor()
|
||||
3. LoadSavedAuctions() // Carica aste salvate
|
||||
4. LoadExportSettings() // Carica export settings
|
||||
5. LoadDefaultSettings() // ? NUOVO - Carica defaults
|
||||
6. UpdateGlobalControlButtons()
|
||||
```
|
||||
|
||||
### Quando vengono applicate le impostazioni?
|
||||
|
||||
| Azione | Impostazioni Applicate |
|
||||
|--------|------------------------|
|
||||
| Avvio app | Carica da file in UI |
|
||||
| Aggiungi asta | Legge da file e applica |
|
||||
| Modifica defaults | Applica solo a nuove aste |
|
||||
| Salva defaults | Scrive su file |
|
||||
| Riavvio app | Ricarica da file |
|
||||
|
||||
---
|
||||
|
||||
## ? Riepilogo
|
||||
|
||||
**Prima**:
|
||||
- ? Defaults hardcoded a 200ms
|
||||
- ? Modifiche non persistenti
|
||||
- ? Nuove aste usano sempre 200ms
|
||||
|
||||
**Dopo**:
|
||||
- ? Defaults letti da `settings.json`
|
||||
- ? Modifiche persistono tra riavvii
|
||||
- ? Nuove aste usano valori salvati
|
||||
- ? Logging dettagliato
|
||||
|
||||
---
|
||||
|
||||
**Data Fix**: 2025
|
||||
**Versione**: 4.0+
|
||||
**Issue**: Impostazioni predefinite non persistenti
|
||||
**Status**: ? RISOLTO
|
||||
@@ -1,199 +0,0 @@
|
||||
# ?? Fix Eliminazione Asta con Tasto Canc
|
||||
|
||||
## Problema Rilevato
|
||||
|
||||
Quando si selezionava un'asta nella griglia e si premeva il tasto **Canc (Delete)**, l'asta **NON veniva eliminata**.
|
||||
|
||||
## Causa del Problema
|
||||
|
||||
Il sistema aveva l'evento `KeyDown` implementato, ma presentava **2 problemi**:
|
||||
|
||||
1. **Focus Keyboard Mancante**: Il `DataGrid` non sempre aveva il focus keyboard dopo la selezione
|
||||
2. **Evento Consumato**: Altri controlli potevano consumare l'evento `KeyDown` prima che arrivasse al gestore
|
||||
|
||||
## Soluzione Implementata
|
||||
|
||||
### ? 1. Cambiato da `KeyDown` a `PreviewKeyDown`
|
||||
|
||||
**Perché?**
|
||||
- `PreviewKeyDown` viene chiamato **PRIMA** di tutti gli altri gestori
|
||||
- Ha **priorità più alta** nella catena di eventi WPF
|
||||
- Previene che l'evento venga consumato da controlli figli
|
||||
|
||||
```xml
|
||||
<!-- PRIMA -->
|
||||
KeyDown="MultiAuctionsGrid_KeyDown"
|
||||
|
||||
<!-- DOPO -->
|
||||
PreviewKeyDown="MultiAuctionsGrid_PreviewKeyDown"
|
||||
```
|
||||
|
||||
### ? 2. Aggiunto `Focusable="True"` nel XAML
|
||||
|
||||
Assicura che il `DataGrid` possa ricevere il focus keyboard.
|
||||
|
||||
```xml
|
||||
Focusable="True"
|
||||
FocusVisualStyle="{x:Null}"
|
||||
```
|
||||
|
||||
### ? 3. Migliorata Gestione del Focus
|
||||
|
||||
Nel `SelectionChanged`, ora il focus viene dato con priorità corretta:
|
||||
|
||||
```csharp
|
||||
grid.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (!grid.IsFocused)
|
||||
{
|
||||
grid.Focus();
|
||||
}
|
||||
}), DispatcherPriority.Background);
|
||||
```
|
||||
|
||||
### ? 4. Aggiunto Logging Debug
|
||||
|
||||
Per diagnostica futura:
|
||||
|
||||
```csharp
|
||||
System.Diagnostics.Debug.WriteLine("[DELETE KEY] Tasto Canc premuto su asta selezionata");
|
||||
System.Diagnostics.Debug.WriteLine("[DELETE KEY] Lancio evento RemoveUrlClicked");
|
||||
```
|
||||
|
||||
### ? 5. **Fix Messaggio Duplicato** (Aggiornamento)
|
||||
|
||||
**Problema**: Apparivano **2 messaggi di conferma** quando si premeva Canc
|
||||
- Primo in `PreviewKeyDown`
|
||||
- Secondo in `RemoveUrlButton_Click`
|
||||
|
||||
**Soluzione**: Rimosso il messaggio da `PreviewKeyDown`, lasciando solo quello in `RemoveUrlButton_Click`
|
||||
|
||||
Ora quando premi Canc:
|
||||
1. ? `PreviewKeyDown` lancia l'evento `RemoveUrlClicked`
|
||||
2. ? `RemoveUrlButton_Click` mostra **UN SOLO** messaggio di conferma
|
||||
3. ? L'utente conferma o annulla una sola volta
|
||||
|
||||
### ? 6. Messaggio di Conferma Unico
|
||||
|
||||
Messaggio chiaro e descrittivo (mostrato una sola volta):
|
||||
|
||||
```
|
||||
Rimuovere l'asta dal monitoraggio?
|
||||
|
||||
Nome Asta
|
||||
(ID: 12345)
|
||||
|
||||
L'asta verrà eliminata dalla lista e non sarà più monitorata.
|
||||
```
|
||||
|
||||
### ? 7. Logging Potenziato
|
||||
|
||||
```
|
||||
[REMOVE] Rimozione annullata: Nome Asta
|
||||
[REMOVE] Asta rimossa: Nome Asta (ID: 12345)
|
||||
[ERROR] Errore rimozione asta: messaggio errore
|
||||
```
|
||||
|
||||
## Come Testare
|
||||
|
||||
1. **Avvia l'applicazione**
|
||||
2. **Aggiungi almeno 2 aste**
|
||||
3. **Seleziona un'asta** nella griglia (clicca sulla riga)
|
||||
4. **Premi il tasto Canc** sulla tastiera
|
||||
5. ? **Verifica che appaia UN SOLO messaggio** di conferma
|
||||
6. **Conferma** la rimozione nel popup
|
||||
7. ? **Verifica** che l'asta sia stata rimossa dalla lista
|
||||
|
||||
## Comportamento Atteso
|
||||
|
||||
### ? Scenario 1: Eliminazione Confermata
|
||||
1. Premi `Canc`
|
||||
2. Appare **UN** popup di conferma
|
||||
3. Clicchi `Sì`
|
||||
4. L'asta viene rimossa dalla griglia
|
||||
5. Nel log appare: `[REMOVE] Asta rimossa: ...`
|
||||
|
||||
### ? Scenario 2: Eliminazione Annullata
|
||||
1. Premi `Canc`
|
||||
2. Appare **UN** popup di conferma
|
||||
3. Clicchi `No`
|
||||
4. L'asta rimane nella griglia
|
||||
5. Nel log appare: `[REMOVE] Rimozione annullata: ...`
|
||||
|
||||
### ? Scenario 3: Nessuna Selezione
|
||||
1. Clicchi sul pulsante "Rimuovi" senza selezione
|
||||
2. Appare popup: `"Seleziona un'asta dalla griglia"`
|
||||
3. Nessuna asta viene rimossa
|
||||
|
||||
## Debug Output (Visual Studio)
|
||||
|
||||
Se apri **Output ? Debug**, vedrai:
|
||||
|
||||
```
|
||||
[FOCUS] DataGrid ora ha il focus keyboard
|
||||
[DELETE KEY] Tasto Canc premuto su asta selezionata
|
||||
[DELETE KEY] Lancio evento RemoveUrlClicked
|
||||
```
|
||||
|
||||
## File Modificati
|
||||
|
||||
1. ? `Controls\AuctionMonitorControl.xaml`
|
||||
- Cambiato `KeyDown` ? `PreviewKeyDown`
|
||||
- Aggiunto `Focusable="True"`
|
||||
|
||||
2. ? `Controls\AuctionMonitorControl.xaml.cs`
|
||||
- Rinominato `MultiAuctionsGrid_KeyDown` ? `MultiAuctionsGrid_PreviewKeyDown`
|
||||
- **Rimosso messaggio di conferma duplicato**
|
||||
- Migliorato focus nel `SelectionChanged`
|
||||
- Aggiunto debug logging
|
||||
|
||||
3. ? `Core\MainWindow.ButtonHandlers.cs`
|
||||
- Messaggio di conferma (UNICO punto di conferma)
|
||||
- Aggiunto logging dettagliato
|
||||
- Migliorata gestione errori
|
||||
|
||||
## Note Tecniche
|
||||
|
||||
### Perché `PreviewKeyDown` invece di `KeyDown`?
|
||||
|
||||
**Bubbling vs Tunneling in WPF:**
|
||||
- `Preview*` eventi = **Tunneling** (dall'alto verso il basso)
|
||||
- Eventi normali = **Bubbling** (dal basso verso l'alto)
|
||||
|
||||
Nel nostro caso, se un controllo figlio (es. cella del DataGrid) consuma l'evento `KeyDown`, il gestore del DataGrid non viene mai chiamato.
|
||||
|
||||
Con `PreviewKeyDown`, il gestore del DataGrid viene chiamato **per primo**, prima che qualsiasi controllo figlio possa consumare l'evento.
|
||||
|
||||
### Perché `Dispatcher.BeginInvoke`?
|
||||
|
||||
Il focus va dato **dopo** che il rendering della selezione è completo. `BeginInvoke` con `DispatcherPriority.Background` assicura che il focus venga dato al momento giusto.
|
||||
|
||||
### Perché Rimuovere il MessageBox dal PreviewKeyDown?
|
||||
|
||||
Il `PreviewKeyDown` è responsabile solo di **catturare l'evento tastiera** e lanciare l'evento `RemoveUrlClicked`.
|
||||
|
||||
La **logica di conferma** appartiene al gestore dell'azione (`RemoveUrlButton_Click`), che viene chiamato sia dal tasto Canc che dal pulsante "Rimuovi".
|
||||
|
||||
Questo garantisce:
|
||||
- ? **DRY** (Don't Repeat Yourself) - Conferma in un solo posto
|
||||
- ? **Coerenza** - Stesso comportamento da tastiera e pulsante
|
||||
- ? **Manutenibilità** - Un solo messaggio da modificare
|
||||
|
||||
---
|
||||
|
||||
## ? Test di Verifica
|
||||
|
||||
- [x] Il tasto `Canc` elimina l'asta selezionata
|
||||
- [x] Appare **UN SOLO** messaggio di conferma
|
||||
- [x] L'asta viene rimossa dalla lista
|
||||
- [x] Il log mostra `[REMOVE] Asta rimossa`
|
||||
- [x] Annullare l'operazione funziona correttamente
|
||||
- [x] Il pulsante "Rimuovi" continua a funzionare normalmente
|
||||
- [x] Stessa conferma da tastiera e da pulsante
|
||||
|
||||
---
|
||||
|
||||
**Data Fix**: 2025
|
||||
**Versione**: 4.0+
|
||||
**Issue 1**: Tasto Canc non eliminava aste ? ? RISOLTO
|
||||
**Issue 2**: Doppio messaggio di conferma ? ? RISOLTO
|
||||
@@ -1,234 +0,0 @@
|
||||
# ?? Fix Avvio Singola Asta dalla Griglia
|
||||
|
||||
## Problema Rilevato
|
||||
|
||||
Quando si cliccava il pulsante **"Avvia"** su una singola asta nella griglia, l'asta **non veniva monitorata** a meno che prima non si fosse cliccato **"Avvia Tutti"**.
|
||||
|
||||
## Causa del Problema
|
||||
|
||||
Il sistema di monitoraggio aveva una **dipendenza rigida** sul flag `_isAutomationActive`:
|
||||
|
||||
1. ? Clic su "Avvia Tutti" ? Avvia `AuctionMonitor.Start()` + imposta `IsActive = true` su tutte le aste
|
||||
2. ? Clic su "Avvia" (singola asta) ? Imposta solo `IsActive = true` MA **non avvia** `AuctionMonitor.Start()`
|
||||
3. ? Risultato: L'asta era marcata come attiva, ma il loop di monitoraggio **non era in esecuzione**
|
||||
|
||||
### Codice Problematico (Prima)
|
||||
|
||||
```csharp
|
||||
private void ExecuteGridStart(AuctionViewModel? vm)
|
||||
{
|
||||
if (vm == null) return;
|
||||
vm.IsActive = true;
|
||||
vm.IsPaused = false;
|
||||
Log($"[START] Asta avviata: {vm.Name}");
|
||||
UpdateGlobalControlButtons();
|
||||
}
|
||||
```
|
||||
|
||||
**Mancava**: Avvio del `AuctionMonitor` se non già attivo.
|
||||
|
||||
## Soluzione Implementata
|
||||
|
||||
### ? 1. Auto-Start del Monitoraggio
|
||||
|
||||
Ora, quando si avvia una singola asta, **il monitoraggio viene avviato automaticamente** se non è già attivo:
|
||||
|
||||
```csharp
|
||||
private void ExecuteGridStart(AuctionViewModel? vm)
|
||||
{
|
||||
if (vm == null) return;
|
||||
|
||||
// Attiva l'asta
|
||||
vm.IsActive = true;
|
||||
vm.IsPaused = false;
|
||||
|
||||
// Se il monitoraggio globale non è attivo, avvialo automaticamente
|
||||
if (!_isAutomationActive)
|
||||
{
|
||||
_auctionMonitor.Start();
|
||||
_isAutomationActive = true;
|
||||
Log($"[AUTO-START] Monitoraggio avviato automaticamente per asta: {vm.Name}", LogLevel.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[START] Asta avviata: {vm.Name}", LogLevel.Info);
|
||||
}
|
||||
|
||||
UpdateGlobalControlButtons();
|
||||
}
|
||||
```
|
||||
|
||||
### ? 2. Auto-Stop del Monitoraggio
|
||||
|
||||
Quando si ferma l'ultima asta attiva, **il monitoraggio viene fermato automaticamente**:
|
||||
|
||||
```csharp
|
||||
private void ExecuteGridStop(AuctionViewModel? vm)
|
||||
{
|
||||
if (vm == null) return;
|
||||
vm.IsActive = false;
|
||||
|
||||
// Se tutte le aste sono fermate, ferma anche il monitoraggio globale
|
||||
bool hasActiveAuctions = _auctionViewModels.Any(a => a.IsActive);
|
||||
if (!hasActiveAuctions && _isAutomationActive)
|
||||
{
|
||||
_auctionMonitor.Stop();
|
||||
_isAutomationActive = false;
|
||||
Log($"[AUTO-STOP] Monitoraggio fermato: nessuna asta attiva", LogLevel.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"[STOP] Asta fermata: {vm.Name}", LogLevel.Info);
|
||||
}
|
||||
|
||||
UpdateGlobalControlButtons();
|
||||
}
|
||||
```
|
||||
|
||||
### ? 3. Migliorato Logging
|
||||
|
||||
Aggiunto logging dettagliato per capire quando il monitoraggio viene avviato/fermato automaticamente:
|
||||
|
||||
- `[AUTO-START] Monitoraggio avviato automaticamente per asta: Nome`
|
||||
- `[AUTO-STOP] Monitoraggio fermato: nessuna asta attiva`
|
||||
- `[START] Asta avviata: Nome` (se monitoraggio già attivo)
|
||||
- `[STOP] Asta fermata: Nome` (se ci sono altre aste attive)
|
||||
|
||||
### ? 4. Coerenza con Pulsanti Globali
|
||||
|
||||
I pulsanti globali ora sono coerenti con il nuovo comportamento:
|
||||
|
||||
- **"Avvia Tutti"**: Avvia monitoraggio + attiva tutte le aste
|
||||
- **"Ferma Tutti"**: Ferma monitoraggio + disattiva tutte le aste
|
||||
- **"Pausa Tutti"**: Mette in pausa tutte le aste attive (monitoraggio rimane attivo)
|
||||
|
||||
## Comportamento Atteso
|
||||
|
||||
### ? Scenario 1: Avvio Singola Asta (Monitoraggio Fermo)
|
||||
|
||||
1. Nessuna asta attiva
|
||||
2. Clic su "Avvia" su Asta A
|
||||
3. ? Monitoraggio si avvia automaticamente
|
||||
4. ? Asta A inizia ad essere monitorata
|
||||
5. ? Log: `[AUTO-START] Monitoraggio avviato automaticamente per asta: Asta A`
|
||||
|
||||
### ? Scenario 2: Avvio Singola Asta (Monitoraggio Già Attivo)
|
||||
|
||||
1. Asta A già attiva
|
||||
2. Clic su "Avvia" su Asta B
|
||||
3. ? Monitoraggio già attivo (non viene riavviato)
|
||||
4. ? Asta B inizia ad essere monitorata
|
||||
5. ? Log: `[START] Asta avviata: Asta B`
|
||||
|
||||
### ? Scenario 3: Stop Ultima Asta
|
||||
|
||||
1. Solo Asta A è attiva
|
||||
2. Clic su "Ferma" su Asta A
|
||||
3. ? Asta A viene fermata
|
||||
4. ? Monitoraggio si ferma automaticamente (nessuna asta attiva)
|
||||
5. ? Log: `[AUTO-STOP] Monitoraggio fermato: nessuna asta attiva`
|
||||
|
||||
### ? Scenario 4: Stop Asta (Altre Attive)
|
||||
|
||||
1. Asta A e Asta B attive
|
||||
2. Clic su "Ferma" su Asta A
|
||||
3. ? Asta A viene fermata
|
||||
4. ? Monitoraggio rimane attivo (Asta B ancora attiva)
|
||||
5. ? Log: `[STOP] Asta fermata: Asta A`
|
||||
|
||||
### ? Scenario 5: Avvia Tutti
|
||||
|
||||
1. Asta A e Asta B ferme
|
||||
2. Clic su "Avvia Tutti"
|
||||
3. ? Monitoraggio si avvia
|
||||
4. ? Tutte le aste vengono attivate
|
||||
5. ? Log: `[START] Monitoraggio avviato!` + `[START ALL] Tutte le aste avviate/riprese`
|
||||
|
||||
### ? Scenario 6: Ferma Tutti
|
||||
|
||||
1. Alcune aste attive
|
||||
2. Clic su "Ferma Tutti"
|
||||
3. ? Tutte le aste vengono fermate
|
||||
4. ? Monitoraggio si ferma
|
||||
5. ? Log: `[STOP ALL] Monitoraggio fermato e tutte le aste arrestate`
|
||||
|
||||
## Vantaggi della Soluzione
|
||||
|
||||
### ?? 1. Maggiore Flessibilità
|
||||
- Puoi avviare solo le aste che ti interessano
|
||||
- Non serve più avviare tutte le aste per monitorarne una
|
||||
|
||||
### ?? 2. Risparmio Risorse
|
||||
- Il monitoraggio si ferma automaticamente quando non serve
|
||||
- Polling solo sulle aste effettivamente attive
|
||||
|
||||
### ?? 3. UX Migliorata
|
||||
- Comportamento più intuitivo
|
||||
- Non serve capire la differenza tra "Avvia Tutti" e "Avvia" singolo
|
||||
|
||||
### ?? 4. Logging Chiaro
|
||||
- Si vede esattamente quando il monitoraggio parte/si ferma
|
||||
- Distingue tra start manuale e automatico
|
||||
|
||||
## File Modificati
|
||||
|
||||
1. ? `Core\MainWindow.Commands.cs`
|
||||
- Aggiunto auto-start in `ExecuteGridStart`
|
||||
- Aggiunto auto-stop in `ExecuteGridStop`
|
||||
- Aggiunta importazione `System.Linq` e `AutoBidder.Utilities`
|
||||
- Migliorato logging con `LogLevel`
|
||||
|
||||
2. ? `Core\MainWindow.ButtonHandlers.cs`
|
||||
- Migliorato logging in `StartButton_Click`
|
||||
- Migliorato logging in `StopButton_Click`
|
||||
- Migliorato logging in `PauseAllButton_Click`
|
||||
|
||||
## Note Tecniche
|
||||
|
||||
### Perché Auto-Start è Sicuro?
|
||||
|
||||
1. **Idempotente**: `AuctionMonitor.Start()` controlla se è già attivo
|
||||
2. **Thread-safe**: Il lock interno previene race conditions
|
||||
3. **Logging**: Si vede esattamente cosa succede
|
||||
|
||||
```csharp
|
||||
public void Start()
|
||||
{
|
||||
if (_monitoringTask != null && !_monitoringTask.IsCompleted)
|
||||
{
|
||||
OnLog?.Invoke("[WARN] Monitoraggio gia' attivo");
|
||||
return; // Non fa nulla se già attivo
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### Perché Auto-Stop è Sicuro?
|
||||
|
||||
1. **Controlla tutte le aste**: Verifica se ci sono altre aste attive prima di fermare
|
||||
2. **Non forza**: Se ci sono altre aste attive, non ferma il monitoraggio
|
||||
3. **Graceful**: Usa `Stop()` che fa cleanup corretto
|
||||
|
||||
## Test di Verifica
|
||||
|
||||
- [x] Avviare singola asta da griglia (monitoraggio fermo)
|
||||
- [x] Avviare seconda asta (monitoraggio già attivo)
|
||||
- [x] Fermare asta (altre attive) ? Monitoraggio continua
|
||||
- [x] Fermare ultima asta ? Monitoraggio si ferma
|
||||
- [x] "Avvia Tutti" continua a funzionare
|
||||
- [x] "Ferma Tutti" continua a funzionare
|
||||
- [x] "Pausa Tutti" continua a funzionare
|
||||
- [x] Pulsanti di griglia abilitati/disabilitati correttamente
|
||||
- [x] Log mostra AUTO-START/AUTO-STOP
|
||||
|
||||
---
|
||||
|
||||
**Data Fix**: 2025
|
||||
**Versione**: 4.0+
|
||||
**Issue**: Pulsante "Avvia" singolo non funzionava senza "Avvia Tutti"
|
||||
**Status**: ? RISOLTO
|
||||
|
||||
## Riepilogo
|
||||
|
||||
Prima: **Dovevi cliccare "Avvia Tutti" per monitorare anche una sola asta**
|
||||
Dopo: **Clicchi "Avvia" su un'asta e parte automaticamente il monitoraggio** ??
|
||||
@@ -1,341 +0,0 @@
|
||||
# ?? Fix Puntata su Asta Già Vinta
|
||||
|
||||
## Problema Rilevato
|
||||
|
||||
Il sistema tentava di **puntare anche quando l'utente era già il vincitore corrente** dell'asta, causando:
|
||||
|
||||
1. ? **Errori inutili** - La puntata falliva con messaggio "Asta chiusa" o simile
|
||||
2. ? **Spreco risorse** - Chiamate API non necessarie
|
||||
3. ? **Logging confuso** - Messaggi di errore quando tutto andava bene
|
||||
4. ? **Puntate perse** - Tentativo di puntata quando non aveva senso
|
||||
|
||||
## Causa del Problema
|
||||
|
||||
Il metodo `ShouldBid()` non controllava se l'utente era già il vincitore corrente prima di decidere di puntare.
|
||||
|
||||
La logica era:
|
||||
```csharp
|
||||
// ? PRIMA - Non controllava IsMyBid
|
||||
private bool ShouldBid(AuctionInfo auction, AuctionState state)
|
||||
{
|
||||
// Controlli prezzo, reset count, max clicks, cooldown...
|
||||
// MA mancava: controllo se sono già vincitore!
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
Scenario problematico:
|
||||
1. ? Utente punta alle 10:00:00 e vince
|
||||
2. ? Timer riparte da 20 secondi
|
||||
3. ? Timer scende a 0.3 secondi (dentro finestra anticipo)
|
||||
4. ? Sistema cerca di puntare di nuovo
|
||||
5. ? Server risponde: "Asta chiusa" o errore simile
|
||||
6. ? Log mostra errore anche se l'utente ha già vinto!
|
||||
|
||||
## Soluzione Implementata
|
||||
|
||||
### ? 1. Controllo `IsMyBid` in `ShouldBid()`
|
||||
|
||||
Aggiunto controllo come **prima condizione**:
|
||||
|
||||
```csharp
|
||||
private bool ShouldBid(AuctionInfo auction, AuctionState state)
|
||||
{
|
||||
// ? NUOVO: Non puntare se sono già il vincitore corrente
|
||||
if (state.IsMyBid)
|
||||
{
|
||||
// Sono già io l'ultimo ad aver puntato, non serve puntare di nuovo
|
||||
return false;
|
||||
}
|
||||
|
||||
// ... altri controlli ...
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
### ? 2. Logging Chiaro in `ExecuteBidStrategy()`
|
||||
|
||||
Aggiunto messaggio informativo quando si evita la puntata:
|
||||
|
||||
```csharp
|
||||
private async Task ExecuteBidStrategy(...)
|
||||
{
|
||||
if (timerMs <= auction.BidBeforeDeadlineMs)
|
||||
{
|
||||
auction.AddLog($"[STRATEGIA] Finestra di puntata raggiunta: {timerMs:F0}ms <= {auction.BidBeforeDeadlineMs}ms");
|
||||
|
||||
// ? NUOVO: Log quando skippo perché sono già vincitore
|
||||
if (state.IsMyBid)
|
||||
{
|
||||
auction.AddLog($"[STRATEGIA] SKIP: Sono già il vincitore corrente (ultimo bidder: {state.LastBidder})");
|
||||
return;
|
||||
}
|
||||
|
||||
// ... continua con puntata ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ? 3. Come Funziona `IsMyBid`
|
||||
|
||||
Il flag `state.IsMyBid` viene calcolato in `BidooApiClient.ParsePollingResponse()`:
|
||||
|
||||
```csharp
|
||||
state.IsMyBid = !string.IsNullOrEmpty(_session.Username) &&
|
||||
state.LastBidder.Equals(_session.Username, StringComparison.OrdinalIgnoreCase);
|
||||
```
|
||||
|
||||
Confronta il `LastBidder` dall'API con lo `Username` della sessione (case-insensitive).
|
||||
|
||||
## Comportamento Atteso
|
||||
|
||||
### ? Scenario 1: Utente NON Vincitore (Deve Puntare)
|
||||
|
||||
```
|
||||
Timer: 0.3s (dentro finestra 0.5s)
|
||||
Ultimo bidder: "altroUtente123"
|
||||
IsMyBid: false
|
||||
|
||||
[STRATEGIA] Finestra di puntata raggiunta: 300ms <= 500ms
|
||||
[STRATEGIA] Eseguo puntata...
|
||||
[BID OK] Latenza: 45ms -> EUR 1.50
|
||||
```
|
||||
|
||||
**Risultato**: ? Punta correttamente
|
||||
|
||||
### ? Scenario 2: Utente GIÀ Vincitore (SKIP Puntata)
|
||||
|
||||
```
|
||||
Timer: 0.3s (dentro finestra 0.5s)
|
||||
Ultimo bidder: "miousername"
|
||||
IsMyBid: true
|
||||
|
||||
[STRATEGIA] Finestra di puntata raggiunta: 300ms <= 500ms
|
||||
[STRATEGIA] SKIP: Sono già il vincitore corrente (ultimo bidder: miousername)
|
||||
```
|
||||
|
||||
**Risultato**: ? NON punta (evita errore)
|
||||
|
||||
### ? Scenario 3: Altro Utente Supera
|
||||
|
||||
```
|
||||
t=10s: Io puntp -> IsMyBid = true
|
||||
t=8s: [STRATEGIA] SKIP: Sono già vincitore
|
||||
t=6s: [STRATEGIA] SKIP: Sono già vincitore
|
||||
t=4s: altroUtente punta -> IsMyBid = false
|
||||
t=0.3s: [STRATEGIA] Finestra raggiunta
|
||||
t=0.3s: [BID OK] Riprendo il controllo!
|
||||
```
|
||||
|
||||
**Risultato**: ? Punta solo quando necessario
|
||||
|
||||
## Vantaggi della Soluzione
|
||||
|
||||
### ?? 1. Nessun Errore Inutile
|
||||
- ? **Prima**: "Asta chiusa" quando eri già vincitore
|
||||
- ? **Dopo**: Nessun errore, log chiaro
|
||||
|
||||
### ?? 2. Risparmio Risorse
|
||||
- ? **Prima**: Chiamata API inutile quando già vincitore
|
||||
- ? **Dopo**: Skip immediato, nessuna chiamata
|
||||
|
||||
### ?? 3. Logging Trasparente
|
||||
```
|
||||
? [STRATEGIA] SKIP: Sono già il vincitore corrente
|
||||
```
|
||||
Invece di:
|
||||
```
|
||||
? [BID FAIL] Asta chiusa
|
||||
```
|
||||
|
||||
### ?? 4. Strategia Ottimizzata
|
||||
- Punta **solo** quando serve riprendersi l'asta
|
||||
- Non spreca puntate quando sei già vincitore
|
||||
|
||||
## Test Scenario
|
||||
|
||||
### Test 1: Vincitore Corrente (Non Deve Puntare)
|
||||
|
||||
**Setup**:
|
||||
- Imposta Anticipo = 500ms
|
||||
- Aggiungi asta X
|
||||
- Punta manualmente
|
||||
- Sei il vincitore (LastBidder = "tuousername")
|
||||
|
||||
**Verifica**:
|
||||
1. ? Timer scende da 20s a 0.4s
|
||||
2. ? Log: `[STRATEGIA] Finestra di puntata raggiunta: 400ms <= 500ms`
|
||||
3. ? Log: `[STRATEGIA] SKIP: Sono già il vincitore corrente`
|
||||
4. ? **Nessuna puntata** effettuata
|
||||
5. ? **Nessun errore** mostrato
|
||||
|
||||
### Test 2: Altro Utente Supera (Deve Puntare)
|
||||
|
||||
**Setup**:
|
||||
- Sei il vincitore
|
||||
- Altro utente punta e diventa vincitore
|
||||
- Timer scende a 0.3s
|
||||
|
||||
**Verifica**:
|
||||
1. ? Log: `[STRATEGIA] Finestra di puntata raggiunta: 300ms <= 500ms`
|
||||
2. ? **Nessun SKIP** (non sei più vincitore)
|
||||
3. ? Log: `[BID OK] Latenza: XXms`
|
||||
4. ? Puntata **effettuata correttamente**
|
||||
|
||||
### Test 3: Alternanza Vincitori
|
||||
|
||||
**Setup**:
|
||||
- Tu: punta
|
||||
- Altro: punta
|
||||
- Tu: riprende controllo
|
||||
- Altro: riprende controllo
|
||||
|
||||
**Verifica**:
|
||||
- ? SKIP solo quando sei vincitore
|
||||
- ? Punta solo quando NON sei vincitore
|
||||
- ? Log chiaro per ogni decisione
|
||||
|
||||
## File Modificati
|
||||
|
||||
### 1. ? `Services\AuctionMonitor.cs`
|
||||
|
||||
**Modifiche**:
|
||||
- `ShouldBid()`: Aggiunto controllo `state.IsMyBid` come prima condizione
|
||||
- `ExecuteBidStrategy()`: Aggiunto logging quando si skippa per vincitore corrente
|
||||
|
||||
**Prima**:
|
||||
```csharp
|
||||
private bool ShouldBid(AuctionInfo auction, AuctionState state)
|
||||
{
|
||||
// ? Mancava controllo IsMyBid
|
||||
|
||||
// Controlli prezzo...
|
||||
// Controlli reset...
|
||||
// Controlli clicks...
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
**Dopo**:
|
||||
```csharp
|
||||
private bool ShouldBid(AuctionInfo auction, AuctionState state)
|
||||
{
|
||||
// ? NUOVO: Prima controlla se sei già vincitore
|
||||
if (state.IsMyBid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// ... altri controlli ...
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
## Ordine di Controllo in `ShouldBid()`
|
||||
|
||||
```
|
||||
1. ? IsMyBid? ? false (skip, sei già vincitore)
|
||||
2. ? Price OK? ? false (skip, prezzo fuori range)
|
||||
3. ? Reset Count OK? ? false (skip, troppi/pochi reset)
|
||||
4. ? Max Clicks OK? ? false (skip, raggiunto limite click)
|
||||
5. ? Cooldown OK? ? false (skip, troppo presto dall'ultimo click)
|
||||
6. ? Tutti OK? ? true (PUNTA!)
|
||||
```
|
||||
|
||||
**Importante**: `IsMyBid` è il **primo** controllo perché è la condizione più comune e più veloce da verificare.
|
||||
|
||||
## Note Tecniche
|
||||
|
||||
### Perché Prima Condizione?
|
||||
|
||||
1. **Performance**: Controllo più veloce (confronto string)
|
||||
2. **Frequenza**: Caso più comune quando monitori un'asta che già vinci
|
||||
3. **Logica**: Non ha senso controllare prezzo/reset se sei già vincitore
|
||||
|
||||
### Quando `IsMyBid` è `true`?
|
||||
|
||||
```csharp
|
||||
// In BidooApiClient.cs
|
||||
state.IsMyBid = !string.IsNullOrEmpty(_session.Username) &&
|
||||
state.LastBidder.Equals(_session.Username, StringComparison.OrdinalIgnoreCase);
|
||||
```
|
||||
|
||||
Condizioni:
|
||||
- ? Sessione ha username valido
|
||||
- ? LastBidder dall'API = Username sessione (case-insensitive)
|
||||
|
||||
### Possibili Edge Case
|
||||
|
||||
#### Caso 1: Username Non Impostato
|
||||
```
|
||||
_session.Username = null o ""
|
||||
? IsMyBid = false sempre
|
||||
? Sistema continua a puntare
|
||||
```
|
||||
**Soluzione**: Richiedi sempre configurazione sessione all'avvio
|
||||
|
||||
#### Caso 2: Username Diverso (Typo)
|
||||
```
|
||||
Username sessione: "MioUsername"
|
||||
LastBidder API: "miousername"
|
||||
? IsMyBid = false (StringComparison.OrdinalIgnoreCase gestisce)
|
||||
```
|
||||
**Soluzione**: Confronto case-insensitive già implementato
|
||||
|
||||
## Log Esempi
|
||||
|
||||
### Log Normale (Non Vincitore)
|
||||
```
|
||||
[STRATEGIA] Finestra di puntata raggiunta: 450ms <= 500ms
|
||||
[BID OK] Latenza: 42ms -> EUR 1.25
|
||||
```
|
||||
|
||||
### Log con SKIP (Già Vincitore)
|
||||
```
|
||||
[STRATEGIA] Finestra di puntata raggiunta: 380ms <= 500ms
|
||||
[STRATEGIA] SKIP: Sono già il vincitore corrente (ultimo bidder: miousername)
|
||||
```
|
||||
|
||||
### Log Alternanza
|
||||
```
|
||||
[STRATEGIA] Finestra di puntata raggiunta: 450ms <= 500ms
|
||||
[STRATEGIA] SKIP: Sono già il vincitore corrente (ultimo bidder: miousername)
|
||||
[RESET] Puntata: EUR 1.30 da altroUtente
|
||||
[STRATEGIA] Finestra di puntata raggiunta: 420ms <= 500ms
|
||||
[BID OK] Latenza: 38ms -> EUR 1.31
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ? Test di Verifica
|
||||
|
||||
- [x] Non punta quando è già vincitore
|
||||
- [x] Log mostra SKIP con motivo chiaro
|
||||
- [x] Punta quando altro utente supera
|
||||
- [x] Nessun errore "Asta chiusa" quando vincitore
|
||||
- [x] Risparmia chiamate API inutili
|
||||
- [x] Logging chiaro in tutti gli scenari
|
||||
|
||||
---
|
||||
|
||||
**Data Fix**: 2025
|
||||
**Versione**: 4.0+
|
||||
**Issue**: Puntata inutile quando già vincitore
|
||||
**Status**: ? RISOLTO
|
||||
|
||||
## Riepilogo
|
||||
|
||||
**Prima**:
|
||||
- ? Puntava anche quando già vincitore
|
||||
- ? Errori "Asta chiusa" senza motivo
|
||||
- ? Spreco risorse e puntate
|
||||
|
||||
**Dopo**:
|
||||
- ? SKIP automatico se già vincitore
|
||||
- ? Log chiaro: `[STRATEGIA] SKIP: Sono già il vincitore corrente`
|
||||
- ? Punta solo quando serve riprendersi l'asta
|
||||
- ? Nessun errore inutile
|
||||
@@ -1,363 +0,0 @@
|
||||
# 📁 Riorganizzazione Progetto - Riepilogo Finale
|
||||
|
||||
## ✅ Operazioni Completate
|
||||
|
||||
### 1. Creazione Struttura a Cartelle
|
||||
|
||||
#### 📂 Nuove Cartelle Create
|
||||
```
|
||||
✅ Core/ # File principali MainWindow
|
||||
✅ Core/EventHandlers/ # Event handlers separati
|
||||
✅ Documentation/ # File markdown documentazione
|
||||
```
|
||||
|
||||
#### 📂 Cartelle Già Esistenti (Mantenute)
|
||||
```
|
||||
✅ Controls/ # UserControls WPF
|
||||
✅ Dialogs/ # Finestre di dialogo
|
||||
✅ Models/ # Data models
|
||||
✅ Services/ # Business logic services
|
||||
✅ ViewModels/ # MVVM ViewModels
|
||||
✅ Utilities/ # Helper utilities
|
||||
✅ Data/ # Database contexts
|
||||
✅ Icon/ # Risorse grafiche
|
||||
```
|
||||
|
||||
### 2. Spostamento File
|
||||
|
||||
#### Core/ (8 file spostati)
|
||||
- ✅ `MainWindow.Commands.cs`
|
||||
- ✅ `MainWindow.AuctionManagement.cs`
|
||||
- ✅ `MainWindow.Logging.cs`
|
||||
- ✅ `MainWindow.UIUpdates.cs`
|
||||
- ✅ `MainWindow.UrlParsing.cs`
|
||||
- ✅ `MainWindow.UserInfo.cs`
|
||||
- ✅ `MainWindow.ButtonHandlers.cs`
|
||||
- ✅ `MainWindow.ControlEvents.cs`
|
||||
|
||||
#### Core/EventHandlers/ (5 file spostati)
|
||||
- ✅ `MainWindow.EventHandlers.cs`
|
||||
- ✅ `MainWindow.EventHandlers.Browser.cs`
|
||||
- ✅ `MainWindow.EventHandlers.Export.cs`
|
||||
- ✅ `MainWindow.EventHandlers.Settings.cs`
|
||||
- ✅ `MainWindow.EventHandlers.Stats.cs`
|
||||
|
||||
#### Documentation/ (6 file spostati)
|
||||
- ✅ `REFACTORING_SUMMARY.md`
|
||||
- ✅ `XAML_REFACTORING_SUMMARY.md`
|
||||
- ✅ `ARCHITECTURE_OVERVIEW.md`
|
||||
- ✅ `XAML_REFACTORING_CHECKLIST.md`
|
||||
- ✅ `CHANGELOG.md`
|
||||
- ✅ `PROJECT_REORGANIZATION.md` (questo file)
|
||||
|
||||
### 3. File Creati
|
||||
|
||||
#### Root Directory
|
||||
- ✅ `README.md` - Overview completo progetto
|
||||
- ✅ `.gitignore` - File da ignorare nel VCS (ESSENZIALE per Git)
|
||||
|
||||
### 4. File Eliminati (Non Necessari)
|
||||
|
||||
#### ❌ Rimossi
|
||||
- ~~`.editorconfig`~~ - Non necessario (Visual Studio ha già le sue impostazioni)
|
||||
- ~~`.vscode/extensions.json`~~ - Non necessario (si usa Visual Studio, non VS Code)
|
||||
- ~~`.vscode/` folder~~ - Cartella vuota rimossa
|
||||
|
||||
**Motivo**: Semplificazione del progetto, mantenendo solo i file essenziali per il workflow di sviluppo.
|
||||
|
||||
### 5. File Rimasti nella Root (Essenziali)
|
||||
|
||||
#### File Principali
|
||||
- ✅ `MainWindow.xaml` - UI principale (deve stare in root)
|
||||
- ✅ `MainWindow.xaml.cs` - Code-behind principale (deve stare in root)
|
||||
- ✅ `App.xaml` - Application entry point
|
||||
- ✅ `App.xaml.cs` - Application code-behind
|
||||
- ✅ `AssemblyInfo.cs` - Assembly metadata
|
||||
- ✅ `AutoBidder.csproj` - File progetto
|
||||
- ✅ `README.md` - Documentazione overview
|
||||
- ✅ `.gitignore` - **ESSENZIALE** per Git (protegge da commit indesiderati)
|
||||
|
||||
## 📊 Statistiche Riorganizzazione
|
||||
|
||||
### Prima della Riorganizzazione
|
||||
```
|
||||
Root Directory: 18 file C#/XAML + 5 file MD
|
||||
├── File difficili da trovare
|
||||
├── Nessuna categorizzazione
|
||||
└── Documentazione mista con codice
|
||||
```
|
||||
|
||||
### Dopo la Riorganizzazione
|
||||
```
|
||||
Root Directory: 8 file essenziali
|
||||
├── Core/: 8 file partial classes
|
||||
├── Core/EventHandlers/: 5 file event handlers
|
||||
├── Controls/: 5 UserControls
|
||||
├── Dialogs/: 3 dialog windows
|
||||
├── Models/: 12 data models
|
||||
├── Services/: 5 servizi
|
||||
├── ViewModels/: 1 ViewModel
|
||||
├── Utilities/: 6 utilities
|
||||
├── Data/: 1 context
|
||||
├── Documentation/: 6 file markdown
|
||||
└── Icon/: 1 risorsa grafica
|
||||
```
|
||||
|
||||
### Metriche
|
||||
| Metrica | Prima | Dopo | Miglioramento |
|
||||
|---------|-------|------|---------------|
|
||||
| File root directory | 23 | 8 | **-65%** |
|
||||
| Cartelle logiche | 6 | 10 | +67% |
|
||||
| File configurazione | 3 | 1 | **-67%** |
|
||||
| File per cartella media | 8 | 4 | -50% |
|
||||
|
||||
## 🎯 Benefici della Riorganizzazione
|
||||
|
||||
### ✅ Navigabilità
|
||||
- **Prima**: Cercare file tra 20+ nella root
|
||||
- **Dopo**: Struttura logica per categoria
|
||||
|
||||
### ✅ Manutenibilità
|
||||
- **Prima**: Difficile capire dipendenze
|
||||
- **Dopo**: Separazione chiara delle responsabilità
|
||||
|
||||
### ✅ Semplicità
|
||||
- **Prima**: File di configurazione inutili (.editorconfig, .vscode)
|
||||
- **Dopo**: Solo file essenziali per il progetto
|
||||
|
||||
### ✅ Scalabilità
|
||||
- **Prima**: Aggiungere file complica la root
|
||||
- **Dopo**: Struttura estendibile con nuove cartelle
|
||||
|
||||
### ✅ Onboarding
|
||||
- **Prima**: Developer deve esplorare tutti i file
|
||||
- **Dopo**: README + struttura guidano l'esplorazione
|
||||
|
||||
## 📐 Struttura Finale
|
||||
|
||||
```
|
||||
AutoBidder/
|
||||
│
|
||||
├── 📁 Core/ # 🔵 PRINCIPALE
|
||||
│ ├── MainWindow.Commands.cs # Comandi WPF
|
||||
│ ├── MainWindow.AuctionManagement.cs # Gestione aste
|
||||
│ ├── MainWindow.Logging.cs # Sistema logging
|
||||
│ ├── MainWindow.UIUpdates.cs # Aggiornamenti UI
|
||||
│ ├── MainWindow.UrlParsing.cs # Parsing URL
|
||||
│ ├── MainWindow.UserInfo.cs # Info utente
|
||||
│ ├── MainWindow.ButtonHandlers.cs # Click handlers
|
||||
│ ├── MainWindow.ControlEvents.cs # Event routing
|
||||
│ └── 📁 EventHandlers/
|
||||
│ ├── MainWindow.EventHandlers.cs
|
||||
│ ├── MainWindow.EventHandlers.Browser.cs
|
||||
│ ├── MainWindow.EventHandlers.Export.cs
|
||||
│ ├── MainWindow.EventHandlers.Settings.cs
|
||||
│ └── MainWindow.EventHandlers.Stats.cs
|
||||
│
|
||||
├── 📁 Controls/ # 🟢 UI COMPONENTS
|
||||
├── 📁 Dialogs/ # 🟡 DIALOGS
|
||||
├── 📁 Models/ # 🟣 DATA MODELS
|
||||
├── 📁 Services/ # 🔴 BUSINESS LOGIC
|
||||
├── 📁 ViewModels/ # 🟠 MVVM
|
||||
├── 📁 Utilities/ # ⚫ HELPERS
|
||||
├── 📁 Data/ # 🟤 DATABASE
|
||||
├── 📁 Documentation/ # 📘 DOCS
|
||||
├── 📁 Icon/ # 🎨 RESOURCES
|
||||
│
|
||||
├── MainWindow.xaml # 🏠 MAIN UI
|
||||
├── MainWindow.xaml.cs # 🏠 MAIN CODE
|
||||
├── App.xaml # 🚀 APP ENTRY
|
||||
├── App.xaml.cs # 🚀 APP CODE
|
||||
├── AssemblyInfo.cs # ℹ️ METADATA
|
||||
├── AutoBidder.csproj # 📦 PROJECT
|
||||
├── README.md # 📖 OVERVIEW
|
||||
└── .gitignore # 🚫 VCS IGNORE (ESSENZIALE)
|
||||
```
|
||||
|
||||
## 🔧 Modifiche al Build System
|
||||
|
||||
### File .csproj
|
||||
- ✅ Nessuna modifica necessaria (SDK-style usa glob pattern impliciti)
|
||||
- ✅ I file nelle sottocartelle sono automaticamente inclusi
|
||||
- ✅ Namespace corretti generati automaticamente
|
||||
|
||||
### Compilazione
|
||||
```bash
|
||||
# Test compilazione
|
||||
dotnet build
|
||||
# ✅ Compilazione riuscita
|
||||
# ✅ 0 Errori
|
||||
# ✅ 0 Warning
|
||||
```
|
||||
|
||||
## 📚 Documentazione Aggiornata
|
||||
|
||||
### File nella Cartella Documentation/
|
||||
1. **REFACTORING_SUMMARY.md**
|
||||
- Dettagli refactoring code-behind
|
||||
- Partial classes organization
|
||||
|
||||
2. **XAML_REFACTORING_SUMMARY.md**
|
||||
- Dettagli refactoring XAML
|
||||
- UserControls modulari
|
||||
|
||||
3. **ARCHITECTURE_OVERVIEW.md**
|
||||
- Overview architettura software
|
||||
- Pattern utilizzati
|
||||
|
||||
4. **XAML_REFACTORING_CHECKLIST.md**
|
||||
- Checklist implementazione
|
||||
- Testing guide
|
||||
|
||||
5. **CHANGELOG.md**
|
||||
- Storico versioni
|
||||
- Breaking changes
|
||||
- Roadmap futura
|
||||
|
||||
6. **PROJECT_REORGANIZATION.md** (questo file)
|
||||
- Guida alla riorganizzazione
|
||||
- Decisioni architetturali
|
||||
|
||||
### File nella Root
|
||||
1. **README.md**
|
||||
- Overview progetto
|
||||
- Setup instructions
|
||||
- Struttura completa
|
||||
|
||||
2. **.gitignore**
|
||||
- Pattern Visual Studio
|
||||
- File build artifacts
|
||||
- File sensibili (DB, config, logs)
|
||||
- **ESSENZIALE** per mantenere repository pulito
|
||||
|
||||
## ✅ Checklist Verifica
|
||||
|
||||
### Build & Runtime
|
||||
- ✅ Compilazione riuscita
|
||||
- ✅ Nessun warning
|
||||
- ✅ Tutti i namespace corretti
|
||||
- ✅ Partial classes funzionanti
|
||||
- ✅ UserControls caricati
|
||||
- ✅ Event routing funzionante
|
||||
|
||||
### Struttura Progetto
|
||||
- ✅ Cartelle logiche create
|
||||
- ✅ File spostati correttamente
|
||||
- ✅ Root directory pulita (solo 8 file essenziali)
|
||||
- ✅ Documentazione organizzata
|
||||
- ✅ File non necessari rimossi
|
||||
|
||||
### Documentazione
|
||||
- ✅ README completo e aggiornato
|
||||
- ✅ CHANGELOG dettagliato
|
||||
- ✅ .gitignore essenziale mantenuto
|
||||
- ✅ File di configurazione IDE rimossi
|
||||
|
||||
## 🎉 Risultato Finale
|
||||
|
||||
### Prima
|
||||
```
|
||||
📁 AutoBidder/
|
||||
├── 📄 MainWindow.xaml
|
||||
├── 📄 MainWindow.xaml.cs
|
||||
├── 📄 MainWindow.Commands.cs
|
||||
├── 📄 MainWindow.AuctionManagement.cs
|
||||
├── 📄 MainWindow.EventHandlers.cs
|
||||
├── ... (18+ file nella root) ...
|
||||
├── 📄 README.md
|
||||
├── 📄 .editorconfig (inutile)
|
||||
├── 📄 .vscode/ (inutile)
|
||||
└── ... (difficile navigare) ...
|
||||
```
|
||||
|
||||
### Dopo
|
||||
```
|
||||
📁 AutoBidder/
|
||||
├── 📁 Core/ (13 file organizzati)
|
||||
├── 📁 Controls/ (5 UserControls)
|
||||
├── 📁 Models/ (12 modelli)
|
||||
├── 📁 Services/ (5 servizi)
|
||||
├── 📁 Documentation/ (6 markdown)
|
||||
├── 📄 MainWindow.xaml
|
||||
├── 📄 MainWindow.xaml.cs
|
||||
├── 📄 App.xaml
|
||||
├── 📄 README.md
|
||||
├── 📄 .gitignore (ESSENZIALE)
|
||||
└── ... (8 file essenziali) ✨
|
||||
```
|
||||
|
||||
## 💡 Filosofia "Less is More"
|
||||
|
||||
### Decisioni Architetturali
|
||||
|
||||
#### ✅ MANTENUTO: `.gitignore`
|
||||
**Motivo**:
|
||||
- Protegge il repository da commit indesiderati
|
||||
- Ignora file temporanei: `bin/`, `obj/`, `.vs/`
|
||||
- Protegge dati sensibili: `app_settings.json`, `stats.db`
|
||||
- Previene bloat nel repo con file utente
|
||||
- **ESSENZIALE per workflow Git pulito**
|
||||
|
||||
#### ❌ RIMOSSO: `.editorconfig`
|
||||
**Motivo**:
|
||||
- Visual Studio ha già impostazioni di formattazione integrate
|
||||
- Non lavori in team con IDE diversi
|
||||
- Aggiunge complessità senza benefici reali
|
||||
- Le convenzioni sono già definite nel README
|
||||
|
||||
#### ❌ RIMOSSO: `.vscode/extensions.json`
|
||||
**Motivo**:
|
||||
- Usi Visual Studio 2022, non VS Code
|
||||
- File specifico per un IDE che non usi
|
||||
- Nessun valore aggiunto al progetto
|
||||
|
||||
### Principio Guida
|
||||
> **"Un progetto dovrebbe contenere solo ciò che serve, niente di più"**
|
||||
|
||||
## 🚀 Prossimi Passi
|
||||
|
||||
1. **Git Commit**
|
||||
```bash
|
||||
git add .
|
||||
git commit -m "refactor: Riorganizzazione finale + Pulizia file non necessari
|
||||
|
||||
- Struttura cartelle logiche (Core, Documentation)
|
||||
- 13 partial classes MainWindow organizzate
|
||||
- 5 UserControls modulari
|
||||
- Layout dashboard con GridSplitters
|
||||
- Documentazione completa (6 file MD)
|
||||
- Rimossi .editorconfig e .vscode/ (non necessari)
|
||||
- Mantenuto solo .gitignore (essenziale)"
|
||||
|
||||
git push origin main
|
||||
```
|
||||
|
||||
2. **Testing Completo**
|
||||
- ✅ Avvio applicazione
|
||||
- ✅ Navigazione tra tab
|
||||
- ✅ Funzionalità core
|
||||
|
||||
3. **Deployment**
|
||||
- Publish per produzione
|
||||
- Installer creation
|
||||
|
||||
---
|
||||
|
||||
## 🎊 **PROGETTO FINALIZZATO!**
|
||||
|
||||
L'applicazione AutoBidder v4.0 ora ha:
|
||||
- ✅ **Architettura pulita e scalabile**
|
||||
- ✅ **UI moderna con dashboard professionale**
|
||||
- ✅ **Documentazione completa e organizzata**
|
||||
- ✅ **Solo file essenziali (no bloat)**
|
||||
- ✅ **Build ottimizzato**
|
||||
- ✅ **Repository Git pulito**
|
||||
|
||||
**Pronto per produzione!** 🚀✨
|
||||
|
||||
---
|
||||
|
||||
**Data**: 2024
|
||||
**Stato**: ✅ **COMPLETATO E OTTIMIZZATO**
|
||||
**Compilazione**: ✅ **SUCCESSO**
|
||||
**File Root**: 📊 **8 ESSENZIALI** (-65% rispetto a prima)
|
||||
@@ -1,172 +0,0 @@
|
||||
# Refactoring Summary - AutoBidder v4.0
|
||||
|
||||
## Overview
|
||||
Il codice è stato completamente refactorizzato dividendo la classe `MainWindow` in più file parziali (partial classes) per migliorare l'organizzazione, la manutenibilità e la leggibilità del codice.
|
||||
|
||||
## Nuova Struttura dei File
|
||||
|
||||
### 1. **MainWindow.xaml.cs** (File Principale)
|
||||
- Contiene solo l'inizializzazione core e i gestori degli eventi del monitor
|
||||
- Responsabilità:
|
||||
- Inizializzazione dei servizi (`AuctionMonitor`)
|
||||
- Binding degli eventi del monitor
|
||||
- Gestione degli aggiornamenti dallo stato delle aste
|
||||
- Coordinamento generale dell'applicazione
|
||||
|
||||
### 2. **MainWindow.Commands.cs**
|
||||
- Gestione dei comandi WPF (ICommand pattern)
|
||||
- Implementazioni dei comandi per:
|
||||
- Avvio/Stop/Pausa globale
|
||||
- Comandi specifici della griglia (Start/Pause/Stop/Bid per singola asta)
|
||||
|
||||
### 3. **MainWindow.AuctionManagement.cs**
|
||||
- Logica di gestione delle aste
|
||||
- Funzionalità:
|
||||
- Aggiunta aste (da ID o URL)
|
||||
- Salvataggio e caricamento delle aste
|
||||
- Validazione e parsing degli input
|
||||
|
||||
### 4. **MainWindow.EventHandlers.Browser.cs**
|
||||
- Gestori eventi per il browser integrato (WebView2)
|
||||
- Funzionalità:
|
||||
- Navigazione (Back/Forward/Refresh/Home)
|
||||
- Gestione URL e indirizzi
|
||||
- Menu contestuale personalizzato
|
||||
- Integrazione con le aste
|
||||
|
||||
### 5. **MainWindow.EventHandlers.Export.cs**
|
||||
- Gestione dell'esportazione dati
|
||||
- Funzionalità:
|
||||
- Esportazione massiva aste
|
||||
- Esportazione singola asta
|
||||
- Supporto formati: CSV, JSON, XML
|
||||
- Configurazione delle opzioni di export
|
||||
- Rimozione automatica dopo export
|
||||
|
||||
### 6. **MainWindow.EventHandlers.Settings.cs**
|
||||
- Gestione delle impostazioni e configurazioni
|
||||
- Funzionalità:
|
||||
- Salvataggio/caricamento cookie di sessione
|
||||
- Import cookie dal browser
|
||||
- Salvataggio preferenze export
|
||||
- Gestione impostazioni globali
|
||||
|
||||
### 7. **MainWindow.EventHandlers.Stats.cs**
|
||||
- Gestione delle statistiche e analisi aste chiuse
|
||||
- Funzionalità:
|
||||
- Caricamento statistiche da file esportati
|
||||
- Analisi dati aggregati
|
||||
- Applicazione raccomandazioni (insights)
|
||||
- Gestione puntate gratuite
|
||||
|
||||
### 8. **MainWindow.Logging.cs**
|
||||
- Sistema di logging centralizzato
|
||||
- Funzionalità:
|
||||
- Logging colorato per livello (Info/Warning/Error)
|
||||
- Timestamp automatico
|
||||
- Auto-scroll intelligente
|
||||
- Pulizia log
|
||||
|
||||
### 9. **MainWindow.UIUpdates.cs**
|
||||
- Aggiornamenti dell'interfaccia utente
|
||||
- Funzionalità:
|
||||
- Aggiornamento dettagli asta selezionata
|
||||
- Refresh log asta
|
||||
- Aggiornamento griglia bidders
|
||||
- Gestione stato bottoni
|
||||
- Aggiornamento contatori
|
||||
|
||||
### 10. **MainWindow.UrlParsing.cs**
|
||||
- Utility per parsing e validazione URL
|
||||
- Funzionalità:
|
||||
- Validazione URL Bidoo
|
||||
- Estrazione ID asta da URL
|
||||
- Estrazione nome prodotto da URL
|
||||
- Supporto per formati multipli
|
||||
|
||||
### 11. **MainWindow.UserInfo.cs**
|
||||
- Gestione informazioni utente e banner
|
||||
- Funzionalità:
|
||||
- Timer per aggiornamento periodico
|
||||
- Aggiornamento banner utente
|
||||
- Sincronizzazione dati HTML
|
||||
- Caricamento sessione salvata
|
||||
- Verifica validità cookie
|
||||
|
||||
### 12. **MainWindow.ButtonHandlers.cs**
|
||||
- Gestori dei click dei bottoni UI
|
||||
- Funzionalità:
|
||||
- Start/Stop/Pause globale
|
||||
- Aggiunta/Rimozione aste
|
||||
- Reset impostazioni
|
||||
- Pulizia liste e log
|
||||
- Gestione TextBox per parametri asta
|
||||
|
||||
### 13. **MainWindow.EventHandlers.cs**
|
||||
- File stub per binding XAML
|
||||
- Contiene solo dichiarazioni per compatibilità XAML
|
||||
- Le implementazioni reali sono nei file dedicati
|
||||
|
||||
## Vantaggi del Refactoring
|
||||
|
||||
### 1. **Organizzazione Migliorata**
|
||||
- Ogni file ha una responsabilità specifica e ben definita
|
||||
- Facile trovare il codice relativo a una funzionalità specifica
|
||||
- Riduzione della complessità cognitiva
|
||||
|
||||
### 2. **Manutenibilità**
|
||||
- Modifiche isolate: cambiare la logica di export non impatta altre aree
|
||||
- Più facile testare singole funzionalità
|
||||
- Riduzione dei conflitti in caso di lavoro in team
|
||||
|
||||
### 3. **Leggibilità**
|
||||
- File più piccoli e focalizzati (100-300 righe invece di 1000+)
|
||||
- Nomi file descrittivi che indicano chiaramente il contenuto
|
||||
- Documentazione XML per ogni partial class
|
||||
|
||||
### 4. **Scalabilità**
|
||||
- Facile aggiungere nuove funzionalità in file separati
|
||||
- Struttura modulare permette estensioni future
|
||||
- Separazione delle preoccupazioni (Separation of Concerns)
|
||||
|
||||
### 5. **Pattern Utilizzati**
|
||||
- **Partial Classes**: Divisione logica della classe principale
|
||||
- **Single Responsibility Principle**: Ogni file ha una responsabilità unica
|
||||
- **Command Pattern**: Separazione dei comandi UI dalla logica
|
||||
- **Event-Driven Architecture**: Gestione eventi centralizzata
|
||||
|
||||
## Compatibilità
|
||||
- ? Tutte le funzionalità esistenti sono preservate
|
||||
- ? Nessuna modifica al file XAML richiesta
|
||||
- ? Tutti i binding e gli event handler continuano a funzionare
|
||||
- ? Compilazione riuscita senza errori o warning
|
||||
|
||||
## File Originali Modificati
|
||||
1. `MainWindow.xaml.cs` - Refactorizzato e ridotto
|
||||
2. `MainWindow.EventHandlers.cs` - Ridotto a stub
|
||||
|
||||
## File Nuovi Creati
|
||||
1. `MainWindow.Commands.cs`
|
||||
2. `MainWindow.AuctionManagement.cs`
|
||||
3. `MainWindow.EventHandlers.Browser.cs`
|
||||
4. `MainWindow.EventHandlers.Export.cs`
|
||||
5. `MainWindow.EventHandlers.Settings.cs`
|
||||
6. `MainWindow.EventHandlers.Stats.cs`
|
||||
7. `MainWindow.Logging.cs`
|
||||
8. `MainWindow.UIUpdates.cs`
|
||||
9. `MainWindow.UrlParsing.cs`
|
||||
10. `MainWindow.UserInfo.cs`
|
||||
11. `MainWindow.ButtonHandlers.cs`
|
||||
|
||||
## Prossimi Passi Consigliati
|
||||
1. ? Testing completo di tutte le funzionalità
|
||||
2. Aggiungere unit test per ogni partial class
|
||||
3. Documentare ogni metodo pubblico con XML comments
|
||||
4. Considerare l'uso di dependency injection per i servizi
|
||||
5. Valutare l'estrazione di ulteriori classi helper dove appropriato
|
||||
|
||||
## Note Tecniche
|
||||
- Il pattern delle partial classes permette di mantenere una singola istanza logica di `MainWindow`
|
||||
- Tutti i membri (campi, proprietà, metodi) sono condivisi tra i file parziali
|
||||
- I modificatori di accesso (`private`, `public`, ecc.) sono consistenti
|
||||
- L'ordine di compilazione dei file parziali è irrilevante per il compilatore C#
|
||||
@@ -1,304 +0,0 @@
|
||||
# ? XAML Refactoring - Checklist Completamento
|
||||
|
||||
## ?? Obiettivo
|
||||
Refactoring completo del MainWindow.xaml utilizzando UserControls modulari per migliorare manutenibilità, scalabilità e design.
|
||||
|
||||
---
|
||||
|
||||
## ? Fase 1: Creazione UserControls
|
||||
|
||||
### AuctionMonitorControl
|
||||
- [x] Creato `Controls/AuctionMonitorControl.xaml` (430 linee)
|
||||
- [x] Creato `Controls/AuctionMonitorControl.xaml.cs`
|
||||
- [x] Implementati 17 Routed Events
|
||||
- [x] Header con toolbar (Start, Pause, Stop, Add, Remove)
|
||||
- [x] Griglia aste con 7 colonne
|
||||
- [x] Pannello dettagli con impostazioni
|
||||
- [x] Lista bidders con DataGrid
|
||||
- [x] Log asta specifico
|
||||
- [x] Log globale nel footer
|
||||
|
||||
### BrowserControl
|
||||
- [x] Creato `Controls/BrowserControl.xaml` (120 linee)
|
||||
- [x] Creato `Controls/BrowserControl.xaml.cs`
|
||||
- [x] Implementati 6 Routed Events
|
||||
- [x] Toolbar navigazione (Back, Forward, Refresh, Home)
|
||||
- [x] Barra indirizzi con SSL indicator
|
||||
- [x] WebView2 embedded
|
||||
- [x] Bottone "Aggiungi Asta"
|
||||
|
||||
### StatisticsControl
|
||||
- [x] Creato `Controls/StatisticsControl.xaml` (80 linee)
|
||||
- [x] Creato `Controls/StatisticsControl.xaml.cs`
|
||||
- [x] Implementato 1 Routed Event
|
||||
- [x] Header con bottone carica
|
||||
- [x] DataGrid con 5 colonne statistiche
|
||||
- [x] Footer con status e progress bar
|
||||
|
||||
### SettingsControl
|
||||
- [x] Creato `Controls/SettingsControl.xaml` (200 linee)
|
||||
- [x] Creato `Controls/SettingsControl.xaml.cs`
|
||||
- [x] Implementati 8 Routed Events
|
||||
- [x] Sezione configurazione sessione (cookie)
|
||||
- [x] Guida ottenimento cookie
|
||||
- [x] Sezione impostazioni export
|
||||
- [x] Formato export (CSV/JSON/XML)
|
||||
- [x] Opzioni export (checkboxes)
|
||||
- [x] Sezione impostazioni predefinite aste
|
||||
|
||||
---
|
||||
|
||||
## ? Fase 2: Refactoring MainWindow.xaml
|
||||
|
||||
- [x] Ridotto da 1000+ a ~100 linee
|
||||
- [x] Implementato TabControl con 4 tab
|
||||
- [x] Applicati stili personalizzati per tab headers
|
||||
- [x] Integrati UserControls in ogni tab
|
||||
- [x] Collegati eventi UserControls
|
||||
|
||||
### Tab Create
|
||||
- [x] ?? Monitor Aste ? AuctionMonitorControl
|
||||
- [x] ?? Browser ? BrowserControl
|
||||
- [x] ?? Statistiche ? StatisticsControl
|
||||
- [x] ?? Impostazioni ? SettingsControl
|
||||
|
||||
---
|
||||
|
||||
## ? Fase 3: Aggiornamento Code-Behind
|
||||
|
||||
### MainWindow.xaml.cs
|
||||
- [x] Aggiunto property exposure per UserControl elements
|
||||
- [x] Mantenuta compatibilità con codice esistente
|
||||
- [x] Configurato DataContext
|
||||
- [x] Inizializzati servizi e timers
|
||||
|
||||
### MainWindow.ControlEvents.cs (NEW)
|
||||
- [x] Creato file per event routing
|
||||
- [x] Implementati handler per AuctionMonitorControl (11 eventi)
|
||||
- [x] Implementati handler per BrowserControl (6 eventi)
|
||||
- [x] Implementati handler per StatisticsControl (1 evento)
|
||||
- [x] Implementati handler per SettingsControl (8 eventi)
|
||||
- [x] Collegamento ai metodi esistenti
|
||||
|
||||
---
|
||||
|
||||
## ? Fase 4: Testing & Validation
|
||||
|
||||
### Compilation
|
||||
- [x] Build riuscita senza errori
|
||||
- [x] Zero warning
|
||||
- [x] Tutti i riferimenti risolti
|
||||
|
||||
### Design-Time
|
||||
- [x] XAML Designer carica MainWindow.xaml
|
||||
- [x] XAML Designer carica ogni UserControl
|
||||
- [x] IntelliSense funziona correttamente
|
||||
- [x] Property binding funzionanti
|
||||
|
||||
### Runtime (Da Testare)
|
||||
- [ ] Avvio applicazione
|
||||
- [ ] Navigazione tra tab
|
||||
- [ ] Aggiunta/rimozione aste
|
||||
- [ ] Monitoraggio aste funzionante
|
||||
- [ ] Browser navigazione
|
||||
- [ ] Caricamento statistiche
|
||||
- [ ] Salvataggio impostazioni
|
||||
- [ ] Export aste
|
||||
|
||||
---
|
||||
|
||||
## ? Fase 5: Documentazione
|
||||
|
||||
- [x] Creato `REFACTORING_SUMMARY.md` (code-behind)
|
||||
- [x] Creato `XAML_REFACTORING_SUMMARY.md` (XAML)
|
||||
- [x] Creato `ARCHITECTURE_OVERVIEW.md` (overview)
|
||||
- [x] Creato `XAML_REFACTORING_CHECKLIST.md` (questo file)
|
||||
- [x] XML comments in UserControls
|
||||
- [x] README.md aggiornato (TODO)
|
||||
|
||||
---
|
||||
|
||||
## ? Fase 6: Pulizia & Ottimizzazione
|
||||
|
||||
### Codice Legacy
|
||||
- [ ] Valutare rimozione `MainWindow.EventHandlers.Browser.cs` (logica ora in BrowserControl)
|
||||
- [ ] Consolidare file partial se necessario
|
||||
- [ ] Rimuovere codice morto/commentato
|
||||
|
||||
### Performance
|
||||
- [x] Lazy loading tab implementato (built-in TabControl)
|
||||
- [x] Async operations mantenute
|
||||
- [x] Virtual scrolling DataGrid
|
||||
- [ ] Memory profiling (future)
|
||||
|
||||
### UI/UX
|
||||
- [x] Palette colori consistente
|
||||
- [x] Icone emoji per usabilità
|
||||
- [x] Layout responsive
|
||||
- [ ] Accessibility (ARIA, keyboard navigation)
|
||||
- [ ] Temi dark/light (future)
|
||||
|
||||
---
|
||||
|
||||
## ?? Checklist Post-Refactoring
|
||||
|
||||
### Immediate Actions (Da fare subito)
|
||||
1. [ ] **Test Completo Applicazione**
|
||||
- Avviare l'app
|
||||
- Testare ogni tab
|
||||
- Verificare tutti i flussi utente
|
||||
- Log eventuali bug
|
||||
|
||||
2. [ ] **Code Review**
|
||||
- Revisione UserControls
|
||||
- Revisione event routing
|
||||
- Verificare best practices WPF
|
||||
|
||||
3. [ ] **Git Commit**
|
||||
```bash
|
||||
git add .
|
||||
git commit -m "feat: Refactoring XAML con UserControls modulari
|
||||
|
||||
- Creati 4 UserControls (AuctionMonitor, Browser, Statistics, Settings)
|
||||
- MainWindow.xaml ridotto da 1000+ a ~100 linee
|
||||
- Implementato TabControl con routing eventi
|
||||
- Mantiene 100% compatibilità con codice esistente
|
||||
- Aggiunta documentazione completa"
|
||||
|
||||
git push origin main
|
||||
```
|
||||
|
||||
### Short-Term (Prossime settimane)
|
||||
4. [ ] **Unit Testing UserControls**
|
||||
- Test isolati per ogni controllo
|
||||
- Test event propagation
|
||||
- Test data binding
|
||||
|
||||
5. [ ] **ViewModels Dedicati**
|
||||
- `AuctionMonitorViewModel`
|
||||
- `BrowserViewModel`
|
||||
- `StatisticsViewModel`
|
||||
- `SettingsViewModel`
|
||||
|
||||
6. [ ] **Styling System**
|
||||
- ResourceDictionary condivisi
|
||||
- Temi customizzabili
|
||||
- Branding consistente
|
||||
|
||||
### Medium-Term (Prossimi mesi)
|
||||
7. [ ] **Dependency Injection**
|
||||
- Configurare DI container
|
||||
- Iniettare servizi nei ViewModels
|
||||
- Eliminare dipendenze dirette
|
||||
|
||||
8. [ ] **Advanced Features**
|
||||
- Drag & drop aste nella griglia
|
||||
- Filtri e sorting avanzati
|
||||
- Export batch con progress
|
||||
- Notifiche sistema
|
||||
|
||||
9. [ ] **Accessibility & Localization**
|
||||
- WCAG 2.1 compliance
|
||||
- Keyboard shortcuts
|
||||
- Multilingua (IT, EN, FR, ES, DE)
|
||||
|
||||
### Long-Term (Future)
|
||||
10. [ ] **Plugin Architecture**
|
||||
- Interface per plugin
|
||||
- Dynamic loading UserControls
|
||||
- Extension marketplace
|
||||
|
||||
11. [ ] **Cloud Integration**
|
||||
- Sync impostazioni cloud
|
||||
- Backup automatico
|
||||
- Multi-device support
|
||||
|
||||
12. [ ] **Analytics & Telemetry**
|
||||
- Usage statistics
|
||||
- Error reporting automatico
|
||||
- Performance monitoring
|
||||
|
||||
---
|
||||
|
||||
## ?? Metriche Successo
|
||||
|
||||
| Obiettivo | Target | Status |
|
||||
|-----------|--------|--------|
|
||||
| File XAML ridotto | <200 linee | ? 100 linee |
|
||||
| UserControls creati | 4+ | ? 4 |
|
||||
| Compatibilità | 100% | ? 100% |
|
||||
| Build errors | 0 | ? 0 |
|
||||
| Documentazione | Completa | ? Completa |
|
||||
| Design consistency | Alta | ? Alta |
|
||||
| Testabilità | >80% | ? ~85% |
|
||||
| Performance | Nessun degrado | ? Migliorata |
|
||||
|
||||
---
|
||||
|
||||
## ?? Known Issues & Workarounds
|
||||
|
||||
### Issue 1: WebView2 Initialization
|
||||
**Problema**: WebView2 potrebbe non inizializzarsi al primo avvio
|
||||
**Workaround**: Installare WebView2 Runtime
|
||||
**Fix Permanente**: Bundling WebView2 nell'installer
|
||||
|
||||
### Issue 2: Event Routing Delay
|
||||
**Problema**: Primo click su bottone potrebbe avere delay
|
||||
**Workaround**: Nessuno necessario (cold start normale)
|
||||
**Fix Permanente**: Preload UserControls critici
|
||||
|
||||
### Issue 3: TabControl Memory
|
||||
**Problema**: Tab non vengono unloaded quando non visibili
|
||||
**Workaround**: Manuale GC se necessario
|
||||
**Fix Permanente**: Implementare lazy unloading
|
||||
|
||||
---
|
||||
|
||||
## ?? Risorse Utili
|
||||
|
||||
### WPF Best Practices
|
||||
- [Microsoft WPF Guide](https://docs.microsoft.com/en-us/dotnet/desktop/wpf/)
|
||||
- [MVVM Pattern](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/mvvm)
|
||||
- [UserControls vs CustomControls](https://stackoverflow.com/questions/471059/)
|
||||
|
||||
### Tools
|
||||
- **XAML Styler**: Formattazione XAML automatica
|
||||
- **Snoop**: WPF debugging visual tree
|
||||
- **dotMemory**: Memory profiling
|
||||
- **ReSharper**: Code analysis
|
||||
|
||||
---
|
||||
|
||||
## ?? Conclusioni
|
||||
|
||||
### ? Completato con Successo
|
||||
Il refactoring XAML è stato completato con successo, creando una base solida e scalabile per AutoBidder v4.0. L'applicazione ora segue le best practices WPF moderne con:
|
||||
|
||||
- ? Architettura modulare e manutenibile
|
||||
- ? Separazione chiara delle responsabilità
|
||||
- ? Design professionale e consistente
|
||||
- ? Compatibilità 100% retroattiva
|
||||
- ? Documentazione completa
|
||||
|
||||
### ?? Pronto per Produzione
|
||||
L'applicazione è pronta per:
|
||||
- Testing estensivo
|
||||
- Deploy in produzione
|
||||
- Future estensioni
|
||||
- Sviluppo in team
|
||||
|
||||
### ?? Benefici Misurabili
|
||||
- **Manutenibilità**: +400% (da file monolitico a moduli)
|
||||
- **Testabilità**: +300% (controlli isolati)
|
||||
- **Leggibilità**: +500% (file piccoli e focused)
|
||||
- **Scalabilità**: ? (architettura estendibile)
|
||||
|
||||
---
|
||||
|
||||
**Data Completamento**: 2024
|
||||
**Versione**: AutoBidder v4.0
|
||||
**Status**: ? **REFACTORING COMPLETO**
|
||||
|
||||
---
|
||||
|
||||
?? **Next Steps**: Procedi con testing e validazione funzionale! ??
|
||||
@@ -1,360 +0,0 @@
|
||||
# XAML Refactoring Summary - AutoBidder v4.0
|
||||
|
||||
## Overview
|
||||
Il file MainWindow.xaml è stato completamente refactorizzato utilizzando **UserControls modulari** organizzati in un **TabControl**. Questo approccio segue le best practices WPF e migliora drasticamente la manutenibilità del codice UI.
|
||||
|
||||
## Nuova Struttura UI
|
||||
|
||||
### MainWindow.xaml (File Principale)
|
||||
- Contiene solo il TabControl principale con 4 tab
|
||||
- Ogni tab ospita un UserControl dedicato
|
||||
- Design pulito e professionale con stili personalizzati
|
||||
|
||||
### UserControls Creati
|
||||
|
||||
#### 1. **AuctionMonitorControl.xaml** (`Controls/`)
|
||||
**Responsabilità**: Monitoraggio e gestione aste in tempo reale
|
||||
|
||||
**Sezioni**:
|
||||
- **Header Toolbar**:
|
||||
- Titolo con conteggio aste
|
||||
- Info utente (username e crediti)
|
||||
- Bottoni: Avvia, Pausa, Stop, Aggiungi, Rimuovi
|
||||
|
||||
- **Contenuto Principale** (2 colonne con splitter):
|
||||
- **Lista Aste** (sinistra):
|
||||
- DataGrid con aste monitorate
|
||||
- Colonne: Nome, Timer, Prezzo, Ultimo, Stato, Reset, Click
|
||||
|
||||
- **Dettagli Asta** (destra):
|
||||
- Info asta selezionata
|
||||
- Impostazioni asta (Timer, Delay, Prezzi, etc.)
|
||||
- Lista bidders
|
||||
- Log asta specifico
|
||||
|
||||
- **Footer**:
|
||||
- Log globale con scrolling automatico
|
||||
- Bottone pulizia log
|
||||
|
||||
**Eventi Esposti** (17 eventi via Routed Events):
|
||||
- StartClicked, PauseAllClicked, StopClicked
|
||||
- AddUrlClicked, RemoveUrlClicked
|
||||
- AuctionSelectionChanged
|
||||
- CopyUrlClicked, ResetSettingsClicked
|
||||
- ClearBiddersClicked, ClearLogClicked, ClearGlobalLogClicked
|
||||
- TimerClickChanged, DelayMsChanged
|
||||
- MinPriceChanged, MaxPriceChanged
|
||||
- MinResetsChanged, MaxResetsChanged, MaxClicksChanged
|
||||
|
||||
---
|
||||
|
||||
#### 2. **BrowserControl.xaml** (`Controls/`)
|
||||
**Responsabilità**: Browser integrato per navigazione Bidoo.com
|
||||
|
||||
**Sezioni**:
|
||||
- **Toolbar**:
|
||||
- Bottoni navigazione: Indietro, Avanti, Ricarica, Home
|
||||
- Barra indirizzi con icona SSL
|
||||
- Bottoni: Vai, Aggiungi Asta
|
||||
|
||||
- **WebView2**:
|
||||
- Browser Chromium embedded
|
||||
- Navigazione completa
|
||||
- Context menu personalizzato
|
||||
|
||||
**Eventi Esposti** (6 eventi):
|
||||
- BrowserBackClicked, BrowserForwardClicked
|
||||
- BrowserRefreshClicked, BrowserHomeClicked
|
||||
- BrowserGoClicked, BrowserAddAuctionClicked
|
||||
|
||||
---
|
||||
|
||||
#### 3. **StatisticsControl.xaml** (`Controls/`)
|
||||
**Responsabilità**: Analisi statistiche aste chiuse
|
||||
|
||||
**Sezioni**:
|
||||
- **Header**:
|
||||
- Titolo con icona
|
||||
- Bottone "Carica Statistiche"
|
||||
|
||||
- **DataGrid Statistiche**:
|
||||
- Colonne: Prodotto, Prezzo Medio, Click Medi, Vincitore Frequente, # Aste
|
||||
- Sorting e alternating rows
|
||||
|
||||
- **Footer**:
|
||||
- Status text
|
||||
- Progress bar per caricamento
|
||||
|
||||
**Eventi Esposti** (1 evento):
|
||||
- LoadClosedAuctionsClicked
|
||||
|
||||
---
|
||||
|
||||
#### 4. **SettingsControl.xaml** (`Controls/`)
|
||||
**Responsabilità**: Configurazioni applicazione
|
||||
|
||||
**Sezioni**:
|
||||
- **Configurazione Sessione**:
|
||||
- TextBox per cookie __stattrb
|
||||
- Bottoni: Salva, Importa dal Browser, Cancella
|
||||
- Guida passo-passo per ottenere il cookie
|
||||
|
||||
- **Impostazioni Export**:
|
||||
- Percorso export con bottone Sfoglia
|
||||
- Formato: RadioButtons (CSV, JSON, XML)
|
||||
- Opzioni: CheckBoxes (include logs, bidders, etc.)
|
||||
- Bottoni: Salva, Ripristina
|
||||
|
||||
- **Impostazioni Predefinite Aste**:
|
||||
- Valori default per nuove aste
|
||||
- Timer, Delay, Prezzi, Max Click
|
||||
- Bottoni: Salva, Reset
|
||||
|
||||
**Eventi Esposti** (8 eventi):
|
||||
- SaveCookieClicked, ImportCookieClicked, CancelCookieClicked
|
||||
- ExportBrowseClicked, SaveSettingsClicked, CancelSettingsClicked
|
||||
- SaveDefaultsClicked, CancelDefaultsClicked
|
||||
|
||||
---
|
||||
|
||||
## File Struttura
|
||||
|
||||
```
|
||||
AutoBidder/
|
||||
??? MainWindow.xaml # TabControl principale
|
||||
??? MainWindow.xaml.cs # Core initialization
|
||||
??? MainWindow.ControlEvents.cs # NEW: Event routing da UserControls
|
||||
??? MainWindow.Commands.cs # Command implementations
|
||||
??? MainWindow.AuctionManagement.cs # Auction CRUD
|
||||
??? MainWindow.EventHandlers.Browser.cs # Browser logic (legacy, ora deprecato)
|
||||
??? MainWindow.EventHandlers.Export.cs # Export logic
|
||||
??? MainWindow.EventHandlers.Settings.cs # Settings logic
|
||||
??? MainWindow.EventHandlers.Stats.cs # Statistics logic
|
||||
??? MainWindow.Logging.cs # Logging system
|
||||
??? MainWindow.UIUpdates.cs # UI updates
|
||||
??? MainWindow.UrlParsing.cs # URL utilities
|
||||
??? MainWindow.UserInfo.cs # User info & session
|
||||
??? MainWindow.ButtonHandlers.cs # Button handlers (legacy)
|
||||
??? Controls/
|
||||
??? AuctionMonitorControl.xaml # Monitor aste UI
|
||||
??? AuctionMonitorControl.xaml.cs # Event handlers
|
||||
??? BrowserControl.xaml # Browser UI
|
||||
??? BrowserControl.xaml.cs # Event handlers
|
||||
??? StatisticsControl.xaml # Statistiche UI
|
||||
??? StatisticsControl.xaml.cs # Event handlers
|
||||
??? SettingsControl.xaml # Impostazioni UI
|
||||
??? SettingsControl.xaml.cs # Event handlers
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pattern e Tecniche Utilizzate
|
||||
|
||||
### 1. **UserControl Pattern**
|
||||
Ogni schermata principale è un UserControl riutilizzabile e testabile in isolamento.
|
||||
|
||||
### 2. **Routed Events**
|
||||
Gli UserControls espongono eventi personalizzati che "bubblano" fino al MainWindow:
|
||||
```csharp
|
||||
// Definizione evento nel UserControl
|
||||
public static readonly RoutedEvent StartClickedEvent =
|
||||
EventManager.RegisterRoutedEvent("StartClicked", ...);
|
||||
|
||||
// Sottoscrizione nel MainWindow
|
||||
<controls:AuctionMonitorControl StartClicked="AuctionMonitor_StartClicked"/>
|
||||
```
|
||||
|
||||
### 3. **Property Exposure**
|
||||
Il MainWindow espone proprietà pubbliche che mappano agli elementi interni dei UserControls:
|
||||
```csharp
|
||||
public DataGrid MultiAuctionsGrid => AuctionMonitor.MultiAuctionsGrid;
|
||||
public RichTextBox LogBox => AuctionMonitor.LogBox;
|
||||
```
|
||||
Questo mantiene la compatibilità con il codice esistente senza modifiche massive.
|
||||
|
||||
### 4. **Event Routing**
|
||||
`MainWindow.ControlEvents.cs` funge da **Event Router** che collega gli eventi dei controlli ai metodi esistenti:
|
||||
```csharp
|
||||
private void AuctionMonitor_StartClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
StartButton_Click(sender, e); // Chiama il metodo esistente
|
||||
}
|
||||
```
|
||||
|
||||
### 5. **Separation of Concerns**
|
||||
- **UI** (XAML): Definisce solo l'aspetto e la struttura
|
||||
- **Code-Behind** (xaml.cs): Gestisce solo eventi locali e notifiche
|
||||
- **MainWindow**: Coordina la logica business tra i controlli
|
||||
|
||||
---
|
||||
|
||||
## Vantaggi del Refactoring XAML
|
||||
|
||||
### 1. **Modularità**
|
||||
? Ogni UserControl può essere sviluppato, testato e debuggato indipendentemente
|
||||
? Riutilizzabilità: i controlli possono essere usati in altre finestre/applicazioni
|
||||
? Facilità di manutenzione: modifiche isolate senza impatto globale
|
||||
|
||||
### 2. **Design-Time Experience**
|
||||
? Designer di Visual Studio funziona perfettamente su ogni controllo
|
||||
? IntelliSense completo per binding e proprietà
|
||||
? Anteprima separata di ogni controllo
|
||||
|
||||
### 3. **Performance**
|
||||
? Lazy loading: i tab caricano il contenuto solo quando selezionati
|
||||
? Minor overhead iniziale dell'applicazione
|
||||
? Rendering più efficiente con UI compartimentata
|
||||
|
||||
### 4. **Scalabilità**
|
||||
? Facile aggiungere nuovi tab/controlli
|
||||
? Struttura pronta per supportare plugins/estensioni
|
||||
? Testing UI automatizzato più semplice
|
||||
|
||||
### 5. **Leggibilità**
|
||||
? File XAML più piccoli (~100-300 righe vs 1000+)
|
||||
? Struttura gerarchica chiara e intuitiva
|
||||
? Nomi descrittivi per ogni componente
|
||||
|
||||
---
|
||||
|
||||
## Compatibilità Retroattiva
|
||||
|
||||
### ? 100% Compatibile
|
||||
Il refactoring mantiene la **completa compatibilità** con il codice esistente:
|
||||
|
||||
1. **Property Exposure**: Tutti gli elementi UI sono accessibili come prima
|
||||
```csharp
|
||||
MultiAuctionsGrid.ItemsSource = _auctionViewModels; // Funziona ancora!
|
||||
```
|
||||
|
||||
2. **Event Routing**: Gli eventi vengono inoltrati ai metodi esistenti
|
||||
```csharp
|
||||
StartButton_Click() // Chiamato quando si clicca "Avvia" nel controllo
|
||||
```
|
||||
|
||||
3. **Nessuna Modifica Richiesta**:
|
||||
- ? Tutti i file `MainWindow.*.cs` funzionano senza modifiche
|
||||
- ? ViewModels, Services, Models inalterati
|
||||
- ? Logica business intatta
|
||||
|
||||
---
|
||||
|
||||
## Design UI Migliorato
|
||||
|
||||
### Palette Colori Consistente
|
||||
- **Primary**: `#3498DB` (Blu) - Azioni principali
|
||||
- **Success**: `#27AE60` (Verde) - Operazioni riuscite
|
||||
- **Warning**: `#F39C12` (Arancione) - Attenzione
|
||||
- **Danger**: `#E74C3C` (Rosso) - Stop/Elimina
|
||||
- **Dark**: `#2C3E50` (Blu scuro) - Backgrounds
|
||||
- **Light**: `#ECF0F1` (Grigio chiaro) - Alternanza righe
|
||||
|
||||
### Icone Emoji
|
||||
Utilizzo di emoji per migliorare l'usabilità:
|
||||
- ?? Monitor Aste
|
||||
- ?? Browser
|
||||
- ?? Statistiche
|
||||
- ?? Impostazioni
|
||||
- ? Avvia
|
||||
- ? Pausa
|
||||
- ? Stop
|
||||
- ? Aggiungi
|
||||
- ? Rimuovi
|
||||
- ?? Ricarica
|
||||
- ?? Log
|
||||
- ?? SSL
|
||||
|
||||
### Responsive Layout
|
||||
- GridSplitter per ridimensionare sezioni
|
||||
- ScrollViewer dove necessario
|
||||
- Adaptive sizing per risoluzioni diverse
|
||||
|
||||
---
|
||||
|
||||
## Testing e Validazione
|
||||
|
||||
### ? Test Effettuati
|
||||
1. **Compilazione**: ? Build riuscita senza errori
|
||||
2. **Binding**: ? Tutti i binding funzionano correttamente
|
||||
3. **Eventi**: ? Tutti gli eventi si propagano correttamente
|
||||
4. **Navigation**: ? Tab switching funziona perfettamente
|
||||
5. **Designer**: ? XAML Designer carica tutti i controlli
|
||||
|
||||
### ?? Test Raccomandati
|
||||
- [ ] Test funzionali completi di ogni tab
|
||||
- [ ] Test WebView2 inizializzazione e navigazione
|
||||
- [ ] Test aggiunta/rimozione aste dalla UI
|
||||
- [ ] Test caricamento statistiche
|
||||
- [ ] Test salvataggio/caricamento impostazioni
|
||||
- [ ] Test su risoluzioni diverse (HD, FullHD, 4K)
|
||||
|
||||
---
|
||||
|
||||
## Prossimi Passi Consigliati
|
||||
|
||||
### 1. **Rimozione Codice Legacy** (Opzionale)
|
||||
Alcuni file partial potrebbero essere semplificati ora che la logica è nei controlli:
|
||||
- `MainWindow.EventHandlers.Browser.cs` ? Logica ora in `BrowserControl`
|
||||
- Valutare consolidamento di altri file
|
||||
|
||||
### 2. **ViewModels per UserControls**
|
||||
Creare ViewModels dedicati per ogni controllo:
|
||||
```
|
||||
ViewModels/
|
||||
??? AuctionMonitorViewModel.cs
|
||||
??? BrowserViewModel.cs
|
||||
??? StatisticsViewModel.cs
|
||||
??? SettingsViewModel.cs
|
||||
```
|
||||
|
||||
### 3. **Dependency Injection**
|
||||
Iniettare servizi nei ViewModels invece di passare dal MainWindow:
|
||||
```csharp
|
||||
public AuctionMonitorControl(IAuctionMonitor monitor, ILogger logger)
|
||||
{
|
||||
_monitor = monitor;
|
||||
_logger = logger;
|
||||
}
|
||||
```
|
||||
|
||||
### 4. **Data Binding Avanzato**
|
||||
Sostituire event handlers con Command binding dove possibile:
|
||||
```xaml
|
||||
<Button Command="{Binding StartCommand}" .../>
|
||||
```
|
||||
|
||||
### 5. **Styling System**
|
||||
Creare ResourceDictionaries condivisi:
|
||||
```
|
||||
Themes/
|
||||
??? Colors.xaml
|
||||
??? Buttons.xaml
|
||||
??? DataGrids.xaml
|
||||
??? Generic.xaml
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Conclusioni
|
||||
|
||||
### ?? Risultati Ottenuti
|
||||
- ? **4 UserControls modulari** creati
|
||||
- ? **MainWindow.xaml ridotto** da ~1000 a ~100 righe
|
||||
- ? **Compilazione riuscita** senza errori
|
||||
- ? **Compatibilità 100%** con codice esistente
|
||||
- ? **Design professionale** e consistente
|
||||
- ? **Manutenibilità drasticamente migliorata**
|
||||
|
||||
### ?? Metriche
|
||||
- **Linee XAML**: 1000+ ? 4×~150 (distributed)
|
||||
- **File Creati**: 8 nuovi (4 XAML + 4 CS)
|
||||
- **Complessità**: Drasticamente ridotta
|
||||
- **Riutilizzabilità**: Massima
|
||||
|
||||
### ?? Benefici Immediati
|
||||
1. **Sviluppo Parallelo**: Team members possono lavorare su controlli diversi senza conflitti
|
||||
2. **Testing Isolato**: Ogni controllo può essere testato indipendentemente
|
||||
3. **Debugging Semplificato**: Problemi UI localizzati in specifici controlli
|
||||
4. **Onboarding Veloce**: Nuovi sviluppatori capiscono la struttura immediatamente
|
||||
|
||||
Il refactoring XAML completa la modernizzazione dell'applicazione AutoBidder, creando una base solida per future estensioni e miglioramenti! ??
|
||||
@@ -0,0 +1,322 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder.Engine
|
||||
{
|
||||
/// <summary>
|
||||
/// Servizi che il runner si aspetta dal monitor. Esiste per non legare il motore
|
||||
/// all'implementazione del monitor: qui dentro c'è solo il timing.
|
||||
/// </summary>
|
||||
public interface IAuctionRunnerHost
|
||||
{
|
||||
/// <summary>Impostazioni correnti (già memorizzate in cache dal chiamante).</summary>
|
||||
AppSettings Settings { get; }
|
||||
|
||||
/// <summary>Una singola interrogazione a data.php. null = nessuna risposta utilizzabile.</summary>
|
||||
Task<AuctionState?> PollAsync(AuctionInfo auction, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Incorpora la risposta: aggiorna orologio server, scadenza, storico e interfaccia.
|
||||
/// </summary>
|
||||
void ApplySnapshot(AuctionInfo auction, AuctionState snapshot);
|
||||
|
||||
/// <summary>True quando l'asta è conclusa e il runner può spegnersi.</summary>
|
||||
bool IsFinished(AuctionInfo auction);
|
||||
|
||||
/// <summary>
|
||||
/// Verdetto delle strategie sulla puntata. Il runner decide <i>quando</i>,
|
||||
/// questo metodo decide <i>se</i>.
|
||||
/// </summary>
|
||||
bool EvaluateBid(AuctionInfo auction, AuctionState state);
|
||||
|
||||
/// <summary>Invia la puntata e registra l'esito.</summary>
|
||||
Task FireBidAsync(AuctionInfo auction, AuctionState state, int leadMs, double actualLeadMs, CancellationToken ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Motore di una singola asta. Due anelli indipendenti che girano in parallelo:
|
||||
///
|
||||
/// - <b>polling</b>: interroga data.php con cadenza che si stringe man mano che la
|
||||
/// scadenza si avvicina, e aggiorna prezzo, ultimo puntatore e scadenza assoluta;
|
||||
/// - <b>cecchino</b>: dorme fino a "scadenza meno anticipo" e spara la puntata lì.
|
||||
///
|
||||
/// Tenerli separati è la differenza sostanziale rispetto a un ticker unico condiviso:
|
||||
/// una risposta lenta del server su un'asta non sposta di un millisecondo il momento
|
||||
/// della puntata sulle altre, e il numero di aste seguite non degrada la precisione.
|
||||
/// </summary>
|
||||
public sealed class AuctionRunner
|
||||
{
|
||||
/// <summary>Quanto prima dell'istante di fuoco si eseguono i controlli di strategia.</summary>
|
||||
private const double PreCheckMs = 60;
|
||||
|
||||
private readonly AuctionInfo _auction;
|
||||
private readonly IAuctionRunnerHost _host;
|
||||
|
||||
private CancellationTokenSource? _cts;
|
||||
private Task? _pollTask;
|
||||
private Task? _sniperTask;
|
||||
|
||||
/// <summary>Scadenza (in secondi unix) del ciclo già gestito: garantisce una sola puntata per ciclo.</summary>
|
||||
private long _handledCycle = -1;
|
||||
|
||||
public AuctionRunner(AuctionInfo auction, IAuctionRunnerHost host)
|
||||
{
|
||||
_auction = auction;
|
||||
_host = host;
|
||||
}
|
||||
|
||||
public AuctionInfo Auction => _auction;
|
||||
|
||||
public bool IsRunning => _pollTask is { IsCompleted: false };
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (IsRunning) return;
|
||||
|
||||
_cts = new CancellationTokenSource();
|
||||
var token = _cts.Token;
|
||||
|
||||
_pollTask = Task.Run(() => PollLoopAsync(token), token);
|
||||
_sniperTask = Task.Run(() => SniperLoopAsync(token), token);
|
||||
}
|
||||
|
||||
public async Task StopAsync()
|
||||
{
|
||||
var cts = _cts;
|
||||
if (cts is null) return;
|
||||
|
||||
_cts = null;
|
||||
try { await cts.CancelAsync().ConfigureAwait(false); } catch { /* già annullato */ }
|
||||
|
||||
var tasks = new[] { _pollTask, _sniperTask }.Where(t => t is not null).Cast<Task>().ToArray();
|
||||
if (tasks.Length > 0)
|
||||
{
|
||||
try { await Task.WhenAll(tasks).WaitAsync(TimeSpan.FromSeconds(3)).ConfigureAwait(false); }
|
||||
catch { /* uscita forzata */ }
|
||||
}
|
||||
|
||||
_pollTask = null;
|
||||
_sniperTask = null;
|
||||
cts.Dispose();
|
||||
}
|
||||
|
||||
// ── Anello di polling ────────────────────────────────────────────────────
|
||||
|
||||
private async Task PollLoopAsync(CancellationToken ct)
|
||||
{
|
||||
var consecutiveErrors = 0;
|
||||
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = _host.Settings;
|
||||
|
||||
var snapshot = await _host.PollAsync(_auction, ct).ConfigureAwait(false);
|
||||
|
||||
if (snapshot is null)
|
||||
{
|
||||
consecutiveErrors++;
|
||||
_auction.PollErrors++;
|
||||
|
||||
if (consecutiveErrors == 3)
|
||||
{
|
||||
_auction.AddLog(
|
||||
"Nessuna risposta da data.php: verifica la connessione o il cookie",
|
||||
AuctionLogLevel.Warning, AuctionLogCategory.Polling);
|
||||
}
|
||||
|
||||
// Backoff progressivo, ma senza superare i 5 s: l'asta potrebbe ripartire.
|
||||
var backoff = Math.Min(300 * consecutiveErrors, 5000);
|
||||
if (!await Wait.DelayAsync(backoff, ct).ConfigureAwait(false)) return;
|
||||
continue;
|
||||
}
|
||||
|
||||
consecutiveErrors = 0;
|
||||
_auction.PollCount++;
|
||||
_host.ApplySnapshot(_auction, snapshot);
|
||||
|
||||
if (_host.IsFinished(_auction)) return;
|
||||
|
||||
if (!await Wait.DelayAsync(NextPollDelay(settings), ct).ConfigureAwait(false)) return;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_auction.AddLog($"Errore nel polling: {ex.Message}",
|
||||
AuctionLogLevel.Error, AuctionLogCategory.Polling);
|
||||
if (!await Wait.DelayAsync(1000, ct).ConfigureAwait(false)) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cadenza del polling: fitta solo dove serve. Un'asta a otto minuti dalla scadenza
|
||||
/// non ha bisogno di quattro chiamate al secondo, una a tre secondi sì.
|
||||
/// </summary>
|
||||
private int NextPollDelay(AppSettings settings)
|
||||
{
|
||||
// Un'asta non ancora cominciata ha una cadenza tutta sua: vedi NotStartedDelay.
|
||||
var notStarted = NotStartedDelay(settings);
|
||||
if (notStarted > 0) return notStarted;
|
||||
|
||||
var remaining = _auction.EstimatedRemainingMs();
|
||||
|
||||
if (remaining == double.MaxValue) return settings.PollIntervalFarMs;
|
||||
|
||||
// In sola osservazione non c'è puntata da azzeccare: si risparmiano chiamate.
|
||||
var critical = _auction.State == RunState.Active
|
||||
? settings.PollIntervalCriticalMs
|
||||
: settings.PollIntervalNearMs;
|
||||
|
||||
if (remaining <= settings.CriticalWindowMs) return critical;
|
||||
if (remaining <= 10_000) return settings.PollIntervalNearMs;
|
||||
if (remaining <= 60_000) return settings.PollIntervalMidMs;
|
||||
return settings.PollIntervalFarMs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cadenza per un'asta che deve ancora cominciare, oppure 0 se non è questo il caso.
|
||||
///
|
||||
/// <para>Bidoo programma le aste con ore di anticipo, e fino all'apertura non
|
||||
/// succede assolutamente nulla: interrogarla ogni due secondi per tre ore sono
|
||||
/// migliaia di richieste per non vedere mai un cambiamento. La cadenza si allarga
|
||||
/// quindi in proporzione all'attesa.</para>
|
||||
///
|
||||
/// <para>Il punto delicato è il risveglio. L'attesa non supera mai il tempo che
|
||||
/// manca all'apertura meno un margine, così l'ultima interrogazione cade
|
||||
/// <i>prima</i> dell'inizio e il motore è già alla cadenza normale quando l'asta
|
||||
/// parte: allargare la cadenza non deve mai far perdere l'apertura.</para>
|
||||
/// </summary>
|
||||
private int NotStartedDelay(AppSettings settings)
|
||||
{
|
||||
if (!settings.ScheduledAuctionBackoffEnabled) return 0;
|
||||
|
||||
var status = _auction.LastState?.Status;
|
||||
if (status is not (AuctionStatus.Scheduled or AuctionStatus.Pending)) return 0;
|
||||
|
||||
var toStartMs = _auction.EstimatedRemainingMs();
|
||||
if (toStartMs == double.MaxValue || toStartMs <= 0) return 0;
|
||||
|
||||
// Vicino all'apertura si torna subito alla cadenza normale.
|
||||
var wakeMs = Math.Max(30, settings.ScheduledPollWakeSeconds) * 1000.0;
|
||||
if (toStartMs <= wakeMs) return 0;
|
||||
|
||||
var desired = toStartMs > 3_600_000
|
||||
? Math.Max(60, settings.ScheduledPollFarSeconds) * 1000.0 // oltre un'ora
|
||||
: toStartMs > 600_000
|
||||
? Math.Max(30, settings.ScheduledPollMidSeconds) * 1000.0 // 10-60 minuti
|
||||
: 30_000.0; // ultimi 10 minuti
|
||||
|
||||
// Non dormire mai oltre il momento del risveglio: è ciò che garantisce di
|
||||
// essere pronti all'inizio.
|
||||
var untilWake = toStartMs - wakeMs;
|
||||
|
||||
return (int)Math.Clamp(Math.Min(desired, untilWake), 1000, 1_800_000);
|
||||
}
|
||||
|
||||
// ── Anello del cecchino ──────────────────────────────────────────────────
|
||||
|
||||
private async Task SniperLoopAsync(CancellationToken ct)
|
||||
{
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_auction.State != RunState.Active || _host.IsFinished(_auction))
|
||||
{
|
||||
if (!await Wait.DelayAsync(150, ct).ConfigureAwait(false)) return;
|
||||
continue;
|
||||
}
|
||||
|
||||
var state = _auction.LastState;
|
||||
var deadline = _auction.DeadlineTicks;
|
||||
|
||||
if (state is null || deadline == 0)
|
||||
{
|
||||
if (!await Wait.DelayAsync(100, ct).ConfigureAwait(false)) return;
|
||||
continue;
|
||||
}
|
||||
|
||||
var cycle = state.ExpiryUnixSeconds;
|
||||
if (cycle == _handledCycle)
|
||||
{
|
||||
// Su questo ciclo abbiamo già deciso: non succede più nulla per noi
|
||||
// finché la scadenza non passa o non ne arriva una nuova. Invece di
|
||||
// svegliarsi quaranta volte al secondo a vuoto — che con venti aste
|
||||
// significa ottocento risvegli inutili — si dorme fino alla scadenza,
|
||||
// con un tetto di un secondo per accorgersi dei cambi di stato.
|
||||
var idle = Math.Clamp(PrecisionWait.MsUntil(deadline), 25, 1000);
|
||||
if (!await Wait.DelayAsync((int)idle, ct).ConfigureAwait(false)) return;
|
||||
continue;
|
||||
}
|
||||
|
||||
var settings = _host.Settings;
|
||||
var leadMs = _auction.BidBeforeDeadlineMs > 0
|
||||
? _auction.BidBeforeDeadlineMs
|
||||
: settings.DefaultBidBeforeDeadlineMs;
|
||||
var fireTicks = deadline - PrecisionWait.MsToTicks(leadMs);
|
||||
|
||||
var msToDeadline = PrecisionWait.MsUntil(deadline);
|
||||
if (msToDeadline <= 0)
|
||||
{
|
||||
// Il ciclo è scaduto senza che si arrivasse alla finestra utile.
|
||||
if (_handledCycle != cycle)
|
||||
{
|
||||
_handledCycle = cycle;
|
||||
_auction.AddLog(
|
||||
$"Ciclo scaduto senza puntata (anticipo {leadMs} ms, ping medio {_auction.AverageLatencyMs:F0} ms)",
|
||||
AuctionLogLevel.Debug, AuctionLogCategory.Ticker);
|
||||
}
|
||||
|
||||
if (!await Wait.DelayAsync(25, ct).ConfigureAwait(false)) return;
|
||||
continue;
|
||||
}
|
||||
|
||||
var msToFire = PrecisionWait.MsUntil(fireTicks);
|
||||
if (msToFire > PreCheckMs)
|
||||
{
|
||||
// Ricontrolla spesso: una puntata altrui sposta la scadenza in avanti.
|
||||
var sleep = Math.Clamp(msToFire - PreCheckMs, 5, 200);
|
||||
if (!await Wait.DelayAsync((int)sleep, ct).ConfigureAwait(false)) return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_host.EvaluateBid(_auction, state))
|
||||
{
|
||||
_handledCycle = cycle;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Da qui il ciclo è nostro: nessun'altra iterazione lo riprenderà.
|
||||
_handledCycle = cycle;
|
||||
|
||||
await PrecisionWait.UntilAsync(fireTicks, ct).ConfigureAwait(false);
|
||||
|
||||
// Ultimo controllo a costo zero: nel frattempo potremmo essere passati in testa.
|
||||
if (_auction.LastState?.IsMyBid == true) continue;
|
||||
|
||||
var actualLeadMs = PrecisionWait.MsUntil(_auction.DeadlineTicks);
|
||||
await _host.FireBidAsync(_auction, state, leadMs, actualLeadMs, ct).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_auction.AddLog($"Errore nel cecchino: {ex.Message}",
|
||||
AuctionLogLevel.Error, AuctionLogCategory.BidAttempt);
|
||||
if (!await Wait.DelayAsync(250, ct).ConfigureAwait(false)) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder.Engine.Backtest
|
||||
{
|
||||
/// <summary>
|
||||
/// Rigioca una cartella di dossier e riassume cosa avrebbe fatto il motore, con un
|
||||
/// anticipo alla volta.
|
||||
///
|
||||
/// <para>Serve a due cose distinte. La prima è la <b>taratura</b>: si vede subito
|
||||
/// quante puntate costerebbe ciascun anticipo, e dove sta il gradino oltre il quale
|
||||
/// il costo esplode. La seconda è il <b>controllo di regressione</b>: se una strategia
|
||||
/// comincia a rifiutare puntate che prima passavano, qui si vede come un numero,
|
||||
/// invece che come aste perse una alla volta senza capire perché.</para>
|
||||
/// </summary>
|
||||
public static class BacktestReport
|
||||
{
|
||||
/// <summary>Riepilogo su un intero insieme di aste, per un dato anticipo.</summary>
|
||||
public sealed class Aggregate
|
||||
{
|
||||
public int LeadMs { get; init; }
|
||||
public int Auctions { get; init; }
|
||||
public int Cycles { get; init; }
|
||||
|
||||
/// <summary>Cicli arrivati fino all'anticipo su tutte le aste.</summary>
|
||||
public int Reached { get; init; }
|
||||
|
||||
/// <summary>Puntate che sarebbero partite davvero.</summary>
|
||||
public int Bids { get; init; }
|
||||
|
||||
public Dictionary<string, int> Blocks { get; init; } = new(StringComparer.Ordinal);
|
||||
|
||||
/// <summary>Puntate per asta: mediana e coda.</summary>
|
||||
public double MedianBidsPerAuction { get; init; }
|
||||
public int P90BidsPerAuction { get; init; }
|
||||
public int MaxBidsPerAuction { get; init; }
|
||||
|
||||
/// <summary>Aste in cui sarebbe bastata una sola puntata.</summary>
|
||||
public int AuctionsWithOneBid { get; init; }
|
||||
|
||||
public int BlockedTotal => Blocks.Values.Sum();
|
||||
|
||||
public double BlockedShare => Reached > 0 ? BlockedTotal * 100.0 / Reached : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rigioca ogni dossier della cartella con ciascun anticipo indicato.
|
||||
/// <paramref name="onProgress"/> riceve (fatti, totale).
|
||||
/// </summary>
|
||||
public static List<Aggregate> Run(
|
||||
string dossierFolder,
|
||||
IReadOnlyList<int> leads,
|
||||
AppSettings settings,
|
||||
string username = "",
|
||||
int maxFiles = 0,
|
||||
Action<int, int>? onProgress = null)
|
||||
{
|
||||
var files = Directory.Exists(dossierFolder)
|
||||
? Directory.GetFiles(dossierFolder, "*.jsonl").OrderBy(f => f).ToArray()
|
||||
: Array.Empty<string>();
|
||||
|
||||
if (maxFiles > 0 && files.Length > maxFiles) files = files.Take(maxFiles).ToArray();
|
||||
|
||||
var perLead = leads.ToDictionary(l => l, _ => new List<BacktestRunner.Result>());
|
||||
|
||||
for (var i = 0; i < files.Length; i++)
|
||||
{
|
||||
DossierReader.Session session;
|
||||
try { session = DossierReader.ReadFile(files[i]); }
|
||||
catch (IOException) { continue; }
|
||||
|
||||
if (!session.IsUsable) continue;
|
||||
|
||||
var cost = session.Header?.BidCostEuro ?? 0.20;
|
||||
|
||||
foreach (var lead in leads)
|
||||
{
|
||||
var options = new BacktestRunner.Options(lead, settings, username, cost);
|
||||
perLead[lead].Add(BacktestRunner.Run(session, options));
|
||||
}
|
||||
|
||||
onProgress?.Invoke(i + 1, files.Length);
|
||||
}
|
||||
|
||||
return leads.Select(lead => Summarize(lead, perLead[lead])).ToList();
|
||||
}
|
||||
|
||||
public static Aggregate Summarize(int leadMs, IReadOnlyList<BacktestRunner.Result> results)
|
||||
{
|
||||
var blocks = new Dictionary<string, int>(StringComparer.Ordinal);
|
||||
foreach (var r in results)
|
||||
foreach (var (key, n) in r.Blocks)
|
||||
blocks[key] = blocks.TryGetValue(key, out var have) ? have + n : n;
|
||||
|
||||
var perAuction = results.Select(r => r.Bids).OrderBy(n => n).ToList();
|
||||
|
||||
return new Aggregate
|
||||
{
|
||||
LeadMs = leadMs,
|
||||
Auctions = results.Count,
|
||||
Cycles = results.Sum(r => r.Cycles),
|
||||
Reached = results.Sum(r => r.Reached),
|
||||
Bids = results.Sum(r => r.Bids),
|
||||
Blocks = blocks,
|
||||
MedianBidsPerAuction = perAuction.Count == 0 ? 0 : perAuction[perAuction.Count / 2],
|
||||
P90BidsPerAuction = perAuction.Count == 0 ? 0 : perAuction[(int)(perAuction.Count * 0.90)],
|
||||
MaxBidsPerAuction = perAuction.Count == 0 ? 0 : perAuction[^1],
|
||||
AuctionsWithOneBid = perAuction.Count(n => n == 1)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Rende il riepilogo in testo, pronto per il registro o per il terminale.</summary>
|
||||
public static string Format(IReadOnlyList<Aggregate> aggregates)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var c = CultureInfo.GetCultureInfo("it-IT");
|
||||
|
||||
sb.AppendLine("RIGIOCATA SUI DOSSIER DELLE ASTE CONCLUSE");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(" Il motore punta solo nei cicli che arrivano fino all'anticipo senza che");
|
||||
sb.AppendLine(" nessun altro abbia puntato. Piu' l'anticipo e' largo, piu' cicli lo");
|
||||
sb.AppendLine(" raggiungono, piu' puntate si spendono.");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(" Bidoo dichiara la scadenza al secondo intero: sotto il secondo i dati non");
|
||||
sb.AppendLine(" distinguono nulla, quindi gli anticipi si confrontano a passi di 1000 ms.");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(" anticipo aste cicli raggiunti puntate bloccate mediana p90 max");
|
||||
sb.AppendLine(" ---------------------------------------------------------------------------");
|
||||
|
||||
foreach (var a in aggregates)
|
||||
{
|
||||
sb.AppendLine(string.Format(c,
|
||||
" {0,6} ms {1,6} {2,8} {3,11} {4,9} {5,9} {6,7} {7,4} {8,5}",
|
||||
a.LeadMs, a.Auctions, a.Cycles, a.Reached, a.Bids,
|
||||
$"{a.BlockedTotal} ({a.BlockedShare:F1}%)",
|
||||
a.MedianBidsPerAuction, a.P90BidsPerAuction, a.MaxBidsPerAuction));
|
||||
}
|
||||
|
||||
var withBlocks = aggregates.Where(a => a.BlockedTotal > 0).ToList();
|
||||
if (withBlocks.Count > 0)
|
||||
{
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(" Blocchi per motivo:");
|
||||
foreach (var a in withBlocks)
|
||||
{
|
||||
var detail = string.Join(", ", a.Blocks.OrderByDescending(kv => kv.Value)
|
||||
.Select(kv => $"{kv.Key}={kv.Value}"));
|
||||
sb.AppendLine($" anticipo {a.LeadMs} ms: {detail}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(" Nessuna puntata bloccata dalle strategie.");
|
||||
}
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(" I blocchi 'pareggio', 'tetto-spesa' e 'tetto-puntate' sono il");
|
||||
sb.AppendLine(" comportamento voluto: sono le puntate che avrebbero fatto perdere");
|
||||
sb.AppendLine(" soldi. Gli altri motivi sono strategie difensive, e vanno guardati.");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(" NOTA: la rigiocata misura i costi, non l'esito. Una nostra puntata rimette");
|
||||
sb.AppendLine(" in gioco l'asta, e come avrebbero reagito gli avversari non e' registrato");
|
||||
sb.AppendLine(" da nessuna parte: dichiarare delle vittorie sarebbe inventarle.");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoBidder.Models;
|
||||
using AutoBidder.Services;
|
||||
using AutoBidder.Utilities;
|
||||
|
||||
namespace AutoBidder.Engine.Backtest
|
||||
{
|
||||
/// <summary>
|
||||
/// Rigioca un'asta già conclusa e conta cosa avrebbe fatto il motore.
|
||||
///
|
||||
/// <para><b>Cosa misura davvero.</b> Il motore punta soltanto nei cicli che arrivano
|
||||
/// fino all'anticipo impostato senza che nessun altro abbia puntato: se un avversario
|
||||
/// punta prima, la scadenza si sposta e il cecchino non spara. Il dossier registra,
|
||||
/// per ogni ciclo, quanto è sceso il timer prima che qualcuno intervenisse — che è
|
||||
/// esattamente il dato che serve. Da lì si ricava <b>quante puntate sarebbero state
|
||||
/// spese</b> e <b>quante volte una strategia le avrebbe bloccate</b>.</para>
|
||||
///
|
||||
/// <para><b>Cosa non può misurare, e perché va detto.</b> Non dice se avresti vinto.
|
||||
/// Una nostra puntata rimette in gioco l'asta, e come avrebbero reagito gli avversari
|
||||
/// non sta in nessun registro: nessuna rigiocata può inventarselo. L'ultimo ciclo di
|
||||
/// ogni asta arriva per forza a zero — è il motivo per cui l'asta è finita — quindi
|
||||
/// contarlo come vittoria sarebbe una conclusione costruita a tavolino. Qui si contano
|
||||
/// i costi e i blocchi, che sono osservabili; l'esito no.</para>
|
||||
/// </summary>
|
||||
public static class BacktestRunner
|
||||
{
|
||||
/// <summary>Parametri della rigiocata.</summary>
|
||||
public sealed record Options(
|
||||
int LeadMs,
|
||||
AppSettings Settings,
|
||||
string Username = "",
|
||||
double BidCostEuro = 0.20);
|
||||
|
||||
/// <summary>Esito su una singola asta.</summary>
|
||||
public sealed class Result
|
||||
{
|
||||
public string AuctionId { get; init; } = "";
|
||||
public string Name { get; init; } = "";
|
||||
public string ProductKey { get; init; } = "";
|
||||
|
||||
/// <summary>Cicli di timer osservati nel dossier.</summary>
|
||||
public int Cycles { get; init; }
|
||||
|
||||
/// <summary>Cicli arrivati fino all'anticipo: qui il motore avrebbe sparato.</summary>
|
||||
public int Reached { get; init; }
|
||||
|
||||
/// <summary>Puntate davvero inviate, cioè i cicli raggiunti che nessuna strategia ha fermato.</summary>
|
||||
public int Bids { get; init; }
|
||||
|
||||
/// <summary>Blocchi per motivo, con il testo che avrebbe scritto la strategia.</summary>
|
||||
public Dictionary<string, int> Blocks { get; init; } = new(StringComparer.Ordinal);
|
||||
|
||||
public double FinalPrice { get; init; }
|
||||
public double? BuyNowPrice { get; init; }
|
||||
|
||||
/// <summary>Costo se l'asta fosse stata vinta all'ultima puntata: prezzo + puntate spese.</summary>
|
||||
public double CostIfWon { get; init; }
|
||||
|
||||
public int BlockedTotal => Blocks.Values.Sum();
|
||||
}
|
||||
|
||||
/// <summary>Motivi di blocco riconosciuti, per raggrupparli senza dipendere dal testo esatto.</summary>
|
||||
public static string Categorize(string? reason)
|
||||
{
|
||||
if (string.IsNullOrEmpty(reason)) return "altro";
|
||||
|
||||
if (reason.StartsWith("Anti-bot", StringComparison.OrdinalIgnoreCase)) return "anti-bot";
|
||||
if (reason.StartsWith("Soft retreat", StringComparison.OrdinalIgnoreCase)) return "soft-retreat";
|
||||
if (reason.StartsWith("Asta troppo calda", StringComparison.OrdinalIgnoreCase)) return "asta-calda";
|
||||
if (reason.StartsWith("Bidder aggressivi", StringComparison.OrdinalIgnoreCase)) return "avversari-aggressivi";
|
||||
if (reason.StartsWith("Skip probabilistico", StringComparison.OrdinalIgnoreCase)) return "probabilistico";
|
||||
if (reason.StartsWith("Prezzo sale", StringComparison.OrdinalIgnoreCase)) return "velocita-prezzo";
|
||||
if (reason.StartsWith("Limite puntate", StringComparison.OrdinalIgnoreCase)) return "limite-puntate";
|
||||
if (reason.StartsWith("Budget", StringComparison.OrdinalIgnoreCase)) return "budget";
|
||||
|
||||
return "altro";
|
||||
}
|
||||
|
||||
public static Result Run(DossierReader.Session session, Options options)
|
||||
{
|
||||
var header = session.Header;
|
||||
var cycles = BuildCycles(session.Polls);
|
||||
|
||||
var strategy = new BidStrategyService();
|
||||
var auction = NewAuction(header, options);
|
||||
|
||||
var blocks = new Dictionary<string, int>(StringComparer.Ordinal);
|
||||
var reached = 0;
|
||||
var bids = 0;
|
||||
|
||||
// Le puntate in ordine cronologico: a ogni ciclo si mostra al motore solo
|
||||
// quelle che a quel momento erano già visibili. Mostrargliele tutte sarebbe
|
||||
// dargli il futuro, e le strategie che guardano lo storico ne uscirebbero
|
||||
// giudicate su informazioni che non avranno mai.
|
||||
var bidsInOrder = session.Bids
|
||||
.Where(b => b.UnixSeconds > 0)
|
||||
.OrderBy(b => b.T)
|
||||
.ToList();
|
||||
|
||||
var nextBid = 0;
|
||||
|
||||
foreach (var cycle in cycles)
|
||||
{
|
||||
while (nextBid < bidsInOrder.Count && bidsInOrder[nextBid].T <= cycle.LastPollT)
|
||||
{
|
||||
Publish(auction, bidsInOrder[nextBid], options.Username);
|
||||
nextBid++;
|
||||
}
|
||||
|
||||
// Il ciclo è arrivato fino a noi solo se il timer è sceso sotto l'anticipo.
|
||||
//
|
||||
// Bidoo dichiara la scadenza al secondo intero, quindi un ciclo che risulta
|
||||
// "sceso a 2" aveva in realtà fra 2 e 3 secondi davanti: il valore letto è un
|
||||
// pavimento, non una misura. Per non contare puntate che forse non sarebbero
|
||||
// partite si richiede il secondo <b>pieno</b> — con anticipo 2000 ms si
|
||||
// considerano solo i cicli scesi sotto i 2 s. È il conteggio prudente, e la
|
||||
// prudenza qui va verso il basso: meglio sottostimare il costo che promettere
|
||||
// un risparmio che i dati non possono garantire.
|
||||
if ((cycle.MinTimerSeconds + 1) * 1000.0 > options.LeadMs) continue;
|
||||
|
||||
var state = ToState(cycle, options.Username);
|
||||
|
||||
// Fuori corsa: il motore non punta su un'asta non aperta.
|
||||
if (state.Status != AuctionStatus.Running && state.Status != AuctionStatus.Pending) continue;
|
||||
if (state.IsMyBid) continue;
|
||||
|
||||
reached++;
|
||||
|
||||
// Budget e pareggio: e' il controllo che decide se la puntata ha ancora
|
||||
// senso economico, e va rigiocato come tutti gli altri. Senza, la prova
|
||||
// misurerebbe tutto tranne la cosa che protegge il portafoglio.
|
||||
var budget = BidBudget.Evaluate(new BidBudget.Situation(
|
||||
CurrentPrice: cycle.Price,
|
||||
BidsAlreadyUsed: bids,
|
||||
BidCostEuro: options.BidCostEuro,
|
||||
ProductValue: header?.BuyNowPrice,
|
||||
ShippingCost: null,
|
||||
MaxBids: auction.MaxClicks,
|
||||
MaxTotalSpendEuro: auction.MaxTotalSpendEuro,
|
||||
MinSavingsPercentage: options.Settings.MinSavingsPercentage,
|
||||
StopAtBreakEven: auction.StopAtBreakEven));
|
||||
|
||||
if (!budget.CanBid)
|
||||
{
|
||||
var key = budget.Reason?.Contains("pareggio") == true ? "pareggio"
|
||||
: budget.Reason?.Contains("spesa") == true ? "tetto-spesa"
|
||||
: "tetto-puntate";
|
||||
blocks[key] = blocks.TryGetValue(key, out var b) ? b + 1 : 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
strategy.UpdateHeatMetric(auction, options.Settings, options.Username);
|
||||
var decision = strategy.ShouldPlaceBid(auction, state, options.Settings, options.Username);
|
||||
|
||||
if (!decision.ShouldBid)
|
||||
{
|
||||
var key = Categorize(decision.Reason);
|
||||
blocks[key] = blocks.TryGetValue(key, out var n) ? n + 1 : 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
bids++;
|
||||
|
||||
// Una puntata riuscita: è ciò che il motore registrerebbe, e alimenta i
|
||||
// contatori su cui le strategie stesse decidono ai giri successivi.
|
||||
strategy.RecordBidAttempt(auction, success: true);
|
||||
auction.BidsUsedOnThisAuction = (auction.BidsUsedOnThisAuction ?? 0) + 1;
|
||||
}
|
||||
|
||||
var finalPrice = session.Summary?.FinalPrice ?? cycles.LastOrDefault()?.Price ?? 0;
|
||||
|
||||
return new Result
|
||||
{
|
||||
AuctionId = header?.AuctionId ?? "",
|
||||
Name = header?.Name ?? "",
|
||||
ProductKey = header?.ProductKey ?? "",
|
||||
Cycles = cycles.Count,
|
||||
Reached = reached,
|
||||
Bids = bids,
|
||||
Blocks = blocks,
|
||||
FinalPrice = finalPrice,
|
||||
BuyNowPrice = header?.BuyNowPrice,
|
||||
CostIfWon = finalPrice + bids * options.BidCostEuro
|
||||
};
|
||||
}
|
||||
|
||||
// ── Ricostruzione dei cicli ──────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Un ciclo di timer: dalla puntata che l'ha aperto alla successiva (o alla fine).
|
||||
/// Lo identifica la <b>scadenza</b> dichiarata dal server, che cambia a ogni
|
||||
/// puntata: è la stessa chiave che usa il cecchino per non puntare due volte
|
||||
/// sullo stesso ciclo.
|
||||
/// </summary>
|
||||
public sealed record Cycle(
|
||||
long ExpiryUnix,
|
||||
double MinTimerSeconds,
|
||||
double Price,
|
||||
string LastBidder,
|
||||
bool Mine,
|
||||
string Status,
|
||||
long ServerUnix,
|
||||
double PingMs,
|
||||
double LastPollT);
|
||||
|
||||
public static List<Cycle> BuildCycles(IReadOnlyList<DossierReader.Poll> polls)
|
||||
{
|
||||
var cycles = new List<Cycle>();
|
||||
|
||||
long currentExpiry = 0;
|
||||
var minTimer = double.MaxValue;
|
||||
DossierReader.Poll? deepest = null;
|
||||
|
||||
foreach (var poll in polls)
|
||||
{
|
||||
if (poll.ExpiryUnix <= 0 || poll.ServerUnix <= 0) continue;
|
||||
|
||||
if (poll.ExpiryUnix != currentExpiry)
|
||||
{
|
||||
if (deepest != null) cycles.Add(Close(currentExpiry, minTimer, deepest));
|
||||
|
||||
currentExpiry = poll.ExpiryUnix;
|
||||
minTimer = double.MaxValue;
|
||||
deepest = null;
|
||||
}
|
||||
|
||||
// Il timer calcolato dai due istanti del server, non quello riportato:
|
||||
// sono la stessa cosa, ma questo non dipende da come è stato arrotondato.
|
||||
var timer = poll.ExpiryUnix - poll.ServerUnix;
|
||||
|
||||
if (timer <= minTimer)
|
||||
{
|
||||
minTimer = timer;
|
||||
deepest = poll;
|
||||
}
|
||||
}
|
||||
|
||||
if (deepest != null) cycles.Add(Close(currentExpiry, minTimer, deepest));
|
||||
|
||||
return cycles;
|
||||
}
|
||||
|
||||
private static Cycle Close(long expiry, double minTimer, DossierReader.Poll deepest) => new(
|
||||
ExpiryUnix: expiry,
|
||||
MinTimerSeconds: Math.Max(0, minTimer),
|
||||
Price: deepest.Price,
|
||||
LastBidder: deepest.LastBidder,
|
||||
Mine: deepest.Mine,
|
||||
Status: deepest.Status,
|
||||
ServerUnix: deepest.ServerUnix,
|
||||
PingMs: deepest.PingMs,
|
||||
LastPollT: deepest.T);
|
||||
|
||||
// ── Adattatori verso i modelli del motore ────────────────────────
|
||||
|
||||
private static AuctionState ToState(Cycle cycle, string username) => new()
|
||||
{
|
||||
AuctionId = "",
|
||||
Timer = cycle.MinTimerSeconds,
|
||||
Price = cycle.Price,
|
||||
LastBidder = cycle.LastBidder,
|
||||
IsMyBid = cycle.Mine ||
|
||||
(!string.IsNullOrEmpty(username) &&
|
||||
cycle.LastBidder.Equals(username, StringComparison.OrdinalIgnoreCase)),
|
||||
Status = ParseStatus(cycle.Status),
|
||||
ServerUnixSeconds = cycle.ServerUnix,
|
||||
ExpiryUnixSeconds = cycle.ExpiryUnix,
|
||||
PollingLatencyMs = (int)cycle.PingMs,
|
||||
SnapshotTime = DateTimeOffset.FromUnixTimeSeconds(cycle.ServerUnix).UtcDateTime
|
||||
};
|
||||
|
||||
private static AuctionStatus ParseStatus(string? status) =>
|
||||
Enum.TryParse<AuctionStatus>(status, ignoreCase: true, out var parsed)
|
||||
? parsed
|
||||
: AuctionStatus.Unknown;
|
||||
|
||||
private static AuctionInfo NewAuction(DossierReader.Header? header, Options options) => new()
|
||||
{
|
||||
AuctionId = header?.AuctionId ?? "",
|
||||
Name = header?.Name ?? "",
|
||||
BuyNowPrice = header?.BuyNowPrice,
|
||||
BidBeforeDeadlineMs = options.LeadMs,
|
||||
BidsUsedOnThisAuction = 0
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Rende visibile al motore una puntata, come farebbe l'incorporazione di una
|
||||
/// risposta di data.php: in testa alla lista, con il tetto delle ultime cinquanta.
|
||||
/// </summary>
|
||||
private static void Publish(AuctionInfo auction, DossierReader.Bid bid, string username)
|
||||
{
|
||||
var entry = new BidHistoryEntry
|
||||
{
|
||||
Price = (decimal)bid.Price,
|
||||
Username = bid.User,
|
||||
Timestamp = bid.UnixSeconds,
|
||||
BidType = "Auto",
|
||||
IsMyBid = bid.Mine ||
|
||||
(!string.IsNullOrEmpty(username) &&
|
||||
bid.User.Equals(username, StringComparison.OrdinalIgnoreCase))
|
||||
};
|
||||
|
||||
lock (auction.BidsLock)
|
||||
{
|
||||
auction.RecentBids.Insert(0, entry);
|
||||
if (auction.RecentBids.Count > 50) auction.RecentBids.RemoveRange(50, auction.RecentBids.Count - 50);
|
||||
|
||||
if (!auction.BidderStats.TryGetValue(bid.User, out var stats))
|
||||
{
|
||||
stats = new BidderInfo { Username = bid.User };
|
||||
auction.BidderStats[bid.User] = stats;
|
||||
}
|
||||
|
||||
stats.BidCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AutoBidder.Engine.Backtest
|
||||
{
|
||||
/// <summary>
|
||||
/// Legge un dossier d'asta (JSON Lines) e lo riporta in memoria come sequenza di
|
||||
/// eventi tipizzati.
|
||||
///
|
||||
/// <para>È volutamente separato da chi lo consuma e non conosce il motore: il dossier
|
||||
/// è un formato scritto altrove e cambierà, quindi la sua interpretazione va tenuta in
|
||||
/// un punto solo e verificabile su righe scritte a mano.</para>
|
||||
///
|
||||
/// <para>Una riga che non si capisce viene <b>saltata</b>, non fa fallire la lettura:
|
||||
/// i dossier vengono chiusi dal processo mentre gira, quindi l'ultima riga di un file
|
||||
/// interrotto può benissimo essere monca — e sarebbe assurdo buttare via otto ore di
|
||||
/// osservazione per l'ultimo mezzo evento.</para>
|
||||
/// </summary>
|
||||
public static class DossierReader
|
||||
{
|
||||
/// <summary>Intestazione: identità dell'asta e configurazione con cui era seguita.</summary>
|
||||
public sealed record Header(
|
||||
string AuctionId,
|
||||
string Name,
|
||||
string ProductKey,
|
||||
double? BuyNowPrice,
|
||||
double BidCostEuro,
|
||||
int ConfiguredLeadMs,
|
||||
string State);
|
||||
|
||||
/// <summary>Una singola interrogazione a data.php.</summary>
|
||||
public sealed record Poll(
|
||||
double T,
|
||||
double Price,
|
||||
double Timer,
|
||||
string Status,
|
||||
string LastBidder,
|
||||
bool Mine,
|
||||
long ExpiryUnix,
|
||||
long ServerUnix,
|
||||
double PingMs);
|
||||
|
||||
/// <summary>Una puntata altrui (o nostra) letta dallo storico.</summary>
|
||||
public sealed record Bid(
|
||||
double T,
|
||||
string User,
|
||||
long UnixSeconds,
|
||||
double Price,
|
||||
bool Mine);
|
||||
|
||||
/// <summary>Riepilogo scritto alla chiusura dell'asta.</summary>
|
||||
public sealed record Summary(
|
||||
string Outcome,
|
||||
string Winner,
|
||||
double FinalPrice,
|
||||
bool WonByMe,
|
||||
int Resets,
|
||||
int DistinctBidders,
|
||||
int MyBids);
|
||||
|
||||
/// <summary>Un dossier completo.</summary>
|
||||
public sealed class Session
|
||||
{
|
||||
public Header? Header { get; init; }
|
||||
public Summary? Summary { get; init; }
|
||||
public List<Poll> Polls { get; init; } = new();
|
||||
public List<Bid> Bids { get; init; } = new();
|
||||
|
||||
/// <summary>Righe che non si è riusciti a interpretare.</summary>
|
||||
public int SkippedLines { get; init; }
|
||||
|
||||
/// <summary>Un dossier senza intestazione non dice di che asta parla.</summary>
|
||||
public bool IsUsable => Header != null && Polls.Count > 0;
|
||||
}
|
||||
|
||||
public static Session ReadFile(string path) => Read(File.ReadLines(path));
|
||||
|
||||
public static Session Read(IEnumerable<string> lines)
|
||||
{
|
||||
Header? header = null;
|
||||
Summary? summary = null;
|
||||
var polls = new List<Poll>();
|
||||
var bids = new List<Bid>();
|
||||
var skipped = 0;
|
||||
|
||||
foreach (var raw in lines)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(raw)) continue;
|
||||
|
||||
// Il primo file scritto porta il segnaposto di codifica in testa.
|
||||
var line = raw.TrimStart('', ' ', '\t');
|
||||
if (line.Length == 0 || line[0] != '{') { skipped++; continue; }
|
||||
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(line);
|
||||
var root = doc.RootElement;
|
||||
|
||||
switch (Str(root, "type"))
|
||||
{
|
||||
case "header": header = ReadHeader(root); break;
|
||||
case "summary": summary = ReadSummary(root); break;
|
||||
case "poll": polls.Add(ReadPoll(root)); break;
|
||||
case "bid": bids.Add(ReadBid(root)); break;
|
||||
// reset e log non servono alla simulazione: il reset è deducibile
|
||||
// dal cambio di scadenza, e il log è testo per l'utente.
|
||||
}
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
skipped++;
|
||||
}
|
||||
}
|
||||
|
||||
return new Session
|
||||
{
|
||||
Header = header,
|
||||
Summary = summary,
|
||||
Polls = polls,
|
||||
Bids = bids,
|
||||
SkippedLines = skipped
|
||||
};
|
||||
}
|
||||
|
||||
// ── Lettura dei singoli eventi ───────────────────────────────────
|
||||
|
||||
private static Header ReadHeader(JsonElement root)
|
||||
{
|
||||
var product = Obj(root, "product");
|
||||
var config = Obj(root, "config");
|
||||
|
||||
return new Header(
|
||||
AuctionId: Str(root, "auctionId") ?? "",
|
||||
Name: Str(root, "name") ?? "",
|
||||
ProductKey: Str(root, "productKey") ?? "",
|
||||
BuyNowPrice: product.HasValue ? NullableNum(product.Value, "buyNowPrice") : null,
|
||||
BidCostEuro: product.HasValue ? Num(product.Value, "bidCostEuro", 0.20) : 0.20,
|
||||
ConfiguredLeadMs: config.HasValue ? (int)Num(config.Value, "bidBeforeDeadlineMs", 0) : 0,
|
||||
State: config.HasValue ? Str(config.Value, "state") ?? "" : "");
|
||||
}
|
||||
|
||||
private static Summary ReadSummary(JsonElement root)
|
||||
{
|
||||
var part = Obj(root, "participation");
|
||||
|
||||
return new Summary(
|
||||
Outcome: Str(root, "outcome") ?? "",
|
||||
Winner: Str(root, "winner") ?? "",
|
||||
FinalPrice: Num(root, "finalPrice", 0),
|
||||
WonByMe: Bool(root, "wonByMe"),
|
||||
Resets: part.HasValue ? (int)Num(part.Value, "resets", 0) : 0,
|
||||
DistinctBidders: part.HasValue ? (int)Num(part.Value, "distinctBidders", 0) : 0,
|
||||
MyBids: part.HasValue ? (int)Num(part.Value, "myBids", 0) : 0);
|
||||
}
|
||||
|
||||
private static Poll ReadPoll(JsonElement root) => new(
|
||||
T: Num(root, "t", 0),
|
||||
Price: Num(root, "price", 0),
|
||||
Timer: Num(root, "timer", 0),
|
||||
Status: Str(root, "status") ?? "",
|
||||
LastBidder: Str(root, "lastBidder") ?? "",
|
||||
Mine: Bool(root, "mine"),
|
||||
ExpiryUnix: (long)Num(root, "expiryUnix", 0),
|
||||
ServerUnix: (long)Num(root, "serverUnix", 0),
|
||||
PingMs: Num(root, "pingMs", 0));
|
||||
|
||||
private static Bid ReadBid(JsonElement root) => new(
|
||||
T: Num(root, "t", 0),
|
||||
User: Str(root, "user") ?? "",
|
||||
UnixSeconds: ParseUnix(Str(root, "bidAt")),
|
||||
Price: Num(root, "price", 0),
|
||||
Mine: Bool(root, "mine"));
|
||||
|
||||
/// <summary>
|
||||
/// Le puntate portano l'istante come data ISO con fuso. Serve il secondo unix,
|
||||
/// perché è nella stessa unità dei timestamp che il motore vede a runtime.
|
||||
/// </summary>
|
||||
private static long ParseUnix(string? iso)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(iso)) return 0;
|
||||
|
||||
return DateTimeOffset.TryParse(iso, CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.RoundtripKind, out var parsed)
|
||||
? parsed.ToUnixTimeSeconds()
|
||||
: 0;
|
||||
}
|
||||
|
||||
// ── Accessori tolleranti ─────────────────────────────────────────
|
||||
|
||||
private static string? Str(JsonElement owner, string name) =>
|
||||
owner.TryGetProperty(name, out var v) && v.ValueKind == JsonValueKind.String
|
||||
? v.GetString()
|
||||
: null;
|
||||
|
||||
private static bool Bool(JsonElement owner, string name) =>
|
||||
owner.TryGetProperty(name, out var v) && v.ValueKind == JsonValueKind.True;
|
||||
|
||||
private static double Num(JsonElement owner, string name, double fallback) =>
|
||||
owner.TryGetProperty(name, out var v) && v.ValueKind == JsonValueKind.Number &&
|
||||
v.TryGetDouble(out var d)
|
||||
? d
|
||||
: fallback;
|
||||
|
||||
private static double? NullableNum(JsonElement owner, string name) =>
|
||||
owner.TryGetProperty(name, out var v) && v.ValueKind == JsonValueKind.Number &&
|
||||
v.TryGetDouble(out var d)
|
||||
? d
|
||||
: null;
|
||||
|
||||
private static JsonElement? Obj(JsonElement owner, string name) =>
|
||||
owner.TryGetProperty(name, out var v) && v.ValueKind == JsonValueKind.Object
|
||||
? v
|
||||
: null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoBidder.Engine
|
||||
{
|
||||
/// <summary>
|
||||
/// Attesa fino a un istante espresso in tick di <see cref="Stopwatch"/>.
|
||||
///
|
||||
/// Task.Delay si appoggia al timer di sistema, che di default scatta ogni 15,6 ms: per un
|
||||
/// anticipo di 200 ms sulla scadenza è un errore inaccettabile. Qui si dorme finché manca
|
||||
/// parecchio, lasciando un margine più ampio della granularità del timer, e si copre
|
||||
/// l'ultimo tratto con attesa attiva. Il costo è qualche decina di millisecondi di CPU per
|
||||
/// puntata; il guadagno è un errore sotto il millisecondo.
|
||||
/// </summary>
|
||||
public static class PrecisionWait
|
||||
{
|
||||
/// <summary>
|
||||
/// Margine da coprire in attesa attiva. Più ampio della granularità del timer di
|
||||
/// sistema, così anche un Task.Delay che sfora si risveglia comunque prima del bersaglio.
|
||||
/// </summary>
|
||||
private const double SpinThresholdMs = 22;
|
||||
|
||||
/// <summary>Ultimo tratto in cui non si cede più il core a nessuno.</summary>
|
||||
private const double TightSpinMs = 2.0;
|
||||
|
||||
public static async Task UntilAsync(long targetTicks, CancellationToken ct)
|
||||
{
|
||||
var frequency = Stopwatch.Frequency;
|
||||
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
var remainingMs = (targetTicks - Stopwatch.GetTimestamp()) * 1000.0 / frequency;
|
||||
if (remainingMs <= 0) return;
|
||||
|
||||
if (remainingMs > SpinThresholdMs)
|
||||
{
|
||||
var sleepMs = remainingMs - SpinThresholdMs;
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(Math.Min(sleepMs, 1000)), ct).ConfigureAwait(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
SpinUntil(targetTicks, ct);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
private static void SpinUntil(long targetTicks, CancellationToken ct)
|
||||
{
|
||||
var frequency = Stopwatch.Frequency;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var remainingMs = (targetTicks - Stopwatch.GetTimestamp()) * 1000.0 / frequency;
|
||||
if (remainingMs <= 0 || ct.IsCancellationRequested) return;
|
||||
|
||||
// Finché c'è margine si cede volentieri il core; nell'ultimo tratto no,
|
||||
// altrimenti bastano due millisecondi di preemption per arrivare tardi.
|
||||
if (remainingMs > TightSpinMs) Thread.Yield();
|
||||
else Thread.SpinWait(40);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Millisecondi mancanti a un istante espresso in tick.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double MsUntil(long targetTicks) =>
|
||||
(targetTicks - Stopwatch.GetTimestamp()) * 1000.0 / Stopwatch.Frequency;
|
||||
|
||||
/// <summary>Converte millisecondi in tick di <see cref="Stopwatch"/>.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static long MsToTicks(double ms) => (long)(ms / 1000.0 * Stopwatch.Frequency);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Porta la granularità del timer di sistema a 1 ms per tutta la durata del processo.
|
||||
///
|
||||
/// Senza questa richiesta ogni Task.Delay può sforare di ~15 ms: si ripercuote sulla
|
||||
/// cadenza del polling e allunga l'attesa attiva necessaria prima di ogni puntata.
|
||||
/// È la stessa cosa che fanno browser e riproduttori multimediali; l'unico effetto
|
||||
/// collaterale è un consumo leggermente maggiore, accettabile per un'applicazione che
|
||||
/// deve rispettare scadenze al millisecondo.
|
||||
/// </summary>
|
||||
public sealed class SystemTimerResolution : IDisposable
|
||||
{
|
||||
[DllImport("winmm.dll", EntryPoint = "timeBeginPeriod")]
|
||||
private static extern uint TimeBeginPeriod(uint milliseconds);
|
||||
|
||||
[DllImport("winmm.dll", EntryPoint = "timeEndPeriod")]
|
||||
private static extern uint TimeEndPeriod(uint milliseconds);
|
||||
|
||||
private const uint TargetMs = 1;
|
||||
private const uint Ok = 0;
|
||||
|
||||
private bool _active;
|
||||
|
||||
public bool IsActive => _active;
|
||||
|
||||
public SystemTimerResolution()
|
||||
{
|
||||
try { _active = TimeBeginPeriod(TargetMs) == Ok; }
|
||||
catch { _active = false; }
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_active) return;
|
||||
|
||||
try { TimeEndPeriod(TargetMs); } catch { /* rilascio best-effort */ }
|
||||
_active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace AutoBidder.Engine
|
||||
{
|
||||
/// <summary>
|
||||
/// Allinea l'orologio monotono locale a quello del server Bidoo.
|
||||
///
|
||||
/// data.php restituisce timestamp in secondi interi: preso da solo, un singolo campione
|
||||
/// vale ±1 s. Ma ogni risposta dice anche "il mio secondo corrente è S", e la risposta è
|
||||
/// stata generata prima di arrivare qui. Detto A = istante locale del confine del secondo
|
||||
/// server 0, ogni campione fornisce un limite superiore per A; il minimo su molti campioni
|
||||
/// converge al valore vero (filtro alla NTP).
|
||||
///
|
||||
/// L'errore residuo è per costruzione verso il basso, cioè verso una scadenza stimata
|
||||
/// leggermente in anticipo: si punta un filo prima, mai dopo.
|
||||
/// </summary>
|
||||
public sealed class ServerClock
|
||||
{
|
||||
private const int WindowSize = 256;
|
||||
|
||||
private readonly long[] _samples = new long[WindowSize];
|
||||
|
||||
/// <summary>
|
||||
/// Round-trip di ciascun campione. Vive qui perché qui arriva già misurato, e
|
||||
/// perché è la latenza che conta davvero: quella delle richieste di polling, le
|
||||
/// stesse su cui il motore decide quando puntare.
|
||||
/// </summary>
|
||||
private readonly int[] _latencies = new int[WindowSize];
|
||||
|
||||
private readonly object _sync = new();
|
||||
private int _index;
|
||||
private int _count;
|
||||
private long _latencySum;
|
||||
|
||||
/// <summary>Numero di campioni utilizzati per la stima corrente.</summary>
|
||||
public int SampleCount { get { lock (_sync) return _count; } }
|
||||
|
||||
/// <summary>True quando la stima è abbastanza solida da essere usata per il timing.</summary>
|
||||
public bool IsSynced { get { lock (_sync) return _count >= 3; } }
|
||||
|
||||
/// <summary>Scarto residuo stimato in millisecondi (dispersione dei campioni).</summary>
|
||||
public double SpreadMs { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Round-trip medio verso Bidoo sugli ultimi campioni, in millisecondi.
|
||||
/// Zero finché non è arrivata nessuna risposta.
|
||||
/// </summary>
|
||||
public double AverageLatencyMs
|
||||
{
|
||||
get { lock (_sync) return _count == 0 ? 0 : (double)_latencySum / _count; }
|
||||
}
|
||||
|
||||
/// <summary>Tick locale corrispondente al secondo unix 0 del server.</summary>
|
||||
public long Origin { get; private set; }
|
||||
|
||||
/// <summary>Registra una risposta del server.</summary>
|
||||
/// <param name="serverUnixSeconds">Secondo unix dichiarato dal server.</param>
|
||||
/// <param name="receivedTicks">Tick di <see cref="Stopwatch"/> alla ricezione.</param>
|
||||
/// <param name="latencyMs">Round-trip misurato.</param>
|
||||
public void AddSample(long serverUnixSeconds, long receivedTicks, int latencyMs)
|
||||
{
|
||||
if (serverUnixSeconds <= 0 || receivedTicks <= 0) return;
|
||||
|
||||
var f = Stopwatch.Frequency;
|
||||
|
||||
// Momento in cui il server ha prodotto la risposta: metà round-trip fa.
|
||||
var generatedTicks = receivedTicks - (long)(latencyMs / 2.0 / 1000.0 * f);
|
||||
|
||||
// Limite superiore per l'origine A.
|
||||
var candidate = generatedTicks - serverUnixSeconds * f;
|
||||
|
||||
lock (_sync)
|
||||
{
|
||||
// La finestra è circolare: prima di sovrascrivere si toglie dalla somma
|
||||
// il campione che esce, altrimenti la media resterebbe ferma sul passato.
|
||||
if (_count == WindowSize) _latencySum -= _latencies[_index];
|
||||
|
||||
_samples[_index] = candidate;
|
||||
_latencies[_index] = latencyMs < 0 ? 0 : latencyMs;
|
||||
_latencySum += _latencies[_index];
|
||||
|
||||
_index = (_index + 1) % WindowSize;
|
||||
if (_count < WindowSize) _count++;
|
||||
|
||||
long min = long.MaxValue, max = long.MinValue;
|
||||
for (var i = 0; i < _count; i++)
|
||||
{
|
||||
var v = _samples[i];
|
||||
if (v < min) min = v;
|
||||
if (v > max) max = v;
|
||||
}
|
||||
|
||||
Origin = min;
|
||||
SpreadMs = (max - min) * 1000.0 / f;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Converte un timestamp unix del server in tick locali di <see cref="Stopwatch"/>.</summary>
|
||||
public long ToLocalTicks(long serverUnixSeconds)
|
||||
{
|
||||
lock (_sync)
|
||||
{
|
||||
return Origin + serverUnixSeconds * Stopwatch.Frequency;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
lock (_sync)
|
||||
{
|
||||
Array.Clear(_samples);
|
||||
Array.Clear(_latencies);
|
||||
_index = 0;
|
||||
_count = 0;
|
||||
_latencySum = 0;
|
||||
Origin = 0;
|
||||
SpreadMs = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="17px" height="18px" viewBox="0 0 17 18" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: sketchtool 57.1 (101010) - https://sketch.com -->
|
||||
<title>E3DC3394-397D-4994-B12B-47234FB13863</title>
|
||||
<desc>Created with sketchtool.</desc>
|
||||
<g id="Product-Pages" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="Home---Portrait-Version-A-Copy-6" transform="translate(-77.000000, -637.000000)">
|
||||
<g id="Group-20" transform="translate(63.000000, 553.000000)">
|
||||
<g id="Group-17-Copy" transform="translate(14.000000, 84.000000)">
|
||||
<g id="001-settings" transform="translate(0.000000, 0.500000)">
|
||||
<path d="M15.6392002,7.48800011 C14.1532002,7.20200011 13.4720002,5.46640008 14.3672002,4.24600006 L14.9952002,3.38800005 L13.6376002,2.03040003 L12.7936002,2.60200004 C11.5408002,3.45200005 9.83120015,2.70520004 9.60160014,1.21000002 L9.44080014,0.160000002 L7.52040011,0.160000002 L7.27200011,1.45360002 C6.9920001,2.90520004 5.31720008,3.59920005 4.09200006,2.76920004 L3.00320004,2.03040003 L1.64520002,3.38800005 L2.27360003,4.24600006 C3.16880005,5.46640008 2.48600004,7.20200011 1.00160001,7.48800011 L0,7.68040011 L0,9.60080014 L1.05000002,9.76160015 C2.54520004,9.99120015 3.29200005,11.7008002 2.44200004,12.9536002 L1.87040003,13.7976002 L3.22800005,15.1552002 L4.08600006,14.5272002 C5.30640008,13.6320002 7.0420001,14.3132002 7.32800011,15.7992002 L7.52040011,16.8008003 L9.44080014,16.8008003 L9.55320014,16.0616002 C9.78920015,14.5336002 11.5608002,13.7992002 12.8080002,14.7132002 L13.4108002,15.1552002 L14.7688002,13.7976002 L14.1968002,12.9536002 C13.3484002,11.7008002 14.0936002,9.99120015 15.5892002,9.76160015 L16.6408002,9.60080014 L16.6408002,7.68040011 L15.6392002,7.48800011 Z M8.47960013,10.0804002 C7.68440011,10.0804002 7.0408001,9.43520014 7.0408001,8.63960013 C7.0408001,7.84440012 7.68440011,7.20080011 8.47960013,7.20080011 C9.27520014,7.20080011 9.92040015,7.84440012 9.92040015,8.63960013 C9.92040015,9.43520014 9.27520014,10.0804002 8.47960013,10.0804002 Z" id="Fill-1" fill="#C7CAC7"/>
|
||||
<path d="M8.47960013,5.60080008 C6.8016001,5.60080008 5.44080008,6.9616001 5.44080008,8.63960013 C5.44080008,10.3192002 6.8016001,11.6804002 8.47960013,11.6804002 C10.1592002,11.6804002 11.5204002,10.3192002 11.5204002,8.63960013 C11.5204002,6.9616001 10.1592002,5.60080008 8.47960013,5.60080008 Z M8.47960013,10.0804002 C7.68440011,10.0804002 7.0408001,9.43520014 7.0408001,8.63960013 C7.0408001,7.84440012 7.68440011,7.20080011 8.47960013,7.20080011 C9.27520014,7.20080011 9.92040015,7.84440012 9.92040015,8.63960013 C9.92040015,9.43520014 9.27520014,10.0804002 8.47960013,10.0804002 Z" id="Fill-2" fill="#556080"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.9 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18.96 32.35"><defs><style>.cls-1{fill:#38454f;}.cls-2{fill:#1caee4;}.cls-3{fill:#1081e0;}.cls-4{fill:#cbd4d8;}.cls-5{fill:#546a79;}</style></defs><title>Asset 10002-app</title><g id="Layer_2" data-name="Layer 2"><g id="Livello_1" data-name="Livello 1"><path class="cls-1" d="M15.76,32.35H3.2A3.21,3.21,0,0,1,0,29.14V3.2A3.2,3.2,0,0,1,3.2,0H15.76A3.2,3.2,0,0,1,19,3.2V29.14A3.21,3.21,0,0,1,15.76,32.35Z"/><rect class="cls-2" x="1.67" y="3.35" width="15.61" height="23.98"/><path class="cls-3" d="M3.35,7.81a.56.56,0,0,0,.39-.17L6,5.41a.56.56,0,0,0,0-.79.57.57,0,0,0-.79,0L3,6.86a.54.54,0,0,0,0,.78A.56.56,0,0,0,3.35,7.81Z"/><path class="cls-3" d="M3.35,10.6a.56.56,0,0,0,.39-.17L4.86,9.32a.57.57,0,0,0,0-.79.56.56,0,0,0-.79,0L3,9.64a.57.57,0,0,0,.4,1Z"/><path class="cls-3" d="M5.18,7.41a.59.59,0,0,0-.16.4.57.57,0,0,0,.16.39.6.6,0,0,0,.4.17A.58.58,0,0,0,6,8.2a.57.57,0,0,0,.16-.39.56.56,0,0,0-1-.4Z"/><path class="cls-3" d="M6.3,7.09a.54.54,0,0,0,.39.16.57.57,0,0,0,.4-.16L8.76,5.41a.56.56,0,0,0,0-.79.57.57,0,0,0-.79,0L6.3,6.3A.56.56,0,0,0,6.3,7.09Z"/><path class="cls-3" d="M8,7.41l-5,5a.56.56,0,0,0,.4,1,.54.54,0,0,0,.39-.16l5-5a.56.56,0,0,0,0-.79A.57.57,0,0,0,8,7.41Z"/><path class="cls-3" d="M9.08,6.3a.57.57,0,0,0-.16.39.59.59,0,0,0,.16.4.61.61,0,0,0,.4.16A.55.55,0,0,0,10,6.69a.57.57,0,0,0-.16-.39A.59.59,0,0,0,9.08,6.3Z"/><path class="cls-3" d="M11.55,4.62a.57.57,0,0,0-.79,0l-.56.56a.56.56,0,0,0,.4,1A.54.54,0,0,0,11,6l.56-.56A.56.56,0,0,0,11.55,4.62Z"/><path class="cls-4" d="M11.15,2.23H7.81a.56.56,0,0,1-.56-.56.55.55,0,0,1,.56-.55h3.34a.55.55,0,0,1,.56.55A.56.56,0,0,1,11.15,2.23Z"/><path class="cls-5" d="M16.17,2.23h-.56a.56.56,0,0,1-.55-.56.55.55,0,0,1,.55-.55h.56a.55.55,0,0,1,.56.55A.56.56,0,0,1,16.17,2.23Z"/><path class="cls-5" d="M13.94,2.23h-.56a.56.56,0,0,1-.55-.56.55.55,0,0,1,.55-.55h.56a.55.55,0,0,1,.56.55A.56.56,0,0,1,13.94,2.23Z"/><path class="cls-4" d="M10.87,30.67H8.09a.84.84,0,0,1-.84-.83h0A.85.85,0,0,1,8.09,29h2.78a.85.85,0,0,1,.84.84h0A.84.84,0,0,1,10.87,30.67Z"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 31.83 32.52"><defs><style>.cls-1{fill:#ffd039;}.cls-2{fill:#f4b70c;}.cls-3{fill:#ffbb64;}.cls-4{fill:#ffae47;}.cls-5{fill:#ffdf65;}.cls-6{fill:#ffcd2c;}.cls-7{fill:#ffa035;}.cls-8{fill:#f78819;}</style></defs><title>Asset 9002-cup</title><g id="Layer_2" data-name="Layer 2"><g id="Livello_1" data-name="Livello 1"><path class="cls-1" d="M31.05,5.85h0a3.61,3.61,0,0,0-2.83-1.36H24.84a.47.47,0,0,0-.47.48V7.05a.47.47,0,0,0,.47.48h3.38a.56.56,0,0,1,.45.22.58.58,0,0,1,.11.46,9,9,0,0,1-1.93,4,5.79,5.79,0,0,1-2.37,1.58.46.46,0,0,0-.31.34,8.32,8.32,0,0,1-.84,2.26.46.46,0,0,0,0,.5.46.46,0,0,0,.39.2h.08a9,9,0,0,0,5.27-2.83,11.8,11.8,0,0,0,2.64-5.33A3.61,3.61,0,0,0,31.05,5.85Z"/><path class="cls-2" d="M27,12.28V12l-.15.16a5.79,5.79,0,0,1-2.37,1.58.46.46,0,0,0-.31.34,8.32,8.32,0,0,1-.84,2.26.46.46,0,0,0,0,.5.46.46,0,0,0,.39.2h.08a10,10,0,0,0,2.22-.65A9.45,9.45,0,0,0,27,12.28Z"/><path class="cls-2" d="M24.37,5V7.05a.47.47,0,0,0,.47.48H27v-3H24.84A.47.47,0,0,0,24.37,5Z"/><path class="cls-3" d="M19.5,28.05c-.14-.11-1.42-1.18-1.58-7a.49.49,0,0,0-.17-.36.54.54,0,0,0-.39-.1,8.66,8.66,0,0,1-1.44.13h0a8.69,8.69,0,0,1-1.45-.13.54.54,0,0,0-.39.1.49.49,0,0,0-.17.36c-.16,5.8-1.44,6.87-1.58,7a.44.44,0,0,0-.32.5.51.51,0,0,0,.5.42h6.81a.51.51,0,0,0,.5-.42A.44.44,0,0,0,19.5,28.05Z"/><path class="cls-4" d="M19.5,28.05c-.14-.11-1.42-1.18-1.58-7a.49.49,0,0,0-.17-.36.54.54,0,0,0-.39-.1,8.66,8.66,0,0,1-1.44.13h0l-.46,0a.48.48,0,0,1,.16.35c.16,5.8,1.43,6.87,1.58,7a.44.44,0,0,1,.32.5A.51.51,0,0,1,17,29h2.31a.51.51,0,0,0,.5-.42A.44.44,0,0,0,19.5,28.05Z"/><path class="cls-1" d="M.79,5.85h0A3.58,3.58,0,0,1,3.61,4.49H7A.47.47,0,0,1,7.46,5V7.05A.47.47,0,0,1,7,7.53H3.61a.56.56,0,0,0-.45.22.58.58,0,0,0-.11.46,9,9,0,0,0,1.93,4,5.79,5.79,0,0,0,2.37,1.58.46.46,0,0,1,.31.34,8.32,8.32,0,0,0,.84,2.26.46.46,0,0,1,0,.5.46.46,0,0,1-.39.2H8a9,9,0,0,1-5.27-2.83A11.8,11.8,0,0,1,.09,8.89,3.58,3.58,0,0,1,.79,5.85Z"/><path class="cls-2" d="M4.83,12.28V12l.15.16a5.79,5.79,0,0,0,2.37,1.58.46.46,0,0,1,.31.34,8.32,8.32,0,0,0,.84,2.26.46.46,0,0,1,0,.5.46.46,0,0,1-.39.2H8a10.16,10.16,0,0,1-2.22-.65A9.45,9.45,0,0,1,4.83,12.28Z"/><path class="cls-2" d="M7.46,5V7.05A.47.47,0,0,1,7,7.53H4.83v-3H7A.47.47,0,0,1,7.46,5Z"/><path class="cls-5" d="M24.84,2.76H7a.47.47,0,0,0-.48.48v9a9.41,9.41,0,1,0,18.81,0v-9A.47.47,0,0,0,24.84,2.76Z"/><path class="cls-6" d="M24.84,2.76H22.62a.47.47,0,0,1,.47.48v9a9.41,9.41,0,0,1-8.29,9.34,8.32,8.32,0,0,0,1.12.07,9.42,9.42,0,0,0,9.4-9.41v-9A.47.47,0,0,0,24.84,2.76Z"/><path class="cls-7" d="M20.06,11.17a1.05,1.05,0,0,0,.27-1.08,1,1,0,0,0-.85-.71l-1.76-.26a.08.08,0,0,1-.07,0l-.79-1.6a1,1,0,0,0-.94-.58h0a1,1,0,0,0-.95.58l-.79,1.6a.08.08,0,0,1-.07,0l-1.76.26a1,1,0,0,0-.85.71,1.05,1.05,0,0,0,.27,1.08L13,12.41a.1.1,0,0,1,0,.09l-.3,1.75a1.05,1.05,0,0,0,1.53,1.11l1.57-.83H16l1.57.83a1.11,1.11,0,0,0,.49.12,1.07,1.07,0,0,0,.62-.2,1,1,0,0,0,.42-1l-.3-1.75a.14.14,0,0,1,0-.09Z"/><path class="cls-8" d="M19.48,9.38,19,9.31,16.74,11.5a.57.57,0,0,0-.17.51l.52,3.11.44.24a1.11,1.11,0,0,0,.49.12,1.07,1.07,0,0,0,.62-.2,1,1,0,0,0,.42-1l-.3-1.75a.14.14,0,0,1,0-.09l1.27-1.24a1.05,1.05,0,0,0,.27-1.08A1,1,0,0,0,19.48,9.38Z"/><path class="cls-5" d="M25.12,31.89A5.14,5.14,0,0,0,20.43,28h-9a5.14,5.14,0,0,0-4.69,3.88.47.47,0,0,0,.07.43.49.49,0,0,0,.39.2h17.5a.48.48,0,0,0,.38-.2A.47.47,0,0,0,25.12,31.89Z"/><path class="cls-6" d="M25.12,31.89A5.14,5.14,0,0,0,20.43,28H16.77a5.14,5.14,0,0,1,4.69,3.88.5.5,0,0,1-.07.43.49.49,0,0,1-.39.2h3.67a.48.48,0,0,0,.38-.2A.47.47,0,0,0,25.12,31.89Z"/><path class="cls-1" d="M25.62,0H6.21a1.86,1.86,0,0,0,0,3.71H25.62a1.86,1.86,0,0,0,0-3.71Z"/><path class="cls-2" d="M25.62,0H23.46a1.86,1.86,0,1,1,0,3.71h2.16a1.86,1.86,0,0,0,0-3.71Z"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 182 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 63 KiB |
@@ -0,0 +1 @@
|
||||
var configuration_map = {"notificationRuleList":[],"config":{"enableNotification":true},"passKey":"{}"};
|
||||
@@ -0,0 +1,2 @@
|
||||
!function(){"use strict";"undefined"!=typeof PushSubscriptionOptions&&PushSubscriptionOptions.prototype.hasOwnProperty("applicationServerKey")||void 0!==window.safari&&void 0!==window.safari.pushNotification?function(){const n=document.createElement("script");n.src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.es6.js?v=160510",n.defer=!0,document.head.appendChild(n)}():function(){let n="Incompatible browser.";"Apple Computer, Inc."===navigator.vendor&&navigator.maxTouchPoints>0&&(n+=" Try these steps: https://tinyurl.com/bdh2j9f7"),console.info(n)}()}();
|
||||
//# sourceMappingURL=OneSignalSDK.page.js.map
|
||||
@@ -0,0 +1,220 @@
|
||||
|
||||
var mult_send = 0;
|
||||
|
||||
function Contest_Send(){
|
||||
|
||||
mult_send = mult_send + 1;
|
||||
PreparaContestSend('senduscontestform',false);
|
||||
|
||||
if (mult_send == 1)
|
||||
{
|
||||
AJAXReqContestSend("POST","send_us_contest.php",true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function PreparaContestSend(nome,ele){
|
||||
stringa = "";
|
||||
var form = document.forms[nome];
|
||||
|
||||
var numeroElementi = form.elements.length;
|
||||
|
||||
for(var i = 0; i < numeroElementi; i++){
|
||||
|
||||
nmfrm = form.elements[i].name;
|
||||
|
||||
if(i < numeroElementi-1)
|
||||
{
|
||||
stringa += form.elements[i].name+"="+encodeURIComponent(form.elements[i].value)+"&";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
stringa += form.elements[i].name+"="+encodeURIComponent(form.elements[i].value);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function AJAXReqContestSend(method,url,bool){
|
||||
if(window.XMLHttpRequest){
|
||||
myReq = new XMLHttpRequest();
|
||||
} else
|
||||
|
||||
if(window.ActiveXObject){
|
||||
myReq = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
|
||||
if(!myReq){
|
||||
myReq = new ActiveXObject("Msxml2.XMLHTTP");
|
||||
}
|
||||
}
|
||||
|
||||
if(myReq){
|
||||
|
||||
myReq.onreadystatechange = state_ContestSend;
|
||||
|
||||
myReq.open(method,url,bool);
|
||||
|
||||
|
||||
myReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
|
||||
myReq.send(stringa);
|
||||
|
||||
}else{
|
||||
alert("Impossibilitati ad usare AJAX");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function state_ContestSend(bReload){
|
||||
|
||||
if (myReq.readyState==4){
|
||||
|
||||
mult_send = 0;
|
||||
|
||||
if (myReq.status==200){
|
||||
|
||||
ResponseContestSend(myReq.responseText);
|
||||
}
|
||||
else {
|
||||
if (bDebug) {alert("Problem retrieving XML data");}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function ResponseContestSend(sResponse){
|
||||
|
||||
|
||||
var vetResp = sResponse.split('|');
|
||||
|
||||
if (vetResp[0].toUpperCase() == 'OK')
|
||||
{
|
||||
if (MM_findObj("contest_name_msg"))
|
||||
{
|
||||
DisplayHTMLData(MM_findObj('contest_name_msg'), ' ');
|
||||
}
|
||||
if (MM_findObj("contest_video_msg"))
|
||||
{
|
||||
DisplayHTMLData(MM_findObj('contest_video_msg'), ' ');
|
||||
}
|
||||
if (MM_findObj("send_box_contest"))
|
||||
{
|
||||
MM_findObj("send_box_contest").style.display='none';
|
||||
}
|
||||
if (MM_findObj("send_box_contest_response"))
|
||||
{
|
||||
MM_findObj("send_box_contest_response").style.display='block';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (MM_findObj("contest_name_msg"))
|
||||
{
|
||||
DisplayHTMLData(MM_findObj('contest_name_msg'), ' ');
|
||||
}
|
||||
if (MM_findObj("contest_video_msg"))
|
||||
{
|
||||
DisplayHTMLData(MM_findObj('contest_video_msg'), ' ');
|
||||
}
|
||||
for (b=1; b<vetResp.length; b++)
|
||||
{
|
||||
var f = vetResp[b].split(';');
|
||||
var fldcont = f[0];
|
||||
var msgcont = f[1];
|
||||
|
||||
if (fldcont == 'contest_name')
|
||||
{
|
||||
DisplayHTMLData(MM_findObj(fldcont + '_msg'), msgcont);
|
||||
}
|
||||
|
||||
if (fldcont == 'contest_video')
|
||||
{
|
||||
DisplayHTMLData(MM_findObj(fldcont + '_msg'), msgcont);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
var HTTP_FIRSTAUCT_URL = new String ('first_auct.php');
|
||||
var xmlhttpFirstAuct = null;
|
||||
|
||||
function FirstAuct() {
|
||||
|
||||
var sUrlFirstAuct = HTTP_FIRSTAUCT_URL + "?chk=" + new Date().valueOf();
|
||||
|
||||
if (xmlhttpFirstAuct) {
|
||||
|
||||
if ((xmlhttpFirstAuct.readyState != 4) && (xmlhttpFirstAuct.readyState != 0)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (window.XMLHttpRequest){
|
||||
|
||||
xmlhttpFirstAuct = new XMLHttpRequest();
|
||||
} else if (window.ActiveXObject){
|
||||
|
||||
xmlhttpFirstAuct = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
if (xmlhttpFirstAuct != null){
|
||||
xmlhttpFirstAuct.onreadystatechange = state_FirstAuct;
|
||||
xmlhttpFirstAuct.open("GET",sUrlFirstAuct,true);
|
||||
xmlhttpFirstAuct.send(null);
|
||||
return true;
|
||||
} else {
|
||||
if (bDebug)
|
||||
{
|
||||
alert("Your browser does not support XMLHTTP.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
xmlhttpFirstAuct = null;
|
||||
if (bDebug) alert('Errore in loadXMLDocElenco');
|
||||
}
|
||||
finally {}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function state_FirstAuct(){
|
||||
|
||||
if (xmlhttpFirstAuct.readyState==4){
|
||||
|
||||
if (xmlhttpFirstAuct.status!=200){
|
||||
|
||||
if (bDebug) {
|
||||
alert("Problem retrieving XML data");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
btn-promo {
|
||||
border-radius: 3px;
|
||||
background: linear-gradient(rgb(82, 157, 253), rgb(46, 114, 202));
|
||||
background: -moz-linear-gradient(rgb(82, 157, 253), rgb(46, 114, 202));
|
||||
background: -webkit-linear-gradient(rgb(82, 157, 253), rgb(46, 114, 202));
|
||||
background: -o-linear-gradient(rgb(82, 157, 253), rgb(46, 114, 202));
|
||||
background: -ms-linear-gradient(rgb(82, 157, 253), rgb(46, 114, 202));
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn.btn-promo:hover {
|
||||
background: linear-gradient(rgb(117, 175, 250), rgb(53, 124, 216));
|
||||
background: -moz-linear-gradient(rgb(117, 175, 250), rgb(53, 124, 216));
|
||||
background: -webkit-linear-gradient(rgb(117, 175, 250), rgb(53, 124, 216));
|
||||
background: -o-linear-gradient(rgb(117, 175, 250), rgb(53, 124, 216));
|
||||
background: -ms-linear-gradient(rgb(117, 175, 250), rgb(53, 124, 216));
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.mCSB_inside > .mCSB_container {
|
||||
margin-right: 0px;
|
||||
}
|
||||
|
||||
.mCSB_scrollTools .mCSB_draggerRail {
|
||||
width: 6px;
|
||||
background-color: #e2e2e2;
|
||||
}
|
||||
|
||||
.mCSB_scrollTools .mCSB_draggerContainer {
|
||||
left: 10px;
|
||||
}
|
||||
|
||||
.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar {
|
||||
background-color: #20cb9a !important;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.loader {
|
||||
margin: 10px auto;
|
||||
border: 5px solid #f3f3f3;
|
||||
/* Light grey */
|
||||
border-top: 5px solid #20cb9a;
|
||||
/* Blue */
|
||||
border-radius: 50%;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
-webkit-animation: spin 2s linear infinite;
|
||||
animation: spin 2s linear infinite;
|
||||
}
|
||||
|
||||
.stopScroll{
|
||||
overflow: hidden !important;
|
||||
}
|
||||
|
||||
@-webkit-keyframes spin {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 384px) {
|
||||
#prod_win_cont_modal h3 {
|
||||
padding-left: 30px;
|
||||
padding-right: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 320px) {
|
||||
.prod_won__2 {
|
||||
margin-left: 1px !important;
|
||||
margin-right: 1px !important;
|
||||
}
|
||||
#prod_win_cont_modal .col-xs-6{
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
#modal iframe {
|
||||
width: 99%;
|
||||
}
|
||||
|
||||
#myModal3 .modal-dialog, #myModal2 .modal-dialog {
|
||||
margin: 30px auto;
|
||||
}
|
||||
|
||||
.settingBox form div {
|
||||
border-bottom: 1px solid #efefef;
|
||||
padding: 15px;
|
||||
font-weight: 500;
|
||||
font-size: 12px;
|
||||
color: #818181;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 991px) {
|
||||
#menuModal .show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#menuModal .modal-header {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
#menuModal .height {
|
||||
height: 0px;
|
||||
}
|
||||
|
||||
.parentOverflowY {
|
||||
overflow-y: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
#notifBoxContainer .mCSB_container {
|
||||
top: 0px;
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.6 KiB |
@@ -0,0 +1,206 @@
|
||||
const AuctionsBidManage = (function() {
|
||||
|
||||
const _defaultPart = "divAsta";
|
||||
let _nAstePerBonus = 10;
|
||||
let _limiteAsteVinte = 10;
|
||||
let _nAstePuntataVinte = 0;
|
||||
let _percentualeBonus = 0;
|
||||
let _nPuntateVinteOggi = 0;
|
||||
let _nAsteConfermate = 0;
|
||||
let _nPuntateRiscattate = 0;
|
||||
let _nPuntateDaRiscattare = 0;
|
||||
let _initialized = false;
|
||||
let _defaultValidUntil = null;
|
||||
let _viewSlot = false;
|
||||
|
||||
function _defaultObj() {
|
||||
return {
|
||||
auctions: {},
|
||||
nAsteConfermate: 0,
|
||||
percentualeBonus: 0,
|
||||
limiteAsteVinte: 10,
|
||||
nAstePerBonus: 10,
|
||||
validUntil: getDefaultValidUntil()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiunge una nuova asta all'oggetto delle aste di puntata vinte in un giorno
|
||||
* @param idAuction {int}
|
||||
*/
|
||||
function add(idAuction){
|
||||
|
||||
let result = get();
|
||||
let retrievedObject = JSON.parse(result);
|
||||
let auctionBidWin = retrievedObject === null ? _defaultObj() : retrievedObject ;
|
||||
let auctionElement = document.getElementById(_defaultPart + idAuction);
|
||||
let creditValue = parseInt(auctionElement.getAttribute('data-credit-value')) > 0 ? parseInt(auctionElement.getAttribute('data-credit-value')) : 0;
|
||||
|
||||
|
||||
|
||||
if(creditValue > 0 && Object.keys(auctionBidWin.auctions).length <= auctionBidWin.limiteAsteVinte){
|
||||
|
||||
// let obj =
|
||||
// {
|
||||
// idAuction: idAuction,
|
||||
// value: creditValue
|
||||
// }
|
||||
// ;
|
||||
//
|
||||
// if(!auctionBidWin.auctions.hasOwnProperty(idAuction)){
|
||||
// auctionBidWin.auctions[idAuction] = obj;
|
||||
// }
|
||||
// let newObj = JSON.stringify(auctionBidWin);
|
||||
//
|
||||
// localStorage.setItem("auctionBidWin", newObj);
|
||||
getRemoteData();
|
||||
}
|
||||
return;
|
||||
}
|
||||
function getDefaultValidUntil(){
|
||||
|
||||
return _defaultValidUntil;
|
||||
|
||||
}
|
||||
|
||||
function setDefaultValidUntil(untilTimestamp){
|
||||
_defaultValidUntil = untilTimestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ritornano le informazioni salvate nel localStorage
|
||||
* @returns {string}
|
||||
*/
|
||||
function get(){
|
||||
return localStorage.getItem('auctionBidWin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rimuove dal localStorage
|
||||
*/
|
||||
function remove(){
|
||||
localStorage.removeItem('auctionBidWin');
|
||||
}
|
||||
|
||||
|
||||
function getRemoteData(callback = null){
|
||||
|
||||
fetch('./ajax/get_auction_bids_info_banner.php',{
|
||||
method: "GET"
|
||||
})
|
||||
// gestisci il successo
|
||||
.then(response => response.json()) // converti a json
|
||||
.then(function (data) {
|
||||
let obj = {
|
||||
auctions: data.auctions,
|
||||
nAsteConfermate: data.nAsteConfermate,
|
||||
nAsteVinte: data.nAsteVinte,
|
||||
nPuntateRiscattate: data.nPuntateRiscattate,
|
||||
nPuntateDaRiscattare: data.nPuntateDaRiscattare,
|
||||
limiteAsteVinte: data.limiteAsteVinte,
|
||||
nAstePerBonus: data.nAstePerBonus,
|
||||
percentualeBonus: data.percentualeBonus,
|
||||
validUntil: data.validUntil,
|
||||
viewSlot: data.viewSlot,
|
||||
extraSlots: data.extraSlots, //un elenco degli slots non scaduti e non aperti
|
||||
nPuntateBonus: data.nPuntateBonus
|
||||
};
|
||||
let newObj = JSON.stringify(obj);
|
||||
|
||||
localStorage.setItem("auctionBidWin", newObj);
|
||||
if(callback !== null){
|
||||
callback();
|
||||
}
|
||||
|
||||
})
|
||||
.catch(err => console.log('Request Failed', err)); // gestisci gli errori
|
||||
}
|
||||
|
||||
function retriveInfoComponent(){
|
||||
let result = JSON.parse(get());
|
||||
|
||||
if(result) {
|
||||
|
||||
_nAstePuntataVinte = result.nAsteVinte;
|
||||
_limiteAsteVinte = result.limiteAsteVinte;
|
||||
_nAsteConfermate = result.nAsteConfermate;
|
||||
_nPuntateDaRiscattare = result.nPuntateDaRiscattare;
|
||||
_nPuntateRiscattate = result.nPuntateRiscattate;
|
||||
_nAstePerBonus = result.nAstePerBonus;
|
||||
_percentualeBonus = result.percentualeBonus;
|
||||
_viewSlot = result.viewSlot;
|
||||
_nPuntateVinteOggi = result.nPuntateDaRiscattare + result.nPuntateRiscattate;
|
||||
|
||||
|
||||
|
||||
/*if (_percentualeBonus > 0) {
|
||||
let valorePercentualeBonus = ((_nPuntateVinteOggi * _percentualeBonus) / 100);
|
||||
_nPuntateVinteOggi = _nPuntateVinteOggi + valorePercentualeBonus;
|
||||
}*/
|
||||
|
||||
|
||||
let asteRimanentiPerBonus = _nAstePerBonus - _nAstePuntataVinte;
|
||||
|
||||
return {
|
||||
auctions: result.auctions,
|
||||
asteRimanentiPerBonus: asteRimanentiPerBonus,
|
||||
nAstePerBonus: _nAstePerBonus,
|
||||
nAstePuntataVinte: _nAstePuntataVinte,
|
||||
percentualeBonus: _percentualeBonus,
|
||||
nPuntateVinteOggi: parseInt(_nPuntateVinteOggi),
|
||||
limiteAsteVinte: _limiteAsteVinte,
|
||||
nAsteConfermate: _nAsteConfermate,
|
||||
nPuntateDaRiscattare: _nPuntateDaRiscattare,
|
||||
nPuntateRiscattate: _nPuntateRiscattate,
|
||||
|
||||
viewSlot: _viewSlot,
|
||||
extraSlots: result.extraSlots,
|
||||
nPuntateBonus: result.nPuntateBonus
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param auctionId
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function searchByAuctionId(auctionId){
|
||||
let data = retriveInfoComponent();
|
||||
let controllo = false;
|
||||
if(data == undefined || data == null ){ return; }
|
||||
|
||||
let keys = Object.keys(data.auctions);
|
||||
|
||||
for(let i= 0; i <= keys.length; i++){
|
||||
if(keys[i] === auctionId){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function initRemoteData(){
|
||||
if(!_initialized){
|
||||
getRemoteData();
|
||||
setInterval(function (){
|
||||
getRemoteData();
|
||||
}, 1000 * 60);
|
||||
}
|
||||
_initialized = true;
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
add,
|
||||
get,
|
||||
remove,
|
||||
getRemoteData,
|
||||
retriveInfoComponent,
|
||||
initRemoteData,
|
||||
setDefaultValidUntil,
|
||||
searchByAuctionId
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
@@ -0,0 +1,927 @@
|
||||
#wrapBonusSection{
|
||||
width: 100%;
|
||||
background-color: #fff;
|
||||
margin-bottom: 20px;
|
||||
-webkit-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.2);
|
||||
-moz-box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.2);
|
||||
box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.2);
|
||||
border-top: 1px solid #d0d0d0;
|
||||
display: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
#wrapBonusSection.visible{
|
||||
display: block;
|
||||
}
|
||||
#BonusSection{
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
width: 65%;
|
||||
min-height: 40px;
|
||||
margin: 0 auto;
|
||||
align-items: center;
|
||||
margin-bottom: -25px;
|
||||
}
|
||||
@media (max-width: 576px) {
|
||||
#BonusSection{
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#BonusSection .wrap-msg-bonus, #BonusSection .pt-2 .wrap-progress, #BonusSection .pt-1 .wrap-progress, #BonusSection .pt-3 .wrap-progress, #BonusSection .pt-3 .wrap-bids, #auctionBidsModal .wrap-msg-bonus, #auctionBidsModal .wrap-msg-bonus .wrap-progress, #bidsBonusSection #section2 .wrap-progress, #bidsBonusSection #section3 .wrap-progress{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
#bidsBonusSection #section2 .wrap-progress{
|
||||
font-size: 14px;
|
||||
}
|
||||
#auctionBidsModal #countdownAddSlot{
|
||||
font-weight: bold;
|
||||
color: #55bc62;
|
||||
}
|
||||
#auctionBidsModal .wrap-msg-bonus{
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
#BonusSection .pt-2 .item, #BonusSection .pt-3 .item{
|
||||
margin: 2px;
|
||||
}
|
||||
#BonusSection .pt-2, #BonusSection .pt-1, #BonusSection .pt-3, #auctionBidsModal .wrap-pt2{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
#auctionBidsModal .wrap-pt2 .bonus-obtained{
|
||||
font-size: 12px;
|
||||
color: #6F6F6F;
|
||||
font-weight: bold;
|
||||
margin-top: 3px;
|
||||
display: none;
|
||||
}
|
||||
#auctionBidsModal .wrap-pt2{
|
||||
justify-content: space-around;
|
||||
align-items: flex-start;
|
||||
margin-top: 20px;
|
||||
border-top: 1px solid #DBDBDB;
|
||||
padding-top: 20px;
|
||||
font-size: 13px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
@media (max-width: 340px) {
|
||||
#auctionBidsModal .wrap-pt2{
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
#auctionToBonusModal{
|
||||
font-size: 15px;
|
||||
color: #333;
|
||||
}
|
||||
#BonusSection .text{
|
||||
color: #6D6D6D;
|
||||
font-size: 15px;
|
||||
margin: auto 4px;
|
||||
}
|
||||
#BonusSection .pt-2 img{
|
||||
height: 29px;
|
||||
}
|
||||
#BonusSection .pt-2 .img-emoji img, #auctionBidsModal .img-emoji img {
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
margin-left: -10px;
|
||||
margin-top: -3px;
|
||||
}
|
||||
#auctionBidsModal .img-emoji img{
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
#auctionBidsModal .img-emoji{
|
||||
z-index: 9;
|
||||
margin-left: -3px;
|
||||
margin-right: 2px;
|
||||
}
|
||||
#BonusSection .pt-dx img, #auctionBidsModal .pt-dx img, #auctionBidsModal .pt-center img{
|
||||
width: 16px;
|
||||
}
|
||||
#BonusSection .pt-2 .wrap-progress .progress{
|
||||
margin-left: 5px;
|
||||
background-color: #D1D1D1;
|
||||
}
|
||||
#auctionBidsModal .progress{
|
||||
width: 56px;
|
||||
height: 24px;
|
||||
margin: 0 6px;
|
||||
position: relative;
|
||||
background-color: #D1D1D1;
|
||||
border-radius: 20px;
|
||||
}
|
||||
#auctionBidsModal .progress{
|
||||
width: 110px;
|
||||
height: 22px;
|
||||
}
|
||||
#auctionBidsModal .pt-1 .progress{
|
||||
height: 11px;
|
||||
}
|
||||
#BonusSection .progress, #auctionBidsModal .progress{
|
||||
width: 60px;
|
||||
height: 13px;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
#auctionBidsModal .progress{
|
||||
width: 90px;
|
||||
}
|
||||
#BonusSection #countdown-bonus{
|
||||
width: 60px;
|
||||
color: #fff;
|
||||
background-color: #FF0658;
|
||||
font-weight: bold;
|
||||
font-size: 11px;
|
||||
padding: 0px 4px;
|
||||
height: 16px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
#BonusSection #bonus-earned, #BonusSection #bonus-active-all{
|
||||
display: none;
|
||||
font-weight: bold;
|
||||
margin-right: 15px;
|
||||
}
|
||||
@media (max-width: 576px) {
|
||||
#BonusSection #bonus-earned, #BonusSection #bonus-active-all{
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
#BonusSection #bonus-active-all{
|
||||
color: #55bc62;
|
||||
}
|
||||
|
||||
|
||||
#BonusSection .progress .progress-bar, #auctionBidsModal .pt-1 .progress .progress-bar, #auctionBidsModal #bidsBonusSection #section2 .progress .progress-bar, #auctionBidsModal .progress .progress-bar{
|
||||
background: rgb(4,170,176);
|
||||
background: linear-gradient(90deg, rgba(4,170,176,1) 0%, rgba(7,206,173,1) 100%);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
#BonusSection .progress .progressbar-text{
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
height: 22px;
|
||||
color: #000;
|
||||
width: 100%;
|
||||
left: 0;
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
#auctionBidsModal .progress .progressbar-text{
|
||||
font-size: 15px;
|
||||
top: 0;
|
||||
}
|
||||
#todayBids, #auctionBidsModal{
|
||||
font-size: 16px;
|
||||
color: #333;
|
||||
}
|
||||
#auctionBidsModal{
|
||||
font-weight: normal;
|
||||
}
|
||||
#auctionToBonus.active{
|
||||
font-weight: bold;
|
||||
color: #000;
|
||||
}
|
||||
#confirmedAuctionWithBonus{
|
||||
display: none;
|
||||
margin-left: 5px;
|
||||
}
|
||||
#confirmedAuctionWithBonus .value{
|
||||
font-weight: bold;
|
||||
}
|
||||
.wrap-bonus-mobile{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.wrap-bonus-mobile .wrap-bonus-value{
|
||||
font-size: 14px;
|
||||
color: #504E4E;
|
||||
margin-left: 5px;
|
||||
}
|
||||
#auctionBidsModal .wrap-bonus-value{
|
||||
margin-right: 2px;
|
||||
}
|
||||
#BonusSection .pt-3 img{
|
||||
width: 15px;
|
||||
}
|
||||
#BonusSection .wrap-title-bonus{
|
||||
display: flex;
|
||||
}
|
||||
#BonusSection .wrap-title-bonus .icon-check{
|
||||
width: 15px;
|
||||
display: none;
|
||||
margin-right: 4px;
|
||||
}
|
||||
#BonusSection .pt-2 #countdown-bonus{
|
||||
display: none;
|
||||
}
|
||||
@media (max-width: 1040px) {
|
||||
#BonusSection{
|
||||
width: 100%;
|
||||
justify-content: space-around;
|
||||
min-height: 50px;
|
||||
}
|
||||
#BonusSection .pt-1, #BonusSection .pt-2, #BonusSection .pt-3{
|
||||
flex-direction: column;
|
||||
}
|
||||
#BonusSection .pt-3 .wrap-bids{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
#BonusSection .text {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#BonusSection .pt-2 img{
|
||||
margin-right: 5px;
|
||||
height: 18px;
|
||||
width: 10px;
|
||||
}
|
||||
#BonusSection .pt-1 .progress {
|
||||
width: 90px;
|
||||
height: 10px;
|
||||
}
|
||||
#todayBids{
|
||||
font-size: 14px;
|
||||
}
|
||||
#BonusSection .pt-3 .item{
|
||||
margin: 0;
|
||||
}
|
||||
#BonusSection .pt-3 img{
|
||||
width: 13px;
|
||||
margin-top: -1px;
|
||||
margin-left: 3px;
|
||||
}
|
||||
#BonusSection .wrap-msg-bonus{
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.wrap-bonus-mobile{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
}
|
||||
@media (max-width: 576px) {
|
||||
#BonusSection {
|
||||
min-height: 45px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 360px) {
|
||||
#BonusSection .text {
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#auctionBidsModal .pt-left .wrap-progress, #auctionBidsModal .pt-dx .wrap-bids, #auctionBidsModal .pt-center .wrap-bids{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-top: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
#auctionBidsModal .pt-center .item, #auctionBidsModal .pt-dx .item{
|
||||
margin-left: 1px;
|
||||
margin-right: 1px;
|
||||
}
|
||||
#auctionBidsModal .pt-center .item img, #auctionBidsModal .pt-dx .item img{
|
||||
margin-left: 2px;
|
||||
margin-right: 2px;
|
||||
margin-top: -5px;
|
||||
}
|
||||
|
||||
#auctionToGoModal{
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
}
|
||||
@media (max-width: 340px) {
|
||||
#auctionBidsModal .wrap-pt2{
|
||||
font-size: 12px;
|
||||
}
|
||||
#auctionToGoModal, #todayBidsModal, #todayBidsPayedModal{
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
#todayBidsModal, #todayBidsPayedModal{
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
}
|
||||
#loaderAuctionBids{
|
||||
min-height: 40px;
|
||||
text-align: center;
|
||||
padding: 5px;
|
||||
font-size: 20px;
|
||||
}
|
||||
#auctionToGo{
|
||||
color: #000;
|
||||
margin-left: 5px;
|
||||
}
|
||||
.loader-data{
|
||||
display: block;
|
||||
position: relative;
|
||||
margin-right: 0px !important;
|
||||
margin-left: 0px !important;
|
||||
}
|
||||
.loader-data::before{
|
||||
content: "";
|
||||
background-color: #eaeaea;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 22px;
|
||||
position: absolute;
|
||||
}
|
||||
@media (max-width: 576px) {
|
||||
.loader-data{
|
||||
margin-top: 2px !important;
|
||||
margin-bottom: 2px !important;
|
||||
}
|
||||
.loader-data::before{
|
||||
height: 16px;
|
||||
min-width: 20px;
|
||||
}
|
||||
}
|
||||
#BonusSection .pt-1, #BonusSection .pt-2, #BonusSection .pt-3{
|
||||
position: relative;
|
||||
}
|
||||
.loader-data img{
|
||||
display: none !important;
|
||||
}
|
||||
.wrap-countdown-auctionBidsModal{
|
||||
color: #55BC62;
|
||||
font-weight: bold;
|
||||
}
|
||||
#auctionBidsModal .wrapTitle{
|
||||
margin: 20px auto 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
#auctionBidsModal .modal-body{
|
||||
padding: 0;
|
||||
}
|
||||
#auctionBidsModal .contentModal #bidsBonusSection .content, #auctionBidsModal .contentModal #rankingBonusSection{
|
||||
font-size: 16px;
|
||||
text-align: center;
|
||||
margin-top: 15px;
|
||||
padding: 15px;
|
||||
}
|
||||
#auctionBidsModal .contentModal #bidsBonusSection .content{
|
||||
margin-top: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#auctionBidsModal .contentModal #bidsBonusSection .content.parent-content-div {
|
||||
padding: 0 0 5px 0;
|
||||
}
|
||||
|
||||
#tabsSection{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
@media (max-width: 576px) {
|
||||
#tabsSection{
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
#tabsSection .pt-1{
|
||||
width: 55%;
|
||||
}
|
||||
#tabsSection .pt-2{
|
||||
width: 40%;
|
||||
}
|
||||
#tabsSection .pt-1, #tabsSection .pt-2{
|
||||
|
||||
padding: 8px 18px;
|
||||
border-bottom: 1px solid #BCBCBC;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
}
|
||||
#tabsSection .pt-1 .fa, #tabsSection .pt-2 .fa{
|
||||
margin-right: 5px;
|
||||
}
|
||||
#tabsSection .pt-3{
|
||||
width: 10%;
|
||||
padding: 5px 10px;
|
||||
border-bottom: 1px solid #BCBCBC;
|
||||
}
|
||||
button[aria-label='Close'] span{
|
||||
font-size: 26px;
|
||||
}
|
||||
@media (max-width: 576px) {
|
||||
#tabsSection .pt-3{
|
||||
padding: 4px 10px;
|
||||
}
|
||||
#tabsSection .pt-1, #tabsSection .pt-2{
|
||||
font-size: 12px;
|
||||
padding: 8px 10px;
|
||||
}
|
||||
button[aria-label='Close'] span{
|
||||
font-size: 25px;
|
||||
}
|
||||
}
|
||||
|
||||
#tabsSection .pt-1.active, #tabsSection .pt-2.active, #tabsSection .pt-3.active{
|
||||
border-color: #2F80ED;
|
||||
}
|
||||
#tabsSection .pt-1.active a, #tabsSection .pt-2.active a, #tabsSection .pt-3.active a, #tabsSection .pt-1.active a:hover, #tabsSection .pt-2.active a:hover{
|
||||
color: #2F80ED;
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
}
|
||||
#tabsSection .pt-1 a, #tabsSection .pt-2 a{
|
||||
color: #7d7d7d;
|
||||
}
|
||||
|
||||
|
||||
#tabsSection .pt-1 a:hover, #tabsSection .pt-2 a:hover{
|
||||
text-decoration: none;
|
||||
font-weight: normal;
|
||||
color: #2F80ED;
|
||||
}
|
||||
#rankingBonusSection{
|
||||
display: none;
|
||||
}
|
||||
#bidsBonusSection #section2 .box-congrats,
|
||||
#bidsBonusSection #section3 .box-congrats{
|
||||
margin-top: 12px;
|
||||
}
|
||||
#bidsBonusSection #section2, #bidsBonusSection #section3{
|
||||
display: none;
|
||||
}
|
||||
#bidsBonusSection #section2 .titleModal{
|
||||
font-size: 20px;
|
||||
}
|
||||
#auctionBidsModal .wrap-credit-bonus{
|
||||
display: inline-block;
|
||||
}
|
||||
#auctionBidsModal #bidsBonusSection .wrap-content{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
#bidsBonusSection #section2 .summary-body #countdown-bonus{
|
||||
font-size: 14px;
|
||||
}
|
||||
#bidsBonusSection #section2 .summary-body .countdown{
|
||||
color: #FF0658;
|
||||
}
|
||||
#bidsBonusSection #section2 .summary-body #countdownForBonus{
|
||||
font-weight: bold;
|
||||
}
|
||||
#bidsBonusSection #section2 .summary{
|
||||
margin-top: 30px;
|
||||
}
|
||||
#bidsBonusSection #section2 .summary-body{
|
||||
width: 250px;
|
||||
margin: -18px auto 25px;
|
||||
border: 1px solid #000;
|
||||
border-radius: 5px;
|
||||
padding: 20px 15px;
|
||||
box-shadow: 2px 2px 3px 1px rgba(208, 209, 213, 0.2), 0 2px 2px 1px rgba(220, 221, 224, 0.2);
|
||||
-webkit-box-shadow: 2px 2px 3px 1px rgba(208, 209, 213, 0.2), 0 2px 2px 1px rgba(220, 221, 224, 0.2);
|
||||
-moz-box-shadow: 2px 2px 3px 1px rgba(208, 209, 213, 0.2), 0 2px 2px 1px rgba(220, 221, 224, 0.2);
|
||||
}
|
||||
#bidsBonusSection #section3 .summaryTitle{
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
margin-top: 40px;
|
||||
|
||||
}
|
||||
#bidsBonusSection #section3 .summaryList img{
|
||||
width: 18px;
|
||||
}
|
||||
#bidsBonusSection #section3 .summaryList ul{
|
||||
text-align: left;
|
||||
width: 300px;
|
||||
margin: 5px auto 20px;
|
||||
line-height: 30px;
|
||||
}
|
||||
.bottom-area{
|
||||
font-size: 16px;
|
||||
}
|
||||
.bottom-area.highlight{
|
||||
color: #FF0658;
|
||||
font-weight: bold;
|
||||
margin-top: 15px;
|
||||
margin-bottom: -10px;
|
||||
}
|
||||
#auctionBidsModal #bidsBonusSection #bonusSection img{
|
||||
width: 20px;
|
||||
margin-top: -2px;
|
||||
}
|
||||
#auctionBidsModal #bidsBonusSection #bonusSection .bottomSection img{
|
||||
width: 16px;
|
||||
margin-right: 4px;
|
||||
}
|
||||
#auctionBidsModal #bidsBonusSection #bonusSection .bottomSection{
|
||||
font-size: 16px;
|
||||
margin-bottom: 15px;
|
||||
color: #5F5F5F;
|
||||
}
|
||||
|
||||
#bonusSection .btnConfirm{
|
||||
font-size: 18px;
|
||||
display: inline-block;
|
||||
color: #333;
|
||||
background-color: #fcc62d;
|
||||
padding: 5px;
|
||||
line-height: 25px;
|
||||
border-radius: 5px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
margin-top: 10px;
|
||||
width: 95%;
|
||||
text-decoration: none;
|
||||
|
||||
}
|
||||
@media (max-width: 576px) {
|
||||
#auctionBidsModal #bidsBonusSection #bonusSection .bottomSection {
|
||||
font-size: 15px;
|
||||
}
|
||||
#bonusSection .btnConfirm{
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
#rankingBonusSection .title{
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
#rankingBonusSection .subtitle{
|
||||
font-size: 14px;
|
||||
}
|
||||
#rankingBonusSection #ranking{
|
||||
padding: 0 10px;
|
||||
}
|
||||
#rankingBonusSection #ranking table{
|
||||
margin-top:30px;
|
||||
width: 100%;
|
||||
}
|
||||
#rankingBonusSection #ranking table td{
|
||||
text-align: left;
|
||||
}
|
||||
#rankingBonusSection #ranking table .td1{
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
font-size: 14px;
|
||||
}
|
||||
#rankingBonusSection #ranking table .td1 img{
|
||||
width: 38px;
|
||||
}
|
||||
#rankingBonusSection #ranking table td.td2{
|
||||
font-size: 16px;
|
||||
width: 70%;
|
||||
padding: 8px 10px;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
#rankingBonusSection #ranking table td.td3{
|
||||
width: 25%;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
}
|
||||
#rankingBonusSection #ranking table td.td3 img{
|
||||
width: 17px;
|
||||
margin-left: 4px;
|
||||
}
|
||||
#auctionBidsModal #section1, #auctionBidsModal #section4{
|
||||
display: none;
|
||||
}
|
||||
#auctionBidsModal #section1{
|
||||
padding: 0px 20px;
|
||||
}
|
||||
#auctionBidsModal #section4 .sad{
|
||||
width: 25px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
#BonusSection .img-lock, #BonusSection .img-lock-open{
|
||||
display: none;
|
||||
}
|
||||
#BonusSection .img-lock img, #BonusSection .img-lock-open img{
|
||||
width: 12px;
|
||||
margin-left: 5px;
|
||||
margin-top: -1px;
|
||||
}
|
||||
#BonusSection .pay-bids-counter{
|
||||
margin-left: 5px;
|
||||
color: #fff;
|
||||
background-color: #FF0658;
|
||||
border-radius: 40px;
|
||||
width: 19px;
|
||||
height: 19px;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
font-size: 11px;
|
||||
padding: 2px;
|
||||
display: none;
|
||||
}
|
||||
#auctionBidsModal .wrap-new-daily-challenge.wrap2{
|
||||
margin-top: 5px;
|
||||
}
|
||||
#auctionBidsModal .wrap-new-daily-challenge{
|
||||
color: #2F80ED;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin: 20px 60px 0px;
|
||||
display: none;
|
||||
}
|
||||
@media (max-width: 576px) {
|
||||
#auctionBidsModal .wrap-new-daily-challenge {
|
||||
margin: 20px 40px 0;
|
||||
}
|
||||
}
|
||||
#BonusSection .img-plus-not-active, #BonusSection .img-plus-active{
|
||||
display: none;
|
||||
}
|
||||
#auctionBidsModal .extraSlots .slot-title .open-lock{
|
||||
margin-top: -5px;
|
||||
width: 15px;
|
||||
margin-right: 3px;
|
||||
}
|
||||
#auctionBidsModal .extraSlots .slot-title span .fa{
|
||||
font-size: 20px;
|
||||
position: absolute;
|
||||
margin-left: 5px;
|
||||
}
|
||||
#auctionBidsModal .extraSlots .wrap-content-slot{
|
||||
padding: 10px 0 15px;
|
||||
}
|
||||
#auctionBidsModal .bonus-obtained{
|
||||
display: none;
|
||||
}
|
||||
#auctionBidsModal .extraSlots{
|
||||
border: none;
|
||||
margin: -5px auto 0;
|
||||
padding: 10px 15px;
|
||||
text-align: center;
|
||||
background-color: #f3f6f9;
|
||||
border-radius: 0;
|
||||
border-bottom-left-radius: 5px;
|
||||
border-bottom-right-radius: 5px;
|
||||
}
|
||||
#auctionBidsModal .extraSlots.avaible{
|
||||
border-color: #55BC62;
|
||||
}
|
||||
#extraSlotTemplate{
|
||||
display: none;
|
||||
}
|
||||
#wrapSlots{
|
||||
display: flex;
|
||||
justify-content: space-evenly;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
#wrapSlots .box-extra-slot{
|
||||
border: 1px solid #6F6F6F;
|
||||
background-color: #f3f6f9;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
width: 100px;
|
||||
margin-top: 15px;
|
||||
display: none;
|
||||
}
|
||||
.wrap-num-other-slot{
|
||||
position: relative;
|
||||
display: none;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.wrap-num-other-slot .reduce{
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 20px;
|
||||
color: #333;
|
||||
text-decoration: underline;
|
||||
}
|
||||
.wrap-num-other-slot .open{
|
||||
color: #55BC62;
|
||||
text-decoration: underline;
|
||||
display: none;
|
||||
}
|
||||
#wrapSlots .box-extra-slot .expire{
|
||||
font-size: 10px;
|
||||
font-weight: bold;
|
||||
color: #6A6B6C;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
#wrapSlots .box-extra-slot .expire img{
|
||||
margin-left: 2px;
|
||||
}
|
||||
#wrapSlots .box-extra-slot .content{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
#wrapSlots .box-extra-slot .content .slot-value{
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
#wrapSlots .box-extra-slot .wrap-cta .cta{
|
||||
background-color: #B4B4B4;
|
||||
color: #fff;
|
||||
padding: 0px 10px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
width: 100%;
|
||||
max-height: 23px;
|
||||
|
||||
}
|
||||
#wrapSlots .box-extra-slot .wrap-cta .cta img{
|
||||
margin-top: -2px;
|
||||
margin-right: 2px;
|
||||
}
|
||||
|
||||
.extraSlots .wrap-content-slot{
|
||||
display: none;
|
||||
}
|
||||
.extraSlots .slot-title a{
|
||||
width: 100%;
|
||||
display: block;
|
||||
color: #333;
|
||||
text-decoration: none;
|
||||
}
|
||||
.extraSlots .slot-title{
|
||||
color: #000;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.extraSlots .slot-content{
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.extraSlots .slot-content .beforeConfirmed, .extraSlots .slot-content .afterConfirmed{
|
||||
display: none;
|
||||
}
|
||||
.wrap-extra-slots .box-noSlot .titleNoSlot{
|
||||
color: #FE4E4E;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.wrap-extra-slots .box-noSlot .contentNoSlot{
|
||||
font-size: 12px;
|
||||
}
|
||||
.wrap-extra-slots .box-noSlot .contentNoSlot img{
|
||||
width: 17px;
|
||||
margin-top: -3px;
|
||||
margin-left: 3px;
|
||||
}
|
||||
.wrap-extra-slots .box-noSlot{
|
||||
margin-top: 10px;
|
||||
}
|
||||
.wrap-extra-slots .box-noSlot{
|
||||
display: none;
|
||||
}
|
||||
.wrap-extra-slots .box-noSlot .box-noextra-slot .no-extra-slot-content .slot-img img{
|
||||
width: 20px;
|
||||
opacity: 0.6;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.wrap-extra-slots .box-noSlot .box-noextra-slot .no-extra-slot-content{
|
||||
font-size: 10px;
|
||||
color: #333;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
}
|
||||
.wrap-extra-slots .box-noSlot .box-noextra-slot{
|
||||
width: 92px;
|
||||
margin: 20px auto;
|
||||
height: 81px;
|
||||
border: 1px solid #55BC62;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#wrapSlots.avaible .box-extra-slot{
|
||||
border-color: #55BC62;
|
||||
background-color: #EDF8EF;
|
||||
}
|
||||
#wrapSlots.avaible .box-extra-slot .wrap-cta .cta{
|
||||
background-color: #55BC62;
|
||||
}
|
||||
.wrap-extra-slots{
|
||||
display: none;
|
||||
}
|
||||
.wrap-extra-slots .title-extraSlot-blocked{
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
width: 100%;
|
||||
margin: 0 0 10px;
|
||||
display: none;
|
||||
text-align: center;
|
||||
}
|
||||
.wrap-extra-slots .title-extraSlot-blocked img{
|
||||
width: 18px;
|
||||
margin-top: -5px;
|
||||
}
|
||||
#auctionBidsModal #bidsBonusSection .img-lock, #auctionBidsModal #bidsBonusSection .img-lock-open{
|
||||
display: none;
|
||||
|
||||
}
|
||||
#auctionBidsModal #bidsBonusSection .img-lock img, #auctionBidsModal #bidsBonusSection .img-lock-open img{
|
||||
margin-left: 5px;
|
||||
width: 14px;
|
||||
margin-top: -5px;
|
||||
}
|
||||
#auctionBidsModal #differenzaAsteDaConfermare{
|
||||
color: #fff;
|
||||
background-color: #FF0658;
|
||||
border-radius: 40px;
|
||||
width: 23px;
|
||||
height: 23px;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
padding: 1px 2px;
|
||||
display: inline-block;
|
||||
font-size: 15px;
|
||||
}
|
||||
#auctionBidsModal #bonusEarned img{
|
||||
width: 15px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
#auctionBidsModal .wrap-already-taken, #auctionBidsModal .bonus-yet-to-be-obtained{
|
||||
display: none;
|
||||
}
|
||||
#auctionBidsModal .wrap-already-taken .txt-already-taken{
|
||||
color: #797979;
|
||||
}
|
||||
#auctionBidsModal .bonus-yet-to-be-obtained{
|
||||
color: #FF0658;
|
||||
}
|
||||
#auctionBidsModal #bonusEarned .wrap-details-bonus{
|
||||
text-align: center;
|
||||
margin: 7px 0;
|
||||
}
|
||||
#auctionBidsModal #modalConfirmSlotStopGame{
|
||||
z-index: 11;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
height: 130px;
|
||||
background-color: #fff;
|
||||
width: 270px;
|
||||
margin: auto;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
display: none;
|
||||
}
|
||||
#auctionBidsModal #modalConfirmSlotStopGame .contentButton .btn{
|
||||
padding: 2px 13px;
|
||||
font-size: 12px;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
margin: 3px;
|
||||
}
|
||||
#auctionBidsModal #modalConfirmSlotStopGame .contentButton .btn-confirm{
|
||||
background-color: #55BC62
|
||||
}
|
||||
#auctionBidsModal #modalConfirmSlotStopGame .contentButton .btn-cancel{
|
||||
background-color: #BFBFBF;
|
||||
}
|
||||
#auctionBidsModal #modalConfirmSlotStopGame .contentButton{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 10px;
|
||||
}
|
||||
#auctionBidsModal #modalConfirmSlotStopGame .content{
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
#auctionBidsModal #modalConfirmSlotStopGame .title{
|
||||
color: #FF0202;
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
#auctionBidsModal .overlayModalConfirmSlotStopGame{
|
||||
background: rgba(0,0,0,0.2);
|
||||
top: 0;
|
||||
left: 0;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: none;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
$(document).ready(function () {
|
||||
window.myAuctionsControlDetail = new Array(); // array di oggetti deputato a contenere l'asta dove si sta autopuntando
|
||||
window.myAuctionsControlDetail_lock = false; // flag to lock SetInterval execution
|
||||
|
||||
/*
|
||||
*
|
||||
* @returns {undefined}
|
||||
* questa funzione si occupa di controllare ogni 2 secondi se l'asta (dettaglio) su cui c'è un'autopuntata sia realmente attive o c'è stato un blocco lato UI
|
||||
*
|
||||
*/
|
||||
|
||||
setInterval(
|
||||
function () {
|
||||
|
||||
if (window.myAuctionsControlDetail_lock == false) {
|
||||
|
||||
window.myAuctionsControlDetail_lock = true; // lock setinterval execution
|
||||
|
||||
//console.log("--- Checking autobids..."); // FOR DEBUG
|
||||
let isAuctionStarted_element = $(".auction-action-timer.auction-header-item-size.closed-timer"); // element not present if auction started
|
||||
|
||||
let callingAjax = false;
|
||||
if (isAuctionStarted_element.length == 0) { // check element not present if auction started
|
||||
|
||||
let element_value = $('.auction-autobid-current-value'); // recupero il valore delle puntate rimanenti nell'asta
|
||||
|
||||
if (element_value.length > 0) {
|
||||
let value = $(element_value[0]).text(); // recupero il valore delle puntate rimanenti nell'asta
|
||||
//console.log("Puntate autobid = "+value); // FOR DEBUG
|
||||
|
||||
if (value > 0) {
|
||||
let idasta = $('input.js-switch.autobid-switch').data("id"); // recupero l'id dell'asta
|
||||
//console.log("Checking Asta: " + idasta); // FOR DEBUG
|
||||
let timestamp = Date.now();
|
||||
|
||||
let myAuctions = {
|
||||
idasta: idasta,
|
||||
value: value,
|
||||
timestamp: timestamp,
|
||||
element_value: element_value
|
||||
}
|
||||
|
||||
if (window.myAuctionsControlDetail.length == 0) { // controllo che questa asta non sia già nell'array
|
||||
//console.log("Adding Asta in array."); // FOR DEBUG
|
||||
window.myAuctionsControlDetail = myAuctions;
|
||||
} else {
|
||||
if (window.myAuctionsControlDetail.value != value) { // controllo che il valore sia cambiato per in modo da aggiornare le informazioni
|
||||
//console.log("Value changed."); // FOR DEBUG
|
||||
window.myAuctionsControlDetail = myAuctions;
|
||||
} else {
|
||||
//console.log("Checking time..."); // FOR DEBUG
|
||||
// in questa condizione il valore non è cambiato dunque controllerò da quanto tempo non cambia
|
||||
var diffMs = (Date.now() - window.myAuctionsControlDetail.timestamp);
|
||||
//console.log("diffMs = "+diffMs); // FOR DEBUG
|
||||
//var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes
|
||||
var diffSecs = Math.round(((diffMs % 86400000) % 3600000) / 1000); // minutes
|
||||
//console.log("diffSecs = "+diffSecs); // FOR DEBUG
|
||||
|
||||
// nel caso in cui la differenza è maggiore o uguale a 2 minuti invoco la funzione che si occuperà di spedire le informazioni lato backend
|
||||
if (diffSecs >= 70) { // default 70 secs
|
||||
callingAjax = true;
|
||||
sentToVerification(myAuctions);
|
||||
window.myAuctionsControlDetail = new Array(); // elimino l'asta dall'array
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
window.myAuctionsControlDetail = new Array(); // elimino l'asta dall'array
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (callingAjax === false) {
|
||||
window.myAuctionsControlDetail_lock = false; // unlock setinterval execution
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
2000);
|
||||
|
||||
|
||||
function sentToVerification(myAuctions) {
|
||||
|
||||
// funzione che serve ad inviare al backend l'asta attiva ma con valori di autopuntata fermi da 2 min
|
||||
//console.log(myAuctions); // FOR DEBUG
|
||||
|
||||
$.ajax({
|
||||
url: "check_autobid.php",
|
||||
//dataType: json,
|
||||
method: 'POST',
|
||||
timeout: 10000, // default 10000
|
||||
data : {
|
||||
idasta: myAuctions.idasta,
|
||||
value: myAuctions.value,
|
||||
timestamp: myAuctions.timestamp
|
||||
},
|
||||
}).done(function (response) {
|
||||
window.myAuctionsControlDetail_lock = false; // unlock setinterval execution
|
||||
//console.log("response = " + response); // FOR DEBUG
|
||||
$(myAuctions.element_value).text(response);
|
||||
}).fail(function(jqXHR, textStatus){
|
||||
if(textStatus === 'timeout') {
|
||||
//console.log("Ajax timeout. Recall ajax."); // FOR DEBUG
|
||||
sentToVerification(myAuctions);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,306 @@
|
||||
function getTexts() {
|
||||
"use strict"
|
||||
return {
|
||||
dialog_confirm: "Sei sicuro di voler rimuovere l\'AutoPuntata?",
|
||||
autobid_active: "Hai attivato la funzione utilizzando le puntate prenotate",
|
||||
autobid_not_active: "Attiva la funzione utilizzando le puntate prenotate",
|
||||
autobid_add: "AGGIUNGI",
|
||||
autobid_insert: "INSERISCI"
|
||||
};
|
||||
}
|
||||
|
||||
function enableAutobid() {
|
||||
"use strict";
|
||||
|
||||
$(".auction-action-autobid-trigger")
|
||||
.toggleClass("button-fucsia-flat", true)
|
||||
.toggleClass("button-gray-flat", false)
|
||||
.off('click')
|
||||
.on('click', setAutobid);
|
||||
|
||||
$(".auction-action-autobid-input")
|
||||
.attr('disabled', false)
|
||||
.off("keyup").keyup(function (e) {
|
||||
if (13 == e.which)
|
||||
$(".auction-action-autobid-trigger").click();
|
||||
$(".auction-action-autobid-mobile .auction-action-autobid-trigger").toggleClass("disable", $(this).val().length == 0);
|
||||
});
|
||||
}
|
||||
|
||||
function disableAutobid(reason) {
|
||||
"use strict";
|
||||
|
||||
$(".auction-action-autobid-trigger")
|
||||
.off('click')
|
||||
.on('click', function () {
|
||||
if (!reason)
|
||||
return;
|
||||
showErrorTooltip('.auction-action-autobid-trigger:eq(' + getAuctionSelector() + ')', {
|
||||
title: reason,
|
||||
html: true,
|
||||
container: "body",
|
||||
trigger: "manual",
|
||||
placement: "top",
|
||||
template: getTemplateTooltip("error")
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
|
||||
function unsetAutobid(evt) {
|
||||
"use strict";
|
||||
if ('undefined' == typeof window['autobid_switchery']) {
|
||||
return;
|
||||
}
|
||||
if (!isSwitchEnabled()) {
|
||||
if (evt) {
|
||||
window._autoController.setAutobid('delete', null, cleanUpAutobidSwitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cleanUpAutobidSwitch() {
|
||||
"use strict"
|
||||
$(".auction-autobid-button")
|
||||
.toggleClass("active", false)
|
||||
.find(".bi-autobid")
|
||||
.toggleClass("bi-dark", true)
|
||||
.toggleClass("bi-green", false);
|
||||
$(".auction-action-bid-mobile .auction-autobid-current-value").empty();
|
||||
setTimeout(function () {
|
||||
if (!isSmartphoneDevice())
|
||||
$('.auction-action-autobid-trigger').text(getTexts().autobid_insert);
|
||||
}, 400);
|
||||
updateAutobid(0);
|
||||
$('.auction-action-autobid:not(.auction-seat-autobid) .autobid-switch-container, .auction-action-autobid-mobile .autobid-switch-container').hide();
|
||||
}
|
||||
|
||||
function isSwitchEnabled() {
|
||||
return 'undefined' != typeof window['autobid_switchery'] && window.autobid_switchery[isSmartphoneDevice() ? 1 : 0].isChecked();
|
||||
}
|
||||
|
||||
function hideAutobid() {
|
||||
"use strict";
|
||||
$(".auction-action-autobid:visible").hide();
|
||||
}
|
||||
|
||||
function showLoginAutobid() {
|
||||
"use strict";
|
||||
$(".auction-action-autobid-trigger")
|
||||
.off('click')
|
||||
.on('click', window.parent.showLogin);
|
||||
|
||||
$(".auction-action-autobid-input").attr('disabled', true);
|
||||
}
|
||||
|
||||
function bindAutobidTrigger() {
|
||||
"use strict";
|
||||
var sNickLoggato = $("#NickLoggato").length > 0 ? $("#NickLoggato").val() : "";
|
||||
|
||||
if (sNickLoggato.length <= 0) {
|
||||
return showLoginAutobid();
|
||||
}
|
||||
$('.auction-action-autobid-trigger').off('click').on('click', function (evt) {
|
||||
var triggerElement = $(this);
|
||||
rippleButton(triggerElement, evt);
|
||||
|
||||
var autobidInputElement = $(".auction-action-autobid-input").eq(isSmartphoneDevice() ? 1 : 0);
|
||||
|
||||
var inputAmount = parseInt(autobidInputElement.val(), 10);
|
||||
var dataInputAmount = parseInt(autobidInputElement.data("amount"), 10);
|
||||
var autobidAmount = !isNaN(dataInputAmount) ? dataInputAmount : inputAmount;
|
||||
autobidInputElement.removeData("amount");
|
||||
|
||||
var autobidLoader = $(".auction-autobid-loader-container");
|
||||
var switchContainer = $('.autobid-switch-container');
|
||||
|
||||
triggerElement.removeAttr("data-autobid-button");
|
||||
|
||||
var isNotValidAmount = isNaN(inputAmount) && isNaN(dataInputAmount);
|
||||
if (isNotValidAmount) {
|
||||
if (isSmartphoneDevice() && !$("[data-stage='2']").is(":visible"))
|
||||
return $(".auction-action-autobid-mobile .auction-action-autobid-input").trigger("focus");
|
||||
} else {
|
||||
autobidLoader.removeClass("hidden");
|
||||
switchContainer.hide();
|
||||
}
|
||||
|
||||
cleanAutobidRequest();
|
||||
window._autoController.setAutobid('create', autobidAmount, function () {
|
||||
switchContainer.show();
|
||||
if (true == isSwitchEnabled())
|
||||
return;
|
||||
$(".autobid-switch.js-switch:hidden")
|
||||
.eq(isSmartphoneDevice() ? 1 : 0)
|
||||
.data("autobid-enabled", "true")
|
||||
.trigger('click');
|
||||
$(".auction-autobid-button")
|
||||
.toggleClass("active", true)
|
||||
.find(".bi-autobid")
|
||||
.toggleClass("bi-dark", false)
|
||||
.toggleClass("bi-green", true);
|
||||
|
||||
var id_product = getUrlParam("a").split("_").reverse()[0];
|
||||
$("#DA"+id_product).find('.favorite').attr('title', "Non puoi rimuoverla dai preferiti se è attiva l\'autopuntata");
|
||||
$("#DA"+id_product).find('.favorite').attr('data-original-title', "Non puoi rimuoverla dai preferiti se è attiva l\'autopuntata");
|
||||
$("#DA"+id_product).find('.favorite').attr('disabled', 'disabled');
|
||||
$("#DA"+id_product).find('.favorite').addClass('active');
|
||||
if (isDeepModal()) {
|
||||
window.parent.BidooCnf.instances.auction.features.startAutobidAuctionUpdate();
|
||||
}
|
||||
|
||||
if (isSmartphoneDevice())
|
||||
return;
|
||||
|
||||
setTimeout(function () {
|
||||
$('.auction-action-autobid-trigger').text(getTexts().autobid_add);
|
||||
}, 400);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function setAutobid() {
|
||||
"use strict";
|
||||
if ('undefined' == typeof window['autobid_switchery']) {
|
||||
return;
|
||||
}
|
||||
bindAutobidTrigger();
|
||||
$('.auction-action-autobid-trigger').not("[data-autobid-button]").trigger('click');
|
||||
}
|
||||
|
||||
function updateAutobid(value) {
|
||||
"use strict";
|
||||
var element = $(".auction-autobid-current-value");
|
||||
var oldValue = parseInt(element.eq(0).text(), 10);
|
||||
|
||||
if (value != oldValue) {
|
||||
element.toggle(value > 0);
|
||||
element.text(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function cleanAutobidRequest() {
|
||||
"use strict";
|
||||
$(".auction-action-autobid-input").val('');
|
||||
window._autoController.stopTicker();
|
||||
}
|
||||
|
||||
function updateAutobidStatus(status, value) {
|
||||
"use strict";
|
||||
switch (status) {
|
||||
case 'set':
|
||||
case 'create':
|
||||
{
|
||||
if (0 == value) {
|
||||
closeSwitch();
|
||||
} else {
|
||||
updateAutobid(value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'unset':
|
||||
{
|
||||
closeSwitch();
|
||||
unsetAutobid(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
function closeSwitch() {
|
||||
$('.js-switch.autobid-switch')
|
||||
.eq(isSmartphoneDevice() ? 1 : 0)
|
||||
.data("autobid-enabled", "false")
|
||||
.trigger("click");
|
||||
}
|
||||
function setAutobidUI(isAutobid) {
|
||||
"use strict"
|
||||
$(".auction-action-autobid-mobile .autobid-switch-container").toggle(isAutobid);
|
||||
$(".auction-action-bid-mobile .auction-autobid-button")
|
||||
.toggleClass("active", isAutobid)
|
||||
.find(".bi-autobid")
|
||||
.toggleClass("bi-dark", !isAutobid)
|
||||
.toggleClass("bi-green", isAutobid);
|
||||
$(".js-switch.autobid-switch")
|
||||
.data("autobid-enabled", "false")
|
||||
.trigger('click');
|
||||
}
|
||||
|
||||
function setCorrectPlaceholder(isFocused) {
|
||||
"use strict"
|
||||
this.attr("placeholder", isFocused ? "" : $(this).data("placeholder"));
|
||||
$(".auction-action-autobid-mobile .auction-action-autobid-trigger").toggleClass("disable", this.val().length == 0);
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
"use strict";
|
||||
window.autobid_switchery = [];
|
||||
window.autobid_seat_switchery = [];
|
||||
$(".js-switch.autobid-switch").each(function (k, item) {
|
||||
window.autobid_switchery.push(new Switchery(item, {size: 'small'}));
|
||||
});
|
||||
|
||||
$(".js-switch.autobid-seat-switch").each(function (k, item) {
|
||||
window.autobid_seat_switchery.push(new Switchery(item, {size: 'small'}));
|
||||
});
|
||||
|
||||
$('.js-switch.autobid-seat-switch').off('change').on('change', function () {
|
||||
var self = this;
|
||||
var isEnabled = $(this).is(':checked');
|
||||
if (isEnabled) {
|
||||
window.stage.getUpdate(function (update) {
|
||||
window._autoController.setAutobid('create', update.me.budget.total, function () {
|
||||
$(".autobid-seat-status").text(getTexts().autobid_active);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
window._autoController.setAutobid('delete', null, function () {
|
||||
updateAutobid(0);
|
||||
$(".autobid-seat-status").text(getTexts().autobid_not_active);
|
||||
});
|
||||
}
|
||||
if (isSmartphoneDevice())
|
||||
setAutobidUI(isEnabled);
|
||||
return true;
|
||||
});
|
||||
|
||||
$('.js-switch.autobid-switch').off('change').on('change', function () {
|
||||
var switchAutobid = $(this);
|
||||
if (isSmartphoneDevice() && $("[data-stage='2']").is(":visible"))
|
||||
return true;
|
||||
if (!switchAutobid.is(':checked') && ("false" == switchAutobid.data("autobid-enabled") || confirm(getTexts().dialog_confirm))) {
|
||||
unsetAutobid({});
|
||||
|
||||
var id_product = getUrlParam("a").split("_").reverse()[0];
|
||||
$("#DA"+id_product).find('.favorite').removeAttr('disabled');
|
||||
$("#DA"+id_product).find('.favorite').attr('title', "Rimuovi quest\'asta dalle tue preferite");
|
||||
if (isDeepModal()) {
|
||||
$("#DA"+id_product).find('.favorite').removeAttr('data-original-title');
|
||||
window.parent.BidooCnf.instances.auction.features.stopAutobidAuctionUpdate();
|
||||
setTimeout(function () {
|
||||
$("#divAsta"+id_product, parent.document).find('.favorite').removeAttr('data-original-title');
|
||||
$("#divAsta"+id_product, parent.document).find('.favorite').removeAttr('disabled');
|
||||
$("#divAsta"+id_product, parent.document).find('.favorite').attr('title', "Rimuovi quest\'asta dalle tue preferite");
|
||||
}, 500);
|
||||
} else {
|
||||
$("#DA"+id_product).find('.favorite').attr("data-original-title", "Rimuovi quest\'asta dalle tue preferite");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
$(".autobid-speed-dial > div > a").on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var self = $(this);
|
||||
var amount = parseInt(self.attr("data-amount"));
|
||||
$(".auction-action-autobid-input").data("amount", amount);
|
||||
$('.auction-action-autobid-trigger').attr("data-autobid-button", true).trigger('click');
|
||||
});
|
||||
|
||||
var scopeElement = $(".auction-action-autobid-input[data-placeholder]");
|
||||
scopeElement
|
||||
.focus(setCorrectPlaceholder.bind(scopeElement, true))
|
||||
.blur(setCorrectPlaceholder.bind(scopeElement, false));
|
||||
});
|
||||
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 40 KiB |
@@ -0,0 +1,255 @@
|
||||
.btn-promo, .btn-promo:hover {
|
||||
background: #2196f3 !important;
|
||||
}
|
||||
|
||||
.mCSB_inside > .mCSB_container {
|
||||
margin-right: 0px;
|
||||
}
|
||||
|
||||
.mCSB_scrollTools .mCSB_draggerRail {
|
||||
width: 6px;
|
||||
background-color: #e2e2e2;
|
||||
}
|
||||
|
||||
.mCSB_scrollTools .mCSB_draggerContainer {
|
||||
left: 10px;
|
||||
}
|
||||
|
||||
.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar {
|
||||
background-color: #20cb9a !important;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#toggleBar {
|
||||
margin-left: 0 !important;
|
||||
left: 20px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.barra {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.btn-promo {
|
||||
margin-top: -2px;
|
||||
line-height: 17.5px;
|
||||
}
|
||||
|
||||
.view_gray_link {
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.leader-btn {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
text-transform: uppercase;
|
||||
font-size: 10px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.bid_chal img.img-lock{
|
||||
display: none;
|
||||
}
|
||||
.bid_chal img{
|
||||
margin-top: -3px;
|
||||
}
|
||||
.wrap-limit-unlock{
|
||||
color: #fff;
|
||||
background-color: #55bc62;
|
||||
border-radius: 5px;
|
||||
font-weight: bold;
|
||||
padding: 0;
|
||||
text-transform: initial;
|
||||
width: 120px;
|
||||
margin: -4px auto 0;
|
||||
}
|
||||
|
||||
.wrap-button-get-bonus{
|
||||
color: #000;
|
||||
background-color: #FFC642;
|
||||
border-radius: 5px;
|
||||
font-weight: bold;
|
||||
padding: 0;
|
||||
display: none;
|
||||
text-transform: initial;
|
||||
margin-top: -4px;
|
||||
}
|
||||
.wrap-button-get-bonus img{
|
||||
width: 14px;
|
||||
}
|
||||
.bid_chal {
|
||||
font-weight: bold;
|
||||
font-size: 13px;
|
||||
text-transform: none;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
|
||||
.next-level {
|
||||
background-color: #eaeaea;
|
||||
margin: 0;
|
||||
width: 124px;
|
||||
height: 8px;
|
||||
box-shadow: none;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
#tickNotif {
|
||||
background: white;
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
transform: rotate(-45deg);
|
||||
border: 1px solid #e2e2e2;
|
||||
position: fixed;
|
||||
margin-top: -15px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.notifIcon {
|
||||
margin-left: 0px;
|
||||
}
|
||||
|
||||
#boxarea.dodici {
|
||||
width: 920px;
|
||||
}
|
||||
|
||||
#tickNotif {
|
||||
margin-left: 17px;
|
||||
}
|
||||
|
||||
.small_notif {
|
||||
margin-left: 119px !important;
|
||||
}
|
||||
|
||||
.bonus_dialog {
|
||||
left: 48.5%;
|
||||
}
|
||||
|
||||
.leader_btn {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.tooltip.reach > .tooltip-inner .wrap{
|
||||
display: flex;
|
||||
}
|
||||
.tooltip.reach > .tooltip-inner .wrap img{
|
||||
width: 16px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.tooltip.reach > .tooltip-inner {
|
||||
background-color: #fff;
|
||||
border: 1px solid #333;
|
||||
color: #232323;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.tooltip.reach > .tooltip-inner > span {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.tooltip.reach > .tooltip-inner > span:last-child {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.tooltip.reach > .tooltip-inner strong {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.bid-challenge > strong {
|
||||
color: darkorange;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.tooltip.reach > .tooltip-inner {
|
||||
max-width: 300px;
|
||||
}
|
||||
|
||||
.leader-btn:hover, .leader-btn {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
.paid-all {
|
||||
color: #565454;
|
||||
margin-top: -5px;
|
||||
text-transform: initial;
|
||||
}
|
||||
.active-all {
|
||||
color: #55bc62;
|
||||
margin-top: -5px;
|
||||
text-transform: initial;
|
||||
}
|
||||
.paid-all img, .active-all img{
|
||||
width: 16px;
|
||||
}
|
||||
|
||||
.bar-right-side .pull-right{
|
||||
margin-right: -30px;
|
||||
}
|
||||
|
||||
.bar-right-side .pull-right > *,
|
||||
.bar-left-side > *{
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.bar-left-side{
|
||||
margin-top: 5px;
|
||||
}
|
||||
.auctions_won_bottom_bar { /*[GR]*/
|
||||
border: 2px solid #ffc518 !important;
|
||||
background-color:#fff;
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
border-radius: 5px;
|
||||
padding: 5px 10px;
|
||||
color:#3d3a3a;
|
||||
outline: 0;
|
||||
font-weight:bold;
|
||||
height:29px;
|
||||
vertical-align: top;
|
||||
}
|
||||
.auctions_won_bottom_bar:hover{ /*[GR]*/
|
||||
background-color: #ffc518 !important;
|
||||
color: #fff;
|
||||
}
|
||||
.auctions_won_bottom_bar .badge { /*[GR]*/
|
||||
background-color: #ff2f4e;
|
||||
left: 20px;
|
||||
top: -12px;
|
||||
margin-left: -20px;
|
||||
}
|
||||
.barra[data-lang="es"] #ba #boxarea .notifIcon{
|
||||
margin-left: 10px;
|
||||
}
|
||||
.barra[data-lang="es"] #ba #boxarea #lim{
|
||||
margin-left: 5px;
|
||||
|
||||
}
|
||||
.barra[data-lang="es"] #ba #boxarea .auctions_won_bottom_bar{
|
||||
margin-left: 5px;
|
||||
margin-top: 1px;
|
||||
|
||||
}
|
||||
@media(max-width: 1200px){
|
||||
.barra[data-lang="es"] #ba #boxarea .auctions_won_bottom_bar, .barra[data-lang="es"] #ba #boxarea #lim{
|
||||
width: 110px;
|
||||
font-size: 11px;
|
||||
padding: 5px;
|
||||
}
|
||||
.barra[data-lang="es"] .notif{
|
||||
margin: -5px 6px !important;
|
||||
}
|
||||
}
|
||||
.bidooBell{
|
||||
color: #c3c0c1;
|
||||
font-size: 21px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
.bidooBell:hover, .bidooBell:active, .bidooBell:focus, .bidooBell.active{
|
||||
color: #666666;
|
||||
transition: color 0.4s;
|
||||
}
|
||||
#auctionBidBottomBar{
|
||||
outline: none !important;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
function BottomBar(){
|
||||
"use strict"
|
||||
var self = this;
|
||||
self.footer = $(".footer");
|
||||
self.checkFooter();
|
||||
}
|
||||
|
||||
BottomBar.prototype.checkFooter = function() {
|
||||
"use strict"
|
||||
var self = this;
|
||||
if (!self.footer.length) return;
|
||||
$(window).scroll(function() {
|
||||
$(".goTop").find("i")
|
||||
.toggleClass("white_top_arrow", isElementInView(self.footer, false));
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
"use strict"
|
||||
new BottomBar();
|
||||
});
|
||||
|
After Width: | Height: | Size: 5.3 KiB |