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; using System.Text; using System.Threading.Tasks; namespace skyscraper5.Data.PostgreSql { public partial class PostgresqlDataStore : DataStorage { private List _existingSgtLists; public bool TestForSgtList(SgtList list) { 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) { 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) { 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) { throw new NotImplementedException(); } } }