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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 49 by william, Fri Mar 8 05:20:12 2013 UTC revision 50 by william, Fri Mar 8 06:15:44 2013 UTC
# Line 4  using System.Linq; Line 4  using System.Linq;
4  using System.Text;  using System.Text;
5  using libxmltv.Interfaces;  using libxmltv.Interfaces;
6  using System.ComponentModel;  using System.ComponentModel;
7    using System.IO;
8    
9  namespace libxmltv.Core  namespace libxmltv.Core
10  {  {
# Line 14  namespace libxmltv.Core Line 15  namespace libxmltv.Core
15      {      {
16          static XMLTV() { xmltv_logger.Initialize(); }          static XMLTV() { xmltv_logger.Initialize(); }
17    
18          private static XMLTVRuntimeInstance instance;          static IXMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance> instance;
19          public static IXMLTVRuntimeInstance GetInstance() { return InternalGetInstance(); }          public static IXMLTVRuntimeInstance GetInstance() { return instance.GetInstance(); }
         internal static XMLTVRuntimeInstance InternalGetInstance() { return instance; }  
20          public static void CreateInstance(string xml_file) { CreateInstance(xml_file, null); }          public static void CreateInstance(string xml_file) { CreateInstance(xml_file, null); }
21          public static void CreateInstance(string xml_file, EventHandler<CancelEventArgs> t) { instance = new XMLTVRuntimeInstance(xml_file, t); }          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 InternalGetInstance().Serializer; }          //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      }      }
33    
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  }  }
81    
82    

Legend:
Removed from v.49  
changed lines
  Added in v.50

  ViewVC Help
Powered by ViewVC 1.1.22