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

Contents of /trunk/libxmltv/Core/XMLTVSerializer.cs

Parent Directory Parent Directory | Revision Log Revision Log


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

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.IO;
6 using libxmltv.Interfaces;
7 using Enterprise.Logging;
8 using System.Runtime.Serialization.Formatters.Binary;
9 using System.Windows.Forms;
10
11 namespace libxmltv.Core
12 {
13 public class XMLTVSerializer<T> : IXMLTVSerializer<T>
14 {
15 private T data;
16 public XMLTVSerializer(T Data) { data = Data; }
17 #region IXMLTVSerializer<T> members
18 public bool Serialize(string file)
19 {
20 bool retVal = false;
21 using (Stream stream = File.Open(file, FileMode.Create)) { retVal = Serialize(stream); }
22 return retVal;
23 }
24 public bool Serialize(Stream stream)
25 {
26 try
27 {
28 BinaryFormatter bin = new BinaryFormatter();
29 bin.Serialize(stream, data);
30 }
31 catch (Exception ex) { xmltv_logger.Log.Error.WriteLine(ex.ToString()); return false; }
32 return true;
33 }
34 public bool DeSerialize(string file, out T unpacked_data)
35 {
36 unpacked_data = default(T);
37 bool retVal = false;
38 using (Stream stream = File.Open(file, FileMode.Open)) { retVal = DeSerialize(stream, out unpacked_data); }
39 return retVal;
40 }
41 public bool DeSerialize(Stream stream, out T unpacked_data)
42 {
43 unpacked_data = default(T);
44 try
45 {
46 BinaryFormatter bin = new BinaryFormatter();
47 unpacked_data = (T)bin.Deserialize(stream);
48 }
49 catch (Exception ex) { xmltv_logger.Log.Error.WriteLine(ex.ToString()); return false; }
50 return true;
51 }
52 #endregion
53 }
54 }

  ViewVC Help
Powered by ViewVC 1.1.22