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

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 22 {
13 william 44 internal class XMLTVLoader : IDisposable
14 william 11 {
15     private string xmlfile = string.Empty;
16 william 44 internal static void CreateInstance(string xml_file, XMLTVRuntimeInstance xmltv)
17     {
18     using (XMLTVLoader g = new XMLTVLoader(xml_file, xmltv)) { }
19     }
20 william 36 private XMLTVRuntimeInstance instance;
21 william 44 protected XMLTVLoader(string xml_file, XMLTVRuntimeInstance xmltv)
22 william 11 {
23 william 55 xmltv_logger.Verbose.Debug.WriteLine("Creating Instance of XMLTVLoader");
24 william 36 //string _xmltv;
25     //if (!Internals.VerifyInstance<string>(xmltv, out _xmltv)) { return; }
26     //xmlfile = _xmltv;
27     //LoadXml();
28     instance = xmltv;
29     instance.XmlFile = new FileInfo(xml_file);
30 william 16 LoadXml();
31 william 11 }
32 william 36 //#region IXMLTV_LOADER
33     //public FileInfo XmlFile { get { return new FileInfo(xmlfile); } }
34     //public XDocument XmlDoc { get; private set; }
35     //#endregion
36 william 16
37     private void LoadXml()
38     {
39 william 55 xmltv_logger.Info.WriteLine("Loading XMLTV File: {0}", instance.XmlFile.Name);
40     //xmltv_logger.Warn.WriteLine("XML File Loading has not been implemented yet!");
41 william 21 try
42     {
43 william 49 var document = XDocument.Load(instance.XmlFile.FullName);
44     using (var ms = new MemoryStream())
45     using (var xw = new XmlTextWriter(ms, Encoding.UTF8))
46     {
47     document.Save(xw);
48     xw.Flush();
49     StreamReader sr = new StreamReader(ms);
50     ms.Seek(0, SeekOrigin.Begin);
51     instance.XmlDoc = sr.ReadToEnd();
52     }
53     document = null;
54 william 21 }
55     catch (Exception ex)
56     {
57 william 55 xmltv_logger.Error.WriteLine("Failed to load XMLTV File: {0}", instance.XmlFile.Name);
58     xmltv_logger.Error.WriteLine(ex.GetBaseException().ToString());
59 william 21 }
60 william 16 }
61 william 44
62     public void Dispose()
63     {
64     //throw new NotImplementedException();
65     }
66 william 49
67    
68 william 11 }
69     }

  ViewVC Help
Powered by ViewVC 1.1.22