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 |
120 |
|
8 |
|
|
namespace libxmltv.Core |
9 |
|
|
{ |
10 |
|
|
public class ChannelList : List<IXMLTVChannel>, IDataSourceBindable |
11 |
|
|
{ |
12 |
william |
126 |
private class ChannelDefintionList : List<ChannelDefintion>, IDataSourceSortable, IDataSourceFilterable |
13 |
william |
121 |
{ |
14 |
william |
126 |
public ChannelDefintionList() { } |
15 |
|
|
public ChannelDefintionList(List<ChannelDefintion> collection) { collection.ForEach(s => this.Add(s)); } |
16 |
william |
125 |
#region IDataSourceSortable members |
17 |
william |
126 |
public void Sort(ref object source, params string[] args) |
18 |
william |
125 |
{ |
19 |
|
|
} |
20 |
|
|
#endregion |
21 |
|
|
#region IDataSourceFilterable members |
22 |
william |
126 |
public void Filter(ref object source, params string[] args) |
23 |
william |
125 |
{ |
24 |
|
|
} |
25 |
|
|
#endregion |
26 |
william |
121 |
} |
27 |
william |
126 |
private class ChannelDefintion |
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 |
william |
122 |
//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 |
william |
120 |
public ChannelList() { } |
47 |
|
|
|
48 |
william |
122 |
|
49 |
|
|
|
50 |
william |
120 |
public object CreateBindableDataSource() |
51 |
|
|
{ |
52 |
|
|
object bindable = new object(); |
53 |
william |
126 |
ChannelDefintionList list = new ChannelDefintionList(); |
54 |
william |
122 |
|
55 |
|
|
foreach (var t in this) |
56 |
|
|
{ |
57 |
|
|
try |
58 |
|
|
{ |
59 |
|
|
ChannelDefintion definition = new ChannelDefintion(); |
60 |
|
|
definition.ChannelId = t.Id; |
61 |
william |
123 |
definition.ChannelName = t.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString(); |
62 |
william |
122 |
list.Add(definition); |
63 |
|
|
} |
64 |
|
|
catch (Exception ex) { throw ex; } |
65 |
|
|
} |
66 |
william |
126 |
list = new ChannelDefintionList(list.OrderBy(s => s.ChannelName).ToList()); |
67 |
william |
122 |
bindable = list; |
68 |
william |
120 |
return bindable; |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
public class ProgramList : List<IXMLTVProgram>, IDataSourceBindable |
72 |
|
|
{ |
73 |
william |
126 |
private class ProgramDefinitionList : List<ProgramDefintion>, IDataSourceSortable, IDataSourceFilterable |
74 |
william |
121 |
{ |
75 |
william |
126 |
public ProgramDefinitionList() { } |
76 |
|
|
public ProgramDefinitionList(List<ProgramDefintion> collection) { collection.ForEach(s => this.Add(s)); } |
77 |
|
|
#region IDataSourceSortable members |
78 |
|
|
public void Sort(ref object source, params string[] args) |
79 |
|
|
{ |
80 |
|
|
ProgramDefinitionList list = null; |
81 |
|
|
try |
82 |
|
|
{ |
83 |
|
|
list = (ProgramDefinitionList)source; |
84 |
|
|
|
85 |
|
|
var col = args[0].ToLower(); |
86 |
|
|
switch (col) |
87 |
|
|
{ |
88 |
|
|
case "channelname": list =new ProgramDefinitionList( list.OrderBy(s => s.ChannelName).ToList()); break; |
89 |
|
|
case "start": list = new ProgramDefinitionList( list.OrderBy(s => s.Start).ToList()); break; |
90 |
|
|
case "stop": list = new ProgramDefinitionList( list.OrderBy(s => s.Stop).ToList()); break; |
91 |
|
|
case "description": list = new ProgramDefinitionList( list.OrderBy(s => s.Description).ToList()); break; |
92 |
|
|
case "title": list = new ProgramDefinitionList( list.OrderBy(s => s.Title).ToList()); break; |
93 |
|
|
case "subtitle": list = new ProgramDefinitionList(list.OrderBy(s => s.SubTitle).ToList()); break; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
} |
97 |
|
|
catch (Exception ex) { throw ex; } |
98 |
|
|
if (list != null) { source = list; } |
99 |
|
|
} |
100 |
|
|
#endregion |
101 |
|
|
#region IDataSourceFilterable members |
102 |
|
|
public void Filter(ref object source, params string[] args) |
103 |
|
|
{ |
104 |
|
|
} |
105 |
|
|
#endregion |
106 |
|
|
} |
107 |
|
|
private class ProgramDefintion |
108 |
|
|
{ |
109 |
william |
122 |
public ProgramDefintion() |
110 |
|
|
{ |
111 |
william |
123 |
//ChannelId = string.Empty; |
112 |
william |
122 |
ChannelName = string.Empty; |
113 |
|
|
Start = new DateTime(); |
114 |
|
|
Stop = new DateTime(); |
115 |
|
|
Description = string.Empty; |
116 |
|
|
Title = string.Empty; |
117 |
|
|
SubTitle = string.Empty; |
118 |
|
|
} |
119 |
william |
123 |
//public string ChannelId { get; internal set; } |
120 |
william |
122 |
public string ChannelName { get; internal set; } |
121 |
|
|
public DateTime Start { get; internal set; } |
122 |
|
|
public DateTime Stop { get; internal set; } |
123 |
|
|
public string Title { get; internal set; } |
124 |
|
|
public string SubTitle { get; internal set; } |
125 |
william |
125 |
public string Description { get; internal set; } |
126 |
|
|
|
127 |
william |
126 |
|
128 |
william |
121 |
} |
129 |
william |
120 |
public ProgramList() { } |
130 |
|
|
|
131 |
|
|
public object CreateBindableDataSource() |
132 |
|
|
{ |
133 |
|
|
object bindable = new object(); |
134 |
william |
126 |
ProgramDefinitionList list = new ProgramDefinitionList(); |
135 |
william |
121 |
|
136 |
william |
122 |
foreach (var t in this) |
137 |
|
|
{ |
138 |
|
|
try |
139 |
|
|
{ |
140 |
|
|
ProgramDefintion definition = new ProgramDefintion(); |
141 |
william |
123 |
string ChannelId = t.MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString(); |
142 |
|
|
//definition.ChannelId = ChannelId; |
143 |
william |
121 |
|
144 |
william |
122 |
var channels = XMLTV.GetChannels(); |
145 |
|
|
if (channels != null) |
146 |
|
|
{ |
147 |
william |
123 |
var channel = channels.Find(p => p.Id == ChannelId); |
148 |
william |
122 |
if (channel != null) |
149 |
|
|
{ |
150 |
|
|
definition.ChannelName = channel.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString(); |
151 |
|
|
} |
152 |
|
|
else |
153 |
|
|
{ |
154 |
|
|
definition.ChannelName = string.Empty; |
155 |
|
|
} |
156 |
|
|
} |
157 |
|
|
else |
158 |
|
|
{ |
159 |
|
|
definition.ChannelName = string.Empty; |
160 |
|
|
} |
161 |
|
|
definition.Start = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStart]; |
162 |
|
|
definition.Stop = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStop]; |
163 |
|
|
definition.Description = t.MetaData[XMLTVConstants.Programs.ProgramDescription].ToString(); |
164 |
|
|
definition.Title = t.MetaData[XMLTVConstants.Programs.ProgramTitle].ToString(); |
165 |
|
|
definition.SubTitle = t.MetaData[XMLTVConstants.Programs.ProgramSubTitle].ToString(); |
166 |
|
|
list.Add(definition); |
167 |
|
|
} |
168 |
|
|
catch (Exception ex) { throw ex; } |
169 |
|
|
} |
170 |
william |
123 |
|
171 |
william |
126 |
list = new ProgramDefinitionList(list.OrderBy(s => s.Start).ToList()); |
172 |
william |
123 |
|
173 |
william |
122 |
bindable = list; |
174 |
william |
120 |
return bindable; |
175 |
|
|
} |
176 |
|
|
} |
177 |
|
|
public class ExtraList : List<IExtraMetaData>, IDataSourceBindable |
178 |
|
|
{ |
179 |
william |
121 |
|
180 |
william |
120 |
public ExtraList() { } |
181 |
|
|
|
182 |
|
|
public object CreateBindableDataSource() |
183 |
|
|
{ |
184 |
william |
124 |
throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented."); |
185 |
|
|
//object bindable = new object(); |
186 |
|
|
//return bindable; |
187 |
william |
120 |
} |
188 |
|
|
} |
189 |
|
|
} |