/[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/09 00:59:05	64
+++ trunk/libxmltv/Core/XMLTVProgramCollection.cs	2013/03/09 01:09:45	65
@@ -65,44 +65,40 @@
                 xmltv_logger.Verbose.Debug.WriteLine("program_Id: {0}", program.Id);
                 if (c.HasAttributes)
                 {
-                    var start = c.Attribute(XMLTVConstants.Programs.ProgramStart).Value;
-                    program.Start = ParseDate(start);
+                    var start = c.Attribute(XMLTVConstants.Programs.ProgramStart);
+                    program.Start = start == null ? new DateTime() : ParseDate(start.Value);
                     xmltv_logger.Verbose.Debug.WriteLine("\tprogram_start: {0}", start);
-                    var stop = c.Attribute(XMLTVConstants.Programs.ProgramStop).Value;
-                    program.Stop = ParseDate(stop);
+
+                    var stop = c.Attribute(XMLTVConstants.Programs.ProgramStop);
+                    program.Stop = stop == null ? new DateTime() : ParseDate(stop.Value);
                     xmltv_logger.Verbose.Debug.WriteLine("\tprogram_stop: {0}", stop);
-                    var channelid = c.Attribute(XMLTVConstants.Programs.ProgramChannelId).Value;
+
+                    var channelid = c.Attribute(XMLTVConstants.Programs.ProgramChannelId);
                     xmltv_logger.Verbose.Debug.WriteLine("\tprogram_channelid: {0}", channelid);
                     IXMLTVChannel channel = new Channel();
-                    try
-                    {
-                        channel = instance.Channels[channelid];
-                    }
-                    catch (KeyNotFoundException)
-                    {
-                        xmltv_logger.Verbose.Error.WriteLine(string.Format("Unable to find Channel by id: '{0}' for this program.", channelid));
-                    }
-                    program.Channel = channel;
+                    string _channelid = channelid == null ? string.Empty : channelid.Value;
+                    if (instance.Channels.ContainsKey(_channelid)) { program.Channel = instance.Channels[_channelid]; }
+                    else { program.Channel = new Channel(); }
                     xmltv_logger.Verbose.Debug.WriteLine("\tprogram_channel: {0}", program.Channel.ToString());
                 }
                 try
                 {
-                    var title = c.Descendants(XMLTVConstants.Programs.ProgramTitle).FirstOrDefault().Value;
-                    program.Title = title;                    
+                    var title = c.Descendants(XMLTVConstants.Programs.ProgramTitle).FirstOrDefault();
+                    program.Title = title == null ? string.Empty : title.Value;         
                 }
                 catch (Exception) { program.Title = string.Empty; }
                 xmltv_logger.Verbose.Debug.WriteLine("\tprogram_title: {0}", program.Title == string.Empty ? "empty" : program.Title);
                 try
                 {
-                    var subtitle = c.Descendants(XMLTVConstants.Programs.ProgramSubTitle).FirstOrDefault().Value;
-                    program.SubTitle = subtitle;                    
+                    var subtitle = c.Descendants(XMLTVConstants.Programs.ProgramSubTitle).FirstOrDefault();
+                    program.SubTitle = subtitle == null ? string.Empty : subtitle.Value;               
                 }
                 catch (Exception) { program.SubTitle = string.Empty; }
                 xmltv_logger.Verbose.Debug.WriteLine("\tprogram_subtitle: {0}", program.SubTitle == string.Empty ? "empty" : program.SubTitle);
                 try
                 {
-                    var description = c.Descendants(XMLTVConstants.Programs.ProgramDescription).FirstOrDefault().Value;
-                    program.Description = description;                    
+                    var description = c.Descendants(XMLTVConstants.Programs.ProgramDescription).FirstOrDefault();
+                    program.Description = description == null ? string.Empty : description.Value; ;                    
                 }
                 catch (Exception) { program.Description = string.Empty; }
                 xmltv_logger.Verbose.Debug.WriteLine("\tprogram_description: {0}", program.Description == string.Empty ? "empty" : program.Description);

 

  ViewVC Help
Powered by ViewVC 1.1.22