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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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 william 43 using System.Windows.Forms;
9 william 26
10     namespace libxmltv.Core
11     {
12     internal class XMLTVChannelCollection
13     {
14     private Dictionary<string, IXMLTVChannel> entries = new Dictionary<string, IXMLTVChannel>();
15 william 36 private XMLTVRuntimeInstance instance;
16     public XMLTVChannelCollection(XMLTVRuntimeInstance xmltv)
17 william 26 {
18     XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection");
19 william 36 //IXMLTV_PARSER _xmltv;
20     //if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
21     //XMLTV_PARSER = _xmltv;
22     instance = xmltv;
23 william 26 Create();
24     }
25    
26     #region IXMLTVSource
27 william 36 //private IXMLTV_PARSER XMLTV_PARSER { get; set; }
28 william 26 public Dictionary<string, IXMLTVChannel> Collection
29     {
30     get { return entries; }
31     }
32     #endregion
33    
34     private void Create()
35     {
36 william 36 var doc = instance.XmlDoc;
37 william 26
38 william 36 foreach (var c in doc.Descendants(XMLTVConstants.CHANNEL_ELEMENT))
39 william 26 {
40     Channel channel = new Channel(c);
41 william 28 entries.Add(channel.Id, channel);
42 william 43 Application.DoEvents();
43 william 26 }
44     }
45     public override string ToString()
46     {
47 william 43 return string.Format("Channel Count: {0}", Collection == null ? 0 : Collection.Count);
48 william 26 }
49     }
50 william 31 [Serializable]
51 william 27 internal class Channel : IXMLTVChannel
52 william 26 {
53     public Channel()
54     {
55 william 28 Id = string.Empty;
56     Number = 0;
57     CallSign = string.Empty;
58     Name = string.Empty;
59 william 26 }
60 william 27 public Channel(XElement e)
61     : this()
62 william 26 {
63     // get the channel id
64 william 36 Id = e.Attribute(XMLTVConstants.Channels.ChannelId).Value;
65 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
66 william 36 var names = e.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
67 william 28 Number = Convert.ToInt32(names[1].Value);
68 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);
69 william 28 CallSign = names[2].Value;
70 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);
71 william 28 Name = names[3].Value;
72 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);
73 william 26 }
74     #region IXMLTVChannel members
75 william 28 public string Id { get; private set; }
76     public int Number { get; private set; }
77     public string CallSign { get; private set; }
78     public string Name { get; private set; }
79 william 26 #endregion
80 william 28 public override string ToString()
81     {
82     return string.Format("{0}: {1} {2} ({3})", Id,Number,Name, CallSign);
83     }
84 william 26 }
85     }
86    

  ViewVC Help
Powered by ViewVC 1.1.22