Aggiornamento dipendenze e passaggio a Newtonsoft.Json
- Aggiornamento alla versione 5.0.0-preview.25503.2 di Microsoft.ML. - Aggiornamento alla versione 33.1.0 di CsvHelper. - Aggiornamento alla versione 13.0.4 di Newtonsoft.Json. - Aggiornamento alla versione 112.1.1-alpha.0.4 di RestSharp. - Sostituzione di System.Text.Json con Newtonsoft.Json. - Modifiche nei metodi per utilizzare JToken e JObject. - Aggiornamento dei file .csproj e packages.config. - Miglioramenti nella gestione delle eccezioni e nei log. - Rimozione di riferimenti inutilizzati e miglioramenti generali.
This commit is contained in:
@@ -1,26 +1,27 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace HorseRacingPredictor.Football.Database
|
||||
{
|
||||
internal class Odds : HorseRacingPredictor.Football.Manager.Database
|
||||
{
|
||||
public void Upsert(SqlConnection connection, JsonNode bookmakers, int fixtureId)
|
||||
public void Upsert(SqlConnection connection, JToken bookmakers, int fixtureId)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Aggiungiamo log per tracciare la struttura dei dati
|
||||
LogError($"Inizio elaborazione quote per fixture {fixtureId} con {bookmakers?.AsArray().Count ?? 0} bookmakers", null);
|
||||
LogError($"Inizio elaborazione quote per fixture {fixtureId} con {bookmakers?.Children().Count() ?? 0} bookmakers", null);
|
||||
|
||||
// Per ogni bookmaker
|
||||
foreach (var bookmaker in bookmakers.AsArray())
|
||||
foreach (var bookmaker in bookmakers.Children())
|
||||
{
|
||||
int bookmakerId = bookmaker["id"].GetValue<int>();
|
||||
int bookmakerId = bookmaker["id"].Value<int>();
|
||||
var bets = bookmaker["bets"];
|
||||
|
||||
// Cerchiamo le quote di tipo Match Winner (1X2)
|
||||
foreach (var bet in bets.AsArray())
|
||||
foreach (var bet in bets.Children())
|
||||
{
|
||||
// Gestiamo in modo più sicuro il recupero di valori dal JSON
|
||||
string betName = GetStringValueSafe(bet, "name");
|
||||
@@ -35,7 +36,7 @@ namespace HorseRacingPredictor.Football.Database
|
||||
if (betTypeId == 0) continue;
|
||||
|
||||
// Estrai e salva le quote
|
||||
foreach (var value in bet["values"].AsArray())
|
||||
foreach (var value in bet["values"].Children())
|
||||
{
|
||||
// Gestiamo in modo più sicuro il recupero di valori dal JSON
|
||||
string valueType = GetStringValueSafe(value, "value");
|
||||
@@ -128,9 +129,9 @@ namespace HorseRacingPredictor.Football.Database
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ottiene un valore stringa da un JsonNode in modo sicuro
|
||||
/// Ottiene un valore stringa da un JToken in modo sicuro
|
||||
/// </summary>
|
||||
private string GetStringValueSafe(JsonNode node, string propertyName)
|
||||
private string GetStringValueSafe(JToken node, string propertyName)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -140,10 +141,10 @@ namespace HorseRacingPredictor.Football.Database
|
||||
var value = node[propertyName];
|
||||
|
||||
// Gestiamo diversi tipi di nodi
|
||||
if (value.GetValueKind() == System.Text.Json.JsonValueKind.String)
|
||||
return value.GetValue<string>();
|
||||
else if (value.GetValueKind() == System.Text.Json.JsonValueKind.Number)
|
||||
return value.GetValue<decimal>().ToString();
|
||||
if (value.Type == JTokenType.String)
|
||||
return value.Value<string>();
|
||||
else if (value.Type == JTokenType.Float || value.Type == JTokenType.Integer)
|
||||
return value.Value<decimal>().ToString();
|
||||
else
|
||||
return value.ToString();
|
||||
}
|
||||
@@ -155,9 +156,9 @@ namespace HorseRacingPredictor.Football.Database
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ottiene un valore decimale da un JsonNode in modo sicuro
|
||||
/// Ottiene un valore decimale da un JToken in modo sicuro
|
||||
/// </summary>
|
||||
private decimal GetDecimalValueSafe(JsonNode node, string propertyName)
|
||||
private decimal GetDecimalValueSafe(JToken node, string propertyName)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -167,15 +168,15 @@ namespace HorseRacingPredictor.Football.Database
|
||||
var value = node[propertyName];
|
||||
|
||||
// Gestiamo diversi tipi di nodi
|
||||
if (value.GetValueKind() == System.Text.Json.JsonValueKind.Number)
|
||||
if (value.Type == JTokenType.Float || value.Type == JTokenType.Integer)
|
||||
{
|
||||
// Assicuriamoci che il valore sia esattamente quello originale
|
||||
return value.GetValue<decimal>();
|
||||
return value.Value<decimal>();
|
||||
}
|
||||
else if (value.GetValueKind() == System.Text.Json.JsonValueKind.String)
|
||||
else if (value.Type == JTokenType.String)
|
||||
{
|
||||
// Utilizziamo InvariantCulture per garantire una corretta interpretazione dei decimali
|
||||
if (decimal.TryParse(value.GetValue<string>(),
|
||||
if (decimal.TryParse(value.Value<string>(),
|
||||
System.Globalization.NumberStyles.Any,
|
||||
System.Globalization.CultureInfo.InvariantCulture,
|
||||
out decimal result))
|
||||
@@ -185,7 +186,7 @@ namespace HorseRacingPredictor.Football.Database
|
||||
}
|
||||
|
||||
// Aggiungiamo un log più dettagliato per aiutare il debug
|
||||
LogError($"Impossibile convertire '{value}' (tipo: {value.GetValueKind()}) in decimal per proprietà '{propertyName}'", null);
|
||||
LogError($"Impossibile convertire '{value}' (tipo: {value.Type}) in decimal per proprietà '{propertyName}'", null);
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user