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

Annotation of /trunk/libxmltv/Core/XMLTVSource.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 120 - (hide annotations) (download)
Sun Mar 10 18:19:12 2013 UTC (7 years, 7 months ago) by william
File size: 4856 byte(s)

1 william 25 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using libxmltv.Interfaces;
6     using System.Diagnostics;
7 william 49 using System.Xml.Linq;
8 william 73 using System.Reflection;
9 william 78 using System.IO;
10 william 25
11     namespace libxmltv.Core
12     {
13 william 31 [Serializable]
14 william 72 internal class XMLTVSource : XMLTVBase<XMLTVRuntimeInstance>, IXMLTVSource, IDisposable//, ICloneable
15 william 25 {
16 william 72
17 william 25 private Dictionary<string, string> entries = new Dictionary<string, string>();
18 william 72 //internal static void CreateInstance(XMLTVRuntimeInstance xmltv)
19     //{
20     // using (XMLTVSource g = new XMLTVSource(xmltv)) { g.instance.Source = (IXMLTVSource)g.Clone(); }
21     //}
22 william 44
23 william 72 //private XMLTVRuntimeInstance instance;
24     //protected XMLTVSource(string sourcename, string generatorname, string generatorurl)
25     //{
26     // this.SourceName = sourcename;
27     // this.GeneratorName = generatorname;
28     // this.GeneratorUrl = generatorurl;
29     //}
30 william 120
31    
32     public object CreateBindableDataSource()
33     {
34     throw new NotImplementedException();
35     }
36    
37 william 73 public XMLTVSource()
38 william 88 : base(null, XMLTVConstants.Root.RootElement)
39 william 25 {
40 william 72 this.SourceName = string.Empty;
41     this.GeneratorName = string.Empty;
42     this.GeneratorUrl = string.Empty;
43 william 44 }
44 william 88 public XMLTVSource(XMLTVRuntimeInstance instance)
45     : base(instance, XMLTVConstants.Root.RootElement)
46 william 44 {
47 william 78 try {
48 william 74 xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVSource");
49 william 25 Create();
50 william 74 xmltv_logger.Verbose.Debug.WriteLine("Created Instance of XMLTVSource '{0}'", SourceName);
51 william 73 UpdateInstance();
52 william 78 }
53     catch (IOException ex) { Debug.WriteLine(ex.ToString()); }
54 william 25 }
55 william 73
56     private void UpdateInstance()
57     {
58     bool found_field = false;
59     var instance_type = this.GetInstance().GetType();
60     var fields = instance_type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
61     foreach (var field in fields)
62     {
63 william 77 if (field.FieldType == typeof(IXMLTVSource))
64 william 73 {
65     found_field = true;
66     try
67     {
68 william 74 xmltv_logger.Verbose.Debug.WriteLine("Updating instance with source information: {0}", this.ToString());
69 william 77 field.SetValue(this.GetInstance(), this);
70 william 73 break;
71     }
72     catch (Exception ex)
73     {
74 william 74 xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with source information.");
75     xmltv_logger.Verbose.Error.WriteLine(ex.ToString());
76 william 73 }
77     }
78     }
79     if (!found_field)
80     {
81 william 74 xmltv_logger.Verbose.Error.WriteLine("Unable to update instance with source information.");
82 william 73 }
83     }
84    
85 william 25 #region IXMLTVSource
86 william 36 //private IXMLTV_PARSER XMLTV_PARSER { get; set; }
87 william 44 public string SourceName { get; private set; }
88     public string GeneratorName { get; private set; }
89     public string GeneratorUrl { get; private set; }
90 william 25 #endregion
91    
92     private void Create()
93     {
94 william 72 var doc = XDocument.Parse(this.GetInstance().XmlDoc);
95 william 88 Debug.Assert(doc.Root.Name == XMLTVConstants.Root.RootElement, string.Format("Expected Root Element: '{0}' but read: '{1}'", XMLTVConstants.Root.RootElement, doc.Root.Name));
96 william 55 //xmltv_logger.Verbose.Debug.WriteLine("\tRoot: {0}", doc.Root.Name);
97 william 25 var attributes = doc.Root.Attributes().ToList();
98     foreach (var attribute in attributes)
99     {
100 william 59 xmltv_logger.Verbose.Debug.WriteLine("\t{0}: {1}", attribute.Name, attribute.Value);
101 william 25 entries.Add(attribute.Name.ToString(), attribute.Value);
102     }
103 william 44
104     SourceName = entries[XMLTVConstants.Source.SourceName];
105     GeneratorName = entries[XMLTVConstants.Source.GeneratorName];
106     GeneratorUrl = entries[XMLTVConstants.Source.GeneratorUrl];
107    
108 william 25 }
109     public override string ToString()
110     {
111     return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl);
112     }
113 william 44
114     public void Dispose()
115     {
116     //throw new NotImplementedException();
117     }
118    
119 william 72 //public object Clone()
120     //{
121     // return new XMLTVSource(this.SourceName, this.GeneratorName, this.GeneratorUrl);
122 william 120 //}
123 william 25 }
124     }

  ViewVC Help
Powered by ViewVC 1.1.22