/[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 55 - (show annotations) (download)
Fri Mar 8 10:19:32 2013 UTC (7 years, 8 months ago) by william
File size: 6588 byte(s)
+ upate for: Enterprise.Logging: 1.2.5.1

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

  ViewVC Help
Powered by ViewVC 1.1.22