diff --git a/.gitignore b/.gitignore index a334d03..3120936 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,4 @@ imgui.ini /GUIs/skyscraper8.UI.ImGui/bin/Debug/net8.0/skyscraper5.ini /.vs/skyscraper8/CopilotIndices/17.14.698.11175 /GUIs/skyscraper8.UI.ImGui/bin/Debug/net8.0 +/.vs/skyscraper8/CopilotIndices/17.14.734.62261 diff --git a/DataTableStorages/skyscraper5.Data.PostgreSql/Sgt.cs b/DataTableStorages/skyscraper5.Data.PostgreSql/Sgt.cs index 63235c7..0a63ece 100644 --- a/DataTableStorages/skyscraper5.Data.PostgreSql/Sgt.cs +++ b/DataTableStorages/skyscraper5.Data.PostgreSql/Sgt.cs @@ -1,5 +1,9 @@ -using skyscraper5.Skyscraper.Scraper.Storage.Split; +using Newtonsoft.Json; +using Npgsql; +using NpgsqlTypes; +using skyscraper5.Skyscraper.Scraper.Storage.Split; using skyscraper8.Ses; +using skyscraper8.Skyscraper.Scraper.Storage.Utilities; using System; using System.Collections.Generic; using System.Linq; @@ -10,20 +14,88 @@ namespace skyscraper5.Data.PostgreSql { public partial class PostgresqlDataStore : DataStorage { + private List _existingSgtLists; public bool TestForSgtList(SgtList list) { - throw new NotImplementedException(); + if (_existingSgtLists == null) + _existingSgtLists = new List(); + + if (_existingSgtLists.Contains(list.ServiceListId)) + return true; + + bool result; + using (NpgsqlConnection connection = new NpgsqlConnection(connectionStringBuilder.ToString())) + { + connection.Open(); + NpgsqlCommand command = connection.CreateCommand(); + command.CommandText = "SELECT dateadded FROM astra_sgt WHERE slid = @slid"; + command.Parameters.AddParameter("@slid", NpgsqlDbType.Integer, (int)list.ServiceListId); + NpgsqlDataReader npgsqlDataReader = command.ExecuteReader(); + if (result = npgsqlDataReader.Read()) + { + _existingSgtLists.Add(list.ServiceListId); + } + npgsqlDataReader.Close(); + command.Dispose(); + connection.Close(); + } + return result; } public void InsertSgtList(SgtList list) { - throw new NotImplementedException(); + using (NpgsqlConnection connection = new NpgsqlConnection(connectionStringBuilder.ToString())) + { + connection.Open(); + NpgsqlCommand command = connection.CreateCommand(); + command.CommandText = "INSERT INTO astra_sgt VALUES (@slid,DEFAULT,@pds,@names,@cavailabilities)"; + command.Parameters.AddWithValue("@slid", NpgsqlDbType.Integer, (int)list.ServiceListId); + command.Parameters.AddWithValue("@pds", NpgsqlDbType.Bigint, (long)list.PrivateDataSpecifier); + command.Parameters.AddWithValue("@names", NpgsqlDbType.Json, JsonConvert.SerializeObject(list.Names)); + command.Parameters.AddWithValue("@cavailabilities", NpgsqlDbType.Json, JsonConvert.SerializeObject(list.CountryAvailabilities)); + SetNulls(command); + command.ExecuteNonQuery(); + connection.Close(); + connection.Dispose(); + } + + if (_existingSgtLists == null) + _existingSgtLists = new List(); + if (!_existingSgtLists.Contains(list.ServiceListId)) + _existingSgtLists.Add(list.ServiceListId); } + private HashSet _knownSgtServices; public bool TestForSgtService(SgtService child) { - throw new NotImplementedException(); + if (_knownSgtServices == null) + _knownSgtServices = new HashSet(); + + DatabaseKeySgtService key = child.GetDatabaseKey(); + if (_knownSgtServices.Contains(key)) + return true; + + bool result; + using (NpgsqlConnection connection = new NpgsqlConnection(connectionStringBuilder.ToString())) + { + connection.Open(); + NpgsqlCommand command = connection.CreateCommand(); + command.CommandText = "SELECT dateadded FROM astra_sgt_services WHERE slid = @slid AND sid = @sid AND tsid = @tsid AND onid = @onid"; + command.Parameters.AddWithValue("@slid", NpgsqlDbType.Integer, (int)child.ServiceListId); + command.Parameters.AddWithValue("@sid", NpgsqlDbType.Integer, (int)child.ServiceId); + command.Parameters.AddWithValue("@tsid", NpgsqlDbType.Integer, (int)child.TransportStreamId); + command.Parameters.AddWithValue("@onid", NpgsqlDbType.Integer, (int)child.OriginalNetworkId); + NpgsqlDataReader dataReader = command.ExecuteReader(); + if (result = dataReader.Read()) + { + _knownSgtServices.Add(key); + } + dataReader.Close(); + command.Dispose(); + connection.Close(); + } + return result; } public void InsertSgtService(SgtService child) diff --git a/DataTableStorages/skyscraper5.Data.PostgreSql/skyscraper5.Data.PostgreSql.csproj b/DataTableStorages/skyscraper5.Data.PostgreSql/skyscraper5.Data.PostgreSql.csproj index d02a6b5..d2e2d87 100644 --- a/DataTableStorages/skyscraper5.Data.PostgreSql/skyscraper5.Data.PostgreSql.csproj +++ b/DataTableStorages/skyscraper5.Data.PostgreSql/skyscraper5.Data.PostgreSql.csproj @@ -6,6 +6,7 @@ + diff --git a/FactoryStorages/skyscraper5.Storage.PostgresqlMinio/PostgresqlMinioStorageFactory.cs b/FactoryStorages/skyscraper5.Storage.PostgresqlMinio/PostgresqlMinioStorageFactory.cs index 5f48d0b..21a30b5 100644 --- a/FactoryStorages/skyscraper5.Storage.PostgresqlMinio/PostgresqlMinioStorageFactory.cs +++ b/FactoryStorages/skyscraper5.Storage.PostgresqlMinio/PostgresqlMinioStorageFactory.cs @@ -29,7 +29,7 @@ namespace skyscraper5.Storage.PostgresqlMinio ncsb.Port = PostgreSqlPort; ncsb.Username = PostgreSqlUsername; - if (Debugger.IsAttached) + if (Debugger.IsAttached) ncsb.Timeout = 1024; IMinioClient mc = new MinioClient() diff --git a/skyscraper8/Ses/SgtService.cs b/skyscraper8/Ses/SgtService.cs index c752725..cd779cd 100644 --- a/skyscraper8/Ses/SgtService.cs +++ b/skyscraper8/Ses/SgtService.cs @@ -1,5 +1,6 @@ using skyscraper5.Dvb.Descriptors; using skyscraper8.Ses.Descriptors; +using skyscraper8.Skyscraper.Scraper.Storage.Utilities; using System; using System.Collections.Generic; using System.Linq; @@ -53,5 +54,10 @@ namespace skyscraper8.Ses return ServiceDescriptor.ServiceName; } + + public DatabaseKeySgtService GetDatabaseKey() + { + return new DatabaseKeySgtService(ServiceListId, ServiceId, TransportStreamId, OriginalNetworkId); + } } } diff --git a/skyscraper8/Skyscraper/Scraper/Storage/Utilities/DatabaseKeySgtService.cs b/skyscraper8/Skyscraper/Scraper/Storage/Utilities/DatabaseKeySgtService.cs new file mode 100644 index 0000000..b1341b5 --- /dev/null +++ b/skyscraper8/Skyscraper/Scraper/Storage/Utilities/DatabaseKeySgtService.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace skyscraper8.Skyscraper.Scraper.Storage.Utilities +{ + public class DatabaseKeySgtService + { + public DatabaseKeySgtService(ushort serviceListId, ushort serviceId, ushort transportStreamId, ushort originalNetworkId) + { + ServiceListId = serviceListId; + ServiceId = serviceId; + TransportStreamId = transportStreamId; + OriginalNetworkId = originalNetworkId; + } + + public ushort ServiceListId { get; } + public ushort ServiceId { get; } + public ushort TransportStreamId { get; } + public ushort OriginalNetworkId { get; } + + public override bool Equals(object? obj) + { + return obj is DatabaseKeySgtService service && + ServiceListId == service.ServiceListId && + ServiceId == service.ServiceId && + TransportStreamId == service.TransportStreamId && + OriginalNetworkId == service.OriginalNetworkId; + } + + public override int GetHashCode() + { + return HashCode.Combine(ServiceListId, ServiceId, TransportStreamId, OriginalNetworkId); + } + } +}