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