/[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 55 by william, Fri Mar 8 10:19:32 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    using System.Xml;
10    
11  namespace libxmltv.Core  namespace libxmltv.Core
12  {  {  
13      /// <summary>      internal class XMLTVLoader : IDisposable
     /// Main class: Creates the XMLTV Loader  
     /// </summary>  
     public static class XMLTV  
14      {      {
15          public static object CreateLoader(string xml_file)          private string xmlfile = string.Empty;
16            internal static void CreateInstance(string xml_file, XMLTVRuntimeInstance xmltv)
17          {          {
18              XMLTV_LOGGER.Initialize();              using (XMLTVLoader g = new XMLTVLoader(xml_file, xmltv)) { }            
             XMLTV_LOADER loader = new XMLTV_LOADER(xml_file);  
             return loader;  
19          }          }
20          public static void Test(object xmltv)          private XMLTVRuntimeInstance instance;
21            protected XMLTVLoader(string xml_file, XMLTVRuntimeInstance xmltv)
22          {          {
23              if (!VerifyInstance<XMLTV_LOADER>(xmltv)) { return; }              xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVLoader");
24                //string _xmltv;
25                //if (!Internals.VerifyInstance<string>(xmltv, out _xmltv)) { return; }
26                //xmlfile = _xmltv;
27                //LoadXml();
28                instance = xmltv;
29                instance.XmlFile = new FileInfo(xml_file);
30                LoadXml();
31          }          }
32            //#region IXMLTV_LOADER
33            //public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }
34            //public XDocument XmlDoc { get; private set; }
35            //#endregion
36    
37            private void LoadXml()
         private static bool VerifyInstance<T>(object xmltv) where T : class  
38          {          {
39                xmltv_logger.Info.WriteLine("Loading XMLTV File: {0}", instance.XmlFile.Name);
40                //xmltv_logger.Warn.WriteLine("XML File Loading has not been implemented yet!");
41              try              try
42              {              {
43                  if (xmltv == null) { return false; }                  var document = XDocument.Load(instance.XmlFile.FullName);
44                  T t = (xmltv as T);                  using (var ms = new MemoryStream())
45                  if (t == null) { throw new InvalidCastException(string.Format("Unable to cast type: {0} to {1}", xmltv.GetType().Name, typeof(T).Name)); }                  using (var xw = new XmlTextWriter(ms, Encoding.UTF8))
46                  else { return true; }                  {
47                        document.Save(xw);
48                        xw.Flush();
49                        StreamReader sr = new StreamReader(ms);
50                        ms.Seek(0, SeekOrigin.Begin);
51                        instance.XmlDoc = sr.ReadToEnd();
52                    }
53                    document = null;
54              }              }
55              catch (Exception ex)              catch (Exception ex)
56              {              {
57                  throw new InvalidCastException(string.Format("Unable to cast type: {0} to {1}", xmltv.GetType().Name, typeof(T).Name), ex);                  xmltv_logger.Error.WriteLine("Failed to load XMLTV File: {0}", instance.XmlFile.Name);
58                    xmltv_logger.Error.WriteLine(ex.GetBaseException().ToString());
59              }              }
60          }          }
     }  
61    
62      internal class XMLTV_LOADER : IXMLTV_LOADER          public void Dispose()
     {  
         private string xmlfile = string.Empty;  
         public XMLTV_LOADER(string xml_file)  
63          {          {
64              xmlfile = xml_file;              //throw new NotImplementedException();
             LoadXml();  
65          }          }
         #region IXMLTV_LOADER  
         public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }  
         #endregion  
66    
67          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!");  
         }  
68      }      }
69  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.22