/[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

revision 14 by william, Thu Mar 7 09:05:18 2013 UTC revision 22 by william, Thu Mar 7 10:20:50 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 XMLTV_LOADER : 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          {          public XMLTV_LOADER(object xmltv)
             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)  
16          {          {
17              if (!VerifyInstance<XMLTV_LOADER>(xmltv)) { return; }              string _xmltv;
18                if (!Internals.VerifyInstance<string>(xmltv, out _xmltv)) { return; }
19                xmlfile = _xmltv;
20                LoadXml();
21          }          }
22            #region IXMLTV_LOADER
23            public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }
24            public XDocument XmlDoc { get; private set; }
25            #endregion
26    
27            private void LoadXml()
         private static bool VerifyInstance<T>(object xmltv) where T : class  
28          {          {
29                XMLTV_LOGGER.Log.Info.WriteLine("Loading XMLTV File: {0}", XmlFile.Name);
30                //XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!");
31              try              try
32              {              {
33                  if (xmltv == null) { return false; }                  XmlDoc =  XDocument.Load(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; }  
34              }              }
35              catch (Exception ex)              catch (Exception ex)
36              {              {
37                  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);
38                    XMLTV_LOGGER.Log.Error.WriteLine(ex.GetBaseException().ToString());
39              }              }
40          }          }
41      }      }
   
     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  
     }  
42  }  }

Legend:
Removed from v.14  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.22