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

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

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

--- trunk/libxmltv/Core/XMLTVRuntimeInstance.cs	2013/03/09 12:41:07	83
+++ trunk/libxmltv/Core/XMLTVRuntimeInstance.cs	2013/03/16 19:56:47	189
@@ -10,6 +10,8 @@
 using System.Globalization;
 using System.Diagnostics;
 using System.Xml.Linq;
+using Enterprise.Logging;
+using System.IO;
 
 namespace libxmltv.Core
 {
@@ -49,12 +51,13 @@
         private void init()
         {
             this.Source = new XMLTVSource();
-            this.Channels = new List<IXMLTVChannel>();
-            this.Programs = new List<IXMLTVProgram>();
+            this.Channels = new ChannelList();
+            this.Programs = new ProgramList();
             this.XmlFile_Name = string.Empty;
             this.XmlFile_FullName = string.Empty;
             this.XmlDoc = string.Empty;
             this.OnInstanceCreated = null;
+            this.ExtraEntries = new ExtraList();
         }
 
         #region IXMLTVRuntimeInstance members
@@ -71,10 +74,13 @@
         public string XmlDoc { get { return _XmlDoc; } set { _XmlDoc = value; } }
         private IXMLTVSource _Source;
         public IXMLTVSource Source { get { return _Source; } set { _Source = value; } }
-        private List<IXMLTVChannel> _Channels;
-        public List<IXMLTVChannel> Channels { get { return _Channels; } set { _Channels = value; } }
-        private List<IXMLTVProgram> _Programs;
-        public List<IXMLTVProgram> Programs { get { return _Programs; } set { _Programs = value; } }
+        private ChannelList _Channels;
+        public ChannelList Channels { get { return _Channels; } set { _Channels = value; } }
+        private ProgramList _Programs;
+        public ProgramList Programs { get { return _Programs; } set { _Programs = value; } }
+
+        private ExtraList _ExtraEntries;
+        public ExtraList ExtraEntries { get { return _ExtraEntries; } set { _ExtraEntries = value; } }
         #endregion       
         #region IOnInstanceCreated members
         [NonSerialized]
@@ -132,6 +138,7 @@
             }
             if (this.Channels != null)
             {
+                this.Channels.TrimExcess();
                 xmltv_logger.Info.WriteLine("Source Loaded: '{0}' Channels from source '{1}'", this.Channels.Count, this.Source.SourceName);
             }
             else
@@ -141,6 +148,7 @@
             }
             if (this.Programs != null)
             {
+                this.Programs.TrimExcess();
                 xmltv_logger.Info.WriteLine("Source Loaded: '{0}' Programs from source '{1}'", this.Programs.Count, this.Source.SourceName);
             }
             else
@@ -306,7 +314,7 @@
                 if (!CreateHandlerForNode(node)) { xmltv_logger.Verbose.Debug.WriteLine("Unable to create handler for node: '{0}'", node.Name.ToString()); }
                 node_index++;
                 progress = 100.0 * (node_index / total_nodes);
-                xmltv_logger.ReportProgress(this, new Enterprise.Logging.ReportProgressEventArgs((int)progress));
+                xmltv_logger.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Loading {0} ==> {1:00}%", this.gInstance.XmlFile_Name, (int)progress)));
                 Application.DoEvents();
             }
         }
@@ -337,6 +345,7 @@
                             var ctors = type.GetConstructors(flags);
                             bool has_default_ctor = false;
                             foreach (var ctor in ctors) { if (ctor.GetParameters().Count() == 0) { has_default_ctor = true; } }
+                            ctors = null;
                             if (!has_default_ctor) { continue; }
                             raw_instance = Activator.CreateInstance(type, flags, null, new object[0], culture);
                             if (raw_instance != null)
@@ -345,13 +354,23 @@
                                 if (handler_value != null && handler_value.ToString() == root_name)
                                 {
                                     handler_type = type;
+                                    handler_value = null;
+                                    raw_instance = null;
+                                    handler_prop = null;
+                                    iface = null;
                                     break;
                                 }
+                                handler_value = null;
                             }
+                            raw_instance = null;
                         }
+                        handler_prop = null;
                     }
+                    iface = null;
                 }
             }
+            asm = null;
+            types = null;
             if (handler_type == null) 
             {
                 StringBuilder node_builder = new StringBuilder();
@@ -362,15 +381,18 @@
             }
             xmltv_logger.Verbose.Debug.WriteLine("Created handler for root: '{0}'", root_name.ToString());
             raw_instance = Activator.CreateInstance(handler_type, flags, null, new object[] { gInstance }, culture);
