using System; using System.Collections.Generic; using System.Linq; using System.Text; using libxmltv.Interfaces; using System.Diagnostics; using System.Xml.Linq; namespace libxmltv.Core { [Serializable] internal class XMLTVSource : IXMLTVSource, IDisposable, ICloneable { private Dictionary entries = new Dictionary(); internal static void CreateInstance(XMLTVRuntimeInstance xmltv) { using (XMLTVSource g = new XMLTVSource(xmltv)) { g.instance.Source = (IXMLTVSource)g.Clone(); } } private XMLTVRuntimeInstance instance; protected XMLTVSource(string sourcename, string generatorname, string generatorurl) { } protected XMLTVSource(XMLTVRuntimeInstance xmltv) { xmltv_logger.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVSource"); //IXMLTV_PARSER _xmltv; //if (!Internals.VerifyInstance(xmltv, out _xmltv)) { return; } //XMLTV_PARSER = _xmltv; instance = xmltv; Create(); } #region IXMLTVSource //private IXMLTV_PARSER XMLTV_PARSER { get; set; } public string SourceName { get; private set; } public string GeneratorName { get; private set; } public string GeneratorUrl { get; private set; } #endregion private void Create() { var doc = XDocument.Parse(instance.XmlDoc); Debug.Assert(doc.Root.Name == XMLTVConstants.ROOT_ELEMENT, string.Format("Expected Root Element: '{0}' but read: '{1}'", XMLTVConstants.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); } SourceName = entries[XMLTVConstants.Source.SourceName]; GeneratorName = entries[XMLTVConstants.Source.GeneratorName]; GeneratorUrl = entries[XMLTVConstants.Source.GeneratorUrl]; } public override string ToString() { return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl); } public void Dispose() { //throw new NotImplementedException(); } public object Clone() { return new XMLTVSource(this.SourceName, this.GeneratorName, this.GeneratorUrl); } } }