/[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 04:01:25	46
+++ trunk/libxmltv/Core/XMLTVLoader.cs	2013/03/09 09:29:40	72
@@ -6,45 +6,50 @@
 using System.IO;
 using Enterprise.Logging;
 using System.Xml.Linq;
+using System.Xml;
 
 namespace libxmltv.Core
-{   
-    internal class XMLTVLoader : IDisposable
+{
+    internal class XMLTVLoader : XMLTVBase<XMLTVRuntimeInstance>, IDisposable
     {
         private string xmlfile = string.Empty;
-        internal static void CreateInstance(string xml_file, XMLTVRuntimeInstance 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)
         {
-            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<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());
             }
         }
 
@@ -52,5 +57,7 @@
         {
             //throw new NotImplementedException();
         }
+
+        
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22