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.Id, 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() { Id = string.Empty; Number = 0; CallSign = string.Empty; Name = string.Empty; } public Channel(XElement e) : this() { // get the channel id Id = e.Attribute(XMLTV_CONSTANTS.Channels.ChannelId).Value; var names = e.Descendants(XMLTV_CONSTANTS.Channels.ChannelDisplayName).ToList(); Number = Convert.ToInt32(names[1].Value); CallSign = names[2].Value; Name = names[3].Value; } #region IXMLTVChannel members public string Id { get; private set; } public int Number { get; private set; } public string CallSign { get; private set; } public string Name { get; private set; } #endregion public override string ToString() { return string.Format("{0}: {1} {2} ({3})", Id,Number,Name, CallSign); } } }