/[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 15:16:59	131
+++ trunk/libxmltv/Core/DataSourceBindable.cs	2013/03/13 15:50:07	134
@@ -4,6 +4,7 @@
 using System.Text;
 using libxmltv.Interfaces;
 using System.Collections;
+using Enterprise.Logging;
 
 namespace libxmltv.Core
 {
@@ -129,6 +130,38 @@
             #region IDataSourceFilterable members
             public void Filter(ref object source, params string[] args)
             {
+                IProgramDefinitionList list = null;
+                List<IProgramDefinition> ordered = null;
+                try
+                {
+                    list = (ProgramDefinitionList)source;
+                    //var col = args.First().ToString().ToLower();
+                    //var data = args.().ToString().ToLower();
+
+                    if (args.Count() != 2) { throw new ArgumentOutOfRangeException("args", "Excpected 2 aguments: columnname and filtertext"); }
+
+                    string columnname = args[0].ToLower();
+                    string filtertext = args[1].ToLower();
+
+                    switch (columnname)
+                    {
+                        case "channelname": ordered = list.ToList().FindAll(s => s.ChannelName.ToLower().Contains(filtertext)); break;
+                        case "start":
+                        case "stop":
+                            throw new ArgumentException("columnname", string.Format("Filtering for column: '{0}' has not been implemented", columnname));
+                        case "description": ordered = list.ToList().FindAll(s => s.Description.ToLower().Contains(filtertext)); break;
+                        case "title": ordered = list.ToList().FindAll(s => s.Title.ToLower().Contains(filtertext)); break;
+                        case "subtitle": ordered = list.ToList().FindAll(s => s.SubTitle.ToLower().Contains(filtertext)); break;
+                    }                   
+                    list = new ProgramDefinitionList(ordered.ToList());
+                    if (list.Count == 0)
+                    {
+                        list = (ProgramDefinitionList)source;
+                        gLog.Warn.WriteLine("Filering by: column='{0}' with filer='{1}' returned no data",columnname, filtertext);
+                    }
+                }
+                catch (Exception ex) { throw ex; }
+                if (list != null) { source = list; }
             }
             #endregion
         }

 

  ViewVC Help
Powered by ViewVC 1.1.22