/[xmltv_parser]/trunk/libxmltv/Core/DataSourceBindable.cs
ViewVC logotype

Diff of /trunk/libxmltv/Core/DataSourceBindable.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libxmltv/Core/DataSourceBindable.cs	2013/03/10 19:44:49	125
+++ trunk/libxmltv/Core/DataSourceBindable.cs	2013/03/10 20:19:33	126
@@ -3,34 +3,39 @@
 using System.Linq;
 using System.Text;
 using libxmltv.Interfaces;
+using System.Collections;
 
 namespace libxmltv.Core
 {
     public class ChannelList : List<IXMLTVChannel>, IDataSourceBindable
     {
-        private class ChannelDefintion : IDataSourceSortable, IDataSourceFilterable
+        private class ChannelDefintionList : List<ChannelDefintion>, IDataSourceSortable, IDataSourceFilterable            
         {
-            public ChannelDefintion()
-            {
-                ChannelId = string.Empty;
-                ChannelName = string.Empty;
-            }
-            public string ChannelId { get; internal set; }
-            public string ChannelName { get; internal set; }
-
+            public ChannelDefintionList() { }
+            public ChannelDefintionList(List<ChannelDefintion> collection) { collection.ForEach(s => this.Add(s)); }
             #region IDataSourceSortable members
-            public object Sort(object source, params string[] args)
+            public void Sort(ref object source, params string[] args)
             {
-                return source;
             }
             #endregion
             #region IDataSourceFilterable members
-            public object Filter(object source, params string[] args)
+            public void Filter(ref object source, params string[] args)
             {
-                return source;
             }
             #endregion
         }
+        private class ChannelDefintion
+        {
+            public ChannelDefintion()
+            {
+                ChannelId = string.Empty;
+                ChannelName = string.Empty;
+            }
+            public string ChannelId { get; internal set; }
+            public string ChannelName { get; internal set; }
+
+            
+        }
         //static private List<string> known_columns;
         //static ChannelList()
         //{
@@ -45,7 +50,7 @@
         public object CreateBindableDataSource()
         {
             object bindable = new object();
-            List<ChannelDefintion> list = new List<ChannelDefintion>();
+            ChannelDefintionList list = new ChannelDefintionList();
             
             foreach (var t in this)
             {
@@ -58,14 +63,48 @@
                 }
                 catch (Exception ex) { throw ex; }
             }
-            list = list.OrderBy(s => s.ChannelName).ToList();
+            list = new ChannelDefintionList(list.OrderBy(s => s.ChannelName).ToList());
             bindable = list;
             return bindable;
         }
     }
     public class ProgramList : List<IXMLTVProgram>, IDataSourceBindable
     {
-        private class ProgramDefintion : IDataSourceSortable, IDataSourceFilterable
+        private class ProgramDefinitionList : List<ProgramDefintion>, IDataSourceSortable, IDataSourceFilterable           
+        {
+            public ProgramDefinitionList() { }
+            public ProgramDefinitionList(List<ProgramDefintion> collection) { collection.ForEach(s => this.Add(s)); }
+            #region IDataSourceSortable members
+            public void Sort(ref object source, params string[] args)
+            {
+                ProgramDefinitionList list = null;
+                try
+                {
+                    list = (ProgramDefinitionList)source;
+
+                    var col = args[0].ToLower();
+                    switch (col)
+                    {
+                        case "channelname": list =new ProgramDefinitionList( list.OrderBy(s => s.ChannelName).ToList()); break;
+                        case "start": list = new ProgramDefinitionList( list.OrderBy(s => s.Start).ToList()); break;
+                        case "stop": list = new ProgramDefinitionList( list.OrderBy(s => s.Stop).ToList()); break;
+                        case "description": list = new ProgramDefinitionList( list.OrderBy(s => s.Description).ToList()); break;
+                        case "title": list = new ProgramDefinitionList( list.OrderBy(s => s.Title).ToList()); break;
+                        case "subtitle": list = new ProgramDefinitionList(list.OrderBy(s => s.SubTitle).ToList()); break;
+                    }
+
+                }
+                catch (Exception ex) { throw ex; }
+                if (list != null) { source = list; }
+            }
+            #endregion
+            #region IDataSourceFilterable members
+            public void Filter(ref object source, params string[] args)
+            {
+            }
+            #endregion
+        }
+        private class ProgramDefintion
         {
             public ProgramDefintion()
             {
@@ -85,25 +124,14 @@
             public string SubTitle { get; internal set; }
             public string Description { get; internal set; }
 
-            #region IDataSourceSortable members
-            public object Sort(object source, params string[] args)
-            {
-                return source;
-            }
-            #endregion
-            #region IDataSourceFilterable members
-            public object Filter(object source, params string[] args)
-            {
-                return source;
-            }
-            #endregion
+          
         }
         public ProgramList() { }
 
         public object CreateBindableDataSource()
         {
             object bindable = new object();
-            List<ProgramDefintion> list = new List<ProgramDefintion>();
+            ProgramDefinitionList list = new ProgramDefinitionList();
 
             foreach (var t in this)
             {
@@ -140,7 +168,7 @@
                 catch (Exception ex) { throw ex; }
             }
 
-            list = list.OrderBy(s => s.Start).ToList();
+            list = new ProgramDefinitionList(list.OrderBy(s => s.Start).ToList());
 
             bindable = list;
             return bindable;

 

  ViewVC Help
Powered by ViewVC 1.1.22