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

  ViewVC Help
Powered by ViewVC 1.1.22