/[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/10 20:19:33	126
+++ trunk/libxmltv/Core/XMLTV.cs	2013/03/13 13:45:05	128
@@ -8,6 +8,7 @@
 using System.Reflection;
 using System.Globalization;
 using System.Windows.Forms;
+using Enterprise.Logging;
 
 namespace libxmltv.Core
 {
@@ -77,42 +78,76 @@
         #endregion
 
         #region Get Data
+        /// <summary>
+        /// Gets the source of the XMLTV Data : <see cref="libxmltv.Interfaces.IXMLTVSource"/>
+        /// </summary>
+        /// <returns>returns an instance of the xmltv data source : <see cref="libxmltv.Interfaces.IXMLTVSource"/></returns>
         public static IXMLTVSource GetSource()
         {
             var gInstance = GetInstance();
             var list = gInstance.Source;
             return list;
         }
+        /// <summary>
+        /// Gets the collection of XMLTV Channels : List of <see cref="libxmltv.Interfaces.IXMLTVChannel"/>
+        /// </summary>
+        /// <returns>returns an instance of the xmltv channels : as a list of:  <see cref="libxmltv.Interfaces.IXMLTVChannel"/></returns>
         public static List<IXMLTVChannel> GetChannels()
         {
             var gInstance = GetInstance();
            var list = gInstance.Channels;
             return list;
         }
+        /// <summary>
+        /// Gets the collection of XMLTV Programs : List of <see cref="libxmltv.Interfaces.IXMLTVProgram"/>
+        /// </summary>
+        /// <returns>returns an instance of the xmltv channels : as a list of:  <see cref="libxmltv.Interfaces.IXMLTVProgram"/></returns>
         public static List<IXMLTVProgram> GetPrograms()
         {
             var gInstance = GetInstance();
             var list = gInstance.Programs;
             return list;
         }
-
-        public static object CreateDataSourceFromObject(object data)
+        /// <summary>
+        /// Creates a binding source for a bindable control
+        /// </summary>
+        /// <param name="data">The object data to create a binding source from</param>
+        /// <param name="type">Represents the underlying type of the created binding source data</param>
+        /// <returns>Returns an object representing the created binding source</returns>
+        public static object CreateBindingSourceFromData(object data, out Type type)
         {
             if (data == null) { throw new ArgumentNullException("data", "cannot be null"); }
             //BindingSource source = new BindingSource();
 
             IDataSourceBindable binder = (data as IDataSourceBindable);
             if (binder == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", data.GetType().Name, typeof(IDataSourceBindable).Name)); }
-            object bindable = binder.CreateBindableDataSource();
+            object bindable = binder.CreateBindableDataSource(out type);
             //source.DataSource = bindable;
             //return source;
             return bindable;
         }
 
+        private static object ConvertSourceType(Type source_type, object source)
+        {
+            //try
+            //{
+            //    IDataConverter converter = (source as IDataConverter);
+            //    if (converter == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(IDataConverter).Name)); }
+            //    object t = converter.ConvertObjectData(source);
+            //    if (t != null) { source = t; }
+            //    return t;
+            //}
+            //catch (Exception ex) { gLog.Verbose.Error.WriteLine(ex.ToString()); return null; }
+            return source;
+        }
+
         public static void CreateFilterFromDataSource(ref object source, params string[] args)
         {
             if (source == null) { throw new ArgumentNullException("source", "cannot be null"); }
+           object t = ConvertSourceType(source.GetType(), source);
+           if (t == null) { throw new ArgumentException("source_type", string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, source.GetType().Name)); }
             if (args == null) { throw new ArgumentNullException("args", "cannot be null"); }
+            source = t;
             IDataSourceFilterable filter = (source as IDataSourceFilterable);
             if (filter == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(IDataSourceFilterable).Name)); }
             filter.Filter(ref source,args);            
@@ -120,7 +155,10 @@
         public static void CreateSorterFromDataSource(ref object source, params string[] args)
         {
             if (source == null) { throw new ArgumentNullException("source", "cannot be null"); }
+            object t = ConvertSourceType(source.GetType(), source);
+            if (t == null) { throw new ArgumentException("source_type", string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, source.GetType().Name)); }
             if (args == null) { throw new ArgumentNullException("args", "cannot be null"); }
+            source = t;
             IDataSourceSortable sorter = (source as IDataSourceSortable);
             if (sorter == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(IDataSourceSortable).Name)); }
             sorter.Sort(ref source, args);            

 

  ViewVC Help
Powered by ViewVC 1.1.22