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

  ViewVC Help
Powered by ViewVC 1.1.22