/[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 46 - (hide annotations) (download)
Fri Mar 8 04:01:25 2013 UTC (7 years, 8 months ago) by william
File size: 2795 byte(s)
+ add support to cancel parseing when main form is closed

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

  ViewVC Help
Powered by ViewVC 1.1.22