/[xmltv_parser]/trunk/libxmltv/Core/XMLTVChannelCollection.cs
ViewVC logotype

Diff of /trunk/libxmltv/Core/XMLTVChannelCollection.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.72  
changed lines
  Added in v.73

  ViewVC Help
Powered by ViewVC 1.1.22