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

  ViewVC Help
Powered by ViewVC 1.1.22