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

  ViewVC Help
Powered by ViewVC 1.1.22