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