/[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 54 by william, Fri Mar 8 08:51:10 2013 UTC revision 56 by william, Fri Mar 8 12:05:33 2013 UTC
# Line 15  namespace libxmltv.Core Line 15  namespace libxmltv.Core
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); }
# Line 32  namespace libxmltv.Core Line 44  namespace libxmltv.Core
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          {          {
# Line 41  namespace libxmltv.Core Line 53  namespace libxmltv.Core
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                            
# Line 56  namespace libxmltv.Core Line 84  namespace libxmltv.Core
84              }              }
85              catch (Exception ex)              catch (Exception ex)
86              {              {
87                  xmltv_logger.Log.Error.WriteLine(ex.ToString());                  xmltv_logger.Error.WriteLine(ex.ToString());
88    
89                  StringBuilder parameter_builder = new StringBuilder();                  StringBuilder parameter_builder = new StringBuilder();
90                  foreach (object arg in args)                  foreach (object arg in args)
# Line 106  namespace libxmltv.Core Line 134  namespace libxmltv.Core
134              }              }
135              else              else
136              {              {
137                  xmltv_logger.Log.Error.WriteLine("Unable to call DestroyInstance() on type: '{0}'", instance.GetType().Name);                  xmltv_logger.Error.WriteLine("Unable to call DestroyInstance() on type: '{0}'", instance.GetType().Name);
138              }                          }            
139          }          }
140          private void SetOnInstanceCreated(EventHandler<EventArgs> event_instance)          private void SetOnInstanceCreated(EventHandler<EventArgs> event_instance)

Legend:
Removed from v.54  
changed lines
  Added in v.56

  ViewVC Help
Powered by ViewVC 1.1.22