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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 43 - (show annotations) (download)
Fri Mar 8 03:09:49 2013 UTC (8 years, 3 months ago) by william
File size: 5943 byte(s)

1 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 using System.Globalization;
8 using System.Windows.Forms;
9
10 namespace libxmltv.Core
11 {
12 internal class XMLTVProgramCollection
13 {
14 private Dictionary<int, IXMLTVProgram> entries = new Dictionary<int, IXMLTVProgram>();
15 private XMLTVRuntimeInstance instance;
16 public XMLTVProgramCollection(XMLTVRuntimeInstance xmltv)
17 {
18 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVProgramCollection");
19 //IXMLTV_PARSER _xmltv;
20 //if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
21 //XMLTV_PARSER = _xmltv;
22 instance = xmltv;
23 Create();
24 }
25
26 #region IXMLTVSource
27 //private IXMLTV_PARSER XMLTV_PARSER { get; set; }
28 public Dictionary<int, IXMLTVProgram> Collection
29 {
30 get { return entries; }
31 }
32 #endregion
33
34 //
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 private void Create()
46 {
47 var doc = instance.XmlDoc;
48 int index = 0;
49 foreach (var c in doc.Descendants(XMLTVConstants.PROGRAM_ELEMENT))
50 {
51 Program program = new Program();
52
53 program.Id = index;
54 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("program_Id: {0}", program.Id);
55 if (c.HasAttributes)
56 {
57 var start = c.Attribute(XMLTVConstants.Programs.ProgramStart).Value;
58 program.Start = ParseDate(start);
59 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_start: {0}", start);
60 var stop = c.Attribute(XMLTVConstants.Programs.ProgramStop).Value;
61 program.Stop = ParseDate(stop);
62 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_stop: {0}", stop);
63 var channelid = c.Attribute(XMLTVConstants.Programs.ProgramChannelId).Value;
64 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_channelid: {0}", channelid);
65 IXMLTVChannel channel = new Channel();
66 try
67 {
68 channel = instance.Channels[channelid];
69 }
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 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_channel: {0}", program.Channel.ToString());
76 }
77 try
78 {
79 var title = c.Descendants(XMLTVConstants.Programs.ProgramTitle).FirstOrDefault().Value;
80 program.Title = title;
81 }
82 catch (Exception) { program.Title = string.Empty; }
83 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_title: {0}", program.Title == string.Empty ? "empty" : program.Title);
84 try
85 {
86 var subtitle = c.Descendants(XMLTVConstants.Programs.ProgramSubTitle).FirstOrDefault().Value;
87 program.SubTitle = subtitle;
88 }
89 catch (Exception) { program.SubTitle = string.Empty; }
90 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_subtitle: {0}", program.SubTitle == string.Empty ? "empty" : program.SubTitle);
91 try
92 {
93 var description = c.Descendants(XMLTVConstants.Programs.ProgramDescription).FirstOrDefault().Value;
94 program.Description = description;
95 }
96 catch (Exception) { program.Description = string.Empty; }
97 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tprogram_description: {0}", program.Description == string.Empty ? "empty" : program.Description);
98
99 entries.Add(program.Id, program);
100 Application.DoEvents();
101 index++;
102 }
103 }
104 public override string ToString()
105 {
106 return string.Format("Program Count: {0}", Collection == null ? 0 : Collection.Count);
107 return string.Empty;
108 }
109 }
110 [Serializable]
111 internal class Program : IXMLTVProgram
112 {
113 public Program()
114 {
115 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 }
123 #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 {
134 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 }
136 }
137 }

  ViewVC Help
Powered by ViewVC 1.1.22