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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 77 - (show annotations) (download)
Sat Mar 9 11:28:41 2013 UTC (7 years, 7 months ago) by william
File size: 3540 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22