/[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 128 - (show annotations) (download)
Wed Mar 13 13:45:05 2013 UTC (6 years, 8 months ago) by william
File size: 10142 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 ProgramDefinitionList list = null;
95 try
96 {
97 list = (ProgramDefinitionList)source;
98
99 var col = args[0].ToLower();
100 switch (col)
101 {
102 case "channelname": list =new ProgramDefinitionList( list.OrderBy(s => s.ChannelName).ToList()); break;
103 case "start": list = new ProgramDefinitionList( list.OrderBy(s => s.Start).ToList()); break;
104 case "stop": list = new ProgramDefinitionList( list.OrderBy(s => s.Stop).ToList()); break;
105 case "description": list = new ProgramDefinitionList( list.OrderBy(s => s.Description).ToList()); break;
106 case "title": list = new ProgramDefinitionList( list.OrderBy(s => s.Title).ToList()); break;
107 case "subtitle": list = new ProgramDefinitionList(list.OrderBy(s => s.SubTitle).ToList()); break;
108 }
109
110 }
111 catch (Exception ex) { throw ex; }
112 if (list != null) { source = list; }
113 }
114 #endregion
115 #region IDataSourceFilterable members
116 public void Filter(ref object source, params string[] args)
117 {
118 }
119 #endregion
120 }
121 private class ProgramDefintion : IProgramDefinition
122 {
123 public ProgramDefintion()
124 {
125 //ChannelId = string.Empty;
126 ChannelName = string.Empty;
127 Start = new DateTime();
128 Stop = new DateTime();
129 Description = string.Empty;
130 Title = string.Empty;
131 SubTitle = string.Empty;
132 }
133 //public string ChannelId { get; internal set; }
134 public string ChannelName { get; internal set; }
135 public DateTime Start { get; internal set; }
136 public DateTime Stop { get; internal set; }
137 public string Title { get; internal set; }
138 public string SubTitle { get; internal set; }
139 public string Description { get; internal set; }
140
141
142 }
143 public ProgramList() { }
144 //public object ConvertObjectData(object source) { return this.ConvertData(source); }
145 //public IProgramDefinitionList ConvertData(object source)
146 //{
147 // if (source.GetType() != typeof(ProgramDefinitionList)) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(ProgramDefinitionList).Name)); }
148 // //if (type != typeof(IProgramDefinitionList)) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", type.Name, typeof(IProgramDefinitionList).Name)); }
149 // IProgramDefinitionList t = (source as IProgramDefinitionList);
150 // return t;
151 //}
152 /// <summary>
153 ///
154 /// </summary>
155 /// <param name="type"></param>
156 /// <returns></returns>
157 public object CreateBindableDataSource(out Type type)
158 {
159 type = typeof(IProgramDefinitionList);
160 object bindable = new object();
161 ProgramDefinitionList list = new ProgramDefinitionList();
162
163 foreach (var t in this)
164 {
165 try
166 {
167 ProgramDefintion definition = new ProgramDefintion();
168 string ChannelId = t.MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString();
169 //definition.ChannelId = ChannelId;
170
171 var channels = XMLTV.GetChannels();
172 if (channels != null)
173 {
174 var channel = channels.Find(p => p.Id == ChannelId);
175 if (channel != null)
176 {
177 definition.ChannelName = channel.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString();
178 }
179 else
180 {
181 definition.ChannelName = string.Empty;
182 }
183 }
184 else
185 {
186 definition.ChannelName = string.Empty;
187 }
188 definition.Start = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStart];
189 definition.Stop = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStop];
190 definition.Description = t.MetaData[XMLTVConstants.Programs.ProgramDescription].ToString();
191 definition.Title = t.MetaData[XMLTVConstants.Programs.ProgramTitle].ToString();
192 definition.SubTitle = t.MetaData[XMLTVConstants.Programs.ProgramSubTitle].ToString();
193 list.Add(definition);
194 }
195 catch (Exception ex) { throw ex; }
196 }
197
198 list = new ProgramDefinitionList(list.OrderBy(s => s.Start).ToList());
199
200 bindable = list;
201 return bindable;
202 }
203 }
204 public class ExtraList : List<IExtraMetaData>, IDataSourceBindable
205 {
206
207 public ExtraList() { }
208 /// <summary>
209 ///
210 /// </summary>
211 /// <param name="type"></param>
212 /// <returns></returns>
213 public object CreateBindableDataSource(out Type type)
214 {
215 type = typeof(object);
216 throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented.");
217 //object bindable = new object();
218 //return bindable;
219 }
220 //public object ConvertObjectData(object source) { return source; }
221 //public object Convert(object source)
222 //{
223 // throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented.");
224 //}
225 }
226 }

  ViewVC Help
Powered by ViewVC 1.1.22