// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web.Caching; using System.Data; namespace Spludlow.Video { /// /// Provides cached accesss to the DVB TextTables created by the "MediaPortal" class /// public class VideoData { public DataSet DataSet; private string CacheName = "Spludlow.Video.VideoData"; public VideoData() { this.DataSet = (DataSet) Spludlow.Caching.Get(CacheName); if (this.DataSet == null) { this.DataSet = new DataSet(); DataTable table; DateTime startTime = DateTime.Now; table = Spludlow.Data.TextTable.ReadFile(Spludlow.Config.ProgramData + @"\Data\DVB.txt"); table.TableName = "Channels"; this.DataSet.Tables.Add(table); table = Spludlow.Data.TextTable.ReadFile(Spludlow.Config.ProgramData + @"\Data\DVBProgrammes.txt"); table.TableName = "Programmes"; this.DataSet.Tables.Add(table); table = Spludlow.Data.TextTable.ReadText(new string[] { "ChannelName HDChannelName", "String* String", "BBC ONE E Mid BBC ONE HD", "BBC TWO BBC TWO HD", "ITV ITV HD", "Channel 4 Channel 4 HD", "Channel 5 Channel 5 HD", "CBBC CBBC HD", }); table.TableName = "HDChannels"; this.DataSet.Tables.Add(table); Spludlow.Log.Info("VideoData; Data Loaded took: " + Spludlow.Text.TimeTook(startTime)); Spludlow.Caching.Set(CacheName, this.DataSet); } } public DataTable Channels { get { return this.DataSet.Tables["Channels"]; } } public DataTable Programmes { get { return this.DataSet.Tables["Programmes"]; } } public DataRow HdEquivalent(string channelName) { DataRow hdRow = this.DataSet.Tables["HDChannels"].Rows.Find(channelName); if (hdRow == null) return null; channelName = (string)hdRow["HDChannelName"]; return this.FindChannel(channelName); } public DataRow FindChannel(string channelName) { DataTable table = this.DataSet.Tables["Channels"]; string filter = "Name = '" + channelName.Replace("'", "''") + "'"; DataRow[] rows = table.Select(filter); if (rows.Length == 0) return null; if (rows.Length > 1) { string subject = "Find Channel on Name, multiple matches: " + channelName + ", count: " + rows.Length; Spludlow.Log.Error(subject, new object[] { table }); throw new ApplicationException(subject); } return rows[0]; } public void LogDataSet() { Spludlow.Log.Report("Video Data", new object[] { this.DataSet }); } } }