183 lines
7.4 KiB
C#
183 lines
7.4 KiB
C#
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;
|
|
|
|
namespace skyscraper5.Data.PostgreSql
|
|
{
|
|
public partial class PostgresqlDataStore
|
|
{
|
|
private Dictionary<NipActualCarrierInformation, int> _knownNipCarriers;
|
|
|
|
public bool DvbNipTestForCarrier(NipActualCarrierInformation currentCarrierInformation)
|
|
{
|
|
if (_knownNipCarriers != null)
|
|
{
|
|
if (_knownNipCarriers.ContainsKey(currentCarrierInformation))
|
|
return true;
|
|
}
|
|
|
|
bool result = false;
|
|
using (NpgsqlConnection connection = new NpgsqlConnection(connectionStringBuilder.ToString()))
|
|
{
|
|
connection.Open();
|
|
NpgsqlCommand command = connection.CreateCommand();
|
|
command.CommandText = "SELECT serial FROM dvbnip_carrier_information WHERE nid = @nid AND cid = @cid AND lid = @lid AND sid = @sid";
|
|
command.Parameters.AddWithValue("@nid", NpgsqlDbType.Integer, (int)currentCarrierInformation.NipNetworkId);
|
|
command.Parameters.AddWithValue("@cid", NpgsqlDbType.Integer, (int)currentCarrierInformation.NipCarrierId);
|
|
command.Parameters.AddWithValue("@lid", NpgsqlDbType.Integer, (int)currentCarrierInformation.NipLinkId);
|
|
command.Parameters.AddWithValue("@sid", NpgsqlDbType.Integer, (int)currentCarrierInformation.NipServiceId);
|
|
NpgsqlDataReader dataReader = command.ExecuteReader();
|
|
if (dataReader.Read())
|
|
{
|
|
if (_knownNipCarriers == null)
|
|
_knownNipCarriers = new Dictionary<NipActualCarrierInformation, int>();
|
|
|
|
int value = dataReader.GetInt32(0);
|
|
_knownNipCarriers.Add(currentCarrierInformation, value);
|
|
result = true;
|
|
}
|
|
dataReader.Close();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public void DvbNipInsertCarrier(NipActualCarrierInformation currentCarrierInformation)
|
|
{
|
|
EnqueueTask(x => DvbNipInsertCarrierEx(x, currentCarrierInformation));
|
|
EnqueueTask(CommitTransaction);
|
|
}
|
|
|
|
private void DvbNipInsertCarrierEx(NpgsqlConnection connection, NipActualCarrierInformation currentCarrierInformation)
|
|
{
|
|
NpgsqlCommand command = connection.CreateCommand();
|
|
command.CommandText = "INSERT INTO dvbnip_carrier_information VALUES (DEFAULT,DEFAULT,@nid,@cid,@lid,@sid,@spn)";
|
|
command.Parameters.AddWithValue("@nid", NpgsqlDbType.Integer, (int)currentCarrierInformation.NipNetworkId);
|
|
command.Parameters.AddWithValue("@cid", NpgsqlDbType.Integer, (int)currentCarrierInformation.NipCarrierId);
|
|
command.Parameters.AddWithValue("@lid", NpgsqlDbType.Integer, (int)currentCarrierInformation.NipLinkId);
|
|
command.Parameters.AddWithValue("@sid", NpgsqlDbType.Integer, (int)currentCarrierInformation.NipServiceId);
|
|
command.Parameters.AddWithValue("@spn", NpgsqlDbType.Text, currentCarrierInformation.NipStreamProviderName);
|
|
int a = command.ExecuteNonQuery();
|
|
if (a != 1)
|
|
throw new DataException(String.Format("Wanted to insert 1 row, got {0}", a));
|
|
command.Dispose();
|
|
}
|
|
|
|
public bool DvbNipPrivateDataSpecifier(NipActualCarrierInformation currentCarrierInformation, DateTime versionUpdate,
|
|
uint privateDataSpecifier, List<string> privateDataSessions)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private bool[] _dvbNipKnownNetworks;
|
|
public bool DvbNipTestForNetwork(BroadcastNetworkType network)
|
|
{
|
|
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)
|
|
{
|
|
_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)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void DvbNipInsertService(BroadcastMediaStreamType broadcastMediaStreamType)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool DvbNipTestForMulticastSession(MulticastSessionType multicastSession)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void DvbNipInsertMulticastSession(MulticastSessionType multicastSession)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool DvbNipTestForMulticastGatewayConfigurationTransportSession(NipActualCarrierInformation carrier,
|
|
MulticastEndpointAddressType multicastEndpointAddressType)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void DvbNipInsertMulticastGatewayConfigurationTransportSession(NipActualCarrierInformation carrier,
|
|
MulticastGatewayConfigurationTransportSessionType multicastGatewayConfigurationTransportSession)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|