using System; using System.Collections.Generic; using System.Linq; using System.Text; using libxmltv.Interfaces; using System.Diagnostics; using System.Xml.Linq; namespace libxmltv.Core { internal class XMLTVChannelCollection { private Dictionary entries = new Dictionary(); public XMLTVChannelCollection(object xmltv) { XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection"); IXMLTV_PARSER _xmltv; if (!Internals.VerifyInstance(xmltv, out _xmltv)) { return; } XMLTV_PARSER = _xmltv; Create(); } #region IXMLTVSource private IXMLTV_PARSER XMLTV_PARSER { get; set; } public Dictionary Collection { get { return entries; } } #endregion private void Create() { var doc = XMLTV_PARSER.XMLTV_LOADER.XmlDoc; foreach (var c in doc.Descendants(XMLTV_CONSTANTS.CHANNEL_ELEMENT)) { Channel channel = new Channel(c); entries.Add(channel.ChannelId, channel); } } public override string ToString() { //return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl); return string.Empty; } } internal class Channel : IXMLTVChannel { public Channel() { ChannelId = string.Empty; ChannelNumber = 0; ChannelCallSign = string.Empty; ChannelName = string.Empty; } public Channel(XElement e) : this() { // get the channel id ChannelId = e.Attribute(XMLTV_CONSTANTS.Channels.ChannelId).Value; var names = e.Descendants(XMLTV_CONSTANTS.Channels.ChannelDisplayName).ToList(); ChannelNumber = Convert.ToInt32(names[1].Value); ChannelCallSign = names[2].Value; ChannelName = names[3].Value; } #region IXMLTVChannel members public string ChannelId { get; private set; } public int ChannelNumber { get; private set; } public string ChannelCallSign { get; private set; } public string ChannelName { get; private set; } #endregion } }