Implemented DvbNipTestForNetwork and DvbNipInsertNetwork in PostgreSQL.

This commit is contained in:
feyris-tan 2025-06-25 21:22:46 +02:00
parent 82a0576903
commit 0a6c1a9acd

View File

@ -1,12 +1,13 @@
using skyscraper8.DvbNip;
using Npgsql;
using NpgsqlTypes;
using skyscraper8.DvbNip;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Npgsql;
using NpgsqlTypes;
namespace skyscraper5.Data.PostgreSql
{
@ -75,14 +76,75 @@ namespace skyscraper5.Data.PostgreSql
throw new NotImplementedException();
}
private bool[] _dvbNipKnownNetworks;
public bool DvbNipTestForNetwork(BroadcastNetworkType network)
{
throw new NotImplementedException();
if (_dvbNipKnownNetworks == null)
_dvbNipKnownNetworks = new bool[ushort.MaxValue];
if (_dvbNipKnownNetworks[network.NIPNetworkID])
return true;
bool result = false;
using (NpgsqlConnection connection = new NpgsqlConnection(connectionStringBuilder.ToString()))
{
connection.Open();
NpgsqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT dateadded FROM dvbnip_network WHERE nid = @nid";
command.Parameters.AddWithValue("@nid", NpgsqlDbType.Integer, (int)network.NIPNetworkID);
NpgsqlDataReader dataReader = command.ExecuteReader();
if (dataReader.Read())
{
_dvbNipKnownNetworks[network.NIPNetworkID] = true;
result = true;
}
dataReader.Close();
connection.Close();
}
return result;
}
public void DvbNipInsertNetwork(BroadcastNetworkType network)
{
throw new NotImplementedException();
_dvbNipKnownNetworks[network.NIPNetworkID] = true;
EnqueueTask(x => DvbNipInsertNetworkEx(x, network));
}
private void DvbNipInsertNetworkEx(NpgsqlConnection connection, BroadcastNetworkType network)
{
NpgsqlCommand command = connection.CreateCommand();
command.CommandText = "INSERT INTO dvbnip_network VALUES (@nid,DEFAULT,@pn,@nn,@nt,@op,@wef)";
command.Parameters.AddWithValue("@nid", NpgsqlDbType.Integer, (int)network.NIPNetworkID);
command.Parameters.AddWithValue("@pn", NpgsqlDbType.Text, network.NIPNetworkProviderName);
command.Parameters.AddWithValue("@nn", NpgsqlDbType.Text, network.NetworkName);
command.Parameters.AddWithValue("@nt", NpgsqlDbType.Integer, (int)network.NetworkType);
command.Parameters.AddWithValue("@op", NpgsqlDbType.Double, network.SatellitePosition.OrbitalPosition);
command.Parameters.AddWithValue("@wef", NpgsqlDbType.Integer, (int)network.SatellitePosition.West_East_flag);
command.ExecuteNonQuery();
command.Dispose();
foreach (NIPStreamType nipStreamType in network.NIPStream)
{
DvbNipInsertNetworkStreamType(connection, network.NIPNetworkID, nipStreamType);
}
}
private void DvbNipInsertNetworkStreamType(NpgsqlConnection connection, ushort networkNipNetworkId, NIPStreamType nipStreamType)
{
NpgsqlCommand command = connection.CreateCommand();
command.CommandText = "INSERT INTO dvbnip_network_stream VALUES (@nid,@cid,@lid,@sid,@spn,DEFAULT,@llf,@bt,@s)";
command.Parameters.AddWithValue("@nid", NpgsqlDbType.Integer, (int)networkNipNetworkId);
command.Parameters.AddWithValue("@cid", NpgsqlDbType.Integer, int.Parse(nipStreamType.NIPCarrierID));
command.Parameters.AddWithValue("@lid", NpgsqlDbType.Integer, int.Parse(nipStreamType.NIPLinkID));
command.Parameters.AddWithValue("@sid", NpgsqlDbType.Integer, (int)nipStreamType.NIPServiceID);
command.Parameters.AddWithValue("@spn", NpgsqlDbType.Text, nipStreamType.NIPStreamProviderName);
command.Parameters.AddWithValue("@llf", NpgsqlDbType.Integer, (int)nipStreamType.LinkLayerFormat);
command.Parameters.AddWithValue("@bt", NpgsqlDbType.Integer, (int)nipStreamType.BootstrapStream.BootstrapType);
command.Parameters.AddWithValue("@s", NpgsqlDbType.Integer, (int)nipStreamType.BootstrapStream.Status);
command.ExecuteNonQuery();
command.Dispose();
}
public bool DvbNipTestForService(BroadcastMediaStreamType broadcastMediaStreamType)