using System; using System.Collections.Generic; using System.Linq; using System.Text; using libxmltv.Interfaces; using System.Diagnostics; using System.Xml.Linq; using System.Windows.Forms; namespace libxmltv.Core { internal class XMLTVChannelCollection : IDisposable { private Dictionary entries = new Dictionary(); internal static void CreateInstance(XMLTVRuntimeInstance xmltv) { using (XMLTVChannelCollection g = new XMLTVChannelCollection(xmltv)) { g.instance.Channels = g.Collection; } } private XMLTVRuntimeInstance instance; public XMLTVChannelCollection(XMLTVRuntimeInstance xmltv) { XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection"); //IXMLTV_PARSER _xmltv; //if (!Internals.VerifyInstance(xmltv, out _xmltv)) { return; } //XMLTV_PARSER = _xmltv; instance = xmltv; Create(); } #region IXMLTVSource //private IXMLTV_PARSER XMLTV_PARSER { get; set; } public Dictionary Collection { get { return entries; } } #endregion private void Create() { var doc = instance.XmlDoc; foreach (var c in doc.Descendants(XMLTVConstants.CHANNEL_ELEMENT)) { Channel channel = new Channel(c); entries.Add(channel.Id, channel); Application.DoEvents(); } //instance.Channels = Collection; } public override string ToString() { return string.Format("Channel Count: {0}", Collection == null ? 0 : Collection.Count); } public void Dispose() { //throw new NotImplementedException(); } } [Serializable] 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(XMLTVConstants.Channels.ChannelId).Value; XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id); var names = e.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList(); Number = Convert.ToInt32(names[1].Value); XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number); CallSign = names[2].Value; XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign); Name = names[3].Value; XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name); } #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); } } }