1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using libxmltv.Interfaces; |
6 |
|
7 |
namespace libxmltv.Core |
8 |
{ |
9 |
public class ChannelList : List<IXMLTVChannel>, IDataSourceBindable |
10 |
{ |
11 |
private class ChannelDefintion : IDataSourceSortable, IDataSourceFilterable |
12 |
{ |
13 |
public ChannelDefintion() |
14 |
{ |
15 |
ChannelId = string.Empty; |
16 |
ChannelName = string.Empty; |
17 |
} |
18 |
public string ChannelId { get; internal set; } |
19 |
public string ChannelName { get; internal set; } |
20 |
|
21 |
#region IDataSourceSortable members |
22 |
public object Sort(object source, params string[] args) |
23 |
{ |
24 |
return source; |
25 |
} |
26 |
#endregion |
27 |
#region IDataSourceFilterable members |
28 |
public object Filter(object source, params string[] args) |
29 |
{ |
30 |
return source; |
31 |
} |
32 |
#endregion |
33 |
} |
34 |
//static private List<string> known_columns; |
35 |
//static ChannelList() |
36 |
//{ |
37 |
// known_columns = new List<string>(); |
38 |
// known_columns.Add("Id"); |
39 |
// known_columns.Add("Name"); |
40 |
//} |
41 |
public ChannelList() { } |
42 |
|
43 |
|
44 |
|
45 |
public object CreateBindableDataSource() |
46 |
{ |
47 |
object bindable = new object(); |
48 |
List<ChannelDefintion> list = new List<ChannelDefintion>(); |
49 |
|
50 |
foreach (var t in this) |
51 |
{ |
52 |
try |
53 |
{ |
54 |
ChannelDefintion definition = new ChannelDefintion(); |
55 |
definition.ChannelId = t.Id; |
56 |
definition.ChannelName = t.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString(); |
57 |
list.Add(definition); |
58 |
} |
59 |
catch (Exception ex) { throw ex; } |
60 |
} |
61 |
list = list.OrderBy(s => s.ChannelName).ToList(); |
62 |
bindable = list; |
63 |
return bindable; |
64 |
} |
65 |
} |
66 |
public class ProgramList : List<IXMLTVProgram>, IDataSourceBindable |
67 |
{ |
68 |
private class ProgramDefintion : IDataSourceSortable, IDataSourceFilterable |
69 |
{ |
70 |
public ProgramDefintion() |
71 |
{ |
72 |
//ChannelId = string.Empty; |
73 |
ChannelName = string.Empty; |
74 |
Start = new DateTime(); |
75 |
Stop = new DateTime(); |
76 |
Description = string.Empty; |
77 |
Title = string.Empty; |
78 |
SubTitle = string.Empty; |
79 |
} |
80 |
//public string ChannelId { get; internal set; } |
81 |
public string ChannelName { get; internal set; } |
82 |
public DateTime Start { get; internal set; } |
83 |
public DateTime Stop { get; internal set; } |
84 |
public string Title { get; internal set; } |
85 |
public string SubTitle { get; internal set; } |
86 |
public string Description { get; internal set; } |
87 |
|
88 |
#region IDataSourceSortable members |
89 |
public object Sort(object source, params string[] args) |
90 |
{ |
91 |
return source; |
92 |
} |
93 |
#endregion |
94 |
#region IDataSourceFilterable members |
95 |
public object Filter(object source, params string[] args) |
96 |
{ |
97 |
return source; |
98 |
} |
99 |
#endregion |
100 |
} |
101 |
public ProgramList() { } |
102 |
|
103 |
public object CreateBindableDataSource() |
104 |
{ |
105 |
object bindable = new object(); |
106 |
List<ProgramDefintion> list = new List<ProgramDefintion>(); |
107 |
|
108 |
foreach (var t in this) |
109 |
{ |
110 |
try |
111 |
{ |
112 |
ProgramDefintion definition = new ProgramDefintion(); |
113 |
string ChannelId = t.MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString(); |
114 |
//definition.ChannelId = ChannelId; |
115 |
|
116 |
var channels = XMLTV.GetChannels(); |
117 |
if (channels != null) |
118 |
{ |
119 |
var channel = channels.Find(p => p.Id == ChannelId); |
120 |
if (channel != null) |
121 |
{ |
122 |
definition.ChannelName = channel.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString(); |
123 |
} |
124 |
else |
125 |
{ |
126 |
definition.ChannelName = string.Empty; |
127 |
} |
128 |
} |
129 |
else |
130 |
{ |
131 |
definition.ChannelName = string.Empty; |
132 |
} |
133 |
definition.Start = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStart]; |
134 |
definition.Stop = (DateTime)t.MetaData[XMLTVConstants.Programs.ProgramStop]; |
135 |
definition.Description = t.MetaData[XMLTVConstants.Programs.ProgramDescription].ToString(); |
136 |
definition.Title = t.MetaData[XMLTVConstants.Programs.ProgramTitle].ToString(); |
137 |
definition.SubTitle = t.MetaData[XMLTVConstants.Programs.ProgramSubTitle].ToString(); |
138 |
list.Add(definition); |
139 |
} |
140 |
catch (Exception ex) { throw ex; } |
141 |
} |
142 |
|
143 |
list = list.OrderBy(s => s.Start).ToList(); |
144 |
|
145 |
bindable = list; |
146 |
return bindable; |
147 |
} |
148 |
} |
149 |
public class ExtraList : List<IExtraMetaData>, IDataSourceBindable |
150 |
{ |
151 |
|
152 |
public ExtraList() { } |
153 |
|
154 |
public object CreateBindableDataSource() |
155 |
{ |
156 |
throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented."); |
157 |
//object bindable = new object(); |
158 |
//return bindable; |
159 |
} |
160 |
} |
161 |
} |