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

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

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

--- trunk/libxmltv/Core/XMLTVChannel.cs	2013/03/09 11:06:39	74
+++ trunk/libxmltv/Core/XMLTVChannel.cs	2013/03/10 09:43:49	97
@@ -5,45 +5,52 @@
 using libxmltv.Interfaces;
 using System.Xml.Linq;
 using System.Reflection;
+using System.IO;
+using System.Diagnostics;
 
 namespace libxmltv.Core
 {
     [Serializable]
     internal class XMLTVChannel : XMLTVBase<XMLTVRuntimeInstance>, IXMLTVChannel
     {
-        public XMLTVChannel() : base(null,XMLTVConstants.CHANNEL_ELEMENT)
+        public XMLTVChannel()
+            : base(null, XMLTVConstants.Channels.RootElement)
         {
+            InternalDictionaryAddKnownProperties();
             Id = string.Empty;
-            Number = 0;
-            CallSign = string.Empty;
-            Name = string.Empty;
+            //Number = 0;
+            //CallSign = string.Empty;
+            //Name = string.Empty;
         }
         public XMLTVChannel(XMLTVRuntimeInstance instance, XElement node)
-            : base(instance, XMLTVConstants.CHANNEL_ELEMENT)
+            : base(instance, XMLTVConstants.Channels.RootElement)
         {
-            xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannel");
-            // get the channel id
-            Id = node.Attribute(XMLTVConstants.Channels.ChannelId).Value;
-            xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
-            var names = node.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
-            Number = Convert.ToInt32(names[1].Value);
-            xmltv_logger.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);
-            CallSign = names[2].Value;
-            xmltv_logger.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);
-            Name = names[3].Value;
-            xmltv_logger.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);
-            xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVChannel");
-            UpdateInstance();            
+            InternalDictionaryAddKnownProperties();
+            try
+            {
+                xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannel");
+                Create(node);
+                xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVChannel");
+                UpdateInstance();
+            }
+            catch (IOException ex) { Debug.WriteLine(ex.ToString()); }
+        }
+        private void InternalDictionaryAddKnownProperties()
+        {
+            MetaData = new PropertyList();
+            //MetaData.AddProperty("Id", string.Empty);
         }
         #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; }
+        //public int Number { get; private set; }
+        //public string CallSign { get; private set; }
+        //public string Name { get; private set; }
+        private PropertyList _MetaData;
+        public PropertyList MetaData { get { return _MetaData; } private set { _MetaData = value; } }
         #endregion
         public override string ToString()
         {
-            return string.Format("{0}: {1} {2} ({3})", Id, Number, Name, CallSign);
+            return string.Format("{0}", Id);
         }
 
         private void UpdateInstance()
@@ -58,11 +65,9 @@
                     found_field = true;
                     try
                     {
-                        xmltv_logger.Verbose.Debug.WriteLine("Updating instance with channel information: {0}", this.ToString());
-                        //field.SetValue(this.GetInstance(), new List<IXMLTVChannel>() { this });
-
                         var list = (List<IXMLTVChannel>)field.GetValue(this.GetInstance());
                         list.Add(this);
+                        xmltv_logger.Verbose.Debug.WriteLine("Updating instance with channel information: {0}", this.ToString());
                         field.SetValue(this.GetInstance(), list);
                         break;
                     }
@@ -78,6 +83,29 @@
                 xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with channel information.");
             }
         }
+
+        private void Create(XElement node)
+        {
+            //throw new NotImplementedException("Channel.Create(node) is not currently implemented.");
+            // get the channel id
+            Id = node.Attribute(XMLTVConstants.Channels.ChannelId).Value;
+            xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
+            var names = node.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
+            //Number = Convert.ToInt32(names[1].Value);
+            //xmltv_logger.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);
+            //CallSign = names[2].Value;
+            //xmltv_logger.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);
+            //Name = names[3].Value;
+            //xmltv_logger.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);
+
+            foreach (var name in names)
+            {
+                PropertyValuePair p = new PropertyValuePair(name.Name.ToString(), name.Value);
+                MetaData.AddProperty(p.Name,p.Value);
+                xmltv_logger.Verbose.Debug.WriteLine("\t{0}: {1}", p.Name, p.Value);
+            }
+
+        }
     }
 
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22