ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/xmltv_parser/trunk/libxmltv/Core/XMLTVProgramCollection.cs
(Generate patch)

Comparing trunk/libxmltv/Core/XMLTVProgramCollection.cs (file contents):
Revision 27 by william, Thu Mar 7 12:11:41 2013 UTC vs.
Revision 28 by william, Thu Mar 7 12:51:53 2013 UTC

# Line 4 | Line 4 | using System.Linq;
4   using System.Text;
5   using libxmltv.Interfaces;
6   using System.Xml.Linq;
7 + using System.Globalization;
8  
9   namespace libxmltv.Core
10   {
# Line 12 | Line 13 | namespace libxmltv.Core
13          private Dictionary<int, IXMLTVProgram> entries = new Dictionary<int, IXMLTVProgram>();
14          public XMLTVProgramCollection(object xmltv)
15          {
16 <            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection");
16 >            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVProgramCollection");
17              IXMLTV_PARSER _xmltv;
18              if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
19              XMLTV_PARSER = _xmltv;
# Line 27 | Line 28 | namespace libxmltv.Core
28          }
29          #endregion
30  
31 +        //
32 +        private DateTime ParseDate(string timeStamp)
33 +        {
34 +            DateTime dt = new DateTime();
35 +            try
36 +            {
37 +                dt = DateTime.ParseExact(timeStamp, "yyyyMMddHHmmss zzzz", System.Globalization.CultureInfo.CurrentCulture);
38 +            }
39 +            catch (Exception ex) { throw ex; }
40 +            return dt;
41 +        }
42          private void Create()
43          {
44              var doc = XMLTV_PARSER.XMLTV_LOADER.XmlDoc;
45              int index = 0;
46              foreach (var c in doc.Descendants(XMLTV_CONSTANTS.PROGRAM_ELEMENT))
47              {
48 <                Program program = new Program(c, index);
49 <                entries.Add(program.ProgramId, program);
48 >                Program program = new Program();
49 >
50 >                program.Id = index;
51 >
52 >                if (c.HasAttributes)
53 >                {
54 >                    var start = c.Attribute(XMLTV_CONSTANTS.Programs.ProgramStart).Value;
55 >                    program.Start = ParseDate(start);
56 >                    
57 >                    var stop = c.Attribute(XMLTV_CONSTANTS.Programs.ProgramStop).Value;
58 >                    program.Stop = ParseDate(stop);
59 >
60 >                    var channelid = c.Attribute(XMLTV_CONSTANTS.Programs.ProgramChannelId).Value;
61 >                    IXMLTVChannel channel = new Channel();
62 >                    try
63 >                    {
64 >                        channel = XMLTV_PARSER.Channels[channelid];
65 >                    }
66 >                    catch (KeyNotFoundException)
67 >                    {
68 >                        XMLTV_LOGGER.Log.Verbose.Error.WriteLine(string.Format("Unable to find Channel by id: '{0}' for this program.", channelid));
69 >                    }
70 >                    program.Channel = channel;
71 >                }
72 >                var title = c.Descendants(XMLTV_CONSTANTS.Programs.ProgramTitle).FirstOrDefault().Value;
73 >                program.Title = title;
74 >                var subtitle = c.Descendants(XMLTV_CONSTANTS.Programs.ProgramSubTitle).FirstOrDefault().Value;
75 >                program.SubTitle = subtitle;
76 >                var description = c.Descendants(XMLTV_CONSTANTS.Programs.ProgramDescription).FirstOrDefault().Value;
77 >                program.Description = description;
78 >
79 >                entries.Add(program.Id, program);
80                  index++;
81              }
82          }
# Line 49 | Line 91 | namespace libxmltv.Core
91      {
92          public Program()
93          {
94 <            ProgramId = 0;
95 <        }
96 <        public Program(XElement e, int index)
97 <            : this()
98 <        {
99 <            //ProgramId = e.Attribute(XMLTV_CONSTANTS.Programs.ChannelStart).Value;
100 <            ProgramId = index;
94 >            Id = 0;
95 >            Start = new DateTime();
96 >            Stop = new DateTime();
97 >            Channel = new Channel();
98 >            Title = string.Empty;
99 >            SubTitle = string.Empty;
100 >            Description = string.Empty;
101          }
102          #region IXMLTVProgram members
103 <        public int ProgramId { get; private set; }
103 >        public int Id { get; set; }
104 >        public DateTime Start { get; set; }
105 >        public DateTime Stop { get; set; }
106 >        public IXMLTVChannel Channel { get; set; }
107 >        public string Title { get; set; }
108 >        public string SubTitle { get; set; }
109 >        public string Description { get; set; }
110          #endregion
111 +        public override string ToString()
112 +        {
113 +            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"));
114 +        }
115      }
116   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines