/[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 36 - (show annotations) (download)
Fri Mar 8 02:13:59 2013 UTC (7 years, 4 months ago) by william
File size: 5929 byte(s)
+ use a MarshalByRefObject

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

  ViewVC Help
Powered by ViewVC 1.1.22