/[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 36 - (hide annotations) (download)
Fri Mar 8 02:13:59 2013 UTC (7 years, 7 months ago) by william
File size: 5751 byte(s)
+ use a MarshalByRefObject

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 36 internal class XMLTVParser //: IXMLTV_PARSER
13 william 22 {
14 william 36 private XMLTVRuntimeInstance instance;
15     public XMLTVParser(XMLTVRuntimeInstance xmltv)
16 william 22 {
17 william 36 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 william 25 Create();
24 william 22 }
25     #region IXMLTV_PARSER members
26 william 36 //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 william 22 #endregion
32 william 23
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 william 36 var doc = instance.XmlDoc;
39 william 23 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 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));
48 william 23 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 william 36 var elements = doc.Root.Descendants(XMLTVConstants.CHANNEL_ELEMENT).ToList();
60 william 23 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 william 36 var elements = doc.Root.Descendants(XMLTVConstants.PROGRAM_ELEMENT).ToList();
87 william 24 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 william 23 }
110     #endregion
111 william 25
112     #region Creation Methods
113     private void Create()
114     {
115     CreateXMLTVSource();
116 william 26 CreateXMLTVChannels();
117 william 27 CreateXMLTVPrograms();
118 william 25 }
119     private void CreateXMLTVSource()
120     {
121 william 36 XMLTVSource source = new XMLTVSource(instance);
122     instance.Source = source;
123 william 25 }
124 william 26 private void CreateXMLTVChannels()
125     {
126 william 36 XMLTVChannelCollection channels = new XMLTVChannelCollection(instance);
127     instance.Channels = channels.Collection;
128 william 26 }
129 william 27 private void CreateXMLTVPrograms()
130     {
131 william 36 XMLTVProgramCollection programs = new XMLTVProgramCollection(instance);
132     instance.Programs = programs.Collection;
133 william 27 }
134 william 25 #endregion
135 william 22 }
136     }

  ViewVC Help
Powered by ViewVC 1.1.22