--- trunk/libxmltv/Core/XMLTV_LOADER.cs 2013/03/07 10:04:58 21 +++ trunk/libxmltv/Core/XMLTVLoader.cs 2013/03/08 02:13:59 36 @@ -8,63 +8,38 @@ using System.Xml.Linq; namespace libxmltv.Core -{ - /// - /// Main class: Creates the XMLTV Loader - /// - 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)) { return; } - } - - - private static bool VerifyInstance(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); - } - } - } - - internal class XMLTV_LOADER : IXMLTV_LOADER +{ + internal class XMLTVLoader// : IXMLTV_LOADER { private string xmlfile = string.Empty; - public XMLTV_LOADER(string xml_file) + private XMLTVRuntimeInstance instance; + public XMLTVLoader(string xml_file, XMLTVRuntimeInstance xmltv) { - xmlfile = xml_file; + XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVLoader"); + //string _xmltv; + //if (!Internals.VerifyInstance(xmltv, out _xmltv)) { return; } + //xmlfile = _xmltv; + //LoadXml(); + instance = xmltv; + instance.XmlFile = new FileInfo(xml_file); LoadXml(); } - #region IXMLTV_LOADER - public FileInfo XmlFile { get { return new FileInfo(xmlfile); } } - #endregion + //#region IXMLTV_LOADER + //public FileInfo XmlFile { get { return new FileInfo(xmlfile); } } + //public XDocument XmlDoc { get; private set; } + //#endregion private void LoadXml() { - XMLTV_LOGGER.Log.Info.WriteLine("Loading XMLTV File: {0}", XmlFile.Name); + XMLTV_LOGGER.Log.Info.WriteLine("Loading XMLTV File: {0}", instance.XmlFile.Name); //XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!"); try { - XDocument doc = XDocument.Load(XmlFile.FullName); + instance.XmlDoc = XDocument.Load(instance.XmlFile.FullName); } catch (Exception ex) { - XMLTV_LOGGER.Log.Error.WriteLine("Failed to load XMLTV File: {0}", XmlFile.Name); + XMLTV_LOGGER.Log.Error.WriteLine("Failed to load XMLTV File: {0}", instance.XmlFile.Name); XMLTV_LOGGER.Log.Error.WriteLine(ex.GetBaseException().ToString()); } }