1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using libxmltv.Interfaces; |
6 |
using System.IO; |
7 |
using Enterprise.Logging; |
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 |
|
45 |
internal class XMLTV_LOADER : IXMLTV_LOADER |
46 |
{ |
47 |
private string xmlfile = string.Empty; |
48 |
public XMLTV_LOADER(string xml_file) |
49 |
{ |
50 |
xmlfile = xml_file; |
51 |
LoadXml(); |
52 |
} |
53 |
#region IXMLTV_LOADER |
54 |
public FileInfo XmlFile { get { return new FileInfo(xmlfile); } } |
55 |
#endregion |
56 |
|
57 |
private void LoadXml() |
58 |
{ |
59 |
XMLTV_LOGGER.Log.Info.WriteLine("Loading XMLTV File: {0}", XmlFile.Name); |
60 |
//XMLTV_LOGGER.Log.Warn.WriteLine("XML File Loading has not been implemented yet!"); |
61 |
try |
62 |
{ |
63 |
XDocument doc = XDocument.Load(XmlFile.FullName); |
64 |
} |
65 |
catch (Exception ex) |
66 |
{ |
67 |
XMLTV_LOGGER.Log.Error.WriteLine("Failed to load XMLTV File: {0}", XmlFile.Name); |
68 |
XMLTV_LOGGER.Log.Error.WriteLine(ex.GetBaseException().ToString()); |
69 |
} |
70 |
} |
71 |
} |
72 |
} |