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

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

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

revision 77 by william, Sat Mar 9 11:28:41 2013 UTC revision 120 by william, Sun Mar 10 18:19:12 2013 UTC
# Line 5  using System.Text; Line 5  using System.Text;
5  using libxmltv.Interfaces;  using libxmltv.Interfaces;
6  using System.Xml.Linq;  using System.Xml.Linq;
7  using System.Reflection;  using System.Reflection;
8    using System.IO;
9    using System.Diagnostics;
10    
11  namespace libxmltv.Core  namespace libxmltv.Core
12  {  {
13      [Serializable]      [Serializable]
14      internal class XMLTVChannel : XMLTVBase<XMLTVRuntimeInstance>, IXMLTVChannel      internal class XMLTVChannel : XMLTVBase<XMLTVRuntimeInstance>, IXMLTVChannel
15      {      {
16          public XMLTVChannel() : base(null,XMLTVConstants.CHANNEL_ELEMENT)          public XMLTVChannel()
17                : base(null, XMLTVConstants.Channels.RootElement)
18          {          {
19                InternalDictionaryAddKnownProperties();
20              Id = string.Empty;              Id = string.Empty;
21              Number = 0;              //Number = 0;
22              CallSign = string.Empty;              //CallSign = string.Empty;
23              Name = string.Empty;              //Name = string.Empty;
24          }          }
25          public XMLTVChannel(XMLTVRuntimeInstance instance, XElement node)          public XMLTVChannel(XMLTVRuntimeInstance instance, XElement node)
26              : base(instance, XMLTVConstants.CHANNEL_ELEMENT)              : base(instance, XMLTVConstants.Channels.RootElement)
27          {          {
28              xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannel");              InternalDictionaryAddKnownProperties();
29              Create(node);              try
30              xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVChannel");              {
31              UpdateInstance();                              xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannel");
32                    Create(node);
33                    xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVChannel");
34                    UpdateInstance();
35                }
36                catch (IOException ex) { Debug.WriteLine(ex.ToString()); }
37            }
38            private void InternalDictionaryAddKnownProperties()
39            {
40                MetaData = new PropertyList();
41          }          }
42          #region IXMLTVChannel members          #region IXMLTVChannel members
43          public string Id { get; private set; }          public string Id { get; private set; }
44          public int Number { get; private set; }          //public int Number { get; private set; }
45          public string CallSign { get; private set; }          //public string CallSign { get; private set; }
46          public string Name { get; private set; }          //public string Name { get; private set; }
47            private IPropertyList _MetaData;
48            public IPropertyList MetaData { get { return _MetaData; } private set { _MetaData = value; } }
49          #endregion          #endregion
50          public override string ToString()          public override string ToString()
51          {          {
52              return string.Format("{0}: {1} {2} ({3})", Id, Number, Name, CallSign);              return string.Format("{0}", Id);
53          }          }
54    
55          private void UpdateInstance()          private void UpdateInstance()
# Line 44  namespace libxmltv.Core Line 59  namespace libxmltv.Core
59              var fields = instance_type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);              var fields = instance_type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
60              foreach (var field in fields)              foreach (var field in fields)
61              {              {
62                  if (field.FieldType == typeof(List<IXMLTVChannel>))                  if (field.FieldType == typeof(ChannelList))
63                  {                  {
64                      found_field = true;                      found_field = true;
65                      try                      try
66                      {                                                                      {
67                          var list = (List<IXMLTVChannel>)field.GetValue(this.GetInstance());                          var list = (ChannelList)field.GetValue(this.GetInstance());
68                          list.Add(this);                          list.Add(this);
69                          xmltv_logger.Verbose.Debug.WriteLine("Updating instance with channel information: {0}", this.ToString());                          xmltv_logger.Verbose.Debug.WriteLine("Updating instance with channel information: {0}", this.ToString());
70                          field.SetValue(this.GetInstance(), list);                          field.SetValue(this.GetInstance(), list);
# Line 70  namespace libxmltv.Core Line 85  namespace libxmltv.Core
85    
86          private void Create(XElement node)          private void Create(XElement node)
87          {          {
88                //throw new NotImplementedException("Channel.Create(node) is not currently implemented.");
89              // get the channel id              // get the channel id
90              Id = node.Attribute(XMLTVConstants.Channels.ChannelId).Value;              Id = node.Attribute(XMLTVConstants.Channels.ChannelId).Value;
91              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
92              var names = node.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();              var names = node.Elements().ToList();
93              Number = Convert.ToInt32(names[1].Value);  
94              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);              foreach (var name in names)
95              CallSign = names[2].Value;              {
96              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);                  PropertyValuePair p = new PropertyValuePair(name.Name.ToString(), name.Value);
97              Name = names[3].Value;                  MetaData.AddProperty(p.Name,p.Value);
98              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);                  xmltv_logger.Verbose.Debug.WriteLine("\t{0}: {1}", p.Name, p.Value);
99                }
100    
101          }          }
102      }      }
103    

Legend:
Removed from v.77  
changed lines
  Added in v.120

  ViewVC Help
Powered by ViewVC 1.1.22