/[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 21 by william, Thu Mar 7 10:04:58 2013 UTC revision 22 by william, Thu Mar 7 10:20:50 2013 UTC
# Line 8  using Enterprise.Logging; Line 8  using Enterprise.Logging;
8  using System.Xml.Linq;  using System.Xml.Linq;
9    
10  namespace libxmltv.Core  namespace libxmltv.Core
11  {  {  
     /// <summary>  
     /// Main class: Creates the XMLTV Loader  
     /// </summary>  
     public static class XMLTV  
     {  
         public static object CreateLoader(string xml_file)  
         {  
             XMLTV_LOGGER.Initialize();  
             XMLTV_LOADER loader = new XMLTV_LOADER(xml_file);  
             return loader;  
         }  
         public static void Test(object xmltv)  
         {  
             if (!VerifyInstance<XMLTV_LOADER>(xmltv)) { return; }  
         }  
   
   
         private static bool VerifyInstance<T>(object xmltv) where T : class  
         {  
             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; }  
             }  
             catch (Exception ex)  
             {  
                 throw new InvalidCastException(string.Format("Unable to cast type: {0} to {1}", xmltv.GetType().Name, typeof(T).Name), ex);  
             }  
         }  
     }  
   
12      internal class XMLTV_LOADER : IXMLTV_LOADER      internal class XMLTV_LOADER : IXMLTV_LOADER
13      {      {
14          private string xmlfile = string.Empty;          private string xmlfile = string.Empty;
15          public XMLTV_LOADER(string xml_file)          public XMLTV_LOADER(object xmltv)
16          {          {
17              xmlfile = xml_file;              string _xmltv;
18                if (!Internals.VerifyInstance<string>(xmltv, out _xmltv)) { return; }
19                xmlfile = _xmltv;
20              LoadXml();              LoadXml();
21          }          }
22          #region IXMLTV_LOADER          #region IXMLTV_LOADER
23          public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }          public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }
24            public XDocument XmlDoc { get; private set; }
25          #endregion          #endregion
26    
27          private void LoadXml()          private void LoadXml()
# Line 60  namespace libxmltv.Core Line 30  namespace libxmltv.Core
30              //XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!");              //XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!");
31              try              try
32              {              {
33                  XDocument doc = XDocument.Load(XmlFile.FullName);                  XmlDoc =  XDocument.Load(XmlFile.FullName);
34              }              }
35              catch (Exception ex)              catch (Exception ex)
36              {              {

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

  ViewVC Help
Powered by ViewVC 1.1.22