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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 74 - (hide annotations) (download)
Sat Mar 9 11:06:39 2013 UTC (7 years, 6 months ago) by william
File size: 3498 byte(s)

1 william 73 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using libxmltv.Interfaces;
6     using System.Xml.Linq;
7 william 74 using System.Reflection;
8 william 73
9     namespace libxmltv.Core
10     {
11     [Serializable]
12 william 74 internal class XMLTVChannel : XMLTVBase<XMLTVRuntimeInstance>, IXMLTVChannel
13 william 73 {
14 william 74 public XMLTVChannel() : base(null,XMLTVConstants.CHANNEL_ELEMENT)
15 william 73 {
16     Id = string.Empty;
17     Number = 0;
18     CallSign = string.Empty;
19     Name = string.Empty;
20     }
21 william 74 public XMLTVChannel(XMLTVRuntimeInstance instance, XElement node)
22     : base(instance, XMLTVConstants.CHANNEL_ELEMENT)
23 william 73 {
24 william 74 xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannel");
25 william 73 // get the channel id
26 william 74 Id = node.Attribute(XMLTVConstants.Channels.ChannelId).Value;
27 william 73 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
28 william 74 var names = node.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
29 william 73 Number = Convert.ToInt32(names[1].Value);
30     xmltv_logger.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);
31     CallSign = names[2].Value;
32     xmltv_logger.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);
33     Name = names[3].Value;
34     xmltv_logger.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);
35 william 74 xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVChannel");
36     UpdateInstance();
37 william 73 }
38     #region IXMLTVChannel members
39     public string Id { get; private set; }
40     public int Number { get; private set; }
41     public string CallSign { get; private set; }
42     public string Name { get; private set; }
43     #endregion
44     public override string ToString()
45     {
46     return string.Format("{0}: {1} {2} ({3})", Id, Number, Name, CallSign);
47     }
48 william 74
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 william 73 }
82    
83     }

  ViewVC Help
Powered by ViewVC 1.1.22