/[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 74 - (show annotations) (download)
Sat Mar 9 11:06:39 2013 UTC (7 years, 7 months ago) by william
File size: 3498 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 // get the channel id
26 Id = node.Attribute(XMLTVConstants.Channels.ChannelId).Value;
27 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
28 var names = node.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
29 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 xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVChannel");
36 UpdateInstance();
37 }
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
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 }

  ViewVC Help
Powered by ViewVC 1.1.22