ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/xmltv_parser/trunk/libxmltv/Core/XMLTV.cs
(Generate patch)

Comparing trunk/libxmltv/Core/XMLTV.cs (file contents):
Revision 55 by william, Fri Mar 8 10:19:32 2013 UTC vs.
Revision 56 by william, Fri Mar 8 12:05:33 2013 UTC

# Line 15 | Line 15 | namespace libxmltv.Core
15      /// </summary>
16      public static class XMLTV
17      {
18 <        static XMLTV() { xmltv_logger.Initialize(); }
18 >        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;
28          public static IXMLTVRuntimeInstance GetInstance() { return instance.GetInstance(); }
29          public static void CreateInstance(params object[] args) { instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(args); }
23        //public static void CreateInstance(string xml_file, EventHandler<CancelEventArgs> t) { instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(xml_file, t); }
24        //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); }
31 >        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
41          public static bool Serialize(string file) { return instance.Serialize(file); }
# Line 32 | Line 44 | namespace libxmltv.Core
44          public static IXMLTVRuntimeInstance DeSerialize(Stream stream, out bool status) { return instance.DeSerialize(stream, out status); }
45          #endregion
46  
47 <        public static void DestroyInstance() { instance.DestroyInstance(); }
47 >        public static void DestroyInstance() { instance.DestroyInstance(); }        
48  
49          public static EventHandler<EventArgs> OnInstanceCreated
50          {
# Line 41 | Line 53 | namespace libxmltv.Core
53          }
54      }
55  
56 <    internal class XMLTV<INTERFACE, CLASS> : IDestroyInstance, IXMLTV<INTERFACE, CLASS> where CLASS : class,INTERFACE
56 >    internal class XMLTV<INTERFACE, CLASS> : IDestroyInstance, IXMLTV<INTERFACE, CLASS> where CLASS : class,INTERFACE,new()
57      {
58 <    
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)
76          {
77              

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines