/[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 43 - (hide annotations) (download)
Fri Mar 8 03:09:49 2013 UTC (8 years, 4 months ago) by william
File size: 5943 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 43 using System.Windows.Forms;
9 william 27
10     namespace libxmltv.Core
11     {
12     internal class XMLTVProgramCollection
13     {
14     private Dictionary<int, IXMLTVProgram> entries = new Dictionary<int, IXMLTVProgram>();
15 william 36 private XMLTVRuntimeInstance instance;
16     public XMLTVProgramCollection(XMLTVRuntimeInstance xmltv)
17 william 27 {
18 william 28 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVProgramCollection");
19 william 36 //IXMLTV_PARSER _xmltv;
20     //if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
21     //XMLTV_PARSER = _xmltv;
22     instance = xmltv;
23 william 27 Create();
24     }
25    
26     #region IXMLTVSource
27 william 36 //private IXMLTV_PARSER XMLTV_PARSER { get; set; }
28 william 27 public Dictionary<int, IXMLTVProgram> Collection
29     {
30     get { return entries; }
31     }
32     #endregion
33    
34 william 28 //
35     private DateTime ParseDate(string timeStamp)
36     {
37     DateTime dt = new DateTime();
38     try
39     {
40     dt = DateTime.ParseExact(timeStamp, "yyyyMMddHHmmss zzzz", System.Globalization.CultureInfo.CurrentCulture);
41     }
42     catch (Exception ex) { throw ex; }
43     return dt;
44     }
45 william 27 private void Create()
46     {
47 william 36 var doc = instance.XmlDoc;
48 william 27 int index = 0;
49 william 36 foreach (var c in doc.Descendants(XMLTVConstants.PROGRAM_ELEMENT))
50 william 27 {
51 william 28 Program program = new Program();
52    
53     program.Id = index;
54 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("program_Id: {0}", program.Id);
55 william 28 if (c.HasAttributes)
56     {
57 william 36 var start = c.Attribute(XMLTVConstants.Programs.ProgramStart).Value;
58 william 28 program.Start = ParseDate(start);
59 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_start: {0}", start);
60 william 36 var stop = c.Attribute(XMLTVConstants.Programs.ProgramStop).Value;
61 william 28 program.Stop = ParseDate(stop);
62 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_stop: {0}", stop);
63 william 36 var channelid = c.Attribute(XMLTVConstants.Programs.ProgramChannelId).Value;
64 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_channelid: {0}", channelid);
65 william 28 IXMLTVChannel channel = new Channel();
66     try
67     {
68 william 36 channel = instance.Channels[channelid];
69 william 28 }
70     catch (KeyNotFoundException)
71     {
72     XMLTV_LOGGER.Log.Verbose.Error.WriteLine(string.Format("Unable to find Channel by id: '{0}' for this program.", channelid));
73     }
74     program.Channel = channel;
75 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_channel: {0}", program.Channel.ToString());
76 william 28 }
77 william 30 try
78     {
79 william 36 var title = c.Descendants(XMLTVConstants.Programs.ProgramTitle).FirstOrDefault().Value;
80 william 30 program.Title = title;
81     }
82     catch (Exception) { program.Title = string.Empty; }
83 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_title: {0}", program.Title == string.Empty ? "empty" : program.Title);
84 william 30 try
85     {
86 william 36 var subtitle = c.Descendants(XMLTVConstants.Programs.ProgramSubTitle).FirstOrDefault().Value;
87 william 30 program.SubTitle = subtitle;
88     }
89     catch (Exception) { program.SubTitle = string.Empty; }
90 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_subtitle: {0}", program.SubTitle == string.Empty ? "empty" : program.SubTitle);
91 william 30 try
92     {
93 william 36 var description = c.Descendants(XMLTVConstants.Programs.ProgramDescription).FirstOrDefault().Value;
94 william 30 program.Description = description;
95     }
96     catch (Exception) { program.Description = string.Empty; }
97 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_description: {0}", program.Description == string.Empty ? "empty" : program.Description);
98 william 28
99     entries.Add(program.Id, program);
100 william 43 Application.DoEvents();
101 william 27 index++;
102     }
103     }
104     public override string ToString()
105     {
106 william 43 return string.Format("Program Count: {0}", Collection == null ? 0 : Collection.Count);
107 william 27 return string.Empty;
108     }
109     }
110 william 31 [Serializable]
111 william 27 internal class Program : IXMLTVProgram
112     {
113     public Program()
114     {
115 william 28 Id = 0;
116     Start = new DateTime();
117     Stop = new DateTime();
118     Channel = new Channel();
119     Title = string.Empty;
120     SubTitle = string.Empty;
121     Description = string.Empty;
122 william 27 }
123 william 28 #region IXMLTVProgram members
124     public int Id { get; set; }
125     public DateTime Start { get; set; }
126     public DateTime Stop { get; set; }
127     public IXMLTVChannel Channel { get; set; }
128     public string Title { get; set; }
129     public string SubTitle { get; set; }
130     public string Description { get; set; }
131     #endregion
132     public override string ToString()
133 william 27 {
134 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"));
135 william 27 }
136     }
137     }

  ViewVC Help
Powered by ViewVC 1.1.22