/[xmltv_parser]/trunk/libxmltv/Core/XMLTV.cs
ViewVC logotype

Annotation of /trunk/libxmltv/Core/XMLTV.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 50 - (hide annotations) (download)
Fri Mar 8 06:15:44 2013 UTC (7 years, 7 months ago) by william
File size: 3702 byte(s)

1 william 22 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using libxmltv.Interfaces;
6 william 46 using System.ComponentModel;
7 william 50 using System.IO;
8 william 22
9     namespace libxmltv.Core
10     {
11     /// <summary>
12     /// Main class: Creates the XMLTV Loader
13     /// </summary>
14     public static class XMLTV
15     {
16 william 46 static XMLTV() { xmltv_logger.Initialize(); }
17 william 23
18 william 50 static IXMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance> instance;
19     public static IXMLTVRuntimeInstance GetInstance() { return instance.GetInstance(); }
20 william 49 public static void CreateInstance(string xml_file) { CreateInstance(xml_file, null); }
21 william 50 public static void CreateInstance(string xml_file, EventHandler<CancelEventArgs> t) { instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(xml_file, t); }
22     //public static IXMLTVSerializer<IXMLTVRuntimeInstance> GetSerializer() {return new XMLTVSerializer<IXMLTVRuntimeInstance>(InternalGetInstance()); }
23    
24     //private static IXMLTVSerializer<T> CreateSerializer<T>() where T : class { return new XMLTVSerializer<T>(InternalGetInstance() as T); }
25    
26     #region IXMLTVSerializer<IXMLTVRuntimeInstance> members
27     public static bool Serialize(string file) { return instance.Serialize(file); }
28     public static bool Serialize(Stream stream) { return instance.Serialize(stream); }
29     public static IXMLTVRuntimeInstance DeSerialize(string file, out bool status) { return instance.DeSerialize(file, out status); }
30     public static IXMLTVRuntimeInstance DeSerialize(Stream stream, out bool status) { return instance.DeSerialize(stream, out status); }
31     #endregion
32 william 22 }
33 william 50
34     internal class XMLTV<INTERFACE, CLASS> : IXMLTV<INTERFACE, CLASS> where CLASS : class,INTERFACE
35     {
36     public XMLTV(string xml_file) : this(xml_file, null) { }
37     public XMLTV(string xml_file, EventHandler<CancelEventArgs> t)
38     {
39     //instance = new CLASS(xml_file, t);
40     instance = null;
41    
42     Type type = typeof(CLASS);
43     var ctors = type.GetConstructors();
44     foreach (var ctor in ctors)
45     {
46     var ctor_params = ctor.GetParameters();
47     if (ctor_params.Count() == 2)
48     {
49     if (ctor_params[0].ParameterType == typeof(string))
50     {
51     if (ctor_params[1].ParameterType == typeof(EventHandler<CancelEventArgs>))
52     {
53     object o = ctor.Invoke(new object[] { xml_file, t });
54     instance = (CLASS)Convert.ChangeType(o, typeof(CLASS));
55     break;
56     }
57     }
58     }
59     else { continue; }
60     }
61     }
62    
63     private CLASS instance;
64     #region IXMLTV<T> members
65     private IXMLTVSerializer<INTERFACE> CreateSerializer() { return new XMLTVSerializer<INTERFACE>(instance); }
66     public INTERFACE GetInstance()
67     {
68     return (INTERFACE)instance;
69     }
70     #endregion
71    
72     #region IXMLTVSerializer<INTERFACE> members
73     public bool Serialize(string file) { return CreateSerializer().Serialize(file); }
74     public bool Serialize(Stream stream) { return CreateSerializer().Serialize(stream); }
75     public INTERFACE DeSerialize(string file, out bool status) { return CreateSerializer().DeSerialize(file, out status); }
76     public INTERFACE DeSerialize(Stream stream, out bool status) { return CreateSerializer().DeSerialize(stream, out status); }
77     #endregion
78     }
79    
80 william 22 }
81 william 46
82 william 49

  ViewVC Help
Powered by ViewVC 1.1.22