using System; using System.Collections.Generic; using System.Linq; using System.Text; using libxmltv.Interfaces; using System.IO; using Enterprise.Logging; using System.Xml.Linq; using System.Xml; namespace libxmltv.Core { internal class XMLTVLoader : IDisposable { private string xmlfile = string.Empty; internal static void CreateInstance(string xml_file, XMLTVRuntimeInstance xmltv) { using (XMLTVLoader g = new XMLTVLoader(xml_file, xmltv)) { } } private XMLTVRuntimeInstance instance; protected XMLTVLoader(string xml_file, XMLTVRuntimeInstance xmltv) { xmltv_logger.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVLoader"); //string _xmltv; //if (!Internals.VerifyInstance(xmltv, out _xmltv)) { return; } //xmlfile = _xmltv; //LoadXml(); instance = xmltv; instance.XmlFile = new FileInfo(xml_file); LoadXml(); } //#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}", instance.XmlFile.Name); //xmltv_logger.Log.Warn.WriteLine("XML File Loading has not been implemented yet!"); try { var document = XDocument.Load(instance.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); instance.XmlDoc = sr.ReadToEnd(); } document = null; } catch (Exception ex) { xmltv_logger.Log.Error.WriteLine("Failed to load XMLTV File: {0}", instance.XmlFile.Name); xmltv_logger.Log.Error.WriteLine(ex.GetBaseException().ToString()); } } public void Dispose() { //throw new NotImplementedException(); } } }