feyris-tan ef86554f9a Import
2025-05-12 22:09:16 +02:00

83 lines
6.6 KiB
C#

using Npgsql;
using skyscraper5.Dvb.DataBroadcasting.IntModel;
using skyscraper5.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
{
private HashSet<DatabaseKeyInt> _knownInts;
public bool TestForIpMacNotification(IpMacNotification notification)
{
if (_knownInts == null)
_knownInts = new HashSet<DatabaseKeyInt>();
DatabaseKeyInt key = new DatabaseKeyInt(notification.PlatformId);
if (_knownInts.Contains(key))
return true;
bool result;
using (NpgsqlConnection conn = new NpgsqlConnection(connectionStringBuilder.ToString()))
{
conn.Open();
NpgsqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT dateadded FROM dvb_int WHERE platform_id = @id";
cmd.Parameters.AddWithValue("@id", NpgsqlTypes.NpgsqlDbType.Bigint, (long)notification.PlatformId);
NpgsqlDataReader reader = cmd.ExecuteReader();
result = reader.Read();
reader.Close();
cmd.Dispose();
conn.Close();
}
if (result)
_knownInts.Add(key);
return result;
}
public void StoreIpMacNotification(IpMacNotification notification)
{
EnqueueTask(x => WriteIpMacNotification(x, notification));
DatabaseKeyInt key = new DatabaseKeyInt(notification.PlatformId);
_knownInts.Add(key);
}
private void WriteIpMacNotification(NpgsqlConnection conn, IpMacNotification notification)
{
NpgsqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into dvb_int (platform_id, platform_name, platform_provider_name,\r\n platform_provider_name_language_code, platform_action_type, platform_name_language_code,\r\n platform_processing_order, target_type, target_name, operational_network_id,\r\n operational_mpe_fec_algorithm, operational_component_tag, operational_transport_stream_id,\r\n operational_time_slice_fec_id, operational_time_slicing, operational_onid, operational_sid,\r\n operational_time_slice_frame_size, operational_time_slice_max_average_rate,\r\n operational_time_slice_max_bust_duration) " +
"values " +
"(@platform_id,@platform_name,@platform_provider_name,@platform_provider_name_language_code,@platform_action_type,@platform_name_language_code,@platform_processing_order,@target_type,@target_name,@operational_network_id,@operational_mpe_fec_algorithm, @operational_component_tag, @operational_transport_stream_id,\r\n @operational_time_slice_fec_id, @operational_time_slicing, @operational_onid, @operational_sid,\r\n @operational_time_slice_frame_size, @operational_time_slice_max_average_rate,\r\n @operational_time_slice_max_bust_duration\r\n\r\n )";
cmd.Parameters.AddWithValue("@platform_id", NpgsqlTypes.NpgsqlDbType.Bigint, (long)notification.PlatformId);
cmd.Parameters.AddWithValue("@platform_name", NpgsqlTypes.NpgsqlDbType.Text, notification.PlatformName);
cmd.Parameters.AddWithValue("@platform_provider_name", NpgsqlTypes.NpgsqlDbType.Text, notification.PlatformProviderName);
cmd.Parameters.AddWithValue("@platform_provider_name_language_code", NpgsqlTypes.NpgsqlDbType.Varchar, notification.PlatformProviderNameLanguageCode);
cmd.Parameters.AddWithValue("@platform_action_type", NpgsqlTypes.NpgsqlDbType.Integer, notification.PlatformActionType);
cmd.Parameters.AddWithValue("@platform_name_language_code", NpgsqlTypes.NpgsqlDbType.Varchar, notification.PlatformNameLanguageCode);
cmd.Parameters.AddWithValue("@platform_processing_order", NpgsqlTypes.NpgsqlDbType.Integer, notification.PlatformProcessingOrder);
cmd.Parameters.AddWithValue("@target_type", NpgsqlTypes.NpgsqlDbType.Integer, notification.TargetType);
cmd.Parameters.AddWithValue("@target_name", NpgsqlTypes.NpgsqlDbType.Text, notification.TargetName);
//@operational_network_id,@operational_mpe_fec_algorithm,@operational_component_tag,@operational_transport_stream_id,@operational_time_slice_fec_id,@operational_time_slicing,@operational_onid,@operational_sid,@operational_time_slice_frame_size, @operational_time_slice_max_average_rate,\r\n @operational_time_slice_max_bust_duration\r\n\r\n )";
cmd.Parameters.AddWithValue("@operational_network_id", NpgsqlTypes.NpgsqlDbType.Integer, (int?)notification.OperationalNetworkId);
cmd.Parameters.AddWithValue("@operational_mpe_fec_algorithm", NpgsqlTypes.NpgsqlDbType.Integer, (int?)notification.OperationalMpeFecAlgorithm);
cmd.Parameters.AddWithValue("@operational_component_tag", NpgsqlTypes.NpgsqlDbType.Integer, (int?)notification.OperationalComponentTag);
cmd.Parameters.AddWithValue("@operational_transport_stream_id", NpgsqlTypes.NpgsqlDbType.Integer, (int?)notification.OperationalTransportStreamId);
cmd.Parameters.AddWithValue("@operational_time_slice_fec_id", NpgsqlTypes.NpgsqlDbType.Integer, (int?)notification.OperationalTimeSliceFecId);
cmd.Parameters.AddWithValue("@operational_time_slicing", NpgsqlTypes.NpgsqlDbType.Boolean, (bool?)notification.OperationalTimeSlicing);
cmd.Parameters.AddWithValue("@operational_onid", NpgsqlTypes.NpgsqlDbType.Integer, (int?)notification.OperationalOriginalNetworkId);
cmd.Parameters.AddWithValue("@operational_sid", NpgsqlTypes.NpgsqlDbType.Integer, (int?)notification.OperationalServiceId);
//@operational_time_slice_frame_size,@operational_time_slice_max_average_rate,@operational_time_slice_max_bust_duration
cmd.Parameters.AddWithValue("@operational_time_slice_frame_size", NpgsqlTypes.NpgsqlDbType.Integer, (int?)notification.OperationalTimeSliceFrameSize);
cmd.Parameters.AddWithValue("@operational_time_slice_max_average_rate", NpgsqlTypes.NpgsqlDbType.Integer, (int?)notification.OperationalTimeSliceMaxAverageRate);
cmd.Parameters.AddWithValue("@operational_time_slice_max_bust_duration", NpgsqlTypes.NpgsqlDbType.Integer, (int?)notification.OperationalTimeSliceMaxBurstDuration);
cmd.Parameters.CheckNulls();
cmd.ExecuteNonQuery();
}
}
}