/[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 45 - (hide annotations) (download)
Fri Mar 8 03:41:18 2013 UTC (7 years, 7 months ago) by william
File size: 3514 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 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 william 45 if (instance.IsDisposing)
45     {
46     break;
47     }
48 william 26 Channel channel = new Channel(c);
49 william 28 entries.Add(channel.Id, channel);
50 william 43 Application.DoEvents();
51 william 26 }
52 william 44 //instance.Channels = Collection;
53 william 26 }
54     public override string ToString()
55     {
56 william 43 return string.Format("Channel Count: {0}", Collection == null ? 0 : Collection.Count);
57 william 26 }
58 william 44
59     public void Dispose()
60     {
61     //throw new NotImplementedException();
62     }
63 william 26 }
64 william 31 [Serializable]
65 william 27 internal class Channel : IXMLTVChannel
66 william 26 {
67     public Channel()
68     {
69 william 28 Id = string.Empty;
70     Number = 0;
71     CallSign = string.Empty;
72     Name = string.Empty;
73 william 26 }
74 william 27 public Channel(XElement e)
75     : this()
76 william 26 {
77     // get the channel id
78 william 36 Id = e.Attribute(XMLTVConstants.Channels.ChannelId).Value;
79 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
80 william 36 var names = e.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
81 william 28 Number = Convert.ToInt32(names[1].Value);
82 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);
83 william 28 CallSign = names[2].Value;
84 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);
85 william 28 Name = names[3].Value;
86 william 43 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);
87 william 26 }
88     #region IXMLTVChannel members
89 william 28 public string Id { get; private set; }
90     public int Number { get; private set; }
91     public string CallSign { get; private set; }
92     public string Name { get; private set; }
93 william 26 #endregion
94 william 28 public override string ToString()
95     {
96     return string.Format("{0}: {1} {2} ({3})", Id,Number,Name, CallSign);
97     }
98 william 26 }
99     }
100    

  ViewVC Help
Powered by ViewVC 1.1.22