/[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 54 - (show annotations) (download)
Fri Mar 8 08:51:10 2013 UTC (7 years, 5 months ago) by william
File size: 3745 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))
18 {
19 g.instance.Channels = g.Collection;
20 xmltv_logger.Log.Info.WriteLine(g.ToString());
21 }
22 }
23 private XMLTVRuntimeInstance instance;
24 public XMLTVChannelCollection(XMLTVRuntimeInstance xmltv)
25 {
26 xmltv_logger.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection");
27 //IXMLTV_PARSER _xmltv;
28 //if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
29 //XMLTV_PARSER = _xmltv;
30 instance = xmltv;
31 Create();
32 }
33
34 #region IXMLTVSource
35 //private IXMLTV_PARSER XMLTV_PARSER { get; set; }
36 public Dictionary<string, IXMLTVChannel> Collection
37 {
38 get { return entries; }
39 }
40 #endregion
41
42 private void Create()
43 {
44 var doc = XDocument.Parse(instance.XmlDoc);
45
46 foreach (var c in doc.Descendants(XMLTVConstants.CHANNEL_ELEMENT))
47 {
48 if (instance.IsAborting)
49 {
50 xmltv_logger.Log.Verbose.Debug.WriteLine("Detected Instance abort event...");
51 break;
52 }
53 Channel channel = new Channel(c);
54 entries.Add(channel.Id, channel);
55 Application.DoEvents();
56 }
57 //instance.Channels = Collection;
58 }
59 public override string ToString()
60 {
61 return string.Format("Total Channels Parsed: {0}", Collection == null ? 0 : Collection.Count);
62 }
63
64 public void Dispose()
65 {
66 //throw new NotImplementedException();
67 }
68 }
69 [Serializable]
70 internal class Channel : IXMLTVChannel
71 {
72 public Channel()
73 {
74 Id = string.Empty;
75 Number = 0;
76 CallSign = string.Empty;
77 Name = string.Empty;
78 }
79 public Channel(XElement e)
80 : this()
81 {
82 // get the channel id
83 Id = e.Attribute(XMLTVConstants.Channels.ChannelId).Value;
84 xmltv_logger.Log.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
85 var names = e.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
86 Number = Convert.ToInt32(names[1].Value);
87 xmltv_logger.Log.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);
88 CallSign = names[2].Value;
89 xmltv_logger.Log.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);
90 Name = names[3].Value;
91 xmltv_logger.Log.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);
92 }
93 #region IXMLTVChannel members
94 public string Id { get; private set; }
95 public int Number { get; private set; }
96 public string CallSign { get; private set; }
97 public string Name { get; private set; }
98 #endregion
99 public override string ToString()
100 {
101 return string.Format("{0}: {1} {2} ({3})", Id,Number,Name, CallSign);
102 }
103 }
104 }
105

  ViewVC Help
Powered by ViewVC 1.1.22