/[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/14 13:08:20	141
+++ trunk/libxmltv/Core/DataSourceBindable.cs	2013/03/17 03:57:57	227
@@ -121,6 +121,7 @@
                         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;
+                        case "rating": ordered = descending ? list.OrderByDescending(s => s.Rating) : list.OrderBy(s => s.Rating); break;
                     }
                     //bool first = true;
                     foreach (var arg in args.Skip(1))
@@ -135,6 +136,7 @@
                             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;
+                            case "rating": ordered = descending ? ordered.ThenByDescending(s => s.Rating) : ordered.ThenBy(s => s.Rating); break;
                         }
                     }
                     list = new ProgramDefinitionList(ordered.ToList());
@@ -163,12 +165,12 @@
                     {
                         case "channelnumber": ordered = list.ToList().FindAll(s => s.ChannelNumber == Convert.ToInt32(filtertext)); break;
                         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 "start": ordered = list.ToList().FindAll(s => s.Start.ToLower().Contains(filtertext)); break;
+                        case "stop": ordered = list.ToList().FindAll(s => s.Stop.ToLower().Contains(filtertext)); break;
                         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;
+                        case "rating": ordered = list.ToList().FindAll(s => s.Rating.ToLower().Contains(filtertext)); break;
                     }                   
                     list = new ProgramDefinitionList(ordered.ToList());
                     if (list.Count == 0)
@@ -182,7 +184,7 @@
             }
             #endregion
         }
-        private class ProgramDefintion : IProgramDefinition
+        public class ProgramDefintion : IProgramDefinition, IEquatable<IProgramDefinition>
         {
             public ProgramDefintion()
             {
@@ -194,16 +196,17 @@
                 Description = string.Empty;
                 Title = string.Empty;
                 SubTitle = string.Empty;
+                Rating = string.Empty;
             }
             //public string ChannelId { get; internal set; }
-            public int ChannelNumber { get; internal set; }
-            public string ChannelName { get; internal set; }
-            public string Start { get; internal set; }
-            public string Stop { get; internal set; }
-            public string Title { get; internal set; }
-            public string SubTitle { get; internal set; }
-            public string Description { get; internal set; }
-
+            public int ChannelNumber { get; set; }
+            public string ChannelName { get; set; }
+            public string Start { get; set; }
+            public string Stop { get; set; }
+            public string Title { get; set; }
+            public string SubTitle { get; set; }
+            public string Description { get; set; }
+            public string Rating { get; set; }
             public override string ToString()
             {
                 StringBuilder builder = new StringBuilder();
@@ -217,7 +220,24 @@
                 }
                 return builder.ToString();
             }
-          
+
+            public bool Equals(IProgramDefinition other)
+            {
+                return this.ToString() == other.ToString();
+            }
+            public override bool Equals(object obj)
+            {
+                if (obj == null) { throw new ArgumentNullException("obj", "Object to compare cannot be null"); }
+                if (obj.GetType().IsAssignableFrom(typeof(IProgramDefinition)))
+                {
+                    return this.Equals((IProgramDefinition)obj);
+                }
+                return base.Equals(obj);
+            }
+            public override int GetHashCode()
+            {
+                return this.ToString().GetHashCode();
+            }
         }
         public ProgramList() { }
         //public object ConvertObjectData(object source) { return this.ConvertData(source); }
@@ -274,6 +294,19 @@
                     definition.Title = t.MetaData[XMLTVConstants.Programs.ProgramTitle].ToString();
                     definition.SubTitle = t.MetaData[XMLTVConstants.Programs.ProgramSubTitle].ToString();
 
+                    
+                    var extras = t.GetExtraMetaData();
+                    foreach (var extra in extras)
+                    {
+                        if (extra.Name.ToLower() == "rating")
+                        {
+                            var root = extra.AsXElement();
+                            var child = root.Descendants("value").FirstOrDefault();
+                            if (child == null) { throw new NullReferenceException("Expected rating element to have a child elemented named: value"); }
+                            string value = child.Value;
+                            definition.Rating = value;
+                        }
+                    }
                     xmltv_logger.Verbose.Debug.WriteLine(definition.ToString());
                     list.Add(definition);
                 }

 

  ViewVC Help
Powered by ViewVC 1.1.22