/[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 72 - (hide annotations) (download)
Sat Mar 9 09:29:40 2013 UTC (7 years, 8 months ago) by william
File size: 2272 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     private string xmlfile = string.Empty;
16 william 72 //internal static void CreateInstance(string xml_file, XMLTVRuntimeInstance xmltv)
17     //{
18     // using (XMLTVLoader g = new XMLTVLoader(xml_file, xmltv)) { }
19     //}
20     protected XMLTVLoader(string xml_file, XMLTVRuntimeInstance instance)
21     : base(instance)
22 william 44 {
23 william 69 xmltv_logger.Debug.WriteLine("Creating Instance of XMLTVLoader");
24 william 72 var fi = new FileInfo(xml_file);
25     this.GetInstance().XmlFile_FullName = fi.FullName;
26     this.GetInstance().XmlFile_Name = fi.Name;
27 william 16 LoadXml();
28 william 72 xmltv_logger.Debug.WriteLine("Created Instance of XMLTVLoader");
29 william 11 }
30 william 16
31     private void LoadXml()
32     {
33 william 72 xmltv_logger.Info.WriteLine("Loading XMLTV File: {0}", this.GetInstance().XmlFile_Name);
34 william 55 //xmltv_logger.Warn.WriteLine("XML File Loading has not been implemented yet!");
35 william 21 try
36     {
37 william 72 var document = XDocument.Load(this.GetInstance().XmlFile_FullName);
38 william 49 using (var ms = new MemoryStream())
39     using (var xw = new XmlTextWriter(ms, Encoding.UTF8))
40     {
41     document.Save(xw);
42     xw.Flush();
43     StreamReader sr = new StreamReader(ms);
44     ms.Seek(0, SeekOrigin.Begin);
45 william 72 this.GetInstance().XmlDoc = sr.ReadToEnd();
46 william 49 }
47     document = null;
48 william 21 }
49     catch (Exception ex)
50     {
51 william 72 xmltv_logger.Error.WriteLine("Failed to load XMLTV File: {0}", this.GetInstance().XmlFile_Name);
52 william 55 xmltv_logger.Error.WriteLine(ex.GetBaseException().ToString());
53 william 21 }
54 william 16 }
55 william 44
56     public void Dispose()
57     {
58     //throw new NotImplementedException();
59     }
60 william 49
61    
62 william 11 }
63     }

  ViewVC Help
Powered by ViewVC 1.1.22