3 |
using System.Linq; |
using System.Linq; |
4 |
using System.Text; |
using System.Text; |
5 |
using libxmltv.Interfaces; |
using libxmltv.Interfaces; |
6 |
|
using System.Collections; |
7 |
|
|
8 |
namespace libxmltv.Core |
namespace libxmltv.Core |
9 |
{ |
{ |
10 |
public class ChannelList : List<IXMLTVChannel>, IDataSourceBindable |
public class ChannelList : List<IXMLTVChannel>, IDataSourceBindable//, IDataConverter<IChannelDefintionList> |
11 |
{ |
{ |
12 |
private class ChannelDefintion |
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, bool descending, 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() |
public ChannelDefintion() |
30 |
{ |
{ |
33 |
} |
} |
34 |
public string ChannelId { get; internal set; } |
public string ChannelId { get; internal set; } |
35 |
public string ChannelName { get; internal set; } |
public string ChannelName { get; internal set; } |
36 |
|
|
37 |
|
|
38 |
} |
} |
39 |
//static private List<string> known_columns; |
//static private List<string> known_columns; |
40 |
//static ChannelList() |
//static ChannelList() |
45 |
//} |
//} |
46 |
public ChannelList() { } |
public ChannelList() { } |
47 |
|
|
48 |
|
//public object ConvertObjectData(object source) { return this.ConvertData(source); } |
49 |
|
//public IChannelDefintionList ConvertData(object source) |
50 |
public object CreateBindableDataSource() |
//{ |
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(); |
object bindable = new object(); |
66 |
List<ChannelDefintion> list = new List<ChannelDefintion>(); |
ChannelDefintionList list = new ChannelDefintionList(); |
67 |
|
|
68 |
foreach (var t in this) |
foreach (var t in this) |
69 |
{ |
{ |
76 |
} |
} |
77 |
catch (Exception ex) { throw ex; } |
catch (Exception ex) { throw ex; } |
78 |
} |
} |
79 |
list = list.OrderBy(s => s.ChannelName).ToList(); |
list = new ChannelDefintionList(list.OrderBy(s => s.ChannelName).ToList()); |
80 |
bindable = list; |
bindable = list; |
81 |
return bindable; |
return bindable; |
82 |
} |
} |
83 |
|
|
84 |
} |
} |
85 |
public class ProgramList : List<IXMLTVProgram>, IDataSourceBindable |
public class ProgramList : List<IXMLTVProgram>, IDataSourceBindable//, IDataConverter<IProgramDefinitionList> |
86 |
{ |
{ |
87 |
private class ProgramDefintion |
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, bool descending, params string[] args) |
93 |
|
{ |
94 |
|
IProgramDefinitionList list = null; |
95 |
|
IOrderedEnumerable<IProgramDefinition> ordered = null; |
96 |
|
try |
97 |
|
{ |
98 |
|
list = (ProgramDefinitionList)source; |
99 |
|
var col = args.First().ToString().ToLower(); |
100 |
|
switch (col) |
101 |
|
{ |
102 |
|
case "channelname": ordered = descending ? list.OrderByDescending(s => s.ChannelName) : list.OrderBy(s => s.ChannelName); break; |
103 |
|
case "start": ordered = descending ? list.OrderByDescending(s => s.Start) : list.OrderBy(s => s.Start); break; |
104 |
|
case "stop": ordered = descending ? list.OrderByDescending(s => s.Stop) : list.OrderBy(s => s.Stop); break; |
105 |
|
case "description": ordered = descending ? list.OrderByDescending(s => s.Description) : list.OrderBy(s => s.Description); break; |
106 |
|
case "title": ordered = descending ? list.OrderByDescending(s => s.Title) : list.OrderBy(s => s.Title); break; |
107 |
|
case "subtitle": ordered = descending ? list.OrderByDescending(s => s.SubTitle) : list.OrderBy(s => s.SubTitle); break; |
108 |
|
} |
109 |
|
//bool first = true; |
110 |
|
foreach (var arg in args.Skip(1)) |
111 |
|
{ |
112 |
|
col = arg.ToLower(); |
113 |
|
switch (col) |
114 |
|
{ |
115 |
|
case "channelname": ordered = descending ? ordered.ThenByDescending(s => s.ChannelName) : ordered.ThenBy(s => s.ChannelName); break; |
116 |
|
case "start": ordered = descending ? ordered.ThenByDescending(s => s.Start) : ordered.ThenBy(s => s.Start); break; |
117 |
|
case "stop": ordered = descending ? ordered.ThenByDescending(s => s.Stop) : ordered.ThenBy(s => s.Stop); break; |
118 |
|
case "description": ordered = descending ? ordered.ThenByDescending(s => s.Description) : ordered.ThenBy(s => s.Description); break; |
119 |
|
case "title": ordered = descending ? ordered.ThenByDescending(s => s.Title) : ordered.ThenBy(s => s.Title); break; |
120 |
|
case "subtitle": ordered = descending ? ordered.ThenByDescending(s => s.SubTitle) : ordered.ThenBy(s => s.SubTitle); break; |
121 |
|
} |
122 |
|
} |
123 |
|
list = new ProgramDefinitionList(ordered.ToList()); |
124 |
|
} |
125 |
|
catch (Exception ex) { throw ex; } |
126 |
|
if (list != null) { source = list; } |
127 |
|
} |
128 |
|
#endregion |
129 |
|
#region IDataSourceFilterable members |
130 |
|
public void Filter(ref object source, params string[] args) |
131 |
|
{ |
132 |
|
} |
133 |
|
#endregion |
134 |
|
} |
135 |
|
private class ProgramDefintion : IProgramDefinition |
136 |
{ |
{ |
137 |
public ProgramDefintion() |
public ProgramDefintion() |
138 |
{ |
{ |
150 |
public DateTime Stop { get; internal set; } |
public DateTime Stop { get; internal set; } |
151 |
public string Title { get; internal set; } |
public string Title { get; internal set; } |
152 |
public string SubTitle { get; internal set; } |
public string SubTitle { get; internal set; } |
153 |
public string Description { get; internal set; } |
public string Description { get; internal set; } |
154 |
|
|
155 |
|
|
156 |
} |
} |
157 |
public ProgramList() { } |
public ProgramList() { } |
158 |
|
//public object ConvertObjectData(object source) { return this.ConvertData(source); } |
159 |
public object CreateBindableDataSource() |
//public IProgramDefinitionList ConvertData(object source) |
160 |
|
//{ |
161 |
|
// if (source.GetType() != typeof(ProgramDefinitionList)) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(ProgramDefinitionList).Name)); } |
162 |
|
// //if (type != typeof(IProgramDefinitionList)) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", type.Name, typeof(IProgramDefinitionList).Name)); } |
163 |
|
// IProgramDefinitionList t = (source as IProgramDefinitionList); |
164 |
|
// return t; |
165 |
|
//} |
166 |
|
/// <summary> |
167 |
|
/// |
168 |
|
/// </summary> |
169 |
|
/// <param name="type"></param> |
170 |
|
/// <returns></returns> |
171 |
|
public object CreateBindableDataSource(out Type type) |
172 |
{ |
{ |
173 |
|
type = typeof(IProgramDefinitionList); |
174 |
object bindable = new object(); |
object bindable = new object(); |
175 |
List<ProgramDefintion> list = new List<ProgramDefintion>(); |
ProgramDefinitionList list = new ProgramDefinitionList(); |
176 |
|
|
177 |
foreach (var t in this) |
foreach (var t in this) |
178 |
{ |
{ |
209 |
catch (Exception ex) { throw ex; } |
catch (Exception ex) { throw ex; } |
210 |
} |
} |
211 |
|
|
212 |
list = list.OrderBy(s => s.Start).ToList(); |
list = new ProgramDefinitionList(list.OrderBy(s => s.Start).ToList()); |
213 |
|
|
214 |
bindable = list; |
bindable = list; |
215 |
return bindable; |
return bindable; |
219 |
{ |
{ |
220 |
|
|
221 |
public ExtraList() { } |
public ExtraList() { } |
222 |
|
/// <summary> |
223 |
public object CreateBindableDataSource() |
/// |
224 |
|
/// </summary> |
225 |
|
/// <param name="type"></param> |
226 |
|
/// <returns></returns> |
227 |
|
public object CreateBindableDataSource(out Type type) |
228 |
{ |
{ |
229 |
|
type = typeof(object); |
230 |
throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented."); |
throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented."); |
231 |
//object bindable = new object(); |
//object bindable = new object(); |
232 |
//return bindable; |
//return bindable; |
233 |
} |
} |
234 |
|
//public object ConvertObjectData(object source) { return source; } |
235 |
|
//public object Convert(object source) |
236 |
|
//{ |
237 |
|
// throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented."); |
238 |
|
//} |
239 |
} |
} |
240 |
} |
} |