/[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 56 by william, Fri Mar 8 12:05:33 2013 UTC revision 120 by william, Sun Mar 10 18:19:12 2013 UTC
# Line 7  using System.ComponentModel; Line 7  using System.ComponentModel;
7  using System.IO;  using System.IO;
8  using System.Reflection;  using System.Reflection;
9  using System.Globalization;  using System.Globalization;
10    using System.Windows.Forms;
11    
12  namespace libxmltv.Core  namespace libxmltv.Core
13  {  {
# Line 24  namespace libxmltv.Core Line 25  namespace libxmltv.Core
25              }              }
26          }          }
27    
28          static IXMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance> instance;          #region public members
29          public static IXMLTVRuntimeInstance GetInstance() { return instance.GetInstance(); }          #region save data
30          public static void CreateInstance(params object[] args) { instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(args); }          public static void Save(string file)
31            {
32                if (!Serialize(file))
33                {
34                    MessageBox.Show("Failed to save data - check log", "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error);
35                    return;
36                }
37                MessageBox.Show("Successfully saved data", "Successfully saved data", MessageBoxButtons.OK, MessageBoxIcon.Information);
38            }
39            public static void Save(Stream stream)
40            {
41                if (!Serialize(stream))
42                {
43                    MessageBox.Show("Failed to save data - check log", "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error);
44                    return;
45                }
46                MessageBox.Show("Successfully saved data", "Successfully saved data", MessageBoxButtons.OK, MessageBoxIcon.Information);
47            }
48            #endregion
49            #region load data
50            public static void Load(string file) { Load(file, null); }
51            public static void Load(string file, EventHandler<EventArgs> handler)
52            {
53                if (!DeSerialize(file, handler))
54                {
55                    MessageBox.Show("Failed to load data - check log", "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error);
56                    return;
57                }
58                MessageBox.Show("Successfully loaded data", "Successfully loaded data", MessageBoxButtons.OK, MessageBoxIcon.Information);
59                OnCreatedInstance();
60    
61          public static void CreateFromInstance(object raw_instance, EventHandler<EventArgs> handler)          }
62          {          public static void Load(Stream stream) { Load(stream, null); }
63              instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(raw_instance,handler);          public static void Load(Stream stream, EventHandler<EventArgs> handler)
64              if (OnInstanceCreated != null)          {
65                if (!DeSerialize(stream, handler))
66              {              {
67                  OnInstanceCreated.Invoke(null, new EventArgs());                  MessageBox.Show("Failed to load data - check log", "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error);
68                    return;
69              }              }
70                MessageBox.Show("Successfully loaded data", "Successfully loaded data", MessageBoxButtons.OK, MessageBoxIcon.Information);
71                OnCreatedInstance();
72            }
73            #endregion
74            #region Create/Destroy
75            public static void Create(params object[] args) { CreateInstance(args); }
76            public static void Destroy() { DestroyInstance(); }
77            #endregion
78    
79            #region Get Data
80            public static IXMLTVSource GetSource()
81            {
82                var gInstance = GetInstance();
83                var list = gInstance.Source;
84                return list;
85            }
86            public static List<IXMLTVChannel> GetChannels()
87            {
88                var gInstance = GetInstance();
89               var list = gInstance.Channels;
90                return list;
91            }
92            public static List<IXMLTVProgram> GetPrograms()
93            {
94                var gInstance = GetInstance();
95                var list = gInstance.Programs;
96                return list;
97            }
98    
99            public static BindingSource CreateBindingSourceForData(object data)
100            {
101                if (data == null) { throw new ArgumentNullException("data", "cannot be null"); }
102                BindingSource source = new BindingSource();
103    
104                IDataSourceBindable binder = (data as IDataSourceBindable);
105                if (binder == null)
106                {
107                    throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", data.GetType().Name, typeof(IDataSourceBindable).Name));
108                }
109    
110                object bindable = binder.CreateBindableDataSource();
111                source.DataSource = bindable;
112                return source;
113          }          }
114    
         #region IXMLTVSerializer<IXMLTVRuntimeInstance> members  
         public static bool Serialize(string file) { return instance.Serialize(file); }  
         public static bool Serialize(Stream stream) { return instance.Serialize(stream); }  
         public static IXMLTVRuntimeInstance DeSerialize(string file, out bool status) { return instance.DeSerialize(file, out status); }  
         public static IXMLTVRuntimeInstance DeSerialize(Stream stream, out bool status) { return instance.DeSerialize(stream, out status); }  
115          #endregion          #endregion
116            #endregion
117    
118    
119          public static void DestroyInstance() { instance.DestroyInstance(); }                  static IXMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance> instance;
120            internal static IXMLTVRuntimeInstance GetInstance() { return instance.GetInstance(); }
121            internal static void CreateInstance(params object[] args) { instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(args); }
122    
123          public static EventHandler<EventArgs> OnInstanceCreated          internal static void CreateFromInstance(object raw_instance, EventHandler<EventArgs> handler)
124            {
125                instance = new XMLTV<IXMLTVRuntimeInstance, XMLTVRuntimeInstance>(raw_instance, handler);
126                //OnCreatedInstance();
127            }
128    
129            internal static void OnCreatedInstance() { if (OnInstanceCreated != null) { OnInstanceCreated.Invoke(null, new EventArgs()); } }
130    
131            #region IXMLTVSerializer<IXMLTVRuntimeInstance> members
132            internal static bool Serialize(string file) { return instance.Serialize(file); }
133            internal static bool Serialize(Stream stream) { return instance.Serialize(stream); }
134            internal static bool DeSerialize(string file, EventHandler<EventArgs> handler)
135            {
136                bool status;
137                var gInstance = instance.DeSerialize(file, out status);            
138                CreateFromInstance(gInstance, handler);
139                return status;
140            }
141            internal static bool DeSerialize(Stream stream, EventHandler<EventArgs> handler)
142            {
143                bool status;
144                var gInstance = instance.DeSerialize(stream, out status);
145                CreateFromInstance(gInstance, handler);
146                return status;
147            }
148            #endregion
149            internal static void DestroyInstance() { instance.DestroyInstance(); }
150    
151            internal static EventHandler<EventArgs> OnInstanceCreated
152          {          {
153              get { return instance.OnInstanceCreated; }              get { return instance.OnInstanceCreated; }
154              set { instance.OnInstanceCreated = value; }              set { instance.OnInstanceCreated = value; }
155          }          }
156    
157          
158      }      }
159    
160      internal class XMLTV<INTERFACE, CLASS> : IDestroyInstance, IXMLTV<INTERFACE, CLASS> where CLASS : class,INTERFACE,new()      internal class XMLTV<INTERFACE, CLASS> : IDestroyInstance, IXMLTV<INTERFACE, CLASS> where CLASS : class,INTERFACE,new()
# Line 117  namespace libxmltv.Core Line 221  namespace libxmltv.Core
221          {          {
222              return (INTERFACE)instance;              return (INTERFACE)instance;
223          }          }
224            public void SetInstance(INTERFACE gInstance)
225            {
226                this.instance = gInstance as CLASS;
227            }
228          #endregion          #endregion
229    
230          #region IXMLTVSerializer<INTERFACE> members          #region IXMLTVSerializer<INTERFACE> members

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

  ViewVC Help
Powered by ViewVC 1.1.22