/[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

trunk/libxmltv/Core/XMLTVChannel.cs revision 27 by william, Thu Mar 7 12:11:41 2013 UTC trunk/libxmltv/Core/XMLTVChannelCollection.cs revision 46 by william, Fri Mar 8 04:01:25 2013 UTC
# Line 5  using System.Text; Line 5  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;
9    
10  namespace libxmltv.Core  namespace libxmltv.Core
11  {  {
12      internal class XMLTVChannelCollection      internal class XMLTVChannelCollection : IDisposable
13      {      {
14          private Dictionary<string, IXMLTVChannel> entries = new Dictionary<string, IXMLTVChannel>();          private Dictionary<string, IXMLTVChannel> entries = new Dictionary<string, IXMLTVChannel>();
15          public XMLTVChannelCollection(object xmltv)          internal static void CreateInstance(XMLTVRuntimeInstance xmltv)
16          {          {
17              XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection");              using (XMLTVChannelCollection g = new XMLTVChannelCollection(xmltv)) { g.instance.Channels = g.Collection; }
18              IXMLTV_PARSER _xmltv;          }
19              if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }          private XMLTVRuntimeInstance instance;
20              XMLTV_PARSER = _xmltv;          public XMLTVChannelCollection(XMLTVRuntimeInstance xmltv)
21            {
22                xmltv_logger.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection");
23                //IXMLTV_PARSER _xmltv;
24                //if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
25                //XMLTV_PARSER = _xmltv;
26                instance = xmltv;
27              Create();              Create();
28          }          }
29    
30          #region IXMLTVSource          #region IXMLTVSource
31          private IXMLTV_PARSER XMLTV_PARSER { get; set; }          //private IXMLTV_PARSER XMLTV_PARSER { get; set; }
32          public Dictionary<string, IXMLTVChannel> Collection          public Dictionary<string, IXMLTVChannel> Collection
33          {          {
34              get { return entries; }              get { return entries; }
# Line 30  namespace libxmltv.Core Line 37  namespace libxmltv.Core
37    
38          private void Create()          private void Create()
39          {          {
40              var doc = XMLTV_PARSER.XMLTV_LOADER.XmlDoc;              var doc = instance.XmlDoc;
41    
42              foreach (var c in doc.Descendants(XMLTV_CONSTANTS.CHANNEL_ELEMENT))              foreach (var c in doc.Descendants(XMLTVConstants.CHANNEL_ELEMENT))
43              {              {
44                    if (instance.IsAborting)
45                    {
46                        break;
47                    }
48                  Channel channel = new Channel(c);                  Channel channel = new Channel(c);
49                  entries.Add(channel.ChannelId, channel);                  entries.Add(channel.Id, channel);
50                    Application.DoEvents();
51              }              }
52                //instance.Channels = Collection;
53          }          }
54          public override string ToString()          public override string ToString()
55          {          {
56              //return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl);              return string.Format("Channel Count: {0}", Collection == null ? 0 : Collection.Count);
             return string.Empty;  
57          }          }
     }  
58    
59            public void Dispose()
60            {
61                //throw new NotImplementedException();
62            }
63        }
64        [Serializable]
65      internal class Channel : IXMLTVChannel      internal class Channel : IXMLTVChannel
66      {      {
67          public Channel()          public Channel()
68          {          {
69              ChannelId = string.Empty;              Id = string.Empty;
70              ChannelNumber = 0;              Number = 0;
71              ChannelCallSign = string.Empty;              CallSign = string.Empty;
72              ChannelName = string.Empty;              Name = string.Empty;
73          }          }
74          public Channel(XElement e)          public Channel(XElement e)
75              : this()              : this()
76          {          {
77              // get the channel id              // get the channel id
78              ChannelId = e.Attribute(XMLTV_CONSTANTS.Channels.ChannelId).Value;              Id = e.Attribute(XMLTVConstants.Channels.ChannelId).Value;
79              var names = e.Descendants(XMLTV_CONSTANTS.Channels.ChannelDisplayName).ToList();              xmltv_logger.Log.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
80              ChannelNumber = Convert.ToInt32(names[1].Value);              var names = e.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
81              ChannelCallSign = names[2].Value;              Number = Convert.ToInt32(names[1].Value);
82              ChannelName = names[3].Value;              xmltv_logger.Log.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);
83                CallSign = names[2].Value;
84                xmltv_logger.Log.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);
85                Name = names[3].Value;
86                xmltv_logger.Log.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);
87          }          }
88          #region IXMLTVChannel members          #region IXMLTVChannel members
89          public string ChannelId { get; private set; }          public string Id { get; private set; }
90          public int ChannelNumber { get; private set; }          public int Number { get; private set; }
91          public string ChannelCallSign { get; private set; }          public string CallSign { get; private set; }
92          public string ChannelName { get; private set; }          public string Name { get; private set; }
93          #endregion          #endregion
94            public override string ToString()
95            {
96                return string.Format("{0}: {1} {2} ({3})", Id,Number,Name, CallSign);
97            }
98      }      }
99  }  }
100    

Legend:
Removed from v.27  
changed lines
  Added in v.46

  ViewVC Help
Powered by ViewVC 1.1.22