/[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/13 13:45:05	128
+++ trunk/libxmltv/Core/DataSourceBindable.cs	2013/03/13 15:16:59	131
@@ -14,7 +14,7 @@
             public ChannelDefintionList() { }
             public ChannelDefintionList(List<IChannelDefintion> collection) { collection.ForEach(s => this.Add(s)); }
             #region IDataSourceSortable members
-            public void Sort(ref object source, params string[] args)
+            public void Sort(ref object source, bool descending, params string[] args)
             {
             }
             #endregion
@@ -89,24 +89,38 @@
             public ProgramDefinitionList() { }
             public ProgramDefinitionList(List<IProgramDefinition> collection) { collection.ForEach(s => this.Add(s)); }
             #region IDataSourceSortable members
-            public void Sort(ref object source, params string[] args)
+            public void Sort(ref object source, bool descending, params string[] args)
             {
-                ProgramDefinitionList list = null;
+                IProgramDefinitionList list = null;
+                IOrderedEnumerable<IProgramDefinition> ordered = null;
                 try
                 {
                     list = (ProgramDefinitionList)source;
-
-                    var col = args[0].ToLower();
+                    var col = args.First().ToString().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;
+                        case "channelname": ordered = descending ? list.OrderByDescending(s => s.ChannelName) : list.OrderBy(s => s.ChannelName); break;
+                        case "start": ordered = descending ? list.OrderByDescending(s => s.Start) : list.OrderBy(s => s.Start); break;
+                        case "stop": ordered = descending ? list.OrderByDescending(s => s.Stop) : list.OrderBy(s => s.Stop); break;
+                        case "description": ordered = descending ? list.OrderByDescending(s => s.Description) : list.OrderBy(s => s.Description); break;
+                        case "title": ordered = descending ? list.OrderByDescending(s => s.Title) : list.OrderBy(s => s.Title); break;
+                        case "subtitle": ordered = descending ? list.OrderByDescending(s => s.SubTitle) : list.OrderBy(s => s.SubTitle); break;
                     }
-
+                    //bool first = true;
+                    foreach (var arg in args.Skip(1))
+                    {
+                        col = arg.ToLower();
+                        switch (col)
+                        {
+                            case "channelname": ordered = descending ? ordered.ThenByDescending(s => s.ChannelName) : ordered.ThenBy(s => s.ChannelName); break;
+                            case "start": ordered = descending ? ordered.ThenByDescending(s => s.Start) : ordered.ThenBy(s => s.Start); break;
+                            case "stop": ordered = descending ? ordered.ThenByDescending(s => s.Stop) : ordered.ThenBy(s => s.Stop); break;
+                            case "description": ordered = descending ? ordered.ThenByDescending(s => s.Description) : ordered.ThenBy(s => s.Description); break;
+                            case "title": ordered = descending ? ordered.ThenByDescending(s => s.Title) : ordered.ThenBy(s => s.Title); break;
+                            case "subtitle": ordered = descending ? ordered.ThenByDescending(s => s.SubTitle) : ordered.ThenBy(s => s.SubTitle); break;
+                        }
+                    }
+                    list = new ProgramDefinitionList(ordered.ToList());
                 }
                 catch (Exception ex) { throw ex; }
                 if (list != null) { source = list; }

 

  ViewVC Help
Powered by ViewVC 1.1.22