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

Annotation of /trunk/xmltv_parser/main.cs

Parent Directory Parent Directory | Revision Log Revision Log


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

1 william 2 using System;
2     using System.Collections.Generic;
3     using System.ComponentModel;
4     using System.Data;
5 william 29 using System.Linq;
6 william 2 using System.Drawing;
7     using System.Text;
8     using System.Windows.Forms;
9 william 11 using libxmltv.Core;
10 william 13 using Enterprise.Logging;
11 william 29 using libxmltv.Interfaces;
12 william 31 using System.IO;
13     using System.Runtime.Serialization.Formatters.Binary;
14 william 2
15     namespace xmltv_parser
16     {
17 william 13 public partial class main : Form
18 william 2 {
19 william 13 public main()
20 william 2 {
21     InitializeComponent();
22 william 13 string log_path = Application.StartupPath;
23     string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);
24 william 18 gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All);
25 william 2 }
26 william 11
27 william 29 //List<IXMLTVChannel> Channels;
28     List<IXMLTVProgram> Programs;
29    
30 william 16 private void main_Load(object sender, EventArgs e)
31 william 11 {
32    
33     }
34 william 16 private void main_Shown(object sender, EventArgs e)
35 william 30 {
36 william 36 //libxmltv.Core.XMLTV
37    
38 william 29 }
39    
40    
41     void LoadXMLTVShcedule(string schedule_xml)
42 william 11 {
43 william 36 //var xmltv_loader = XMLTV.CreateLoader(schedule_xml);
44     //var xmltv_parser = XMLTV.CreateParser(xmltv_loader);
45     //var p = XMLTV.GetParser(xmltv_parser);
46 william 29
47 william 36 ////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 william 29 //Programs = program_list(0, program_count).ToList();
58     Programs = new List<IXMLTVProgram>(program_list.ToArray());
59 william 11 }
60 william 29
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 william 30
75     private void mnuItemOpenXMLTVFile_Click(object sender, EventArgs e)
76     {
77 william 32 //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 william 30 CreateControls();
82     }
83    
84     private void mnuItemOpenSavedData_Click(object sender, EventArgs e)
85     {
86 william 31 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 william 33 catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
98 william 31 }
99     }
100 william 33 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 william 31 CreateControls();
103 william 30 }
104    
105     private void mnuItemSaveData_Click(object sender, EventArgs e)
106     {
107 william 31 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 william 33 catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
119 william 31 }
120     }
121 william 33 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 william 30 }
124 william 2 }
125     }
126 william 29

  ViewVC Help
Powered by ViewVC 1.1.22