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

  ViewVC Help
Powered by ViewVC 1.1.22