/[xmltv_parser]/trunk/libxmltv/Core/XMLTVChannelCollection.cs
ViewVC logotype

Diff of /trunk/libxmltv/Core/XMLTVChannelCollection.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libxmltv/Core/XMLTVChannelCollection.cs	2013/03/08 01:22:03	35
+++ trunk/libxmltv/Core/XMLTVChannelCollection.cs	2013/03/08 05:20:12	49
@@ -5,23 +5,34 @@
 using libxmltv.Interfaces;
 using System.Diagnostics;
 using System.Xml.Linq;
+using System.Windows.Forms;
 
 namespace libxmltv.Core
 {
-    internal class XMLTVChannelCollection
+    internal class XMLTVChannelCollection : IDisposable
     {
         private Dictionary<string, IXMLTVChannel> entries = new Dictionary<string, IXMLTVChannel>();
-        public XMLTVChannelCollection(object xmltv)
+        internal static void CreateInstance(XMLTVRuntimeInstance xmltv)
         {
-            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection");
-            IXMLTV_PARSER _xmltv;
-            if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
-            XMLTV_PARSER = _xmltv;
+            using (XMLTVChannelCollection g = new XMLTVChannelCollection(xmltv)) 
+            {
+                g.instance.Channels = g.Collection;
+                xmltv_logger.Log.Info.WriteLine(g.ToString());
+            }
+        }
+        private XMLTVRuntimeInstance instance;
+        public XMLTVChannelCollection(XMLTVRuntimeInstance xmltv)
+        {
+            xmltv_logger.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection");
+            //IXMLTV_PARSER _xmltv;
+            //if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
+            //XMLTV_PARSER = _xmltv;
+            instance = xmltv;
             Create();
         }
 
         #region IXMLTVSource
-        private IXMLTV_PARSER XMLTV_PARSER { get; set; }
+        //private IXMLTV_PARSER XMLTV_PARSER { get; set; }
         public Dictionary<string, IXMLTVChannel> Collection
         {
             get { return entries; }
@@ -30,18 +41,28 @@
 
         private void Create()
         {
-            var doc = XMLTV_PARSER.XMLTV_LOADER.XmlDoc;
+            var doc = XDocument.Parse(instance.XmlDoc);
 
-            foreach (var c in doc.Descendants(XMLTV_CONSTANTS.CHANNEL_ELEMENT))
+            foreach (var c in doc.Descendants(XMLTVConstants.CHANNEL_ELEMENT))
             {
+                if (instance.IsAborting)
+                {
+                    break;
+                }
                 Channel channel = new Channel(c);
                 entries.Add(channel.Id, channel);
+                Application.DoEvents();
             }
+            //instance.Channels = Collection;
         }
         public override string ToString()
         {
-            //return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl);
-            return string.Empty;
+            return string.Format("Total Channels Parsed: {0}", Collection == null ? 0 : Collection.Count);
+        }
+
+        public void Dispose()
+        {
+            //throw new NotImplementedException();
         }
     }
     [Serializable]
@@ -58,11 +79,15 @@
             : this()
         {
             // get the channel id
-            Id = e.Attribute(XMLTV_CONSTANTS.Channels.ChannelId).Value;
-            var names = e.Descendants(XMLTV_CONSTANTS.Channels.ChannelDisplayName).ToList();
+            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; }

 

  ViewVC Help
Powered by ViewVC 1.1.22