/[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 126 - (show annotations) (download)
Sun Mar 10 20:19:33 2013 UTC (6 years, 8 months ago) by william
File size: 7699 byte(s)

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
11 {
12 private class ChannelDefintionList : List<ChannelDefintion>, IDataSourceSortable, IDataSourceFilterable
13 {
14 public ChannelDefintionList() { }
15 public ChannelDefintionList(List<ChannelDefintion> 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
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
49
50 public object CreateBindableDataSource()
51 {
52 object bindable = new object();
53 ChannelDefintionList list = new ChannelDefintionList();
54
55 foreach (var t in this)
56 {
57 try
58 {
59 ChannelDefintion definition = new ChannelDefintion();
60 definition.ChannelId = t.Id;
61 definition.ChannelName = t.MetaData[XMLTVConstants.Channels.ChannelDisplayName].FirstOrDefault().Value.ToString();
62 list.Add(definition);
63 }
64 catch (Exception ex) { throw ex; }
65 }
66 list = new ChannelDefintionList(list.OrderBy(s => s.ChannelName).ToList());
67 bindable = list;
68 return bindable;
69 }
70 }
71 public class ProgramList : List<IXMLTVProgram>, IDataSourceBindable
72 {
73 private class ProgramDefinitionList : List<ProgramDefintion>, IDataSourceSortable, IDataSourceFilterable
74 {
75 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 public ProgramDefintion()
110 {
111 //ChannelId = string.Empty;
112 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 //public string ChannelId { get; internal set; }
120 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 public string Description { get; internal set; }
126
127
128 }
129 public ProgramList() { }
130
131 public object CreateBindableDataSource()
132 {
133 object bindable = new object();
134 ProgramDefinitionList list = new ProgramDefinitionList();
135
136 foreach (var t in this)
137 {
138 try
139 {
140 ProgramDefintion definition = new ProgramDefintion();
141 string ChannelId = t.MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString();
142 //definition.ChannelId = ChannelId;
143
144 var channels = XMLTV.GetChannels();
145 if (channels != null)
146 {
147 var channel = channels.Find(p => p.Id == ChannelId);
148 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
171 list = new ProgramDefinitionList(list.OrderBy(s => s.Start).ToList());
172
173 bindable = list;
174 return bindable;
175 }
176 }
177 public class ExtraList : List<IExtraMetaData>, IDataSourceBindable
178 {
179
180 public ExtraList() { }
181
182 public object CreateBindableDataSource()
183 {
184 throw new NotImplementedException("Conversion of Extra MetaData to a bindable datasource has not been implemented.");
185 //object bindable = new object();
186 //return bindable;
187 }
188 }
189 }

  ViewVC Help
Powered by ViewVC 1.1.22