15 |
/// </summary> |
/// </summary> |
16 |
public static class XMLTV |
public static class XMLTV |
17 |
{ |
{ |
18 |
static XMLTV() { xmltv_logger.Initialize(); } |
static XMLTV() |
19 |
|
{ |
20 |
|
xmltv_logger.Initialize(); |
21 |
|
if (instance == null) |
22 |
|
{ |
23 |
|
instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(); |
24 |
|
} |
25 |
|
} |
26 |
|
|
27 |
static IXMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance> instance; |
static IXMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance> instance; |
28 |
public static IXMLTVRuntimeInstance GetInstance() { return instance.GetInstance(); } |
public static IXMLTVRuntimeInstance GetInstance() { return instance.GetInstance(); } |
29 |
public static void CreateInstance(params object[] args) { instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(args); } |
public static void CreateInstance(params object[] args) { instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(args); } |
|
//public static void CreateInstance(string xml_file, EventHandler<CancelEventArgs> t) { instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(xml_file, t); } |
|
|
//public static IXMLTVSerializer<IXMLTVRuntimeInstance> GetSerializer() {return new XMLTVSerializer<IXMLTVRuntimeInstance>(InternalGetInstance()); } |
|
30 |
|
|
31 |
//private static IXMLTVSerializer<T> CreateSerializer<T>() where T : class { return new XMLTVSerializer<T>(InternalGetInstance() as T); } |
public static void CreateFromInstance(object raw_instance, EventHandler<EventArgs> handler) |
32 |
|
{ |
33 |
|
instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(raw_instance,handler); |
34 |
|
if (OnInstanceCreated != null) |
35 |
|
{ |
36 |
|
OnInstanceCreated.Invoke(null, new EventArgs()); |
37 |
|
} |
38 |
|
} |
39 |
|
|
40 |
#region IXMLTVSerializer<IXMLTVRuntimeInstance> members |
#region IXMLTVSerializer<IXMLTVRuntimeInstance> members |
41 |
public static bool Serialize(string file) { return instance.Serialize(file); } |
public static bool Serialize(string file) { return instance.Serialize(file); } |
44 |
public static IXMLTVRuntimeInstance DeSerialize(Stream stream, out bool status) { return instance.DeSerialize(stream, out status); } |
public static IXMLTVRuntimeInstance DeSerialize(Stream stream, out bool status) { return instance.DeSerialize(stream, out status); } |
45 |
#endregion |
#endregion |
46 |
|
|
47 |
public static void DestroyInstance() { instance.DestroyInstance(); } |
public static void DestroyInstance() { instance.DestroyInstance(); } |
48 |
|
|
49 |
public static EventHandler<EventArgs> OnInstanceCreated |
public static EventHandler<EventArgs> OnInstanceCreated |
50 |
{ |
{ |
53 |
} |
} |
54 |
} |
} |
55 |
|
|
56 |
internal class XMLTV<INTERFACE, CLASS> : IDestroyInstance, IXMLTV<INTERFACE, CLASS> where CLASS : class,INTERFACE |
internal class XMLTV<INTERFACE, CLASS> : IDestroyInstance, IXMLTV<INTERFACE, CLASS> where CLASS : class,INTERFACE,new() |
57 |
{ |
{ |
58 |
|
public XMLTV() |
59 |
|
{ |
60 |
|
instance = new CLASS(); |
61 |
|
} |
62 |
|
public XMLTV(object raw_instance, EventHandler<EventArgs> handler) |
63 |
|
{ |
64 |
|
instance = (CLASS)Convert.ChangeType(raw_instance, typeof(CLASS)); |
65 |
|
if (instance != null) |
66 |
|
{ |
67 |
|
IRuntimeInstanceLoader<CLASS> loader = (instance as IRuntimeInstanceLoader<CLASS>); |
68 |
|
if (loader != null) |
69 |
|
{ |
70 |
|
SetOnInstanceCreated(handler); |
71 |
|
instance = loader.LoadFromInstance(instance); |
72 |
|
} |
73 |
|
} |
74 |
|
} |
75 |
public XMLTV(params object[] args) |
public XMLTV(params object[] args) |
76 |
{ |
{ |
77 |
|
|