/[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 11:06:39	74
+++ trunk/libxmltv/Core/XMLTVProgram.cs	2013/03/09 11:28:41	77
@@ -25,9 +25,9 @@
             : base(instance, XMLTVConstants.PROGRAM_ELEMENT)
         {
             xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVProgram");
-            // do the work here
+            Create(node);
             xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVProgram");
-            //UpdateInstance();
+            UpdateInstance();
         }
         #region IXMLTVProgram members
         public int Id { get; set; }
@@ -50,16 +50,16 @@
             var fields = instance_type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
             foreach (var field in fields)
             {
-                if (field.FieldType == typeof(List<IXMLTVChannel>))
+                if (field.FieldType == typeof(List<IXMLTVProgram>))
                 {
                     found_field = true;
                     try
                     {
-                        xmltv_logger.Verbose.Debug.WriteLine("Updating instance with program information: {0}", this.ToString());
-                        //field.SetValue(this.GetInstance(), new List<IXMLTVChannel>() { this });
-
+                        
                         var list = (List<IXMLTVProgram>)field.GetValue(this.GetInstance());
+                        this.Id = list.Count + 1;
                         list.Add(this);
+                        xmltv_logger.Verbose.Debug.WriteLine("Updating instance with program information: {0}", this.ToString());
                         field.SetValue(this.GetInstance(), list);
                         break;
                     }
@@ -75,5 +75,64 @@
                 xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with program information.");
             }
         }
+
+        private void Create(XElement node)
+        {
+            if (node.HasAttributes)
+            {
+                var start = node.Attribute(XMLTVConstants.Programs.ProgramStart);
+                this.Start = start == null ? new DateTime() : ParseDate(start.Value);
+                if (!this.Start.Equals(new DateTime())) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_start: {0}", start); }
+
+                var stop = node.Attribute(XMLTVConstants.Programs.ProgramStop);
+                this.Stop = stop == null ? new DateTime() : ParseDate(stop.Value);
+                if (!this.Stop.Equals(new DateTime())) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_stop: {0}", stop); }
+
+                var channelid = node.Attribute(XMLTVConstants.Programs.ProgramChannelId);
+                if (!string.IsNullOrEmpty(this.Description)) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_channelid: {0}", channelid); }
+                IXMLTVChannel channel = new XMLTVChannel();
+                string _channelid = channelid == null ? string.Empty : channelid.Value;
+                this.Channel = this.GetInstance().Channels.Find(m => m.Id == _channelid);
+                if (this.Channel == null) { this.Channel = new XMLTVChannel(); }
+                if (!string.IsNullOrEmpty(_channelid)) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_channel: {0}", this.Channel.ToString()); }
+            }
+            try
+            {
+                var title = node.Descendants(XMLTVConstants.Programs.ProgramTitle).FirstOrDefault();
+                this.Title = title == null ? string.Empty : title.Value;
+            }
+            catch (Exception) { this.Title = string.Empty; }
+            if (!string.IsNullOrEmpty(this.Title)) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_title: {0}", this.Title == string.Empty ? "empty" : this.Title); }
+            try
+            {
+                var subtitle = node.Descendants(XMLTVConstants.Programs.ProgramSubTitle).FirstOrDefault();
+                this.SubTitle = subtitle == null ? string.Empty : subtitle.Value;
+            }
+            catch (Exception) { this.SubTitle = string.Empty; }
+            if (!string.IsNullOrEmpty(this.SubTitle)) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_subtitle: {0}", this.SubTitle == string.Empty ? "empty" : this.SubTitle); }
+            try
+            {
+                var description = node.Descendants(XMLTVConstants.Programs.ProgramDescription).FirstOrDefault();
+                this.Description = description == null ? string.Empty : description.Value; ;
+            }
+            catch (Exception) { this.Description = string.Empty; }
+            if (!string.IsNullOrEmpty(this.Description)) { xmltv_logger.Verbose.Debug.WriteLine("\tprogram_description: {0}", this.Description == string.Empty ? "empty" : this.Description); }
+
+            //entries.Add(program.Id, program);
+            //program_index++;
+            //progress = 100.0 * (program_index / program_count);
+            //xmltv_logger.ReportProgress(this, new Enterprise.Logging.ReportProgressEventArgs((int)progress));
+            //Application.DoEvents();
+        }
+        private DateTime ParseDate(string timeStamp)
+        {
+            DateTime dt = new DateTime();
+            try
+            {
+                dt = DateTime.ParseExact(timeStamp, "yyyyMMddHHmmss zzzz", System.Globalization.CultureInfo.CurrentCulture);
+            }
+            catch (Exception ex) { throw ex; }
+            return dt;
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22