8 |
|
using System.Xml.Linq; |
9 |
|
|
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 |
< |
XMLTV_LOGGER.Initialize(); |
20 |
< |
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 |
< |
|
11 |
> |
{ |
12 |
|
internal class XMLTV_LOADER : IXMLTV_LOADER |
13 |
|
{ |
14 |
|
private string xmlfile = string.Empty; |
15 |
< |
public XMLTV_LOADER(string xml_file) |
15 |
> |
public XMLTV_LOADER(object xmltv) |
16 |
|
{ |
17 |
< |
xmlfile = xml_file; |
17 |
> |
string _xmltv; |
18 |
> |
if (!Internals.VerifyInstance<string>(xmltv, out _xmltv)) { return; } |
19 |
> |
xmlfile = _xmltv; |
20 |
|
LoadXml(); |
21 |
|
} |
22 |
|
#region IXMLTV_LOADER |
23 |
|
public FileInfo XmlFile { get { return new FileInfo(xmlfile); } } |
24 |
+ |
public XDocument XmlDoc { get; private set; } |
25 |
|
#endregion |
26 |
|
|
27 |
|
private void LoadXml() |
30 |
|
//XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!"); |
31 |
|
try |
32 |
|
{ |
33 |
< |
XDocument doc = XDocument.Load(XmlFile.FullName); |
33 |
> |
XmlDoc = XDocument.Load(XmlFile.FullName); |
34 |
|
} |
35 |
|
catch (Exception ex) |
36 |
|
{ |