/[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 55 - (show annotations) (download)
Fri Mar 8 10:19:32 2013 UTC (7 years, 7 months ago) by william
File size: 6174 byte(s)
+ upate for: Enterprise.Logging: 1.2.5.1

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 : IDisposable
13 {
14 private XMLTVRuntimeInstance instance;
15
16 internal static void CreateInstance(XMLTVRuntimeInstance xmltv)
17 {
18 using (XMLTVParser g = new XMLTVParser(xmltv)) { }
19 }
20
21
22 protected XMLTVParser(XMLTVRuntimeInstance xmltv)
23 {
24 xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVParser");
25 //IXMLTV_LOADER _xmltv;
26 //if (!Internals.VerifyInstance<IXMLTV_LOADER>(xmltv, out _xmltv)) { return; }
27 //XMLTV_LOADER = _xmltv;
28 //Create();
29 instance = xmltv;
30 Create();
31 }
32 #region IXMLTV_PARSER members
33 //public IXMLTV_LOADER XMLTV_LOADER { get; private set; }
34 ////public void TestParse() { _imp_TestParse(); }
35 //public IXMLTVSource Source { get; private set; }
36 //public Dictionary<string, IXMLTVChannel> Channels { get; private set; }
37 //public Dictionary<int, IXMLTVProgram> Programs { get; private set; }
38 #endregion
39
40 #region Parser Testing Methods
41 [Conditional("XMLTV_PARSER_TESTING")]
42 private void _imp_TestParse()
43 {
44 xmltv_logger.Verbose.Debug.WriteLine("Running XML_PARSER Test");
45 var doc = XDocument.Parse(instance.XmlDoc);
46 ParseRootElements(doc);
47 ParseChannels(doc);
48 ParsePrograms(doc);
49 }
50 [Conditional("XMLTV_PARSER_TESTING")]
51 private void ParseRootElements(XDocument doc)
52 {
53 xmltv_logger.Verbose.Debug.WriteLine("Parseing Root Data");
54 Debug.Assert(doc.Root.Name == XMLTVConstants.ROOT_ELEMENT, string.Format("Expected Root Element: '{0}' but read: '{1}'", XMLTVConstants.ROOT_ELEMENT, doc.Root.Name));
55 xmltv_logger.Verbose.Debug.WriteLine("\tRoot: {0}", doc.Root.Name);
56 var attributes = doc.Root.Attributes().ToList();
57 foreach (var attribute in attributes)
58 {
59 xmltv_logger.Verbose.Debug.WriteLine("\t{0}: {1}", attribute.Name, attribute.Value);
60 }
61 }
62 [Conditional("XMLTV_PARSER_TESTING")]
63 private void ParseChannels(XDocument doc)
64 {
65 xmltv_logger.Verbose.Debug.WriteLine("Parsing Channel Data");
66 var elements = doc.Root.Descendants(XMLTVConstants.CHANNEL_ELEMENT).ToList();
67 foreach (var element in elements)
68 {
69 if (element.HasAttributes)
70 {
71 foreach (var attribute in element.Attributes())
72 {
73 xmltv_logger.Verbose.Debug.WriteLine("\t\t{0} {1}: {2}",element.Name, attribute.Name, attribute.Value);
74 }
75 }
76 foreach (var childEllement in element.Descendants())
77 {
78 if (childEllement.HasAttributes)
79 {
80 foreach (var attribute in childEllement.Attributes())
81 {
82 xmltv_logger.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", attribute.Name, attribute.Value);
83 }
84 }
85 xmltv_logger.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", childEllement.Name, childEllement.Value);
86 }
87 }
88 }
89 [Conditional("XMLTV_PARSER_TESTING")]
90 private void ParsePrograms(XDocument doc)
91 {
92 xmltv_logger.Verbose.Debug.WriteLine("Parsing Program Data");
93 var elements = doc.Root.Descendants(XMLTVConstants.PROGRAM_ELEMENT).ToList();
94 foreach (var element in elements)
95 {
96 if (element.HasAttributes)
97 {
98 foreach (var attribute in element.Attributes())
99 {
100 xmltv_logger.Verbose.Debug.WriteLine("\t\t{0} {1}: {2}", element.Name, attribute.Name, attribute.Value);
101 }
102 }
103 foreach (var childEllement in element.Descendants())
104 {
105 if (childEllement.HasAttributes)
106 {
107 foreach (var attribute in childEllement.Attributes())
108 {
109 xmltv_logger.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", attribute.Name, attribute.Value);
110 }
111 }
112 xmltv_logger.Verbose.Debug.WriteLine("\t\t\t{0}: {1}", childEllement.Name, childEllement.Value);
113 }
114 //break;
115 }
116 }
117 #endregion
118
119 #region Creation Methods
120 private void Create()
121 {
122 CreateXMLTVSource();
123 CreateXMLTVChannels();
124 CreateXMLTVPrograms();
125 }
126 private void CreateXMLTVSource()
127 {
128 //XMLTVSource source = new XMLTVSource(instance);
129 //instance.Source = source;
130 XMLTVSource.CreateInstance(instance);
131 }
132 private void CreateXMLTVChannels()
133 {
134 //XMLTVChannelCollection channels = new XMLTVChannelCollection(instance);
135 //instance.Channels = channels.Collection;
136 XMLTVChannelCollection.CreateInstance(instance);
137 }
138 private void CreateXMLTVPrograms()
139 {
140 //XMLTVProgramCollection programs = new XMLTVProgramCollection(instance);
141 //instance.Programs = programs.Collection;
142 XMLTVProgramCollection.CreateInstance(instance);
143 }
144 #endregion
145
146 public void Dispose()
147 {
148 //throw new NotImplementedException();
149 }
150 }
151 }

  ViewVC Help
Powered by ViewVC 1.1.22