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 |
|
|
|
8 |
|
|
namespace libxmltv.Core |
9 |
|
|
{ |
10 |
|
|
/// <summary> |
11 |
|
|
/// Main class: Creates the XMLTV Loader |
12 |
|
|
/// </summary> |
13 |
|
|
public static class XMLTV |
14 |
|
|
{ |
15 |
|
|
public static object CreateLoader(string xml_file) |
16 |
|
|
{ |
17 |
|
|
XMLTV_LOADER loader = new XMLTV_LOADER(xml_file); |
18 |
|
|
return loader; |
19 |
|
|
} |
20 |
|
|
public static void Test(object xmltv) |
21 |
|
|
{ |
22 |
|
|
if (!VerifyInstance<XMLTV_LOADER>(xmltv)) { return; } |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
private static bool VerifyInstance<T>(object xmltv) where T : class |
27 |
|
|
{ |
28 |
|
|
try |
29 |
|
|
{ |
30 |
|
|
if (xmltv == null) { return false; } |
31 |
|
|
T t = (xmltv as T); |
32 |
|
|
if (t == null) { throw new InvalidCastException(string.Format("Unable to cast type: {0} to {1}", xmltv.GetType().Name, typeof(T).Name)); } |
33 |
|
|
else { return true; } |
34 |
|
|
} |
35 |
|
|
catch (Exception ex) |
36 |
|
|
{ |
37 |
|
|
throw new InvalidCastException(string.Format("Unable to cast type: {0} to {1}", xmltv.GetType().Name, typeof(T).Name), ex); |
38 |
|
|
} |
39 |
|
|
} |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
internal class XMLTV_LOADER : IXMLTV_LOADER |
43 |
|
|
{ |
44 |
|
|
private string xmlfile = string.Empty; |
45 |
|
|
public XMLTV_LOADER(string xml_file) |
46 |
|
|
{ |
47 |
|
|
xmlfile = xml_file; |
48 |
|
|
} |
49 |
|
|
#region IXMLTV_LOADER |
50 |
|
|
public FileInfo XmlFile { get { return new FileInfo(xmlfile); } } |
51 |
|
|
#endregion |
52 |
|
|
} |
53 |
|
|
} |