/[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 73 by william, Sat Mar 9 10:27:39 2013 UTC revision 74 by william, Sat Mar 9 11:06:39 2013 UTC
# Line 4  using System.Linq; Line 4  using System.Linq;
4  using System.Text;  using System.Text;
5  using libxmltv.Interfaces;  using libxmltv.Interfaces;
6  using System.Xml.Linq;  using System.Xml.Linq;
7    using System.Reflection;
8    
9  namespace libxmltv.Core  namespace libxmltv.Core
10  {  {
11      [Serializable]      [Serializable]
12      internal class XMLTVChannel : IXMLTVChannel      internal class XMLTVChannel : XMLTVBase<XMLTVRuntimeInstance>, IXMLTVChannel
13      {      {
14          public XMLTVChannel()          public XMLTVChannel() : base(null,XMLTVConstants.CHANNEL_ELEMENT)
15          {          {
16              Id = string.Empty;              Id = string.Empty;
17              Number = 0;              Number = 0;
18              CallSign = string.Empty;              CallSign = string.Empty;
19              Name = string.Empty;              Name = string.Empty;
20          }          }
21          public XMLTVChannel(XElement e)          public XMLTVChannel(XMLTVRuntimeInstance instance, XElement node)
22              : this()              : base(instance, XMLTVConstants.CHANNEL_ELEMENT)
23          {          {
24                xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannel");
25              // get the channel id              // get the channel id
26              Id = e.Attribute(XMLTVConstants.Channels.ChannelId).Value;              Id = node.Attribute(XMLTVConstants.Channels.ChannelId).Value;
27              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
28              var names = e.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();              var names = node.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
29              Number = Convert.ToInt32(names[1].Value);              Number = Convert.ToInt32(names[1].Value);
30              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);
31              CallSign = names[2].Value;              CallSign = names[2].Value;
32              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);
33              Name = names[3].Value;              Name = names[3].Value;
34              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);              xmltv_logger.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);
35                xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVChannel");
36                UpdateInstance();            
37          }          }
38          #region IXMLTVChannel members          #region IXMLTVChannel members
39          public string Id { get; private set; }          public string Id { get; private set; }
# Line 41  namespace libxmltv.Core Line 45  namespace libxmltv.Core
45          {          {
46              return string.Format("{0}: {1} {2} ({3})", Id, Number, Name, CallSign);              return string.Format("{0}: {1} {2} ({3})", Id, Number, Name, CallSign);
47          }          }
48    
49            private void UpdateInstance()
50            {
51                bool found_field = false;
52                var instance_type = this.GetInstance().GetType();
53                var fields = instance_type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
54                foreach (var field in fields)
55                {
56                    if (field.FieldType == typeof(List<IXMLTVChannel>))
57                    {
58                        found_field = true;
59                        try
60                        {
61                            xmltv_logger.Verbose.Debug.WriteLine("Updating instance with channel information: {0}", this.ToString());
62                            //field.SetValue(this.GetInstance(), new List<IXMLTVChannel>() { this });
63    
64                            var list = (List<IXMLTVChannel>)field.GetValue(this.GetInstance());
65                            list.Add(this);
66                            field.SetValue(this.GetInstance(), list);
67                            break;
68                        }
69                        catch (Exception ex)
70                        {
71                            xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with channel information.");
72                            xmltv_logger.Verbose.Error.WriteLine(ex.ToString());
73                        }
74                    }
75                }
76                if (!found_field)
77                {
78                    xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with channel information.");
79                }
80            }
81      }      }
82    
83  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.22