diff --git a/HorseRacingPredictor/HorseRacingPredictor/BettingPredictor.csproj b/HorseRacingPredictor/HorseRacingPredictor/BettingPredictor.csproj index 57b5cac..a289333 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/BettingPredictor.csproj +++ b/HorseRacingPredictor/HorseRacingPredictor/BettingPredictor.csproj @@ -1,8 +1,8 @@ - - - + + + Debug @@ -59,49 +59,50 @@ - ..\packages\CsvHelper.33.0.1\lib\net48\CsvHelper.dll + ..\packages\CsvHelper.33.1.0\lib\net48\CsvHelper.dll + True ..\packages\Dapper.2.1.66\lib\net461\Dapper.dll - ..\packages\Microsoft.Bcl.AsyncInterfaces.10.0.0-preview.4.25258.110\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + ..\packages\Microsoft.Bcl.AsyncInterfaces.10.0.0-rc.1.25451.107\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll ..\packages\Microsoft.Bcl.HashCode.6.0.0\lib\net462\Microsoft.Bcl.HashCode.dll - ..\packages\Microsoft.Bcl.Numerics.10.0.0-preview.4.25258.110\lib\net462\Microsoft.Bcl.Numerics.dll + ..\packages\Microsoft.Bcl.Numerics.10.0.0-rc.1.25451.107\lib\net462\Microsoft.Bcl.Numerics.dll - ..\packages\Microsoft.ML.5.0.0-preview.1.25127.4\lib\netstandard2.0\Microsoft.ML.Core.dll + ..\packages\Microsoft.ML.5.0.0-preview.25503.2\lib\netstandard2.0\Microsoft.ML.Core.dll - ..\packages\Microsoft.ML.CpuMath.5.0.0-preview.1.25127.4\lib\netstandard2.0\Microsoft.ML.CpuMath.dll + ..\packages\Microsoft.ML.CpuMath.5.0.0-preview.25503.2\lib\netstandard2.0\Microsoft.ML.CpuMath.dll - ..\packages\Microsoft.ML.5.0.0-preview.1.25127.4\lib\netstandard2.0\Microsoft.ML.Data.dll + ..\packages\Microsoft.ML.5.0.0-preview.25503.2\lib\netstandard2.0\Microsoft.ML.Data.dll - ..\packages\Microsoft.ML.DataView.5.0.0-preview.1.25127.4\lib\netstandard2.0\Microsoft.ML.DataView.dll + ..\packages\Microsoft.ML.DataView.5.0.0-preview.25503.2\lib\netstandard2.0\Microsoft.ML.DataView.dll - ..\packages\Microsoft.ML.FastTree.5.0.0-preview.1.25127.4\lib\netstandard2.0\Microsoft.ML.FastTree.dll + ..\packages\Microsoft.ML.FastTree.5.0.0-preview.25503.2\lib\netstandard2.0\Microsoft.ML.FastTree.dll - ..\packages\Microsoft.ML.5.0.0-preview.1.25127.4\lib\netstandard2.0\Microsoft.ML.KMeansClustering.dll + ..\packages\Microsoft.ML.5.0.0-preview.25503.2\lib\netstandard2.0\Microsoft.ML.KMeansClustering.dll - ..\packages\Microsoft.ML.5.0.0-preview.1.25127.4\lib\netstandard2.0\Microsoft.ML.PCA.dll + ..\packages\Microsoft.ML.5.0.0-preview.25503.2\lib\netstandard2.0\Microsoft.ML.PCA.dll - ..\packages\Microsoft.ML.5.0.0-preview.1.25127.4\lib\netstandard2.0\Microsoft.ML.StandardTrainers.dll + ..\packages\Microsoft.ML.5.0.0-preview.25503.2\lib\netstandard2.0\Microsoft.ML.StandardTrainers.dll - ..\packages\Microsoft.ML.5.0.0-preview.1.25127.4\lib\netstandard2.0\Microsoft.ML.Transforms.dll + ..\packages\Microsoft.ML.5.0.0-preview.25503.2\lib\netstandard2.0\Microsoft.ML.Transforms.dll - ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll ..\packages\RestSharp.112.1.1-alpha.0.4\lib\net48\RestSharp.dll @@ -111,21 +112,21 @@ ..\packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll - ..\packages\System.CodeDom.10.0.0-preview.4.25258.110\lib\net462\System.CodeDom.dll + ..\packages\System.CodeDom.10.0.0-rc.1.25451.107\lib\net462\System.CodeDom.dll - ..\packages\System.Collections.Immutable.10.0.0-preview.4.25258.110\lib\net462\System.Collections.Immutable.dll + ..\packages\System.Collections.Immutable.10.0.0-rc.1.25451.107\lib\net462\System.Collections.Immutable.dll - ..\packages\System.IO.Pipelines.10.0.0-preview.2.25163.2\lib\net462\System.IO.Pipelines.dll + ..\packages\System.IO.Pipelines.10.0.0-rc.1.25451.107\lib\net462\System.IO.Pipelines.dll ..\packages\System.Memory.4.6.3\lib\net462\System.Memory.dll - ..\packages\System.Numerics.Tensors.10.0.0-preview.4.25258.110\lib\net462\System.Numerics.Tensors.dll + ..\packages\System.Numerics.Tensors.10.0.0-rc.1.25451.107\lib\net462\System.Numerics.Tensors.dll ..\packages\System.Numerics.Vectors.4.6.1\lib\net462\System.Numerics.Vectors.dll @@ -134,13 +135,13 @@ ..\packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll - ..\packages\System.Text.Encodings.Web.10.0.0-preview.2.25163.2\lib\net462\System.Text.Encodings.Web.dll + ..\packages\System.Text.Encodings.Web.10.0.0-rc.1.25451.107\lib\net462\System.Text.Encodings.Web.dll - ..\packages\System.Text.Json.10.0.0-preview.2.25163.2\lib\net462\System.Text.Json.dll + ..\packages\System.Text.Json.10.0.0-rc.1.25451.107\lib\net462\System.Text.Json.dll - ..\packages\System.Threading.Channels.10.0.0-preview.4.25258.110\lib\net462\System.Threading.Channels.dll + ..\packages\System.Threading.Channels.10.0.0-rc.1.25451.107\lib\net462\System.Threading.Channels.dll ..\packages\System.Threading.Tasks.Extensions.4.6.3\lib\net462\System.Threading.Tasks.Extensions.dll @@ -240,10 +241,10 @@ Questo progetto fa riferimento a uno o più pacchetti NuGet che non sono presenti in questo computer. Usare lo strumento di ripristino dei pacchetti NuGet per scaricarli. Per altre informazioni, vedere http://go.microsoft.com/fwlink/?LinkID=322105. Il file mancante è {0}. - - - - + + + + - + \ No newline at end of file diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/BetType.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/BetType.cs index c44c58d..7a71681 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/BetType.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/BetType.cs @@ -1,20 +1,16 @@ using System; -using System.Collections.Generic; using System.Data.SqlClient; -using System.Linq; -using System.Text; -using System.Text.Json.Nodes; -using System.Threading.Tasks; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class BetType : HorseRacingPredictor.Football.Manager.Database { - public void Upsert(SqlConnection connection, JsonNode betType) + public void Upsert(SqlConnection connection, JToken betType) { try { - var id = betType["id"]?.GetValue(); + var id = betType["id"]?.Value(); if (id == null) return; // Salta il record se l'id è null var query = @" @@ -29,7 +25,7 @@ namespace HorseRacingPredictor.Football.Database using (var command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@bet_type_id", id); - command.Parameters.AddWithValue("@name", betType["name"]?.GetValue() ?? ""); + command.Parameters.AddWithValue("@name", betType["name"]?.Value() ?? ""); command.ExecuteNonQuery(); } } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Bookmaker.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Bookmaker.cs index 1746424..2a4e08f 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Bookmaker.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Bookmaker.cs @@ -1,20 +1,16 @@ using System; -using System.Collections.Generic; using System.Data.SqlClient; -using System.Linq; -using System.Text; -using System.Text.Json.Nodes; -using System.Threading.Tasks; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class Bookmaker : HorseRacingPredictor.Football.Manager.Database { - public void Upsert(SqlConnection connection, JsonNode bookmaker) + public void Upsert(SqlConnection connection, JToken bookmaker) { try { - var id = bookmaker["id"]?.GetValue(); + var id = bookmaker["id"]?.Value(); if (id == null) return; // Salta il record se l'id è null var query = @" @@ -29,7 +25,7 @@ namespace HorseRacingPredictor.Football.Database using (var command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@bookmaker_id", id); - command.Parameters.AddWithValue("@name", bookmaker["name"]?.GetValue() ?? ""); + command.Parameters.AddWithValue("@name", bookmaker["name"]?.Value() ?? ""); command.ExecuteNonQuery(); } } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Comparison.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Comparison.cs index 76c61d1..905307f 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Comparison.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Comparison.cs @@ -1,16 +1,12 @@ using System; -using System.Collections.Generic; using System.Data.SqlClient; -using System.Linq; -using System.Text; -using System.Text.Json.Nodes; -using System.Threading.Tasks; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class Comparison : HorseRacingPredictor.Football.Manager.Database { - public void Upsert(SqlConnection connection, int predictionId, JsonNode comparison) + public void Upsert(SqlConnection connection, int predictionId, JToken comparison) { try { @@ -56,20 +52,20 @@ namespace HorseRacingPredictor.Football.Database command.Parameters.AddWithValue("@prediction_id", predictionId); // Aggiungi tutti i parametri del confronto - command.Parameters.AddWithValue("@form_home", comparison["form"]?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@form_away", comparison["form"]?["away"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@att_home", comparison["att"]?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@att_away", comparison["att"]?["away"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@def_home", comparison["def"]?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@def_away", comparison["def"]?["away"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@poisson_home", comparison["poisson_distribution"]?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@poisson_away", comparison["poisson_distribution"]?["away"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@h2h_home", comparison["h2h"]?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@h2h_away", comparison["h2h"]?["away"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@goals_home", comparison["goals"]?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@goals_away", comparison["goals"]?["away"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@total_home", comparison["total"]?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@total_away", comparison["total"]?["away"]?.GetValue() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@form_home", comparison["form"]?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@form_away", comparison["form"]?["away"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@att_home", comparison["att"]?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@att_away", comparison["att"]?["away"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@def_home", comparison["def"]?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@def_away", comparison["def"]?["away"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@poisson_home", comparison["poisson_distribution"]?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@poisson_away", comparison["poisson_distribution"]?["away"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@h2h_home", comparison["h2h"]?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@h2h_away", comparison["h2h"]?["away"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@goals_home", comparison["goals"]?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@goals_away", comparison["goals"]?["away"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@total_home", comparison["total"]?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@total_away", comparison["total"]?["away"]?.Value() ?? (object)DBNull.Value); command.ExecuteNonQuery(); } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Fixture.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Fixture.cs index 41fba7e..9d18089 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Fixture.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Fixture.cs @@ -1,17 +1,17 @@ using System; using System.Data; using System.Data.SqlClient; -using System.Text.Json.Nodes; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class Fixture : HorseRacingPredictor.Football.Manager.Database { - public void Upsert(SqlConnection connection, SqlTransaction transaction, JsonNode fixture) + public void Upsert(SqlConnection connection, SqlTransaction transaction, JToken fixture) { try { - var id = fixture["id"]?.GetValue(); + var id = fixture["id"]?.Value(); if (id == null) return; // Salta il record se l'id è null var query = @" @@ -63,20 +63,20 @@ namespace HorseRacingPredictor.Football.Database // Parametri principali command.Parameters.AddWithValue("@fixture_id", id); - command.Parameters.AddWithValue("@timezone", fixture["timezone"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@date", fixture["date"]?.GetValue() ?? DateTime.MinValue); - command.Parameters.AddWithValue("@timestamp", fixture["timestamp"]?.GetValue() ?? 0L); - command.Parameters.AddWithValue("@referee", fixture["referee"]?.GetValue() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@timezone", fixture["timezone"]?.Value() ?? ""); + command.Parameters.AddWithValue("@date", fixture["date"]?.Value() ?? DateTime.MinValue); + command.Parameters.AddWithValue("@timestamp", fixture["timestamp"]?.Value() ?? 0L); + command.Parameters.AddWithValue("@referee", fixture["referee"]?.Value() ?? (object)DBNull.Value); // Parametri venue - int? venueId = venue?["id"]?.GetValue(); + int? venueId = venue?["id"]?.Value(); command.Parameters.AddWithValue("@venue_id", venueId.HasValue ? (object)venueId.Value : DBNull.Value); // Parametri status - command.Parameters.AddWithValue("@status_long", status?["long"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@status_short", status?["short"]?.GetValue() ?? ""); + command.Parameters.AddWithValue("@status_long", status?["long"]?.Value() ?? ""); + command.Parameters.AddWithValue("@status_short", status?["short"]?.Value() ?? ""); - int? elapsed = status?["elapsed"]?.GetValue(); + int? elapsed = status?["elapsed"]?.Value(); int? extra = null; // Assumo che l'API restituisca questo valore, altrimenti va gestito come gli altri command.Parameters.AddWithValue("@status_elapsed", elapsed.HasValue ? (object)elapsed.Value : DBNull.Value); @@ -101,11 +101,11 @@ namespace HorseRacingPredictor.Football.Database /// /// Metodo di supporto per inserire/aggiornare le informazioni sulla venue /// - private void UpsertVenue(SqlConnection connection, SqlTransaction transaction, JsonNode venue) + private void UpsertVenue(SqlConnection connection, SqlTransaction transaction, JToken venue) { try { - var id = venue["id"]?.GetValue(); + var id = venue["id"]?.Value(); if (id == null) return; var query = @" @@ -121,8 +121,8 @@ namespace HorseRacingPredictor.Football.Database using (var command = new SqlCommand(query, connection, transaction)) { command.Parameters.AddWithValue("@venue_id", id); - command.Parameters.AddWithValue("@name", venue["name"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@city", venue["city"]?.GetValue() ?? ""); + command.Parameters.AddWithValue("@name", venue["name"]?.Value() ?? ""); + command.Parameters.AddWithValue("@city", venue["city"]?.Value() ?? ""); command.ExecuteNonQuery(); } } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/FixtureLeague.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/FixtureLeague.cs index ae95b57..8faf7b2 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/FixtureLeague.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/FixtureLeague.cs @@ -3,20 +3,20 @@ using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; -using System.Text.Json.Nodes; +using Newtonsoft.Json.Linq; using System.Threading.Tasks; namespace HorseRacingPredictor.Football.Database { internal class FixtureLeague : HorseRacingPredictor.Football.Manager.Database { - public void Upsert(SqlConnection connection, SqlTransaction transaction, int fixtureId, int leagueId, JsonNode leagueData) + public void Upsert(SqlConnection connection, SqlTransaction transaction, int fixtureId, int leagueId, JToken leagueData) { try { // Estrai i valori prima della query per utilizzarli nel log - string round = leagueData["round"]?.GetValue() ?? ""; - bool? standings = leagueData["standings"]?.GetValue(); + string round = leagueData["round"]?.Value() ?? ""; + bool? standings = leagueData["standings"]?.Value(); string standingsValue = standings.HasValue ? standings.Value.ToString() : "NULL"; // Log dell'operazione prima di tentare l'upsert diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Goals.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Goals.cs index b2de854..1dd96b9 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Goals.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Goals.cs @@ -1,12 +1,12 @@ using System; using System.Data.SqlClient; -using System.Text.Json.Nodes; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class Goals : HorseRacingPredictor.Football.Manager.Database { - public void Upsert(SqlConnection connection, JsonNode goals, int fixtureId) + public void Upsert(SqlConnection connection, JToken goals, int fixtureId) { try { @@ -27,8 +27,8 @@ namespace HorseRacingPredictor.Football.Database END"; using (var command = new SqlCommand(query, connection)) { - command.Parameters.AddWithValue("@home", goals["home"]?.GetValue() ?? 0); - command.Parameters.AddWithValue("@away", goals["away"]?.GetValue() ?? 0); + command.Parameters.AddWithValue("@home", goals["home"]?.Value() ?? 0); + command.Parameters.AddWithValue("@away", goals["away"]?.Value() ?? 0); command.Parameters.AddWithValue("@fixture_id", fixtureId); command.ExecuteNonQuery(); } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/League.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/League.cs index 7bbe13b..d452002 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/League.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/League.cs @@ -1,16 +1,16 @@ using System; using System.Data.SqlClient; -using System.Text.Json.Nodes; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class League : HorseRacingPredictor.Football.Manager.Database { - public void Upsert(SqlConnection connection, JsonNode league) + public void Upsert(SqlConnection connection, JToken league) { try { - var id = league["id"]?.GetValue(); + var id = league["id"]?.Value(); if (id == null) return; // Salta il record se l'id è null var query = @" @@ -25,11 +25,11 @@ namespace HorseRacingPredictor.Football.Database using (var command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@league_id", id); - command.Parameters.AddWithValue("@name", league["name"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@country", league["country"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@logo", league["logo"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@flag", league["flag"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@season", league["season"]?.GetValue() ?? 0); + command.Parameters.AddWithValue("@name", league["name"]?.Value() ?? ""); + command.Parameters.AddWithValue("@country", league["country"]?.Value() ?? ""); + command.Parameters.AddWithValue("@logo", league["logo"]?.Value() ?? ""); + command.Parameters.AddWithValue("@flag", league["flag"]?.Value() ?? ""); + command.Parameters.AddWithValue("@season", league["season"]?.Value() ?? 0); command.ExecuteNonQuery(); } } @@ -39,11 +39,11 @@ namespace HorseRacingPredictor.Football.Database } } - public void Upsert(SqlConnection connection, SqlTransaction transaction, JsonNode league) + public void Upsert(SqlConnection connection, SqlTransaction transaction, JToken league) { try { - var id = league["id"]?.GetValue(); + var id = league["id"]?.Value(); if (id == null) return; // Salta il record se l'id è null var query = @" @@ -58,11 +58,11 @@ namespace HorseRacingPredictor.Football.Database using (var command = new SqlCommand(query, connection, transaction)) { command.Parameters.AddWithValue("@league_id", id); - command.Parameters.AddWithValue("@name", league["name"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@country", league["country"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@logo", league["logo"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@flag", league["flag"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@season", league["season"]?.GetValue() ?? 0); + command.Parameters.AddWithValue("@name", league["name"]?.Value() ?? ""); + command.Parameters.AddWithValue("@country", league["country"]?.Value() ?? ""); + command.Parameters.AddWithValue("@logo", league["logo"]?.Value() ?? ""); + command.Parameters.AddWithValue("@flag", league["flag"]?.Value() ?? ""); + command.Parameters.AddWithValue("@season", league["season"]?.Value() ?? 0); command.ExecuteNonQuery(); } } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/LeagueStats.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/LeagueStats.cs index 44598f7..b561545 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/LeagueStats.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/LeagueStats.cs @@ -1,12 +1,12 @@ using System; using System.Data.SqlClient; -using System.Text.Json.Nodes; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class LeagueStats : HorseRacingPredictor.Football.Manager.Database { - public int Insert(SqlConnection connection, int? teamId, int? predictionId, bool isHome, JsonNode stats) + public int Insert(SqlConnection connection, int? teamId, int? predictionId, bool isHome, JToken stats) { try { @@ -35,27 +35,27 @@ namespace HorseRacingPredictor.Football.Database command.Parameters.AddWithValue("@team_id", teamId.HasValue ? (object)teamId.Value : DBNull.Value); command.Parameters.AddWithValue("@prediction_id", predictionId.HasValue ? (object)predictionId.Value : DBNull.Value); command.Parameters.AddWithValue("@is_home", isHome); - command.Parameters.AddWithValue("@form", stats["form"]?.GetValue() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@form", stats["form"]?.Value() ?? (object)DBNull.Value); var fixtures = stats["fixtures"]; - command.Parameters.AddWithValue("@fixtures_played_home", fixtures?["played"]?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@fixtures_played_away", fixtures?["played"]?["away"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@fixtures_played_total", fixtures?["played"]?["total"]?.GetValue() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@fixtures_played_home", fixtures?["played"]?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@fixtures_played_away", fixtures?["played"]?["away"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@fixtures_played_total", fixtures?["played"]?["total"]?.Value() ?? (object)DBNull.Value); var wins = stats["fixtures"]?["wins"]; - command.Parameters.AddWithValue("@wins_home", wins?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@wins_away", wins?["away"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@wins_total", wins?["total"]?.GetValue() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@wins_home", wins?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@wins_away", wins?["away"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@wins_total", wins?["total"]?.Value() ?? (object)DBNull.Value); var draws = stats["fixtures"]?["draws"]; - command.Parameters.AddWithValue("@draws_home", draws?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@draws_away", draws?["away"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@draws_total", draws?["total"]?.GetValue() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@draws_home", draws?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@draws_away", draws?["away"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@draws_total", draws?["total"]?.Value() ?? (object)DBNull.Value); var loses = stats["fixtures"]?["loses"]; - command.Parameters.AddWithValue("@loses_home", loses?["home"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@loses_away", loses?["away"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@loses_total", loses?["total"]?.GetValue() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@loses_home", loses?["home"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@loses_away", loses?["away"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@loses_total", loses?["total"]?.Value() ?? (object)DBNull.Value); command.ExecuteNonQuery(); } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Odds.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Odds.cs index e396613..c9282ed 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Odds.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Odds.cs @@ -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 bookmakerId = bookmaker["id"].Value(); 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 } /// - /// Ottiene un valore stringa da un JsonNode in modo sicuro + /// Ottiene un valore stringa da un JToken in modo sicuro /// - 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(); - else if (value.GetValueKind() == System.Text.Json.JsonValueKind.Number) - return value.GetValue().ToString(); + if (value.Type == JTokenType.String) + return value.Value(); + else if (value.Type == JTokenType.Float || value.Type == JTokenType.Integer) + return value.Value().ToString(); else return value.ToString(); } @@ -155,9 +156,9 @@ namespace HorseRacingPredictor.Football.Database } /// - /// Ottiene un valore decimale da un JsonNode in modo sicuro + /// Ottiene un valore decimale da un JToken in modo sicuro /// - 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(); + return value.Value(); } - 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(), + if (decimal.TryParse(value.Value(), 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) diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Prediction.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Prediction.cs index cc1f9ec..2251004 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Prediction.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Prediction.cs @@ -1,30 +1,30 @@ using System; using System.Data.SqlClient; -using System.Text.Json.Nodes; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class Prediction : HorseRacingPredictor.Football.Manager.Database { - public void Upsert(SqlConnection connection, JsonNode predictions, int fixtureId) + public void Upsert(SqlConnection connection, JToken predictions, int fixtureId) { try { // Estrazione dei dati dalla risposta JSON - string advice = predictions["advice"]?.GetValue(); + string advice = predictions["advice"]?.Value(); if (string.IsNullOrEmpty(advice)) return; // Nessuna previsione se non c'è consiglio // Estrazione degli altri valori, con gestione null - int? winnerId = predictions["winner"]?["id"]?.GetValue(); - string winnerName = predictions["winner"]?["name"]?.GetValue(); - string winnerComment = predictions["winner"]?["comment"]?.GetValue(); - bool? winOrDraw = predictions["win_or_draw"]?.GetValue(); - string underOver = predictions["under_over"]?.GetValue(); - string goalsHome = predictions["goals"]?["home"]?.GetValue(); - string goalsAway = predictions["goals"]?["away"]?.GetValue(); - string percentHome = predictions["percent"]?["home"]?.GetValue(); - string percentDraw = predictions["percent"]?["draw"]?.GetValue(); - string percentAway = predictions["percent"]?["away"]?.GetValue(); + int? winnerId = predictions["winner"]?["id"]?.Value(); + string winnerName = predictions["winner"]?["name"]?.Value(); + string winnerComment = predictions["winner"]?["comment"]?.Value(); + bool? winOrDraw = predictions["win_or_draw"]?.Value(); + string underOver = predictions["under_over"]?.Value(); + string goalsHome = predictions["goals"]?["home"]?.Value(); + string goalsAway = predictions["goals"]?["away"]?.Value(); + string percentHome = predictions["percent"]?["home"]?.Value(); + string percentDraw = predictions["percent"]?["draw"]?.Value(); + string percentAway = predictions["percent"]?["away"]?.Value(); // Query per l'upsert con tutti i campi disponibili var query = @" diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Score.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Score.cs index 5dd730f..02308e1 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Score.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Score.cs @@ -1,12 +1,12 @@ using System; using System.Data.SqlClient; -using System.Text.Json.Nodes; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class Score : HorseRacingPredictor.Football.Manager.Database { - public void Upsert(SqlConnection connection, JsonNode score, int fixtureId) + public void Upsert(SqlConnection connection, JToken score, int fixtureId) { try { @@ -26,14 +26,14 @@ namespace HorseRacingPredictor.Football.Database END"; using (var command = new SqlCommand(query, connection)) { - command.Parameters.AddWithValue("@home_halftime", score["halftime"]["home"]?.GetValue() ?? 0); - command.Parameters.AddWithValue("@away_halftime", score["halftime"]["away"]?.GetValue() ?? 0); - command.Parameters.AddWithValue("@home_fulltime", score["fulltime"]["home"]?.GetValue() ?? 0); - command.Parameters.AddWithValue("@away_fulltime", score["fulltime"]["away"]?.GetValue() ?? 0); - command.Parameters.AddWithValue("@home_extratime", score["extratime"]["home"]?.GetValue() ?? 0); - command.Parameters.AddWithValue("@away_extratime", score["extratime"]["away"]?.GetValue() ?? 0); - command.Parameters.AddWithValue("@home_penalty", score["penalty"]["home"]?.GetValue() ?? 0); - command.Parameters.AddWithValue("@away_penalty", score["penalty"]["away"]?.GetValue() ?? 0); + command.Parameters.AddWithValue("@home_halftime", score["halftime"]?["home"]?.Value() ?? 0); + command.Parameters.AddWithValue("@away_halftime", score["halftime"]?["away"]?.Value() ?? 0); + command.Parameters.AddWithValue("@home_fulltime", score["fulltime"]?["home"]?.Value() ?? 0); + command.Parameters.AddWithValue("@away_fulltime", score["fulltime"]?["away"]?.Value() ?? 0); + command.Parameters.AddWithValue("@home_extratime", score["extratime"]?["home"]?.Value() ?? 0); + command.Parameters.AddWithValue("@away_extratime", score["extratime"]?["away"]?.Value() ?? 0); + command.Parameters.AddWithValue("@home_penalty", score["penalty"]?["home"]?.Value() ?? 0); + command.Parameters.AddWithValue("@away_penalty", score["penalty"]?["away"]?.Value() ?? 0); command.Parameters.AddWithValue("@fixture_id", fixtureId); command.ExecuteNonQuery(); } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Team.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Team.cs index 8efa9b0..3f51d6c 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Team.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/Team.cs @@ -1,17 +1,17 @@ using System; using System.Data.SqlClient; -using System.Text.Json.Nodes; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class Team : HorseRacingPredictor.Football.Manager.Database { - public void UpsertTeams(SqlConnection connection, SqlTransaction transaction, JsonNode teams, int fixtureId) + public void UpsertTeams(SqlConnection connection, SqlTransaction transaction, JToken teams, int fixtureId) { try { - var homeTeamId = teams["home"]["id"]?.GetValue(); - var awayTeamId = teams["away"]["id"]?.GetValue(); + var homeTeamId = teams["home"]["id"]?.Value(); + var awayTeamId = teams["away"]["id"]?.Value(); if (homeTeamId == null || awayTeamId == null) return; // Salta il record se uno degli id è null var queryTeam = @" @@ -31,14 +31,14 @@ namespace HorseRacingPredictor.Football.Database // Upsert home team command.Parameters.AddWithValue("@team_id", homeTeamId); - command.Parameters.AddWithValue("@name", homeTeam["name"]?.GetValue() ?? ""); - command.Parameters.AddWithValue("@logo", homeTeam["logo"]?.GetValue() ?? ""); + command.Parameters.AddWithValue("@name", homeTeam["name"]?.Value() ?? ""); + command.Parameters.AddWithValue("@logo", homeTeam["logo"]?.Value() ?? ""); command.ExecuteNonQuery(); // Upsert away team command.Parameters["@team_id"].Value = awayTeamId; - command.Parameters["@name"].Value = awayTeam["name"]?.GetValue() ?? ""; - command.Parameters["@logo"].Value = awayTeam["logo"]?.GetValue() ?? ""; + command.Parameters["@name"].Value = awayTeam["name"]?.Value() ?? ""; + command.Parameters["@logo"].Value = awayTeam["logo"]?.Value() ?? ""; command.ExecuteNonQuery(); } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/TeamStats.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/TeamStats.cs index b5a26e8..f082c93 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Database/TeamStats.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Database/TeamStats.cs @@ -1,16 +1,12 @@ using System; -using System.Collections.Generic; using System.Data.SqlClient; -using System.Linq; -using System.Text; -using System.Text.Json.Nodes; -using System.Threading.Tasks; +using Newtonsoft.Json.Linq; namespace HorseRacingPredictor.Football.Database { internal class TeamStats : HorseRacingPredictor.Football.Manager.Database { - public int Insert(SqlConnection connection, int? teamId, int? predictionId, bool isHome, JsonNode stats) + public int Insert(SqlConnection connection, int? teamId, int? predictionId, bool isHome, JToken stats) { try { @@ -35,18 +31,18 @@ namespace HorseRacingPredictor.Football.Database command.Parameters.AddWithValue("@team_id", teamId.HasValue ? (object)teamId.Value : DBNull.Value); command.Parameters.AddWithValue("@prediction_id", predictionId.HasValue ? (object)predictionId.Value : DBNull.Value); command.Parameters.AddWithValue("@is_home", isHome); - command.Parameters.AddWithValue("@played", stats["played"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@form", stats["form"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@att", stats["att"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@def", stats["def"]?.GetValue() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@played", stats["played"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@form", stats["form"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@att", stats["att"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@def", stats["def"]?.Value() ?? (object)DBNull.Value); var goalsFor = stats["goals"]?["for"]; - command.Parameters.AddWithValue("@goals_for_total", goalsFor?["total"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@goals_for_average", goalsFor?["average"]?.GetValue() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@goals_for_total", goalsFor?["total"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@goals_for_average", goalsFor?["average"]?.Value() ?? (object)DBNull.Value); var goalsAgainst = stats["goals"]?["against"]; - command.Parameters.AddWithValue("@goals_against_total", goalsAgainst?["total"]?.GetValue() ?? (object)DBNull.Value); - command.Parameters.AddWithValue("@goals_against_average", goalsAgainst?["average"]?.GetValue() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@goals_against_total", goalsAgainst?["total"]?.Value() ?? (object)DBNull.Value); + command.Parameters.AddWithValue("@goals_against_average", goalsAgainst?["average"]?.Value() ?? (object)DBNull.Value); command.ExecuteNonQuery(); } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Main.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Main.cs index 7e895ca..7ae34a1 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Main.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Main.cs @@ -2,12 +2,11 @@ using System.Collections.Generic; using System.Data; using System.Linq; -using System.Text; using System.Threading.Tasks; -using RestSharp; -using System.Text.Json; -using System.Text.Json.Nodes; using System.Data.SqlClient; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using RestSharp; namespace HorseRacingPredictor.Football { @@ -156,20 +155,20 @@ namespace HorseRacingPredictor.Football return; } - var json = JsonDocument.Parse(fixturesResponse.Content).RootElement; + var json = JObject.Parse(fixturesResponse.Content); // Verifica che la risposta contenga dati validi - if (!json.TryGetProperty("response", out var responseElement)) + if (json["response"] == null) { return; } // Per ogni partita, recupera la previsione - foreach (var item in responseElement.EnumerateArray()) + foreach (var item in json["response"]) { try { - int fixtureId = item.GetProperty("fixture").GetProperty("id").GetInt32(); + int fixtureId = item["fixture"]["id"].Value(); // Utilizza il prediction manager per ottenere la previsione _predictionManager.GetPredictionByFixture(fixtureId); @@ -255,11 +254,10 @@ namespace HorseRacingPredictor.Football responses.Add(response); // Controlla se ci sono altre pagine - var json = JsonDocument.Parse(response.Content).RootElement; - if (json.TryGetProperty("paging", out var pagingElement) && - pagingElement.TryGetProperty("total", out var totalElement)) + var json = JObject.Parse(response.Content); + if (json["paging"] != null && json["paging"]["total"] != null) { - int totalPages = totalElement.GetInt32(); + int totalPages = json["paging"]["total"].Value(); hasMorePages = currentPage < totalPages; } else @@ -281,7 +279,7 @@ namespace HorseRacingPredictor.Football { try { - var jsonObject = JsonNode.Parse(jsonResponse); + var jsonObject = JObject.Parse(jsonResponse); _database.ExecuteTransactionalQuery("l'elaborazione dei dati calcistici", (connection, transaction) => { @@ -291,7 +289,7 @@ namespace HorseRacingPredictor.Football ((Manager.Database)_database).DisableAllConstraints(connection, transaction); // FASE 1: Inserisci le leghe - foreach (var responseItem in jsonObject["response"].AsArray()) + foreach (var responseItem in jsonObject["response"]) { var league = responseItem["league"]; if (league != null && league["id"] != null) @@ -301,11 +299,11 @@ namespace HorseRacingPredictor.Football } // FASE 2: Inserisci i bookmakers e i tipi di scommessa - foreach (var responseItem in jsonObject["response"].AsArray()) + foreach (var responseItem in jsonObject["response"]) { if (responseItem["bookmakers"] != null) { - foreach (var bookmaker in responseItem["bookmakers"].AsArray()) + foreach (var bookmaker in responseItem["bookmakers"]) { if (bookmaker["id"] != null) { @@ -314,7 +312,7 @@ namespace HorseRacingPredictor.Football // Tipi di scommessa if (bookmaker["bets"] != null) { - foreach (var bet in bookmaker["bets"].AsArray()) + foreach (var bet in bookmaker["bets"]) { if (bet["id"] != null && bet["name"] != null) { @@ -328,7 +326,7 @@ namespace HorseRacingPredictor.Football } // FASE 3: Inserisci le squadre (senza relazione con fixture) - foreach (var responseItem in jsonObject["response"].AsArray()) + foreach (var responseItem in jsonObject["response"]) { var teams = responseItem["teams"]; if (teams != null && teams["home"] != null && teams["away"] != null && @@ -340,7 +338,7 @@ namespace HorseRacingPredictor.Football } // FASE 4: Inserisci i fixture e venue - foreach (var responseItem in jsonObject["response"].AsArray()) + foreach (var responseItem in jsonObject["response"]) { var fixture = responseItem["fixture"]; if (fixture != null && fixture["id"] != null) @@ -350,7 +348,7 @@ namespace HorseRacingPredictor.Football } // FASE 5: Inserisci relazioni tra entità e dati dipendenti - foreach (var responseItem in jsonObject["response"].AsArray()) + foreach (var responseItem in jsonObject["response"]) { int? fixtureId = null; try @@ -358,7 +356,7 @@ namespace HorseRacingPredictor.Football var fixture = responseItem["fixture"]; if (fixture != null && fixture["id"] != null) { - fixtureId = fixture["id"].GetValue(); + fixtureId = fixture["id"].Value(); // Relazioni fixture-team var teams = responseItem["teams"]; @@ -372,7 +370,7 @@ namespace HorseRacingPredictor.Football var league = responseItem["league"]; if (league != null && league["id"] != null) { - int leagueId = league["id"].GetValue(); + int leagueId = league["id"].Value(); _fixtureLeagueRepository.Upsert(connection, transaction, fixtureId.Value, leagueId, league); } @@ -399,7 +397,7 @@ namespace HorseRacingPredictor.Football } // FASE 6: Inserisci dati che richiedono fixture e teams: quote e previsioni - foreach (var responseItem in jsonObject["response"].AsArray()) + foreach (var responseItem in jsonObject["response"]) { int? fixtureId = null; try @@ -407,7 +405,7 @@ namespace HorseRacingPredictor.Football var fixture = responseItem["fixture"]; if (fixture != null && fixture["id"] != null) { - fixtureId = fixture["id"].GetValue(); + fixtureId = fixture["id"].Value(); // Quote if (responseItem["bookmakers"] != null) @@ -442,15 +440,15 @@ namespace HorseRacingPredictor.Football } // Head-to-head - if (predictions["h2h"] != null && predictions["h2h"].AsArray().Any()) + if (predictions["h2h"] != null && predictions["h2h"].Any()) { _h2hRepository.DeleteForPrediction(connection, predictionId.Value); - foreach (var h2hFixture in predictions["h2h"].AsArray()) + foreach (var h2hFixture in predictions["h2h"]) { if (h2hFixture["fixture"] != null && h2hFixture["fixture"]["id"] != null) { - _h2hRepository.Insert(connection, predictionId.Value, h2hFixture["fixture"]["id"].GetValue()); + _h2hRepository.Insert(connection, predictionId.Value, h2hFixture["fixture"]["id"].Value()); } } } @@ -462,7 +460,7 @@ namespace HorseRacingPredictor.Football // Home team stats if (teams["home"] != null && teams["home"]["id"] != null && predictions["teams"]["home"] != null) { - int homeTeamId = teams["home"]["id"].GetValue(); + int homeTeamId = teams["home"]["id"].Value(); if (predictions["teams"]["home"]["team"] != null) { @@ -480,7 +478,7 @@ namespace HorseRacingPredictor.Football // Away team stats if (teams["away"] != null && teams["away"]["id"] != null && predictions["teams"]["away"] != null) { - int awayTeamId = teams["away"]["id"].GetValue(); + int awayTeamId = teams["away"]["id"].Value(); if (predictions["teams"]["away"]["team"] != null) { @@ -583,36 +581,36 @@ namespace HorseRacingPredictor.Football try { - var json = JsonDocument.Parse(response.Content).RootElement; + var json = JObject.Parse(response.Content); // Verifica che la risposta contenga dati validi - if (!json.TryGetProperty("response", out var responseElement)) + if (json["response"] == null) { return dataTable; } // Aggiungi righe - foreach (var item in responseElement.EnumerateArray()) + foreach (var item in json["response"]) { try { var row = dataTable.NewRow(); // Estrai i dati dalla risposta JSON - row["ID"] = item.GetProperty("fixture").GetProperty("id").GetInt32(); - row["Paese"] = item.GetProperty("league").GetProperty("country").GetString(); - row["Campionato"] = item.GetProperty("league").GetProperty("name").GetString(); - row["Data / Ora"] = DateTime.Parse(item.GetProperty("fixture").GetProperty("date").GetString()); - row["Stato"] = item.GetProperty("fixture").GetProperty("status").GetProperty("long").GetString(); - row["Casa"] = item.GetProperty("teams").GetProperty("home").GetProperty("name").GetString(); - row["Trasferta"] = item.GetProperty("teams").GetProperty("away").GetProperty("name").GetString(); + row["ID"] = item["fixture"]["id"].Value(); + row["Paese"] = item["league"]["country"].Value(); + row["Campionato"] = item["league"]["name"].Value(); + row["Data / Ora"] = DateTime.Parse(item["fixture"]["date"].Value()); + row["Stato"] = item["fixture"]["status"]["long"].Value(); + row["Casa"] = item["teams"]["home"]["name"].Value(); + row["Trasferta"] = item["teams"]["away"]["name"].Value(); // Per i goals, controlla se sono null - var goalsElement = item.GetProperty("goals"); - row["Goals Casa"] = goalsElement.GetProperty("home").ValueKind == JsonValueKind.Null ? - 0 : goalsElement.GetProperty("home").GetInt32(); - row["Goals Trasferta"] = goalsElement.GetProperty("away").ValueKind == JsonValueKind.Null ? - 0 : goalsElement.GetProperty("away").GetInt32(); + var goalsElement = item["goals"]; + row["Goals Casa"] = goalsElement["home"].Type == JTokenType.Null ? + 0 : goalsElement["home"].Value(); + row["Goals Trasferta"] = goalsElement["away"].Type == JTokenType.Null ? + 0 : goalsElement["away"].Value(); // Le colonne delle quote e previsione rimangono temporaneamente vuote row["Quota Casa"] = DBNull.Value; @@ -662,18 +660,18 @@ namespace HorseRacingPredictor.Football continue; } - var json = JsonDocument.Parse(response.Content).RootElement; + var json = JObject.Parse(response.Content); - if (!json.TryGetProperty("response", out var responseElement)) + if (json["response"] == null) { continue; } - foreach (var item in responseElement.EnumerateArray()) + foreach (var item in json["response"]) { try { - int fixtureId = item.GetProperty("fixture").GetProperty("id").GetInt32(); + int fixtureId = item["fixture"]["id"].Value(); // Trova la riga corrispondente nella tabella delle partite DataRow[] matchingRows = combinedTable.Select($"ID = {fixtureId}"); @@ -682,23 +680,23 @@ namespace HorseRacingPredictor.Football DataRow row = matchingRows[0]; // Cerca le quote del bookmaker (assumiamo Bet365 con ID 8) - if (item.TryGetProperty("bookmakers", out var bookmakersElement)) + if (item["bookmakers"] != null) { - foreach (var bookmaker in bookmakersElement.EnumerateArray()) + foreach (var bookmaker in item["bookmakers"]) { - if (bookmaker.GetProperty("id").GetInt32() == 8) // Bet365 + if (bookmaker["id"].Value() == 8) // Bet365 { - if (bookmaker.TryGetProperty("bets", out var betsElement)) + if (bookmaker["bets"] != null) { - foreach (var bet in betsElement.EnumerateArray()) + foreach (var bet in bookmaker["bets"]) { - if (bet.GetProperty("name").GetString() == "Match Winner") + if (bet["name"].Value() == "Match Winner") { // Elabora le quote 1X2 - foreach (var value in bet.GetProperty("values").EnumerateArray()) + foreach (var value in bet["values"]) { - string betType = value.GetProperty("value").GetString(); - string odd = value.GetProperty("odd").GetString(); + string betType = value["value"].Value(); + string odd = value["odd"].Value(); switch (betType) { @@ -729,16 +727,15 @@ namespace HorseRacingPredictor.Football var predictionResponse = _predictionManager.GetPredictionByFixture(fixtureId); if (predictionResponse != null && predictionResponse.IsSuccessful) { - var predictionJson = JsonDocument.Parse(predictionResponse.Content).RootElement; - if (predictionJson.TryGetProperty("response", out var predResponse) && - predResponse.EnumerateArray().Any()) + var predictionJson = JObject.Parse(predictionResponse.Content); + if (predictionJson["response"] != null && predictionJson["response"].Any()) { - var prediction = predResponse.EnumerateArray().First(); - if (prediction.TryGetProperty("predictions", out var predsElement) && - predsElement.TryGetProperty("winner", out var winnerElement) && - winnerElement.TryGetProperty("name", out var winnerNameElement)) + var prediction = predictionJson["response"].First; + if (prediction["predictions"] != null && + prediction["predictions"]["winner"] != null && + prediction["predictions"]["winner"]["name"] != null) { - row["Previsione"] = winnerNameElement.GetString(); + row["Previsione"] = prediction["predictions"]["winner"]["name"].Value(); } } } diff --git a/HorseRacingPredictor/HorseRacingPredictor/Football/Manager/API.cs b/HorseRacingPredictor/HorseRacingPredictor/Football/Manager/API.cs index 153ddb7..98450e3 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/Football/Manager/API.cs +++ b/HorseRacingPredictor/HorseRacingPredictor/Football/Manager/API.cs @@ -2,7 +2,6 @@ using System; using System.Threading.Tasks; using RestSharp; using HorseRacingPredictor.Football.Database; -using HorseRacingPredictor.Football.API; using League = HorseRacingPredictor.Football.API.League; using Fixture = HorseRacingPredictor.Football.API.Fixture; diff --git a/HorseRacingPredictor/HorseRacingPredictor/packages.config b/HorseRacingPredictor/HorseRacingPredictor/packages.config index 026db5e..65052d6 100644 --- a/HorseRacingPredictor/HorseRacingPredictor/packages.config +++ b/HorseRacingPredictor/HorseRacingPredictor/packages.config @@ -1,23 +1,28 @@  - - + + - + - - - - - + + + + + + - - + + + - + - + + + + \ No newline at end of file