/[xmltv_parser]/trunk/libxmltv/Core/XMLTVLoader.cs
ViewVC logotype

Diff of /trunk/libxmltv/Core/XMLTVLoader.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libxmltv/Core/XMLTVLoader.cs	2013/03/08 02:13:59	36
+++ trunk/libxmltv/Core/XMLTVLoader.cs	2013/03/09 12:23:27	81
@@ -6,42 +6,55 @@
 using System.IO;
 using Enterprise.Logging;
 using System.Xml.Linq;
+using System.Xml;
 
 namespace libxmltv.Core
-{   
-    internal class XMLTVLoader// : IXMLTV_LOADER
+{
+    internal class XMLTVLoader : XMLTVBase<XMLTVRuntimeInstance>, IDisposable
     {
-        private string xmlfile = string.Empty;
-        private XMLTVRuntimeInstance instance;
-        public XMLTVLoader(string xml_file, XMLTVRuntimeInstance xmltv)
+        //private string xmlfile = string.Empty;
+        public XMLTVLoader(string xml_file) : base(null, xml_file) { }
+        protected XMLTVLoader(string xml_file, XMLTVRuntimeInstance instance)
+            : base(instance, xml_file)
         {
-            XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVLoader");
-            //string _xmltv;
-            //if (!Internals.VerifyInstance<string>(xmltv, out _xmltv)) { return; }
-            //xmlfile = _xmltv;
-            //LoadXml();
-            instance = xmltv;
-            instance.XmlFile = new FileInfo(xml_file);
+            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}", instance.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
             {
-                instance.XmlDoc = XDocument.Load(instance.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}", instance.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();
+        }
+
+        
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22