121 lines
4.3 KiB
C#

using skyscraper8.DvbNip;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Npgsql;
using NpgsqlTypes;
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();
}
public bool DvbNipTestForNetwork(BroadcastNetworkType network)
{
throw new NotImplementedException();
}
public void DvbNipInsertNetwork(BroadcastNetworkType network)
{
throw new NotImplementedException();
}
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();
}
}
}