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

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

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

--- trunk/libxmltv/Core/XMLTVProgramCollection.cs	2013/03/07 12:11:41	27
+++ trunk/libxmltv/Core/XMLTVProgramCollection.cs	2013/03/07 12:51:53	28
@@ -4,6 +4,7 @@
 using System.Text;
 using libxmltv.Interfaces;
 using System.Xml.Linq;
+using System.Globalization;
 
 namespace libxmltv.Core
 {
@@ -12,7 +13,7 @@
         private Dictionary<int, IXMLTVProgram> entries = new Dictionary<int, IXMLTVProgram>();
         public XMLTVProgramCollection(object xmltv)
         {
-            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection");
+            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVProgramCollection");
             IXMLTV_PARSER _xmltv;
             if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
             XMLTV_PARSER = _xmltv;
@@ -27,14 +28,55 @@
         }
         #endregion
 
+        //
+        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;
+        }
         private void Create()
         {
             var doc = XMLTV_PARSER.XMLTV_LOADER.XmlDoc;
             int index = 0;
             foreach (var c in doc.Descendants(XMLTV_CONSTANTS.PROGRAM_ELEMENT))
             {
-                Program program = new Program(c, index);
-                entries.Add(program.ProgramId, program);
+                Program program = new Program();
+
+                program.Id = index;
+
+                if (c.HasAttributes)
+                {
+                    var start = c.Attribute(XMLTV_CONSTANTS.Programs.ProgramStart).Value;
+                    program.Start = ParseDate(start);
+                    
+                    var stop = c.Attribute(XMLTV_CONSTANTS.Programs.ProgramStop).Value;
+                    program.Stop = ParseDate(stop);
+
+                    var channelid = c.Attribute(XMLTV_CONSTANTS.Programs.ProgramChannelId).Value;
+                    IXMLTVChannel channel = new Channel();
+                    try
+                    {
+                        channel = XMLTV_PARSER.Channels[channelid];
+                    }
+                    catch (KeyNotFoundException)
+                    {
+                        XMLTV_LOGGER.Log.Verbose.Error.WriteLine(string.Format("Unable to find Channel by id: '{0}' for this program.", channelid));
+                    }
+                    program.Channel = channel;
+                }
+                var title = c.Descendants(XMLTV_CONSTANTS.Programs.ProgramTitle).FirstOrDefault().Value;
+                program.Title = title;
+                var subtitle = c.Descendants(XMLTV_CONSTANTS.Programs.ProgramSubTitle).FirstOrDefault().Value;
+                program.SubTitle = subtitle;
+                var description = c.Descendants(XMLTV_CONSTANTS.Programs.ProgramDescription).FirstOrDefault().Value;
+                program.Description = description;
+
+                entries.Add(program.Id, program);
                 index++;
             }
         }
@@ -49,16 +91,26 @@
     {
         public Program()
         {
-            ProgramId = 0;
-        }
-        public Program(XElement e, int index)
-            : this()
-        {
-            //ProgramId = e.Attribute(XMLTV_CONSTANTS.Programs.ChannelStart).Value;
-            ProgramId = index;
+            Id = 0;
+            Start = new DateTime();
+            Stop = new DateTime();
+            Channel = new Channel();
+            Title = string.Empty;
+            SubTitle = string.Empty;
+            Description = string.Empty;
         }
         #region IXMLTVProgram members
-        public int ProgramId { get; private set; }
+        public int Id { get; set; }
+        public DateTime Start { get; set; }
+        public DateTime Stop { get; set; }
+        public IXMLTVChannel Channel { get; set; }
+        public string Title { get; set; }
+        public string SubTitle { get; set; }
+        public string Description { get; set; }
         #endregion
+        public override string ToString()
+        {
+            return string.Format("{0}: {1} - {2} ({3}) ['{4}' <==> '{5}']", Id, Title, SubTitle, Channel.ToString(), Start.ToString("yyyy/MM/dd hh:mm tt"), Stop.ToString("yyyy/MM/dd hh:mm tt"));
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22