/[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 revision 16 by william, Thu Mar 7 09:26:43 2013 UTC trunk/libxmltv/Core/XMLTVLoader.cs revision 36 by william, Fri Mar 8 02:13:59 2013 UTC
# Line 5  using System.Text; Line 5  using System.Text;
5  using libxmltv.Interfaces;  using libxmltv.Interfaces;
6  using System.IO;  using System.IO;
7  using Enterprise.Logging;  using Enterprise.Logging;
8    using System.Xml.Linq;
9    
10  namespace libxmltv.Core  namespace libxmltv.Core
11  {  {  
12      /// <summary>      internal class XMLTVLoader// : IXMLTV_LOADER
     /// Main class: Creates the XMLTV Loader  
     /// </summary>  
     public static class XMLTV  
13      {      {
14          public static object CreateLoader(string xml_file)          private string xmlfile = string.Empty;
15          {          private XMLTVRuntimeInstance instance;
16              XMLTV_LOGGER.Initialize();          public XMLTVLoader(string xml_file, XMLTVRuntimeInstance xmltv)
             XMLTV_LOADER loader = new XMLTV_LOADER(xml_file);  
             return loader;  
         }  
         public static void Test(object xmltv)  
17          {          {
18              if (!VerifyInstance<XMLTV_LOADER>(xmltv)) { return; }              XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVLoader");
19                //string _xmltv;
20                //if (!Internals.VerifyInstance<string>(xmltv, out _xmltv)) { return; }
21                //xmlfile = _xmltv;
22                //LoadXml();
23                instance = xmltv;
24                instance.XmlFile = new FileInfo(xml_file);
25                LoadXml();
26          }          }
27            //#region IXMLTV_LOADER
28            //public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }
29            //public XDocument XmlDoc { get; private set; }
30            //#endregion
31    
32            private void LoadXml()
         private static bool VerifyInstance<T>(object xmltv) where T : class  
33          {          {
34                XMLTV_LOGGER.Log.Info.WriteLine("Loading XMLTV File: {0}", instance.XmlFile.Name);
35                //XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!");
36              try              try
37              {              {
38                  if (xmltv == null) { return false; }                  instance.XmlDoc = XDocument.Load(instance.XmlFile.FullName);
                 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; }  
39              }              }
40              catch (Exception ex)              catch (Exception ex)
41              {              {
42                  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}", instance.XmlFile.Name);
43                    XMLTV_LOGGER.Log.Error.WriteLine(ex.GetBaseException().ToString());
44              }              }
45          }          }
46      }      }
   
     internal class XMLTV_LOADER : IXMLTV_LOADER  
     {  
         private string xmlfile = string.Empty;  
         public XMLTV_LOADER(string xml_file)  
         {  
             xmlfile = xml_file;  
             LoadXml();  
         }  
         #region IXMLTV_LOADER  
         public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }  
         #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!");  
         }  
     }  
47  }  }

Legend:
Removed from v.16  
changed lines
  Added in v.36

  ViewVC Help
Powered by ViewVC 1.1.22