/[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 45 - (show annotations) (download)
Fri Mar 8 03:41:18 2013 UTC (7 years, 6 months ago) by william
File size: 3514 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22