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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 130 - (show annotations) (download)
Wed Mar 13 14:39:08 2013 UTC (6 years, 8 months ago) by william
File size: 11262 byte(s)
+ current wip

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using libxmltv.Interfaces;
6 using System.Collections;
7
8 namespace libxmltv.Core
9 {
10 public class ChannelList : List<IXMLTVChannel>, IDataSourceBindable//, IDataConverter<IChannelDefintionList>
11 {
12 private class ChannelDefintionList : List<IChannelDefintion>, IDataSourceSortable, IDataSourceFilterable, IChannelDefintionList
13 {
14 public ChannelDefintionList() { }
15 public ChannelDefintionList(List<IChannelDefintion> collection) { collection.ForEach(s => this.Add(s)); }
16 #region IDataSourceSortable members
17 public void Sort(ref object source, params string[] args)
18 {
19 }
20 #endregion
21 #region IDataSourceFilterable members
22 public void Filter(ref object source, params string[] args)
23 {
24 }
25 #endregion
26 }
27 private class ChannelDefintion : IChannelDefintion
28 {
29 public ChannelDefintion()
30 {
31 ChannelId = string.Empty;
32 ChannelName = string.Empty;
33 }
34 public string ChannelId { get; internal set; }
35 public string ChannelName { get; internal set; }
36
37
38 }
39 //static private List<string> known_columns;
40 //static ChannelList()
41 //{
42 // known_columns = new List<string>();
43 // known_columns.Add("Id");
44 // known_columns.Add("Name");
45 //}
46 public ChannelList() { }
47
48 //public object ConvertObjectData(object source) { return this.ConvertData(source); }
49 //public IChannelDefintionList ConvertData(object source)
50 //{
51 // //object t = source;
52 // if (source.GetType() != typeof(ChannelDefintionList)) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(ChannelDefintionList).Name)); }
53 // //if (type != typeof(IChannelDefintionList)) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", type.Name, typeof(IChannelDefintionList).Name)); }
54 // IChannelDefintionList t = (source as IChannelDefintionList);
55 // return t;
56 //}
57 /// <summary>
58 ///
59 /// </summary>
60 /// <param name="type"></param>
61 /// <returns></returns>
62 public object CreateBindableDataSource(out Type type)
63 {
64 type = typeof(IChannelDefintionList);
65 object bindable = new object();
66 ChannelDefintionList list = new ChannelDefintionList();
67
68 foreach (var t in this)
69 {
70 try
71 {
72 ChannelDefintion definition = new ChannelDefintion();
73 definition.ChannelId = t.Id;
74 definition.ChannelName = t.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString();
75 list.Add(definition);
76 }
77 catch (Exception ex) { throw ex; }
78 }
79 list = new ChannelDefintionList(list.OrderBy(s => s.ChannelName).ToList());
80 bindable = list;
81 return bindable;
82 }
83
84 }
85 public class ProgramList : List<IXMLTVProgram>, IDataSourceBindable//, IDataConverter<IProgramDefinitionList>
86 {
87 private class ProgramDefinitionList : List<IProgramDefinition>, IDataSourceSortable, IDataSourceFilterable, IProgramDefinitionList
88 {
89 public ProgramDefinitionList() { }
90 public ProgramDefinitionList(List<IProgramDefinition> collection) { collection.ForEach(s => this.Add(s)); }
91 #region IDataSourceSortable members
92 public void Sort(ref object source, params string[] args)
93 {
94 List<IProgramDefinition> list = null;
95 IOrderedEnumerable<IProgramDefinition> ordered = null;
96 try
97 {
98 list = (ProgramDefinitionList)source;
99 ordered = list.OrderBy(s => s);
100
101 foreach (object arg in args)
102 {
103 var col = arg.ToString().ToLower();
104 switch (col)
105 {
106 case "channelname": ordered = ordered.ThenBy(s => s.ChannelName); break;
107 case "start": ordered = ordered.ThenBy(s => s.Start); break;
108 case "stop": ordered = ordered.ThenBy(s => s.Stop); break;
109 case "description": ordered = ordered.ThenBy(s => s.Description); break;
110 case "title": ordered = ordered.ThenBy(s => s.Title); break;
111 case "subtitle": ordered = ordered.ThenBy(s => s.SubTitle); break;
112 }
113 }
114
115 var k = ordered.ToList();
116
117 //list = new ProgramDefinitionList(ordered.ToList()).ToList();
118 //var col = args[0].ToLower();
119 //switch (col)
120 //{
121 // case "channelname": list =new ProgramDefinitionList( list.OrderBy(s => s.ChannelName).ToList()); break;
122 // case "start": list = new ProgramDefinitionList( list.OrderBy(s => s.Start).ToList()); break;
123 // case "stop": list = new ProgramDefinitionList( list.OrderBy(s => s.Stop).ToList()); break;
124 // case "description": list = new ProgramDefinitionList( list.OrderBy(s => s.Description).ToList()); break;
125 // case "title": list = new ProgramDefinitionList( list.OrderBy(s => s.Title).ToList()); break;
126 // case "subtitle": list = new ProgramDefinitionList(list.OrderBy(s => s.SubTitle).ToList()); break;
127 //}
128
129 }
130 catch (Exception ex) { throw ex; }
131 if (list != null) { source = list; }
132 }
133 #endregion
134 #region IDataSourceFilterable members
135 public void Filter(ref object source, params string[] args)
136 {
137 }
138 #endregion
139 }
140 private class ProgramDefintion : IProgramDefinition
141 {
142 public ProgramDefintion()
143 {
144 //ChannelId = string.Empty;
145 ChannelName = string.Empty;
146 Start = new DateTime();
147 Stop = new DateTime();
148 Description = string.Empty;
149 Title = string.Empty;
150 SubTitle = string.Empty;
151 }
152 //public string ChannelId { get; internal set; }
153 public string ChannelName { get; internal set; }
154 public DateTime Start { get; internal set; }
155 public DateTime Stop { get; internal set; }
156 public string Title { get; internal set; }
157 public string SubTitle { get; internal set; }
158 public string Description { get; internal set; }
159
160
161 }
162 public ProgramList() { }
163 //public object ConvertObjectData(object source) { return this.ConvertData(source); }
164 //public IProgramDefinitionList ConvertData(object source)
165 //{
166 // if (source.GetType() != typeof(ProgramDefinitionList)) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(ProgramDefinitionList).Name)); }
167 // //if (type != typeof(IProgramDefinitionList)) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", type.Name, typeof(IProgramDefinitionList).Name)); }
168 // IProgramDefinitionList t = (source as IProgramDefinitionList);
169 // return t;
170 //}
171 /// <summary>
172 ///
173 /// </summary>
174 /// <param name="type"></param>
175 /// <returns></returns>
176 public object CreateBindableDataSource(out Type type)
177 {
178 type = typeof(IProgramDefinitionList);
179 object bindable = new object();
180 ProgramDefinitionList list = new ProgramDefinitionList();
181
182 foreach (var t in this)
183 {
184 try
185 {
186 ProgramDefintion definition = new ProgramDefintion();
187 string ChannelId = t.MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString();
188 //definition.ChannelId = ChannelId;
189
190 var channels = XMLTV.GetChannels();
191 if (channels != null)
192 {
193 var channel = channels.Find(p => p.Id == ChannelId);
194 if (channel != null)
195 {
196 definition.ChannelName = channel.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString();
197 }
198 else
199 {
200 definition.ChannelName = string.Empty;
201 }
202 }
203 else
204 {
205 definition.ChannelName = string.Empty;
206 }
207 definition.Start = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStart];
208 definition.Stop = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStop];
209 definition.Description = t.MetaData[XMLTVConstants.Programs.ProgramDescription].ToString();
210 definition.Title = t.MetaData[XMLTVConstants.Programs.ProgramTitle].ToString();
211 definition.SubTitle = t.MetaData[XMLTVConstants.Programs.ProgramSubTitle].ToString();
212 list.Add(definition);
213 }
214 catch (Exception ex) { throw ex; }
215 }
216
217 list = new ProgramDefinitionList(list.OrderBy(s => s.Start).ToList());
218
219 bindable = list;
220 return bindable;
221 }
222 }
223 public class ExtraList : List<IExtraMetaData>, IDataSourceBindable
224 {
225
226 public ExtraList() { }
227 /// <summary>
228 ///
229 /// </summary>
230 /// <param name="type"></param>
231 /// <returns></returns>
232 public object CreateBindableDataSource(out Type type)
233 {
234 type = typeof(object);
235 throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented.");
236 //object bindable = new object();
237 //return bindable;
238 }
239 //public object ConvertObjectData(object source) { return source; }
240 //public object Convert(object source)
241 //{
242 // throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented.");
243 //}
244 }
245 }

  ViewVC Help
Powered by ViewVC 1.1.22