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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49 - (hide annotations) (download)
Fri Mar 8 05:20:12 2013 UTC (7 years, 7 months ago) by william
File size: 6226 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22