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