/[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/04/17 21:55:30	254
@@ -24,6 +24,8 @@
             {
             }
             #endregion
+
+            
         }
         private class ChannelDefintion : IChannelDefintion
         {
@@ -48,6 +50,28 @@
                 }
                 return builder.ToString();
             }
+
+            private IXMLTVChannel _RawDataSource; public IXMLTVChannel RawDataSource { get { return _RawDataSource; } set { _RawDataSource = value; } }
+
+
+            public bool Equals(IChannelDefintion 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(IChannelDefintion)))
+                {
+                    return this.Equals((IChannelDefintion)obj);
+                }
+                return base.Equals(obj);
+            }
+            public override int GetHashCode()
+            {
+                return this.ToString().GetHashCode();
+            }
+
             
         }
         //static private List<string> known_columns;
@@ -84,6 +108,7 @@
                 try
                 {
                     ChannelDefintion definition = new ChannelDefintion();
+                    definition.RawDataSource = t;
                     definition.ChannelId = t.Id;
                     definition.ChannelName = t.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString();
                     xmltv_logger.Verbose.Debug.WriteLine(definition.ToString());
@@ -116,11 +141,12 @@
                     {
                         case "channelnumber": ordered = descending ? list.OrderByDescending(s => s.ChannelNumber) : list.OrderBy(s => s.ChannelNumber); 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 "start": ordered = descending ? list.OrderByDescending(s => DateTime.Parse(s.Start)) : list.OrderBy(s => DateTime.Parse(s.Start)); break;
+                        case "stop": ordered = descending ? list.OrderByDescending(s => DateTime.Parse(s.Stop)) : list.OrderBy(s => DateTime.Parse(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;
+                        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))
@@ -130,11 +156,12 @@
                         {
                             case "channelnumber": ordered = descending ? ordered.ThenByDescending(s => s.ChannelNumber) : ordered.ThenBy(s => s.ChannelNumber); break;
                             case "channelname": ordered = descending ? list.OrderByDescending(s => s.ChannelName) : list.OrderBy(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 "start": ordered = descending ? ordered.ThenByDescending(s => DateTime.Parse(s.Start)) : ordered.ThenBy(s => DateTime.Parse(s.Start)); break;
+                            case "stop": ordered = descending ? ordered.ThenByDescending(s => DateTime.Parse(s.Stop)) : ordered.ThenBy(s => DateTime.Parse(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;
+                            case "rating": ordered = descending ? ordered.ThenByDescending(s => s.Rating) : ordered.ThenBy(s => s.Rating); break;
                         }
                     }
                     list = new ProgramDefinitionList(ordered.ToList());
@@ -163,12 +190,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)
@@ -181,8 +208,9 @@
                 if (list != null) { source = list; }
             }
             #endregion
+            
         }
-        private class ProgramDefintion : IProgramDefinition
+        public class ProgramDefintion : IProgramDefinition, IEquatable<IProgramDefinition>
         {
             public ProgramDefintion()
             {
@@ -194,16 +222,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 +246,26 @@
                 }
                 return builder.ToString();
             }
-          
+
+            private IXMLTVProgram _RawDataSource; public IXMLTVProgram RawDataSource { get { return _RawDataSource; } set { _RawDataSource = value; } }
+
+            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); }
@@ -244,6 +292,7 @@
                 try
                 {
                     ProgramDefintion definition = new ProgramDefintion();
+                    definition.RawDataSource = t;
                     string ChannelId = t.MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString();
                     //definition.ChannelId = ChannelId;
 
@@ -274,13 +323,26 @@
                     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);
                 }
                 catch (Exception ex) { throw ex; }
             }
 
-            list = new ProgramDefinitionList(list.OrderBy(s => s.Start).ToList());
+            list = new ProgramDefinitionList(list.OrderBy(s => DateTime.Parse(s.Start)).ToList());
 
             bindable = list;
             return bindable;

 

  ViewVC Help
Powered by ViewVC 1.1.22