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