/[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

--- trunk/libxmltv/Core/XMLTV.cs	2013/03/08 10:19:32	55
+++ trunk/libxmltv/Core/XMLTV.cs	2013/03/08 12:05:33	56
@@ -15,15 +15,27 @@
     /// </summary>
     public static class XMLTV
     {
-        static XMLTV() { xmltv_logger.Initialize(); }
+        static XMLTV()
+        {
+            xmltv_logger.Initialize();
+            if (instance == null)
+            {
+                instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>();
+            }
+        }
 
         static IXMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance> instance;
         public static IXMLTVRuntimeInstance GetInstance() { return instance.GetInstance(); }
         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()); }
 
-        //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) 
+        { 
+            instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(raw_instance,handler);
+            if (OnInstanceCreated != null)
+            {
+                OnInstanceCreated.Invoke(null, new EventArgs());
+            }
+        }
 
         #region IXMLTVSerializer<IXMLTVRuntimeInstance> members
         public static bool Serialize(string file) { return instance.Serialize(file); }
@@ -32,7 +44,7 @@
         public static IXMLTVRuntimeInstance DeSerialize(Stream stream, out bool status) { return instance.DeSerialize(stream, out status); }
         #endregion
 
-        public static void DestroyInstance() { instance.DestroyInstance(); }
+        public static void DestroyInstance() { instance.DestroyInstance(); }        
 
         public static EventHandler<EventArgs> OnInstanceCreated
         {
@@ -41,9 +53,25 @@
         }
     }
 
-    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()
     {
-     
+        public XMLTV()
+        {
+            instance = new CLASS();
+        }
+        public XMLTV(object raw_instance, EventHandler<EventArgs> handler) 
+        {
+            instance = (CLASS)Convert.ChangeType(raw_instance, typeof(CLASS));
+            if (instance != null)
+            {
+                IRuntimeInstanceLoader<CLASS> loader = (instance as IRuntimeInstanceLoader<CLASS>);
+                if (loader != null)
+                {
+                    SetOnInstanceCreated(handler);
+                    instance = loader.LoadFromInstance(instance);
+                }
+            }
+        }
         public XMLTV(params object[] args)
         {
             

 

  ViewVC Help
Powered by ViewVC 1.1.22