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 |
using System.Windows.Forms; |
9 |
|
10 |
namespace libxmltv.Core |
11 |
{ |
12 |
internal class XMLTVChannelCollection |
13 |
{ |
14 |
private Dictionary<string, IXMLTVChannel> entries = new Dictionary<string, IXMLTVChannel>(); |
15 |
private XMLTVRuntimeInstance instance; |
16 |
public XMLTVChannelCollection(XMLTVRuntimeInstance xmltv) |
17 |
{ |
18 |
XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVChannelCollection"); |
19 |
//IXMLTV_PARSER _xmltv; |
20 |
//if (!Internals.VerifyInstance<IXMLTV_PARSER>(xmltv, out _xmltv)) { return; } |
21 |
//XMLTV_PARSER = _xmltv; |
22 |
instance = xmltv; |
23 |
Create(); |
24 |
} |
25 |
|
26 |
#region IXMLTVSource |
27 |
//private IXMLTV_PARSER XMLTV_PARSER { get; set; } |
28 |
public Dictionary<string, IXMLTVChannel> Collection |
29 |
{ |
30 |
get { return entries; } |
31 |
} |
32 |
#endregion |
33 |
|
34 |
private void Create() |
35 |
{ |
36 |
var doc = instance.XmlDoc; |
37 |
|
38 |
foreach (var c in doc.Descendants(XMLTVConstants.CHANNEL_ELEMENT)) |
39 |
{ |
40 |
Channel channel = new Channel(c); |
41 |
entries.Add(channel.Id, channel); |
42 |
Application.DoEvents(); |
43 |
} |
44 |
} |
45 |
public override string ToString() |
46 |
{ |
47 |
return string.Format("Channel Count: {0}", Collection == null ? 0 : Collection.Count); |
48 |
} |
49 |
} |
50 |
[Serializable] |
51 |
internal class Channel : IXMLTVChannel |
52 |
{ |
53 |
public Channel() |
54 |
{ |
55 |
Id = string.Empty; |
56 |
Number = 0; |
57 |
CallSign = string.Empty; |
58 |
Name = string.Empty; |
59 |
} |
60 |
public Channel(XElement e) |
61 |
: this() |
62 |
{ |
63 |
// get the channel id |
64 |
Id = e.Attribute(XMLTVConstants.Channels.ChannelId).Value; |
65 |
XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_id: {0}", Id); |
66 |
var names = e.Descendants(XMLTVConstants.Channels.ChannelDisplayName).ToList(); |
67 |
Number = Convert.ToInt32(names[1].Value); |
68 |
XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_number: {0}", Number); |
69 |
CallSign = names[2].Value; |
70 |
XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_callsign: {0}", CallSign); |
71 |
Name = names[3].Value; |
72 |
XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tchannel_name: {0}", Name); |
73 |
} |
74 |
#region IXMLTVChannel members |
75 |
public string Id { get; private set; } |
76 |
public int Number { get; private set; } |
77 |
public string CallSign { get; private set; } |
78 |
public string Name { get; private set; } |
79 |
#endregion |
80 |
public override string ToString() |
81 |
{ |
82 |
return string.Format("{0}: {1} {2} ({3})", Id,Number,Name, CallSign); |
83 |
} |
84 |
} |
85 |
} |
86 |
|