/[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 32 - (hide annotations) (download)
Thu Mar 7 13:52:56 2013 UTC (6 years, 5 months ago) by william
File size: 4501 byte(s)

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 29 }
37    
38    
39     void LoadXMLTVShcedule(string schedule_xml)
40 william 11 {
41 william 29 var xmltv_loader = XMLTV.CreateLoader(schedule_xml);
42 william 22 var xmltv_parser = XMLTV.CreateParser(xmltv_loader);
43 william 23 var p = XMLTV.GetParser(xmltv_parser);
44 william 29
45     //var channel_count = p.Channels.Values.Count;
46     //Channels = p.Channels.Values.ToList().GetRange(0, channel_count).ToList();
47     var program_count = p.Programs.Values.Count;
48     var program_list = p.Programs.Values.ToList().OrderBy(s => s.Start);
49     //Programs = program_list(0, program_count).ToList();
50     Programs = new List<IXMLTVProgram>(program_list.ToArray());
51 william 11 }
52 william 29
53     void CreateControls()
54     {
55     foreach (var program in Programs)
56     {
57     ListViewItem li = new ListViewItem(string.Format("{0} {1}", program.Channel.Number, program.Channel.CallSign));
58     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Title));
59     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.SubTitle));
60     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Description));
61     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Start.ToString("yyyy/MM/dd hh:mm tt")));
62     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Stop.ToString("yyyy/MM/dd hh:mm tt")));
63     lstPrograms.Items.Add(li);
64     }
65     }
66 william 30
67     private void mnuItemOpenXMLTVFile_Click(object sender, EventArgs e)
68     {
69 william 32 //LoadXMLTVShcedule("20130307_continuum_schedule.xml");
70     var result = xmltv_file_chooser.ShowDialog();
71     if (result != DialogResult.OK) return;
72     LoadXMLTVShcedule(xmltv_file_chooser.FileName);
73 william 30 CreateControls();
74     }
75    
76     private void mnuItemOpenSavedData_Click(object sender, EventArgs e)
77     {
78 william 31 var result = xmltv_program_data_loader.ShowDialog();
79     if (result != DialogResult.OK) return;
80     try
81     {
82     using (Stream stream = File.Open(xmltv_program_data_loader.FileName, FileMode.Open))
83     {
84     try
85     {
86     BinaryFormatter bin = new BinaryFormatter();
87     Programs = (List<IXMLTVProgram>)bin.Deserialize(stream);
88     }
89     catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); }
90     }
91     }
92     catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); }
93     CreateControls();
94 william 30 }
95    
96     private void mnuItemSaveData_Click(object sender, EventArgs e)
97     {
98 william 31 var result = xmltv_program_data_saver.ShowDialog();
99     if (result != DialogResult.OK) return;
100     try
101     {
102     using (Stream stream = File.Open(xmltv_program_data_saver.FileName, FileMode.Create))
103     {
104     try
105     {
106     BinaryFormatter bin = new BinaryFormatter();
107     bin.Serialize(stream, Programs);
108     }
109     catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); }
110     }
111     }
112     catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); }
113 william 30 }
114 william 2 }
115     }
116 william 29

  ViewVC Help
Powered by ViewVC 1.1.22