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