ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/xmltv_parser/trunk/libxmltv/Core/XMLTVChannel.cs
Revision: 28
Committed: Thu Mar 7 12:51:53 2013 UTC (10 years, 6 months ago) by william
File size: 2581 byte(s)
Log Message:

File Contents

# User Rev Content
1 william 26 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 william 28 entries.Add(channel.Id, channel);
39 william 26 }
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 william 27 internal class Channel : IXMLTVChannel
49 william 26 {
50     public Channel()
51     {
52 william 28 Id = string.Empty;
53     Number = 0;
54     CallSign = string.Empty;
55     Name = string.Empty;
56 william 26 }
57 william 27 public Channel(XElement e)
58     : this()
59 william 26 {
60     // get the channel id
61 william 28 Id = e.Attribute(XMLTV_CONSTANTS.Channels.ChannelId).Value;
62 william 26 var names = e.Descendants(XMLTV_CONSTANTS.Channels.ChannelDisplayName).ToList();
63 william 28 Number = Convert.ToInt32(names[1].Value);
64     CallSign = names[2].Value;
65     Name = names[3].Value;
66 william 26 }
67     #region IXMLTVChannel members
68 william 28 public string Id { get; private set; }
69     public int Number { get; private set; }
70     public string CallSign { get; private set; }
71     public string Name { get; private set; }
72 william 26 #endregion
73 william 28 public override string ToString()
74     {
75     return string.Format("{0}: {1} {2} ({3})", Id,Number,Name, CallSign);
76     }
77 william 26 }
78     }
79