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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 26 - (show annotations) (download)
Thu Mar 7 11:58:34 2013 UTC (8 years, 4 months ago) by william
Original Path: trunk/libxmltv/Core/XMLTVChannel.cs
File size: 2519 byte(s)
+ implement channel parsing

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using libxmltv.Interfaces;
6 using System.Diagnostics;
7 using System.Xml.Linq;
8
9 namespace libxmltv.Core
10 {
11 internal class XMLTVChannelCollection
12 {
13 private Dictionary<string, IXMLTVChannel> entries = new Dictionary<string, IXMLTVChannel>();
14 public XMLTVChannelCollection(object xmltv)
15 {
16 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection");
17 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<string, IXMLTVChannel> Collection
26 {
27 get { return entries; }
28 }
29 #endregion
30
31 private void Create()
32 {
33 var doc = XMLTV_PARSER.XMLTV_LOADER.XmlDoc;
34
35 foreach (var c in doc.Descendants(XMLTV_CONSTANTS.CHANNEL_ELEMENT))
36 {
37 Channel channel = new Channel(c);
38 entries.Add(channel.ChannelId, channel);
39 }
40 }
41 public override string ToString()
42 {
43 //return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl);
44 return string.Empty;
45 }
46 }
47
48 public class Channel : IXMLTVChannel
49 {
50 public Channel()
51 {
52 ChannelId = string.Empty;
53 ChannelNumber = 0;
54 ChannelCallSign = string.Empty;
55 ChannelName = string.Empty;
56 }
57 public Channel(XElement e) : this()
58 {
59 // get the channel id
60 ChannelId = e.Attribute(XMLTV_CONSTANTS.Channels.ChannelId).Value;
61 var names = e.Descendants(XMLTV_CONSTANTS.Channels.ChannelDisplayName).ToList();
62 ChannelNumber = Convert.ToInt32(names[1].Value);
63 ChannelCallSign = names[2].Value;
64 ChannelName = names[3].Value;
65 }
66 #region IXMLTVChannel members
67 public string ChannelId { get; private set; }
68 public int ChannelNumber { get; private set; }
69 public string ChannelCallSign { get; private set; }
70 public string ChannelName { get; private set; }
71 #endregion
72 }
73 }
74

  ViewVC Help
Powered by ViewVC 1.1.22