/[xmltv_parser]/trunk/libxmltv/Core/XMLTVChannel.cs
ViewVC logotype

Contents of /trunk/libxmltv/Core/XMLTVChannel.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Thu Mar 7 13:46:39 2013 UTC (7 years, 3 months ago) by william
File size: 2599 byte(s)
+ add support to save and read serialized Program/Channel data

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using libxmltv.Interfaces;
6 using System.Diagnostics;
7 using System.Xml.Linq;
8
9 namespace libxmltv.Core
10 {
11 internal class XMLTVChannelCollection
12 {
13 private Dictionary<string, IXMLTVChannel> entries = new Dictionary<string, IXMLTVChannel>();
14 public XMLTVChannelCollection(object xmltv)
15 {
16 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection");
17 IXMLTV_PARSER _xmltv;
18 if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; }
19 XMLTV_PARSER = _xmltv;
20 Create();
21 }
22
23 #region IXMLTVSource
24 private IXMLTV_PARSER XMLTV_PARSER { get; set; }
25 public Dictionary<string, IXMLTVChannel> Collection
26 {
27 get { return entries; }
28 }
29 #endregion
30
31 private void Create()
32 {
33 var doc = XMLTV_PARSER.XMLTV_LOADER.XmlDoc;
34
35 foreach (var c in doc.Descendants(XMLTV_CONSTANTS.CHANNEL_ELEMENT))
36 {
37 Channel channel = new Channel(c);
38 entries.Add(channel.Id, channel);
39 }
40 }
41 public override string ToString()
42 {
43 //return string.Format("XmlTv Source: '{0}' (Generated by: '{1}') (support: '{2}')", SourceName, GeneratorName, GeneratorUrl);
44 return string.Empty;
45 }
46 }
47 [Serializable]
48 internal class Channel : IXMLTVChannel
49 {
50 public Channel()
51 {
52 Id = string.Empty;
53 Number = 0;
54 CallSign = string.Empty;
55 Name = string.Empty;
56 }
57 public Channel(XElement e)
58 : this()
59 {
60 // get the channel id
61 Id = e.Attribute(XMLTV_CONSTANTS.Channels.ChannelId).Value;
62 var names = e.Descendants(XMLTV_CONSTANTS.Channels.ChannelDisplayName).ToList();
63 Number = Convert.ToInt32(names[1].Value);
64 CallSign = names[2].Value;
65 Name = names[3].Value;
66 }
67 #region IXMLTVChannel members
68 public string Id { get; private set; }
69 public int Number { get; private set; }
70 public string CallSign { get; private set; }
71 public string Name { get; private set; }
72 #endregion
73 public override string ToString()
74 {
75 return string.Format("{0}: {1} {2} ({3})", Id,Number,Name, CallSign);
76 }
77 }
78 }
79

  ViewVC Help
Powered by ViewVC 1.1.22