/[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 19 by william, Thu Mar 7 10:00:40 2013 UTC trunk/libxmltv/Core/XMLTVLoader.cs revision 44 by william, Fri Mar 8 03:36:44 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  {  {  
12      /// <summary>      internal class XMLTVLoader : IDisposable
     /// 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            internal static void CreateInstance(string xml_file, XMLTVRuntimeInstance xmltv)
16          {          {
17              XMLTV_LOGGER.Initialize();              using (XMLTVLoader g = new XMLTVLoader(xml_file, xmltv)) { }            
             XMLTV_LOADER loader = new XMLTV_LOADER(xml_file);  
             return loader;  
18          }          }
19          public static void Test(object xmltv)          private XMLTVRuntimeInstance instance;
20            protected XMLTVLoader(string xml_file, XMLTVRuntimeInstance xmltv)
21          {          {
22              if (!VerifyInstance<XMLTV_LOADER>(xmltv)) { return; }              XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVLoader");
23                //string _xmltv;
24                //if (!Internals.VerifyInstance<string>(xmltv, out _xmltv)) { return; }
25                //xmlfile = _xmltv;
26                //LoadXml();
27                instance = xmltv;
28                instance.XmlFile = new FileInfo(xml_file);
29                LoadXml();
30          }          }
31            //#region IXMLTV_LOADER
32            //public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }
33            //public XDocument XmlDoc { get; private set; }
34            //#endregion
35    
36            private void LoadXml()
         private static bool VerifyInstance<T>(object xmltv) where T : class  
37          {          {
38                XMLTV_LOGGER.Log.Info.WriteLine("Loading XMLTV File: {0}", instance.XmlFile.Name);
39                //XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!");
40              try              try
41              {              {
42                  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; }  
43              }              }
44              catch (Exception ex)              catch (Exception ex)
45              {              {
46                  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);
47                    XMLTV_LOGGER.Log.Error.WriteLine(ex.GetBaseException().ToString());
48              }              }
49          }          }
     }  
   
     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  
50    
51          private void LoadXml()          public void Dispose()
52          {          {
53              XMLTV_LOGGER.Log.Info.WriteLine("Loading XMLTV File: {0}", XmlFile.Name);              //throw new NotImplementedException();
             //XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!");  
             XDocument doc = XDocument.Load(XmlFile.FullName);  
54          }          }
55      }      }
56  }  }

Legend:
Removed from v.19  
changed lines
  Added in v.44

  ViewVC Help
Powered by ViewVC 1.1.22