--- trunk/libxmltv/Core/XMLTV_LOADER.cs 2013/03/07 10:20:50 22 +++ trunk/libxmltv/Core/XMLTVLoader.cs 2013/03/09 09:29:40 72 @@ -6,37 +6,58 @@ using System.IO; using Enterprise.Logging; using System.Xml.Linq; +using System.Xml; namespace libxmltv.Core -{ - internal class XMLTV_LOADER : IXMLTV_LOADER +{ + internal class XMLTVLoader : XMLTVBase, IDisposable { private string xmlfile = string.Empty; - public XMLTV_LOADER(object xmltv) + //internal static void CreateInstance(string xml_file, XMLTVRuntimeInstance xmltv) + //{ + // using (XMLTVLoader g = new XMLTVLoader(xml_file, xmltv)) { } + //} + protected XMLTVLoader(string xml_file, XMLTVRuntimeInstance instance) + : base(instance) { - string _xmltv; - if (!Internals.VerifyInstance(xmltv, out _xmltv)) { return; } - xmlfile = _xmltv; + xmltv_logger.Debug.WriteLine("Creating Instance of XMLTVLoader"); + var fi = new FileInfo(xml_file); + this.GetInstance().XmlFile_FullName = fi.FullName; + this.GetInstance().XmlFile_Name = fi.Name; LoadXml(); + xmltv_logger.Debug.WriteLine("Created Instance of XMLTVLoader"); } - #region IXMLTV_LOADER - public FileInfo XmlFile { get { return new FileInfo(xmlfile); } } - public XDocument XmlDoc { get; private set; } - #endregion private void LoadXml() { - XMLTV_LOGGER.Log.Info.WriteLine("Loading XMLTV File: {0}", XmlFile.Name); - //XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!"); + xmltv_logger.Info.WriteLine("Loading XMLTV File: {0}", this.GetInstance().XmlFile_Name); + //xmltv_logger.Warn.WriteLine("XML File Loading has not been implemented yet!"); try { - XmlDoc = XDocument.Load(XmlFile.FullName); + var document = XDocument.Load(this.GetInstance().XmlFile_FullName); + using (var ms = new MemoryStream()) + using (var xw = new XmlTextWriter(ms, Encoding.UTF8)) + { + document.Save(xw); + xw.Flush(); + StreamReader sr = new StreamReader(ms); + ms.Seek(0, SeekOrigin.Begin); + this.GetInstance().XmlDoc = sr.ReadToEnd(); + } + document = null; } catch (Exception ex) { - XMLTV_LOGGER.Log.Error.WriteLine("Failed to load XMLTV File: {0}", XmlFile.Name); - XMLTV_LOGGER.Log.Error.WriteLine(ex.GetBaseException().ToString()); + xmltv_logger.Error.WriteLine("Failed to load XMLTV File: {0}", this.GetInstance().XmlFile_Name); + xmltv_logger.Error.WriteLine(ex.GetBaseException().ToString()); } } + + public void Dispose() + { + //throw new NotImplementedException(); + } + + } }