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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (show annotations) (download)
Fri Mar 8 02:13:59 2013 UTC (7 years, 4 months ago) by william
File size: 5751 byte(s)
+ use a MarshalByRefObject

1 //#define XMLTV_PARSER_TESTING // when defined will allow calls to be made to _imp_TestParse()
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using libxmltv.Interfaces;
7 using System.Diagnostics;
8 using System.Xml.Linq;
9
10 namespace libxmltv.Core
11 {
12 internal class XMLTVParser //: IXMLTV_PARSER
13 {
14 private XMLTVRuntimeInstance instance;
15 public XMLTVParser(XMLTVRuntimeInstance xmltv)
16 {
17 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Creating Instance of XMLTVParser");
18 //IXMLTV_LOADER _xmltv;
19 //if (!Internals.VerifyInstance<IXMLTV_LOADER>(xmltv, out _xmltv)) { return; }
20 //XMLTV_LOADER = _xmltv;
21 //Create();
22 instance = xmltv;
23 Create();
24 }
25 #region IXMLTV_PARSER members
26 //public IXMLTV_LOADER XMLTV_LOADER { get; private set; }
27 ////public void TestParse() { _imp_TestParse(); }
28 //public IXMLTVSource Source { get; private set; }
29 //public Dictionary<string, IXMLTVChannel> Channels { get; private set; }
30 //public Dictionary<int, IXMLTVProgram> Programs { get; private set; }
31 #endregion
32
33 #region Parser Testing Methods
34 [Conditional("XMLTV_PARSER_TESTING")]
35 private void _imp_TestParse()
36 {
37 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Running XML_PARSER Test");
38 var doc = instance.XmlDoc;
39 ParseRootElements(doc);
40 ParseChannels(doc);
41 ParsePrograms(doc);
42 }
43 [Conditional("XMLTV_PARSER_TESTING")]
44 private void ParseRootElements(XDocument doc)
45 {
46 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parseing Root Data");
47 Debug.Assert(doc.Root.Name == XMLTVConstants.ROOT_ELEMENT, string.Format("Expected Root Element: '{0}' but read: '{1}'", XMLTVConstants.ROOT_ELEMENT, doc.Root.Name));
48 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\tRoot: {0}", doc.Root.Name);
49 var attributes = doc.Root.Attributes().ToList();
50 foreach (var attribute in attributes)
51 {
52 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t{0}: {1}", attribute.Name, attribute.Value);
53 }
54 }
55 [Conditional("XMLTV_PARSER_TESTING")]
56 private void ParseChannels(XDocument doc)
57 {
58 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parsing Channel Data");
59 var elements = doc.Root.Descendants(XMLTVConstants.CHANNEL_ELEMENT).ToList();
60 foreach (var element in elements)
61 {
62 if (element.HasAttributes)
63 {
64 foreach (var attribute in element.Attributes())
65 {
66 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t{0} {1}: {2}",element.Name, attribute.Name, attribute.Value);
67 }
68 }
69 foreach (var childEllement in element.Descendants())
70 {
71 if (childEllement.HasAttributes)
72 {
73 foreach (var attribute in childEllement.Attributes())
74 {
75 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", attribute.Name, attribute.Value);
76 }
77 }
78 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", childEllement.Name, childEllement.Value);
79 }
80 }
81 }
82 [Conditional("XMLTV_PARSER_TESTING")]
83 private void ParsePrograms(XDocument doc)
84 {
85 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("Parsing Program Data");
86 var elements = doc.Root.Descendants(XMLTVConstants.PROGRAM_ELEMENT).ToList();
87 foreach (var element in elements)
88 {
89 if (element.HasAttributes)
90 {
91 foreach (var attribute in element.Attributes())
92 {
93 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t{0} {1}: {2}", element.Name, attribute.Name, attribute.Value);
94 }
95 }
96 foreach (var childEllement in element.Descendants())
97 {
98 if (childEllement.HasAttributes)
99 {
100 foreach (var attribute in childEllement.Attributes())
101 {
102 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", attribute.Name, attribute.Value);
103 }
104 }
105 XMLTV_LOGGER.Log.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", childEllement.Name, childEllement.Value);
106 }
107 //break;
108 }
109 }
110 #endregion
111
112 #region Creation Methods
113 private void Create()
114 {
115 CreateXMLTVSource();
116 CreateXMLTVChannels();
117 CreateXMLTVPrograms();
118 }
119 private void CreateXMLTVSource()
120 {
121 XMLTVSource source = new XMLTVSource(instance);
122 instance.Source = source;
123 }
124 private void CreateXMLTVChannels()
125 {
126 XMLTVChannelCollection channels = new XMLTVChannelCollection(instance);
127 instance.Channels = channels.Collection;
128 }
129 private void CreateXMLTVPrograms()
130 {
131 XMLTVProgramCollection programs = new XMLTVProgramCollection(instance);
132 instance.Programs = programs.Collection;
133 }
134 #endregion
135 }
136 }

  ViewVC Help
Powered by ViewVC 1.1.22