using System; using System.Collections.Generic; using System.Linq; using System.Text; using libxmltv.Interfaces; using System.Diagnostics; namespace libxmltv.Core { internal class XMLTVSource : IXMLTVSource { private Dictionary entries = new Dictionary(); public XMLTVSource(object xmltv) { XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVSource"); IXMLTV_PARSER _xmltv; if (!Internals.VerifyInstance(xmltv, out _xmltv)) { return; } XMLTV_PARSER = _xmltv; Create(); } #region IXMLTVSource private IXMLTV_PARSER XMLTV_PARSER { get; set; } public string SourceName { get { return entries[XMLTV_CONSTANTS.Source.SourceName]; } } public string GeneratorName { get { return entries[XMLTV_CONSTANTS.Source.GeneratorName]; } } public string GeneratorUrl { get { return entries[XMLTV_CONSTANTS.Source.GeneratorUrl]; } } #endregion private void Create() { var doc = XMLTV_PARSER.XMLTV_LOADER.XmlDoc; 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)); XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tRoot: {0}", doc.Root.Name); var attributes = doc.Root.Attributes().ToList(); foreach (var attribute in attributes) { //XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t{0}: {1}", attribute.Name, attribute.Value); entries.Add(attribute.Name.ToString(), attribute.Value); } } public override string ToString() { return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl); } } }