ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/xmltv_parser/trunk/libxmltv/Core/XMLTV_LOADER.cs
(Generate patch)

Comparing trunk/libxmltv/Core/XMLTV_LOADER.cs (file contents):
Revision 14 by william, Thu Mar 7 09:05:18 2013 UTC vs.
Revision 22 by william, Thu Mar 7 10:20:50 2013 UTC

--- trunk/libxmltv/Core/XMLTV_LOADER.cs	2013/03/07 09:05:18	14
+++ trunk/libxmltv/Core/XMLTV_LOADER.cs	2013/03/07 10:20:50	22
@@ -5,52 +5,38 @@ using System.Text;
 using libxmltv.Interfaces;
 using System.IO;
 using Enterprise.Logging;
+using System.Xml.Linq;
 
 namespace libxmltv.Core
-{
-    /// <summary>
-    /// Main class: Creates the XMLTV Loader
-    /// </summary>
-    public static class XMLTV
+{   
+    internal class XMLTV_LOADER : IXMLTV_LOADER
     {
-        public static object CreateLoader(string xml_file)
-        {
-            xmltv_logger.Initialize();
-            xmltv_logger.Log.Debug.WriteLine("Logged from XMLTV.CreateLoader");
-            XMLTV_LOADER loader = new XMLTV_LOADER(xml_file);
-            return loader;
-        }
-        public static void Test(object xmltv)
+        private string xmlfile = string.Empty;
+        public XMLTV_LOADER(object xmltv)
         {
-            if (!VerifyInstance<XMLTV_LOADER>(xmltv)) { return; }
+            string _xmltv;
+            if (!Internals.VerifyInstance<string>(xmltv, out _xmltv)) { return; }
+            xmlfile = _xmltv;
+            LoadXml();
         }
+        #region IXMLTV_LOADER
+        public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }
+        public XDocument XmlDoc { get; private set; }
+        #endregion
 
-
-        private static bool VerifyInstance<T>(object xmltv) where T : class
+        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!");
             try
             {
-                if (xmltv == null) { return false; }
-                T t = (xmltv as T);
-                if (t == null) { throw new InvalidCastException(string.Format("Unable to cast type: {0} to {1}", xmltv.GetType().Name, typeof(T).Name)); }
-                else { return true; }
+                XmlDoc =  XDocument.Load(XmlFile.FullName);
             }
             catch (Exception ex)
             {
-                throw new InvalidCastException(string.Format("Unable to cast type: {0} to {1}", xmltv.GetType().Name, typeof(T).Name), ex); 
+                XMLTV_LOGGER.Log.Error.WriteLine("Failed to load XMLTV File: {0}", XmlFile.Name);
+                XMLTV_LOGGER.Log.Error.WriteLine(ex.GetBaseException().ToString());
             }
         }
     }
-
-    internal class XMLTV_LOADER : IXMLTV_LOADER
-    {
-        private string xmlfile = string.Empty;
-        public XMLTV_LOADER(string xml_file)
-        {
-            xmlfile = xml_file;            
-        }
-        #region IXMLTV_LOADER
-        public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }
-        #endregion
-    }
 }