/[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 75 - (show annotations) (download)
Sat Mar 9 11:17:13 2013 UTC (7 years, 8 months ago) by william
File size: 3593 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 xmltv_logger.Verbose.Debug.WriteLine("Updating instance with channel information: {0}", this.ToString());
53 //field.SetValue(this.GetInstance(), new List<IXMLTVChannel>() { this });
54
55 var list = (List<IXMLTVChannel>)field.GetValue(this.GetInstance());
56 list.Add(this);
57 field.SetValue(this.GetInstance(), list);
58 break;
59 }
60 catch (Exception ex)
61 {
62 xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with channel information.");
63 xmltv_logger.Verbose.Error.WriteLine(ex.ToString());
64 }
65 }
66 }
67 if (!found_field)
68 {
69 xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with channel information.");
70 }
71 }
72
73 private void Create(XElement node)
74 {
75 // get the channel id
76 Id = node.Attribute(XMLTVConstants.Channels.ChannelId).Value;
77 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
78 var names = node.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList();
79 Number = Convert.ToInt32(names[1].Value);
80 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number);
81 CallSign = names[2].Value;
82 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign);
83 Name = names[3].Value;
84 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name);
85 }
86 }
87
88 }

  ViewVC Help
Powered by ViewVC 1.1.22