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

Legend:
Removed from v.26  
changed lines
  Added in v.49

  ViewVC Help
Powered by ViewVC 1.1.22