/[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 126 by william, Sun Mar 10 20:19:33 2013 UTC revision 131 by william, Wed Mar 13 15:16:59 2013 UTC
# Line 8  using System.IO; Line 8  using System.IO;
8  using System.Reflection;  using System.Reflection;
9  using System.Globalization;  using System.Globalization;
10  using System.Windows.Forms;  using System.Windows.Forms;
11    using Enterprise.Logging;
12    
13  namespace libxmltv.Core  namespace libxmltv.Core
14  {  {
# Line 77  namespace libxmltv.Core Line 78  namespace libxmltv.Core
78          #endregion          #endregion
79    
80          #region Get Data          #region Get Data
81            /// <summary>
82            /// Gets the source of the XMLTV Data : <see cref="libxmltv.Interfaces.IXMLTVSource"/>
83            /// </summary>
84            /// <returns>returns an instance of the xmltv data source : <see cref="libxmltv.Interfaces.IXMLTVSource"/></returns>
85          public static IXMLTVSource GetSource()          public static IXMLTVSource GetSource()
86          {          {
87              var gInstance = GetInstance();              var gInstance = GetInstance();
88              var list = gInstance.Source;              var list = gInstance.Source;
89              return list;              return list;
90          }          }
91            /// <summary>
92            /// Gets the collection of XMLTV Channels : List of <see cref="libxmltv.Interfaces.IXMLTVChannel"/>
93            /// </summary>
94            /// <returns>returns an instance of the xmltv channels : as a list of:  <see cref="libxmltv.Interfaces.IXMLTVChannel"/></returns>
95          public static List<IXMLTVChannel> GetChannels()          public static List<IXMLTVChannel> GetChannels()
96          {          {
97              var gInstance = GetInstance();              var gInstance = GetInstance();
98             var list = gInstance.Channels;             var list = gInstance.Channels;
99              return list;              return list;
100          }          }
101            /// <summary>
102            /// Gets the collection of XMLTV Programs : List of <see cref="libxmltv.Interfaces.IXMLTVProgram"/>
103            /// </summary>
104            /// <returns>returns an instance of the xmltv channels : as a list of:  <see cref="libxmltv.Interfaces.IXMLTVProgram"/></returns>
105          public static List<IXMLTVProgram> GetPrograms()          public static List<IXMLTVProgram> GetPrograms()
106          {          {
107              var gInstance = GetInstance();              var gInstance = GetInstance();
108              var list = gInstance.Programs;              var list = gInstance.Programs;
109              return list;              return list;
110          }          }
111            /// <summary>
112          public static object CreateDataSourceFromObject(object data)          /// Creates a binding source for a bindable control
113            /// </summary>
114            /// <param name="data">The object data to create a binding source from</param>
115            /// <param name="type">Represents the underlying type of the created binding source data</param>
116            /// <returns>Returns an object representing the created binding source</returns>
117            public static object CreateBindingSourceFromData(object data, out Type type)
118          {          {
119              if (data == null) { throw new ArgumentNullException("data", "cannot be null"); }              if (data == null) { throw new ArgumentNullException("data", "cannot be null"); }
120              //BindingSource source = new BindingSource();              //BindingSource source = new BindingSource();
121    
122              IDataSourceBindable binder = (data as IDataSourceBindable);              IDataSourceBindable binder = (data as IDataSourceBindable);
123              if (binder == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", data.GetType().Name, typeof(IDataSourceBindable).Name)); }              if (binder == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", data.GetType().Name, typeof(IDataSourceBindable).Name)); }
124              object bindable = binder.CreateBindableDataSource();              object bindable = binder.CreateBindableDataSource(out type);
125              //source.DataSource = bindable;              //source.DataSource = bindable;
126              //return source;              //return source;
127              return bindable;              return bindable;
128          }          }
129    
130            private static object ConvertSourceType(Type source_type, object source)
131            {
132                //try
133                //{
134                //    IDataConverter converter = (source as IDataConverter);
135                //    if (converter == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(IDataConverter).Name)); }
136                //    object t = converter.ConvertObjectData(source);
137                //    if (t != null) { source = t; }
138                //    return t;
139                //}
140                //catch (Exception ex) { gLog.Verbose.Error.WriteLine(ex.ToString()); return null; }
141                return source;
142            }
143    
144          public static void CreateFilterFromDataSource(ref object source, params string[] args)          public static void CreateFilterFromDataSource(ref object source, params string[] args)
145          {          {
146              if (source == null) { throw new ArgumentNullException("source", "cannot be null"); }              if (source == null) { throw new ArgumentNullException("source", "cannot be null"); }
147                object t = ConvertSourceType(source.GetType(), source);
148                if (t == null) { throw new ArgumentException("source_type", string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, source.GetType().Name)); }
149              if (args == null) { throw new ArgumentNullException("args", "cannot be null"); }              if (args == null) { throw new ArgumentNullException("args", "cannot be null"); }
150                source = t;
151              IDataSourceFilterable filter = (source as IDataSourceFilterable);              IDataSourceFilterable filter = (source as IDataSourceFilterable);
152              if (filter == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(IDataSourceFilterable).Name)); }              if (filter == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(IDataSourceFilterable).Name)); }
153              filter.Filter(ref source,args);                          filter.Filter(ref source, args);            
154          }          }
155          public static void CreateSorterFromDataSource(ref object source, params string[] args)          public static void CreateSorterFromDataSource(ref object source, bool descending, params string[] args)
156          {          {
157              if (source == null) { throw new ArgumentNullException("source", "cannot be null"); }              if (source == null) { throw new ArgumentNullException("source", "cannot be null"); }
158                object t = ConvertSourceType(source.GetType(), source);
159                if (t == null) { throw new ArgumentException("source_type", string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, source.GetType().Name)); }
160              if (args == null) { throw new ArgumentNullException("args", "cannot be null"); }              if (args == null) { throw new ArgumentNullException("args", "cannot be null"); }
161                source = t;
162              IDataSourceSortable sorter = (source as IDataSourceSortable);              IDataSourceSortable sorter = (source as IDataSourceSortable);
163              if (sorter == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(IDataSourceSortable).Name)); }              if (sorter == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(IDataSourceSortable).Name)); }
164              sorter.Sort(ref source, args);                          sorter.Sort(ref source, descending, args);            
165          }          }
166          #endregion          #endregion
167          #endregion          #endregion

Legend:
Removed from v.126  
changed lines
  Added in v.131

  ViewVC Help
Powered by ViewVC 1.1.22