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

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

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

--- trunk/libxmltv/Core/XMLTVProgram.cs	2013/03/09 13:51:58	86
+++ trunk/libxmltv/Core/XMLTVProgram.cs	2013/03/09 14:33:18	87
@@ -57,22 +57,53 @@
         private void InternalDictionaryTestOrThrow()
         {
             if (Properties == null) { throw new NullReferenceException("Properties collection has not been initialized."); }
-            if (Properties.Count == 0) { throw new IndexOutOfRangeException("Properties collection has 0 elements."); }
+            //if (Properties.Count == 0) { throw new IndexOutOfRangeException("Properties collection has 0 elements."); }
         }
-        private void InternalProperyExistsOrThrow(string name)
+        private void InternalProperyExistsOrThrow(string propertyname)
         {
             InternalDictionaryTestOrThrow();
-            if (!Properties.ContainsKey(name)) { throw new KeyNotFoundException(string.Format("Property '{0}' does not exist", name)); }
+            //if (!ContainsProperty(propertyname)) { throw new KeyNotFoundException(string.Format("Property '{0}' does not exist.", propertyname)); }
         }
-        public object GetProperty(string name)
+
+        public void RemoveProperty(string propertyname)
+        {
+            if (ContainsProperty(propertyname))
+            {
+                Properties.Remove(propertyname);
+            }
+            else
+            {
+                throw new ArgumentException(string.Format("Property '{0}' deos not exist", propertyname), propertyname);
+            }
+        }
+
+        public void AddProperty(string propertyname) { AddProperty(propertyname, new object()); }
+        public void AddProperty(string propertyname, object propertyvalue)
+        {
+            if (!ContainsProperty(propertyname))
+            {
+                Properties.Add(propertyname, propertyvalue);
+            }
+            else
+            {
+                SetProperty(propertyname, propertyvalue);
+            }
+        }
+        public bool ContainsProperty(string propertyname)
         {
-            InternalProperyExistsOrThrow(name);
-            return Properties[name];            
+            return Properties.ContainsKey(propertyname);
         }
-        public void SetProperty(string name, object value)
+        public object GetProperty(string propertyname)
         {
-            InternalProperyExistsOrThrow(name);
-            Properties[name] = value;
+            InternalProperyExistsOrThrow(propertyname);
+            if (!ContainsProperty(propertyname)) { throw new KeyNotFoundException(string.Format("Property '{0}' does not exist.", propertyname)); }
+            return Properties[propertyname];            
+        }
+        public void SetProperty(string propertyname, object propertyvalue)
+        {
+            InternalProperyExistsOrThrow(propertyname);
+            if (!ContainsProperty(propertyname)) { throw new KeyNotFoundException(string.Format("Property '{0}' does not exist.", propertyname)); }
+            Properties[propertyname] = propertyvalue;
         }
         #endregion
         public override string ToString()
@@ -80,7 +111,7 @@
             return string.Format("{0}: {1} - {2} ({3}) ['{4}' <==> '{5}']",
                 GetProperty("Id").ToString(),
                 GetProperty(XMLTVConstants.Programs.ProgramTitle).ToString(),
-                GetProperty(XMLTVConstants.Programs.ProgramSubTitle), ToString(),
+                GetProperty(XMLTVConstants.Programs.ProgramSubTitle).ToString(),
                 GetProperty(XMLTVConstants.Programs.ProgramChannelId).ToString(),
                 ((DateTime)GetProperty(XMLTVConstants.Programs.ProgramStart)).ToString("yyyy/MM/dd hh:mm tt"),
                 ((DateTime)GetProperty(XMLTVConstants.Programs.ProgramStop)).ToString("yyyy/MM/dd hh:mm tt"));
@@ -165,7 +196,7 @@
 
             //ParseExtraData(node);
 
-            var nodes = node.Elements().ToList();
+            var nodes = node.DescendantsAndSelf().ToList();
             foreach (var sub_node in nodes)
             {
                 if (this.GetInstance().IsAborting)
@@ -175,7 +206,7 @@
                 CreateHandlerForProgramMetaDataNode(sub_node);
             }
         }
-        private DateTime ParseDate(string timeStamp)
+        private static DateTime ParseDate(string timeStamp)
         {
             DateTime dt = new DateTime();
             try
@@ -188,6 +219,7 @@
 
         private void CreateHandlerForProgramMetaDataNode(XElement node)
         {
+
             Type t = this.GetType();
             Assembly asm = t.Assembly;
             var types = asm.GetTypes();
@@ -239,7 +271,10 @@
                 string node_text = string.Format("{0}>", node_builder.ToString().TrimEnd(new char[] { ' ' }));
                 xmltv_logger.Verbose.Warn.WriteLine("Ignoring unhandled extra meta-data: {0}", node_text);
             }
-            raw_instance = Activator.CreateInstance(handler_type, flags, null, new object[] { this, node }, culture);
+            else
+            {
+                raw_instance = Activator.CreateInstance(handler_type, flags, null, new object[] { this, node }, culture);
+            }
         }
 
 
@@ -250,7 +285,12 @@
             public title() : base(null, XMLTVConstants.Programs.ProgramTitle) { }
             public title(XMLTVProgram instance, XElement node)
                 : base(instance, XMLTVConstants.Programs.ProgramTitle)
-            {
+            {                
+                if(node == null){throw new NullReferenceException("The node instance was null");}
+                if (node.Value != null)
+                {
+                    instance.AddProperty(XMLTVConstants.Programs.ProgramTitle, node.Value);
+                }
             }
         }
         #endregion

 

  ViewVC Help
Powered by ViewVC 1.1.22