/[xmltv_parser]/trunk/libxmltv/Core/DataSourceBindable.cs
ViewVC logotype

Annotation of /trunk/libxmltv/Core/DataSourceBindable.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 125 - (hide annotations) (download)
Sun Mar 10 19:44:49 2013 UTC (6 years, 8 months ago) by william
File size: 6039 byte(s)

1 william 120 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using libxmltv.Interfaces;
6    
7     namespace libxmltv.Core
8     {
9     public class ChannelList : List<IXMLTVChannel>, IDataSourceBindable
10     {
11 william 125 private class ChannelDefintion : IDataSourceSortable, IDataSourceFilterable
12 william 121 {
13 william 122 public ChannelDefintion()
14     {
15     ChannelId = string.Empty;
16 william 123 ChannelName = string.Empty;
17 william 122 }
18     public string ChannelId { get; internal set; }
19 william 123 public string ChannelName { get; internal set; }
20 william 125
21     #region IDataSourceSortable members
22     public object Sort(object source, params string[] args)
23     {
24     return source;
25     }
26     #endregion
27     #region IDataSourceFilterable members
28     public object Filter(object source, params string[] args)
29     {
30     return source;
31     }
32     #endregion
33 william 121 }
34 william 122 //static private List<string> known_columns;
35     //static ChannelList()
36     //{
37     // known_columns = new List<string>();
38     // known_columns.Add("Id");
39     // known_columns.Add("Name");
40     //}
41 william 120 public ChannelList() { }
42    
43 william 122
44    
45 william 120 public object CreateBindableDataSource()
46     {
47     object bindable = new object();
48 william 122 List<ChannelDefintion> list = new List<ChannelDefintion>();
49    
50     foreach (var t in this)
51     {
52     try
53     {
54     ChannelDefintion definition = new ChannelDefintion();
55     definition.ChannelId = t.Id;
56 william 123 definition.ChannelName = t.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString();
57 william 122 list.Add(definition);
58     }
59     catch (Exception ex) { throw ex; }
60     }
61 william 123 list = list.OrderBy(s => s.ChannelName).ToList();
62 william 122 bindable = list;
63 william 120 return bindable;
64     }
65     }
66     public class ProgramList : List<IXMLTVProgram>, IDataSourceBindable
67     {
68 william 125 private class ProgramDefintion : IDataSourceSortable, IDataSourceFilterable
69 william 121 {
70 william 122 public ProgramDefintion()
71     {
72 william 123 //ChannelId = string.Empty;
73 william 122 ChannelName = string.Empty;
74     Start = new DateTime();
75     Stop = new DateTime();
76     Description = string.Empty;
77     Title = string.Empty;
78     SubTitle = string.Empty;
79     }
80 william 123 //public string ChannelId { get; internal set; }
81 william 122 public string ChannelName { get; internal set; }
82     public DateTime Start { get; internal set; }
83     public DateTime Stop { get; internal set; }
84     public string Title { get; internal set; }
85     public string SubTitle { get; internal set; }
86 william 125 public string Description { get; internal set; }
87    
88     #region IDataSourceSortable members
89     public object Sort(object source, params string[] args)
90     {
91     return source;
92     }
93     #endregion
94     #region IDataSourceFilterable members
95     public object Filter(object source, params string[] args)
96     {
97     return source;
98     }
99     #endregion
100 william 121 }
101 william 120 public ProgramList() { }
102    
103     public object CreateBindableDataSource()
104     {
105     object bindable = new object();
106 william 122 List<ProgramDefintion> list = new List<ProgramDefintion>();
107 william 121
108 william 122 foreach (var t in this)
109     {
110     try
111     {
112     ProgramDefintion definition = new ProgramDefintion();
113 william 123 string ChannelId = t.MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString();
114     //definition.ChannelId = ChannelId;
115 william 121
116 william 122 var channels = XMLTV.GetChannels();
117     if (channels != null)
118     {
119 william 123 var channel = channels.Find(p => p.Id == ChannelId);
120 william 122 if (channel != null)
121     {
122     definition.ChannelName = channel.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString();
123     }
124     else
125     {
126     definition.ChannelName = string.Empty;
127     }
128     }
129     else
130     {
131     definition.ChannelName = string.Empty;
132     }
133     definition.Start = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStart];
134     definition.Stop = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStop];
135     definition.Description = t.MetaData[XMLTVConstants.Programs.ProgramDescription].ToString();
136     definition.Title = t.MetaData[XMLTVConstants.Programs.ProgramTitle].ToString();
137     definition.SubTitle = t.MetaData[XMLTVConstants.Programs.ProgramSubTitle].ToString();
138     list.Add(definition);
139     }
140     catch (Exception ex) { throw ex; }
141     }
142 william 123
143     list = list.OrderBy(s => s.Start).ToList();
144    
145 william 122 bindable = list;
146 william 120 return bindable;
147     }
148     }
149     public class ExtraList : List<IExtraMetaData>, IDataSourceBindable
150     {
151 william 121
152 william 120 public ExtraList() { }
153    
154     public object CreateBindableDataSource()
155     {
156 william 124 throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented.");
157     //object bindable = new object();
158     //return bindable;
159 william 120 }
160     }
161     }

  ViewVC Help
Powered by ViewVC 1.1.22