/[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 70 - (show annotations) (download)
Sat Mar 9 01:42:46 2013 UTC (7 years, 10 months ago) by william
File size: 4091 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.Info.WriteLine(g.ToString());
21 }
22 }
23 private XMLTVRuntimeInstance instance;
24 public XMLTVChannelCollection(XMLTVRuntimeInstance xmltv)
25 {
26 xmltv_logger.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 double channel_index = 0;
46 double channel_count = doc.Descendants(XMLTVConstants.CHANNEL_ELEMENT).Count();
47 double progress = 0;
48 foreach (var c in doc.Descendants(XMLTVConstants.CHANNEL_ELEMENT))
49 {
50 if (instance.IsAborting)
51 {
52 xmltv_logger.Verbose.Debug.WriteLine("Detected Instance abort event...");
53 break;
54 }
55 Channel channel = new Channel(c);
56 entries.Add(channel.Id, channel);
57 channel_index++;
58 progress = 100.0 * (channel_index / channel_count);
59 xmltv_logger.ReportProgress(this, new Enterprise.Logging.ReportProgressEventArgs((int)progress));
60 Application.DoEvents();
61 }
62 //instance.Channels = Collection;
63 }
64 public override string ToString()
65 {
66 return string.Format("Total Channels Parsed: {0}", Collection == null ? 0 : Collection.Count);
67 }
68
69 public void Dispose()
70 {
71 //throw new NotImplementedException();
72 }
73 }
74 [Serializable]
75 internal class Channel : IXMLTVChannel
76 {
77 public Channel()
78 {
79 Id = string.Empty;
80 Number = 0;
81 CallSign = string.Empty;
82 Name = string.Empty;
83 }
84 public Channel(XElement e)
85 : this()
86 {
87 // get the channel id
88 Id = e.Attribute(XMLTVConstants.Channels.ChannelId).Value;
89 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
90 var names = e.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
91 Number = Convert.ToInt32(names[1].Value);
92 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);
93 CallSign = names[2].Value;
94 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);
95 Name = names[3].Value;
96 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);
97 }
98 #region IXMLTVChannel members
99 public string Id { get; private set; }
100 public int Number { get; private set; }
101 public string CallSign { get; private set; }
102 public string Name { get; private set; }
103 #endregion
104 public override string ToString()
105 {
106 return string.Format("{0}: {1} {2} ({3})", Id,Number,Name, CallSign);
107 }
108 }
109 }
110

  ViewVC Help
Powered by ViewVC 1.1.22