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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 81 - (hide annotations) (download)
Sat Mar 9 12:23:27 2013 UTC (7 years, 7 months ago) by william
File size: 2150 byte(s)

1 william 11 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using libxmltv.Interfaces;
6     using System.IO;
7 william 14 using Enterprise.Logging;
8 william 19 using System.Xml.Linq;
9 william 49 using System.Xml;
10 william 11
11     namespace libxmltv.Core
12 william 72 {
13     internal class XMLTVLoader : XMLTVBase<XMLTVRuntimeInstance>, IDisposable
14 william 11 {
15 william 81 //private string xmlfile = string.Empty;
16     public XMLTVLoader(string xml_file) : base(null, xml_file) { }
17 william 72 protected XMLTVLoader(string xml_file, XMLTVRuntimeInstance instance)
18 william 73 : base(instance, xml_file)
19 william 44 {
20 william 69 xmltv_logger.Debug.WriteLine("Creating Instance of XMLTVLoader");
21 william 72 var fi = new FileInfo(xml_file);
22     this.GetInstance().XmlFile_FullName = fi.FullName;
23     this.GetInstance().XmlFile_Name = fi.Name;
24 william 16 LoadXml();
25 william 72 xmltv_logger.Debug.WriteLine("Created Instance of XMLTVLoader");
26 william 11 }
27 william 16
28     private void LoadXml()
29     {
30 william 72 xmltv_logger.Info.WriteLine("Loading XMLTV File: {0}", this.GetInstance().XmlFile_Name);
31 william 55 //xmltv_logger.Warn.WriteLine("XML File Loading has not been implemented yet!");
32 william 21 try
33     {
34 william 72 var document = XDocument.Load(this.GetInstance().XmlFile_FullName);
35 william 49 using (var ms = new MemoryStream())
36     using (var xw = new XmlTextWriter(ms, Encoding.UTF8))
37     {
38     document.Save(xw);
39     xw.Flush();
40     StreamReader sr = new StreamReader(ms);
41     ms.Seek(0, SeekOrigin.Begin);
42 william 72 this.GetInstance().XmlDoc = sr.ReadToEnd();
43 william 49 }
44     document = null;
45 william 21 }
46     catch (Exception ex)
47     {
48 william 72 xmltv_logger.Error.WriteLine("Failed to load XMLTV File: {0}", this.GetInstance().XmlFile_Name);
49 william 55 xmltv_logger.Error.WriteLine(ex.GetBaseException().ToString());
50 william 21 }
51 william 16 }
52 william 44
53     public void Dispose()
54     {
55     //throw new NotImplementedException();
56     }
57 william 49
58    
59 william 11 }
60     }

  ViewVC Help
Powered by ViewVC 1.1.22