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

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

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

--- trunk/libxmltv/Core/XMLTVSource.cs	2013/03/09 09:29:40	72
+++ trunk/libxmltv/Core/XMLTVSource.cs	2013/03/09 11:28:41	77
@@ -5,6 +5,7 @@
 using libxmltv.Interfaces;
 using System.Diagnostics;
 using System.Xml.Linq;
+using System.Reflection;
 
 namespace libxmltv.Core
 {
@@ -25,19 +26,50 @@
         //    this.GeneratorName = generatorname;
         //    this.GeneratorUrl = generatorurl;
         //}
-        public XMLTVSource() : base(null) 
+        public XMLTVSource()
+            : base(null, XMLTVConstants.ROOT_ELEMENT) 
         {
             this.SourceName = string.Empty;
             this.GeneratorName = string.Empty;
             this.GeneratorUrl = string.Empty;
         }
-        public XMLTVSource(XMLTVRuntimeInstance instance) : base(instance)
+        public XMLTVSource(XMLTVRuntimeInstance instance) : base(instance, XMLTVConstants.ROOT_ELEMENT)
         {
-            xmltv_logger.Debug.WriteLine("Creating Instance of XMLTVSource");
+            xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVSource");
             Create();
-            xmltv_logger.Debug.WriteLine("Created Instance of XMLTVSource '{0}'", SourceName);
+            xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVSource '{0}'", SourceName);
+            UpdateInstance();
         }
-       
+
+        private void UpdateInstance()
+        {
+            bool found_field = false;
+            var instance_type = this.GetInstance().GetType();
+            var fields = instance_type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
+            foreach (var field in fields)
+            {
+                if (field.FieldType == typeof(IXMLTVSource))
+                {
+                    found_field = true;
+                    try
+                    {
+                        xmltv_logger.Verbose.Debug.WriteLine("Updating instance with source information: {0}", this.ToString());
+                        field.SetValue(this.GetInstance(), this);                        
+                        break;
+                    }
+                    catch (Exception ex)
+                    {
+                        xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with source information.");
+                        xmltv_logger.Verbose.Error.WriteLine(ex.ToString());
+                    }
+                }
+            }
+            if (!found_field)
+            {
+                xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with source information.");
+            }
+        }
+
         #region IXMLTVSource
         //private IXMLTV_PARSER XMLTV_PARSER { get; set; }
         public string SourceName { get; private set; }

 

  ViewVC Help
Powered by ViewVC 1.1.22