/[xmltv_parser]/trunk/libxmltv/Core/XMLTVLoader.cs
ViewVC logotype

Annotation of /trunk/libxmltv/Core/XMLTVLoader.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 19 - (hide annotations) (download)
Thu Mar 7 10:00:40 2013 UTC (7 years, 7 months ago) by william
Original Path: trunk/libxmltv/Core/XMLTV_LOADER.cs
File size: 2012 byte(s)

1 william 11 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using libxmltv.Interfaces;
6     using System.IO;
7 william 14 using Enterprise.Logging;
8 william 19 using System.Xml.Linq;
9 william 11
10     namespace libxmltv.Core
11     {
12     /// <summary>
13     /// Main class: Creates the XMLTV Loader
14     /// </summary>
15     public static class XMLTV
16     {
17     public static object CreateLoader(string xml_file)
18     {
19 william 16 XMLTV_LOGGER.Initialize();
20 william 11 XMLTV_LOADER loader = new XMLTV_LOADER(xml_file);
21     return loader;
22     }
23     public static void Test(object xmltv)
24     {
25     if (!VerifyInstance<XMLTV_LOADER>(xmltv)) { return; }
26     }
27    
28    
29     private static bool VerifyInstance<T>(object xmltv) where T : class
30     {
31     try
32     {
33     if (xmltv == null) { return false; }
34     T t = (xmltv as T);
35     if (t == null) { throw new InvalidCastException(string.Format("Unable to cast type: {0} to {1}", xmltv.GetType().Name, typeof(T).Name)); }
36     else { return true; }
37     }
38     catch (Exception ex)
39     {
40     throw new InvalidCastException(string.Format("Unable to cast type: {0} to {1}", xmltv.GetType().Name, typeof(T).Name), ex);
41     }
42     }
43     }
44    
45     internal class XMLTV_LOADER : IXMLTV_LOADER
46     {
47     private string xmlfile = string.Empty;
48     public XMLTV_LOADER(string xml_file)
49     {
50 william 16 xmlfile = xml_file;
51     LoadXml();
52 william 11 }
53     #region IXMLTV_LOADER
54     public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }
55     #endregion
56 william 16
57     private void LoadXml()
58     {
59     XMLTV_LOGGER.Log.Info.WriteLine("Loading XMLTV File: {0}", XmlFile.Name);
60 william 19 //XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!");
61     XDocument doc = XDocument.Load(XmlFile.FullName);
62 william 16 }
63 william 11 }
64     }

  ViewVC Help
Powered by ViewVC 1.1.22