/[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/10 18:30:13	121
+++ trunk/libxmltv/Core/DataSourceBindable.cs	2013/03/10 19:22:06	122
@@ -8,42 +8,110 @@
 {
     public class ChannelList : List<IXMLTVChannel>, IDataSourceBindable
     {
-        static private List<string> known_columns;
-        static ChannelList()
+        private class ChannelDefintion
         {
-            known_columns = new List<string>();
-            known_columns.Add("Id");
-            known_columns.Add("Name");
+            public ChannelDefintion()
+            {
+                ChannelId = string.Empty;
+                Name = string.Empty;
+            }
+            public string ChannelId { get; internal set; }
+            public string Name { get; internal set; }
         }
+        //static private List<string> known_columns;
+        //static ChannelList()
+        //{
+        //    known_columns = new List<string>();
+        //    known_columns.Add("Id");
+        //    known_columns.Add("Name");
+        //}
         public ChannelList() { }
 
+
+
         public object CreateBindableDataSource()
         {
             object bindable = new object();
+            List<ChannelDefintion> list = new List<ChannelDefintion>();
+            
+            foreach (var t in this)
+            {
+                try
+                {
+                    ChannelDefintion definition = new ChannelDefintion();
+                    definition.ChannelId = t.Id;
+                    definition.Name = t.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString();                    
+                    list.Add(definition);
+                }
+                catch (Exception ex) { throw ex; }
+            }
+            bindable = list;
             return bindable;
         }
     }
     public class ProgramList : List<IXMLTVProgram>, IDataSourceBindable
     {
-        static private List<string> known_columns;
-        static ProgramList()
+        private class ProgramDefintion
         {
-            known_columns = new List<string>();
-            known_columns.Add("Channel");
-            known_columns.Add("Title");
-            known_columns.Add("Sub-Title");
-            known_columns.Add("Description");
-            known_columns.Add("Start");
-            known_columns.Add("End");
+            public ProgramDefintion()
+            {
+                ChannelId = string.Empty;
+                ChannelName = string.Empty;
+                Start = new DateTime();
+                Stop = new DateTime();
+                Description = string.Empty;
+                Title = string.Empty;
+                SubTitle = string.Empty;
+            }
+            public string ChannelId { get; internal set; }
+            public string ChannelName { get; internal set; }
+            public DateTime Start { get; internal set; }
+            public DateTime Stop { get; internal set; }
+            public string Description { get; internal set; }
+            public string Title { get; internal set; }
+            public string SubTitle { get; internal set; }
         }
         public ProgramList() { }
 
         public object CreateBindableDataSource()
         {
             object bindable = new object();
+            List<ProgramDefintion> list = new List<ProgramDefintion>();
 
-            
+            foreach (var t in this)
+            {
+                try
+                {
+                    ProgramDefintion definition = new ProgramDefintion();
+                    definition.ChannelId = t.MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString();
 
+                    var channels = XMLTV.GetChannels();
+                    if (channels != null)
+                    {
+                        var channel = channels.Find(p => p.Id == definition.ChannelId);
+                        if (channel != null)
+                        {
+                            definition.ChannelName = channel.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString();
+                        }
+                        else
+                        {
+                            definition.ChannelName = string.Empty;
+                        }
+                    }
+                    else
+                    {
+                        definition.ChannelName = string.Empty;
+                    }
+                    definition.Start = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStart];
+                    definition.Stop = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStop];
+                    definition.Description = t.MetaData[XMLTVConstants.Programs.ProgramDescription].ToString();
+                    definition.Title = t.MetaData[XMLTVConstants.Programs.ProgramTitle].ToString();
+                    definition.SubTitle = t.MetaData[XMLTVConstants.Programs.ProgramSubTitle].ToString();
+                    list.Add(definition);
+                }
+                catch (Exception ex) { throw ex; }
+            }
+            bindable = list;
             return bindable;
         }
     }

 

  ViewVC Help
Powered by ViewVC 1.1.22