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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 28 - (hide annotations) (download)
Thu Mar 7 12:51:53 2013 UTC (7 years, 4 months ago) by william
File size: 4429 byte(s)

1 william 27 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using libxmltv.Interfaces;
6     using System.Xml.Linq;
7 william 28 using System.Globalization;
8 william 27
9     namespace libxmltv.Core
10     {
11     internal class XMLTVProgramCollection
12     {
13     private Dictionary<int, IXMLTVProgram> entries = new Dictionary<int, IXMLTVProgram>();
14     public XMLTVProgramCollection(object xmltv)
15     {
16 william 28 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVProgramCollection");
17 william 27 IXMLTV_PARSER _xmltv;
18     if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
19     XMLTV_PARSER = _xmltv;
20     Create();
21     }
22    
23     #region IXMLTVSource
24     private IXMLTV_PARSER XMLTV_PARSER { get; set; }
25     public Dictionary<int, IXMLTVProgram> Collection
26     {
27     get { return entries; }
28     }
29     #endregion
30    
31 william 28 //
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 william 27 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 william 28 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 william 27 index++;
81     }
82     }
83     public override string ToString()
84     {
85     //return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl);
86     return string.Empty;
87     }
88     }
89    
90     internal class Program : IXMLTVProgram
91     {
92     public Program()
93     {
94 william 28 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 william 27 }
102 william 28 #region IXMLTVProgram members
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 william 27 {
113 william 28 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 william 27 }
115     }
116     }

  ViewVC Help
Powered by ViewVC 1.1.22