/[xmltv_parser]/trunk/xmltv_parser/main.cs
ViewVC logotype

Contents of /trunk/xmltv_parser/main.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (show annotations) (download)
Fri Mar 8 02:13:59 2013 UTC (6 years, 9 months ago) by william
File size: 5625 byte(s)
+ use a MarshalByRefObject

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Linq;
6 using System.Drawing;
7 using System.Text;
8 using System.Windows.Forms;
9 using libxmltv.Core;
10 using Enterprise.Logging;
11 using libxmltv.Interfaces;
12 using System.IO;
13 using System.Runtime.Serialization.Formatters.Binary;
14
15 namespace xmltv_parser
16 {
17 public partial class main : Form
18 {
19 public main()
20 {
21 InitializeComponent();
22 string log_path = Application.StartupPath;
23 string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);
24 gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All);
25 }
26
27 //List<IXMLTVChannel> Channels;
28 List<IXMLTVProgram> Programs;
29
30 private void main_Load(object sender, EventArgs e)
31 {
32
33 }
34 private void main_Shown(object sender, EventArgs e)
35 {
36 //libxmltv.Core.XMLTV
37
38 }
39
40
41 void LoadXMLTVShcedule(string schedule_xml)
42 {
43 //var xmltv_loader = XMLTV.CreateLoader(schedule_xml);
44 //var xmltv_parser = XMLTV.CreateParser(xmltv_loader);
45 //var p = XMLTV.GetParser(xmltv_parser);
46
47 ////var channel_count = p.Channels.Values.Count;
48 ////Channels = p.Channels.Values.ToList().GetRange(0, channel_count).ToList();
49 //var program_count = p.Programs.Values.Count;
50 //var program_list = p.Programs.Values.ToList().OrderBy(s => s.Start);
51 ////Programs = program_list(0, program_count).ToList();
52 //Programs = new List<IXMLTVProgram>(program_list.ToArray());
53
54 IXMLTVRuntimeInstance xmltv = XMLTV.CreateInstance(schedule_xml);
55 var program_count = xmltv.Programs.Values.Count;
56 var program_list = xmltv.Programs.Values.ToList().OrderBy(s => s.Start);
57 //Programs = program_list(0, program_count).ToList();
58 Programs = new List<IXMLTVProgram>(program_list.ToArray());
59 }
60
61 void CreateControls()
62 {
63 foreach (var program in Programs)
64 {
65 ListViewItem li = new ListViewItem(string.Format("{0} {1}", program.Channel.Number, program.Channel.CallSign));
66 li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Title));
67 li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.SubTitle));
68 li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Description));
69 li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Start.ToString("yyyy/MM/dd hh:mm tt")));
70 li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Stop.ToString("yyyy/MM/dd hh:mm tt")));
71 lstPrograms.Items.Add(li);
72 }
73 }
74
75 private void mnuItemOpenXMLTVFile_Click(object sender, EventArgs e)
76 {
77 //LoadXMLTVShcedule("20130307_continuum_schedule.xml");
78 var result = xmltv_file_chooser.ShowDialog();
79 if (result != DialogResult.OK) return;
80 LoadXMLTVShcedule(xmltv_file_chooser.FileName);
81 CreateControls();
82 }
83
84 private void mnuItemOpenSavedData_Click(object sender, EventArgs e)
85 {
86 var result = xmltv_program_data_loader.ShowDialog();
87 if (result != DialogResult.OK) return;
88 try
89 {
90 using (Stream stream = File.Open(xmltv_program_data_loader.FileName, FileMode.Open))
91 {
92 try
93 {
94 BinaryFormatter bin = new BinaryFormatter();
95 Programs = (List<IXMLTVProgram>)bin.Deserialize(stream);
96 }
97 catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
98 }
99 }
100 catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
101 MessageBox.Show("Successfully loaded data", "Successfully loaded data", MessageBoxButtons.OK, MessageBoxIcon.Information);
102 CreateControls();
103 }
104
105 private void mnuItemSaveData_Click(object sender, EventArgs e)
106 {
107 var result = xmltv_program_data_saver.ShowDialog();
108 if (result != DialogResult.OK) return;
109 try
110 {
111 using (Stream stream = File.Open(xmltv_program_data_saver.FileName, FileMode.Create))
112 {
113 try
114 {
115 BinaryFormatter bin = new BinaryFormatter();
116 bin.Serialize(stream, Programs);
117 }
118 catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
119 }
120 }
121 catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
122 MessageBox.Show("Successfully saved data", "Successfully saved data", MessageBoxButtons.OK, MessageBoxIcon.Information);
123 }
124 }
125 }
126

  ViewVC Help
Powered by ViewVC 1.1.22