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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 69 - (show annotations) (download)
Sat Mar 9 01:36:49 2013 UTC (7 years, 8 months ago) by william
File size: 2953 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.Diagnostics;
7 using System.Xml.Linq;
8
9 namespace libxmltv.Core
10 {
11 [Serializable]
12 internal class XMLTVSource : IXMLTVSource, IDisposable, ICloneable
13 {
14 private Dictionary<string, string> entries = new Dictionary<string, string>();
15 internal static void CreateInstance(XMLTVRuntimeInstance xmltv)
16 {
17 using (XMLTVSource g = new XMLTVSource(xmltv)) { g.instance.Source = (IXMLTVSource)g.Clone(); }
18 }
19
20 private XMLTVRuntimeInstance instance;
21 protected XMLTVSource(string sourcename, string generatorname, string generatorurl)
22 {
23 this.SourceName = sourcename;
24 this.GeneratorName = generatorname;
25 this.GeneratorUrl = generatorurl;
26 }
27 protected XMLTVSource(XMLTVRuntimeInstance xmltv)
28 {
29 xmltv_logger.Debug.WriteLine("Creating Instance of XMLTVSource");
30 //IXMLTV_PARSER _xmltv;
31 //if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
32 //XMLTV_PARSER = _xmltv;
33 instance = xmltv;
34 Create();
35 }
36
37 #region IXMLTVSource
38 //private IXMLTV_PARSER XMLTV_PARSER { get; set; }
39 public string SourceName { get; private set; }
40 public string GeneratorName { get; private set; }
41 public string GeneratorUrl { get; private set; }
42 #endregion
43
44 private void Create()
45 {
46 var doc = XDocument.Parse(instance.XmlDoc);
47 Debug.Assert(doc.Root.Name == XMLTVConstants.ROOT_ELEMENT, string.Format("Expected Root Element: '{0}' but read: '{1}'", XMLTVConstants.ROOT_ELEMENT, doc.Root.Name));
48 //xmltv_logger.Verbose.Debug.WriteLine("\tRoot: {0}", doc.Root.Name);
49 var attributes = doc.Root.Attributes().ToList();
50 foreach (var attribute in attributes)
51 {
52 xmltv_logger.Verbose.Debug.WriteLine("\t{0}: {1}", attribute.Name, attribute.Value);
53 entries.Add(attribute.Name.ToString(), attribute.Value);
54 }
55
56 SourceName = entries[XMLTVConstants.Source.SourceName];
57 GeneratorName = entries[XMLTVConstants.Source.GeneratorName];
58 GeneratorUrl = entries[XMLTVConstants.Source.GeneratorUrl];
59
60 }
61 public override string ToString()
62 {
63 return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl);
64 }
65
66 public void Dispose()
67 {
68 //throw new NotImplementedException();
69 }
70
71 public object Clone()
72 {
73 return new XMLTVSource(this.SourceName, this.GeneratorName, this.GeneratorUrl);
74 }
75 }
76 }

  ViewVC Help
Powered by ViewVC 1.1.22