/[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

revision 131 by william, Wed Mar 13 15:16:59 2013 UTC revision 134 by william, Wed Mar 13 15:50:07 2013 UTC
# Line 4  using System.Linq; Line 4  using System.Linq;
4  using System.Text;  using System.Text;
5  using libxmltv.Interfaces;  using libxmltv.Interfaces;
6  using System.Collections;  using System.Collections;
7    using Enterprise.Logging;
8    
9  namespace libxmltv.Core  namespace libxmltv.Core
10  {  {
# Line 129  namespace libxmltv.Core Line 130  namespace libxmltv.Core
130              #region IDataSourceFilterable members              #region IDataSourceFilterable members
131              public void Filter(ref object source, params string[] args)              public void Filter(ref object source, params string[] args)
132              {              {
133                    IProgramDefinitionList list = null;
134                    List<IProgramDefinition> ordered = null;
135                    try
136                    {
137                        list = (ProgramDefinitionList)source;
138                        //var col = args.First().ToString().ToLower();
139                        //var data = args.().ToString().ToLower();
140    
141                        if (args.Count() != 2) { throw new ArgumentOutOfRangeException("args", "Excpected 2 aguments: columnname and filtertext"); }
142    
143                        string columnname = args[0].ToLower();
144                        string filtertext = args[1].ToLower();
145    
146                        switch (columnname)
147                        {
148                            case "channelname": ordered = list.ToList().FindAll(s => s.ChannelName.ToLower().Contains(filtertext)); break;
149                            case "start":
150                            case "stop":
151                                throw new ArgumentException("columnname", string.Format("Filtering for column: '{0}' has not been implemented", columnname));
152                            case "description": ordered = list.ToList().FindAll(s => s.Description.ToLower().Contains(filtertext)); break;
153                            case "title": ordered = list.ToList().FindAll(s => s.Title.ToLower().Contains(filtertext)); break;
154                            case "subtitle": ordered = list.ToList().FindAll(s => s.SubTitle.ToLower().Contains(filtertext)); break;
155                        }                  
156                        list = new ProgramDefinitionList(ordered.ToList());
157                        if (list.Count == 0)
158                        {
159                            list = (ProgramDefinitionList)source;
160                            gLog.Warn.WriteLine("Filering by: column='{0}' with filer='{1}' returned no data",columnname, filtertext);
161                        }
162                    }
163                    catch (Exception ex) { throw ex; }
164                    if (list != null) { source = list; }
165              }              }
166              #endregion              #endregion
167          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.22