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 |
12 |
{ |
13 |
private Dictionary<string, string> entries = new Dictionary<string, string>(); |
14 |
public XMLTVSource(object xmltv) |
15 |
{ |
16 |
XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVSource"); |
17 |
IXMLTV_PARSER _xmltv; |
18 |
if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; } |
19 |
XMLTV_PARSER = _xmltv; |
20 |
Create(); |
21 |
} |
22 |
|
23 |
#region IXMLTVSource |
24 |
private IXMLTV_PARSER XMLTV_PARSER { get; set; } |
25 |
public string SourceName { get { return entries[XMLTV_CONSTANTS.Source.SourceName]; } } |
26 |
public string GeneratorName { get { return entries[XMLTV_CONSTANTS.Source.GeneratorName]; } } |
27 |
public string GeneratorUrl { get { return entries[XMLTV_CONSTANTS.Source.GeneratorUrl]; } } |
28 |
#endregion |
29 |
|
30 |
private void Create() |
31 |
{ |
32 |
var doc = XMLTV_PARSER.XMLTV_LOADER.XmlDoc; |
33 |
Debug.Assert(doc.Root.Name == XMLTV_CONSTANTS.ROOT_ELEMENT, string.Format("Expected Root Element: '{0}' but read: '{1}'", XMLTV_CONSTANTS.ROOT_ELEMENT, doc.Root.Name)); |
34 |
XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tRoot: {0}", doc.Root.Name); |
35 |
var attributes = doc.Root.Attributes().ToList(); |
36 |
foreach (var attribute in attributes) |
37 |
{ |
38 |
//XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t{0}: {1}", attribute.Name, attribute.Value); |
39 |
entries.Add(attribute.Name.ToString(), attribute.Value); |
40 |
} |
41 |
} |
42 |
public override string ToString() |
43 |
{ |
44 |
return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl); |
45 |
} |
46 |
} |
47 |
} |