/[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/XMLTV_LOADER.cs	2013/03/07 10:20:50	22
+++ trunk/libxmltv/Core/XMLTVLoader.cs	2013/03/08 13:40:32	59
@@ -6,37 +6,64 @@
 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 : IDisposable
     {
         private string xmlfile = string.Empty;
-        public XMLTV_LOADER(object xmltv)
+        internal static void CreateInstance(string xml_file, XMLTVRuntimeInstance xmltv)
         {
-            string _xmltv;
-            if (!Internals.VerifyInstance<string>(xmltv, out _xmltv)) { return; }
-            xmlfile = _xmltv;
+            using (XMLTVLoader g = new XMLTVLoader(xml_file, xmltv)) { }            
+        }
+        private XMLTVRuntimeInstance instance;
+        protected XMLTVLoader(string xml_file, XMLTVRuntimeInstance xmltv)
+        {
+            xmltv_logger.Info.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);
             LoadXml();
         }
-        #region IXMLTV_LOADER
-        public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }
-        public XDocument XmlDoc { get; private set; }
-        #endregion
+        //#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}", instance.XmlFile.Name);
+            //xmltv_logger.Warn.WriteLine("XML File Loading has not been implemented yet!");
             try
             {
-                XmlDoc =  XDocument.Load(XmlFile.FullName);
+                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}", XmlFile.Name);
-                XMLTV_LOGGER.Log.Error.WriteLine(ex.GetBaseException().ToString());
+                xmltv_logger.Error.WriteLine("Failed to load XMLTV File: {0}", instance.XmlFile.Name);
+                xmltv_logger.Error.WriteLine(ex.GetBaseException().ToString());
             }
         }
+
+        public void Dispose()
+        {
+            //throw new NotImplementedException();
+        }
+
+        
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22