+            raw_instance = null;
+            flags = 0;
+            culture = null;            
         }
 
         private bool CreateHandlerForNode(XElement node)
         {
             if (node == null) { throw new NullReferenceException("Node element is null"); }
             if (node.Name == null) { throw new NullReferenceException("Node element's Name is null"); }
-            var node_name = node.Name.ToString();
+            //var node_name = node.Name.ToString();
 
-            xmltv_logger.Verbose.Debug.WriteLine("Creating handler for node: '{0}'", node_name.ToString());
+            xmltv_logger.Verbose.Debug.WriteLine("Creating handler for node: '{0}'", node.Name.ToString());
             object raw_instance = null;
             BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
             CultureInfo culture = CultureInfo.CurrentCulture;
@@ -390,33 +412,79 @@
                             var ctors = type.GetConstructors(flags);
                             bool has_default_ctor = false;
                             foreach (var ctor in ctors) { if (ctor.GetParameters().Count() == 0) { has_default_ctor = true; } }
+                            ctors = null;
                             if (!has_default_ctor) { continue; }
                             raw_instance = Activator.CreateInstance(type, flags, null, new object[0], culture);
                             if (raw_instance != null)
                             {
                                 object handler_value = handler_prop.GetValue(raw_instance, null);
-                                if (handler_value != null && handler_value.ToString() == node_name)
+                                if (handler_value != null && handler_value.ToString() == node.Name.ToString())
                                 {
                                     handler_type = type;
+                                    handler_value = null;
+                                    raw_instance = null;
+                                    handler_prop = null;
+                                    iface = null;
                                     break;
                                 }
+                                handler_value = null;
                             }
+                            raw_instance = null;
                         }
+                        handler_prop = null;
                     }
+                    iface = null;
                 }
             }
-            if (handler_type == null) 
+            asm = null;
+            types = null;
+            if (handler_type == null)
             {
-                StringBuilder node_builder = new StringBuilder();
-                node_builder.AppendFormat("<{0} ", node.Name);
-                if (node.HasAttributes) { foreach (var attribute in node.Attributes()) { node_builder.AppendFormat("{0}=\"{1}\" ", attribute.Name, attribute.Value); } }
-                string node_text = string.Format("{0}>", node_builder.ToString().TrimEnd(new char[] { ' ' }));
-                throw new Exception(string.Format("Unable to find a compatible handler to parse node: {0}", node_text)); 
+                try
+                {
+                    raw_instance = Activator.CreateInstance(typeof(UnhandledNodeData), flags, null, new object[] { gInstance, node }, culture);
+                }
+                catch (Exception ex) { throw ex; }
+
+                if (raw_instance == null)
+                {
+                    StringBuilder node_builder = new StringBuilder();
+                    node_builder.AppendFormat("<{0} ", node.Name);
+                    if (node.HasAttributes) { foreach (var attribute in node.Attributes()) { node_builder.AppendFormat("{0}=\"{1}\" ", attribute.Name, attribute.Value); } }
+                    string node_text = string.Format("{0}>", node_builder.ToString().TrimEnd(new char[] { ' ' }));
+                    throw new Exception(string.Format("Unable to find a compatible handler to parse node: {0}", node_text));
+                }
             }
-            xmltv_logger.Verbose.Debug.WriteLine("Created handler for node: '{0}'", node_name.ToString());
-            raw_instance = Activator.CreateInstance(handler_type, flags, null, new object[] { gInstance, node }, culture);
+            else
+            {
+                xmltv_logger.Verbose.Debug.WriteLine("Created handler for node: '{0}'", node.Name.ToString());
+                raw_instance = Activator.CreateInstance(handler_type, flags, null, new object[] { gInstance, node }, culture);                
+            }
+            raw_instance = null;
+            flags = 0;
+            culture = null;
+            node = null;
             return true;
         }
+        #region UnhandledExtraMetaData
+        private class UnhandledNodeData : XMLTVBase<XMLTVRuntimeInstance>
+        {
+            public UnhandledNodeData() : base(null, null) { }
+            public UnhandledNodeData(XMLTVRuntimeInstance instance, XElement node)
+                : base(instance, null)
+            {
+                if (node == null) { throw new NullReferenceException("The node instance was null"); }
+                xmltv_logger.Verbose.Debug.WriteLine("Parsng unhandled node data: {0}", node.Name.ToString());
+                if (this.GetInstance() != null)
+                {
+                    ExtraMetaData data = new ExtraMetaData(node);
+                    instance.ExtraEntries.Add(data);
+                    data = null;
+                }
+                node = null;
+            }
+        }
+        #endregion
         
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22