ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/xmltv_parser/trunk/libxmltv/Core/XMLTVChannel.cs
Revision: 118
Committed: Sun Mar 10 17:41:52 2013 UTC (10 years, 9 months ago) by william
File size: 4024 byte(s)
Log Message:

File Contents

# Content
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 InternalDictionaryAddKnownProperties();
20 Id = string.Empty;
21 //Number = 0;
22 //CallSign = string.Empty;
23 //Name = string.Empty;
24 }
25 public XMLTVChannel(XMLTVRuntimeInstance instance, XElement node)
26 : base(instance, XMLTVConstants.Channels.RootElement)
27 {
28 InternalDictionaryAddKnownProperties();
29 try
30 {
31 xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannel");
32 Create(node);
33 xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVChannel");
34 UpdateInstance();
35 }
36 catch (IOException ex) { Debug.WriteLine(ex.ToString()); }
37 }
38 private void InternalDictionaryAddKnownProperties()
39 {
40 MetaData = new PropertyList();
41 }
42 #region IXMLTVChannel members
43 public string Id { get; private set; }
44 //public int Number { get; private set; }
45 //public string CallSign { get; private set; }
46 //public string Name { get; private set; }
47 private IPropertyList _MetaData;
48 public IPropertyList MetaData { get { return _MetaData; } private set { _MetaData = value; } }
49 #endregion
50 public override string ToString()
51 {
52 return string.Format("{0}", Id);
53 }
54
55 private void UpdateInstance()
56 {
57 bool found_field = false;
58 var instance_type = this.GetInstance().GetType();
59 var fields = instance_type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
60 foreach (var field in fields)
61 {
62 if (field.FieldType == typeof(List<IXMLTVChannel>))
63 {
64 found_field = true;
65 try
66 {
67 var list = (List<IXMLTVChannel>)field.GetValue(this.GetInstance());
68 list.Add(this);
69 xmltv_logger.Verbose.Debug.WriteLine("Updating instance with channel information: {0}", this.ToString());
70 field.SetValue(this.GetInstance(), list);
71 break;
72 }
73 catch (Exception ex)
74 {
75 xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with channel information.");
76 xmltv_logger.Verbose.Error.WriteLine(ex.ToString());
77 }
78 }
79 }
80 if (!found_field)
81 {
82 xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with channel information.");
83 }
84 }
85
86 private void Create(XElement node)
87 {
88 //throw new NotImplementedException("Channel.Create(node) is not currently implemented.");
89 // get the channel id
90 Id = node.Attribute(XMLTVConstants.Channels.ChannelId).Value;
91 xmltv_logger.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id);
92 var names = node.Elements().ToList();
93
94 foreach (var name in names)
95 {
96 PropertyValuePair p = new PropertyValuePair(name.Name.ToString(), name.Value);
97 MetaData.AddProperty(p.Name,p.Value);
98 xmltv_logger.Verbose.Debug.WriteLine("\t{0}: {1}", p.Name, p.Value);
99 }
100
101 }
102 }
103
104 }