SGT Lists (not services) work in Postgresql now.

This commit is contained in:
feyris-tan 2025-06-05 22:15:32 +02:00
parent 60cf0b4ffe
commit 65f62e82cb
6 changed files with 123 additions and 5 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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<ushort> _existingSgtLists;
public bool TestForSgtList(SgtList list)
{
throw new NotImplementedException();
if (_existingSgtLists == null)
_existingSgtLists = new List<ushort>();
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<ushort>();
if (!_existingSgtLists.Contains(list.ServiceListId))
_existingSgtLists.Add(list.ServiceListId);
}
private HashSet<DatabaseKeySgtService> _knownSgtServices;
public bool TestForSgtService(SgtService child)
{
throw new NotImplementedException();
if (_knownSgtServices == null)
_knownSgtServices = new HashSet<DatabaseKeySgtService>();
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)

View File

@ -6,6 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql" Version="9.0.3" />
</ItemGroup>

View File

@ -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()

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}