/[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 41 - (hide annotations) (download)
Fri Mar 8 02:44:25 2013 UTC (6 years, 9 months ago) by william
File size: 6364 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 40 using System.Threading;
15 william 2
16     namespace xmltv_parser
17     {
18 william 13 public partial class main : Form
19 william 2 {
20 william 13 public main()
21 william 2 {
22     InitializeComponent();
23 william 13 string log_path = Application.StartupPath;
24     string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);
25 william 41 gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
26 william 2 }
27 william 11
28 william 40 StringBuilder log_flusher = new StringBuilder();
29 william 41 void Log_OnFlush(object sender, LoggerOnFlushEventArgs e)
30 william 40 {
31     //Console.Write(e.Buffer);
32     log_flusher.Append(e.Buffer);
33     if(e.Buffer == System.Environment.NewLine[0])
34     {
35     OnLogFlush(log_flusher.ToString().TrimEnd(new char[] { System.Environment.NewLine[0] }).TrimStart(new char[]{'\n'}));
36     log_flusher = new StringBuilder();
37     }
38     }
39    
40     void OnLogFlush(string logmessage)
41     {
42     txtStatus.Text = logmessage;
43     Thread.Sleep(100);
44     }
45    
46 william 29 //List<IXMLTVChannel> Channels;
47     List<IXMLTVProgram> Programs;
48    
49 william 16 private void main_Load(object sender, EventArgs e)
50 william 11 {
51    
52     }
53 william 16 private void main_Shown(object sender, EventArgs e)
54 william 30 {
55 william 36 //libxmltv.Core.XMLTV
56    
57 william 29 }
58    
59    
60     void LoadXMLTVShcedule(string schedule_xml)
61 william 11 {
62 william 36 //var xmltv_loader = XMLTV.CreateLoader(schedule_xml);
63     //var xmltv_parser = XMLTV.CreateParser(xmltv_loader);
64     //var p = XMLTV.GetParser(xmltv_parser);
65 william 29
66 william 36 ////var channel_count = p.Channels.Values.Count;
67     ////Channels = p.Channels.Values.ToList().GetRange(0, channel_count).ToList();
68     //var program_count = p.Programs.Values.Count;
69     //var program_list = p.Programs.Values.ToList().OrderBy(s => s.Start);
70     ////Programs = program_list(0, program_count).ToList();
71     //Programs = new List<IXMLTVProgram>(program_list.ToArray());
72    
73     IXMLTVRuntimeInstance xmltv = XMLTV.CreateInstance(schedule_xml);
74     var program_count = xmltv.Programs.Values.Count;
75     var program_list = xmltv.Programs.Values.ToList().OrderBy(s => s.Start);
76 william 29 //Programs = program_list(0, program_count).ToList();
77     Programs = new List<IXMLTVProgram>(program_list.ToArray());
78 william 11 }
79 william 29
80     void CreateControls()
81     {
82     foreach (var program in Programs)
83     {
84     ListViewItem li = new ListViewItem(string.Format("{0} {1}", program.Channel.Number, program.Channel.CallSign));
85     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Title));
86     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.SubTitle));
87     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Description));
88     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Start.ToString("yyyy/MM/dd hh:mm tt")));
89     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Stop.ToString("yyyy/MM/dd hh:mm tt")));
90     lstPrograms.Items.Add(li);
91     }
92     }
93 william 30
94     private void mnuItemOpenXMLTVFile_Click(object sender, EventArgs e)
95     {
96 william 32 //LoadXMLTVShcedule("20130307_continuum_schedule.xml");
97     var result = xmltv_file_chooser.ShowDialog();
98     if (result != DialogResult.OK) return;
99     LoadXMLTVShcedule(xmltv_file_chooser.FileName);
100 william 30 CreateControls();
101     }
102    
103     private void mnuItemOpenSavedData_Click(object sender, EventArgs e)
104     {
105 william 31 var result = xmltv_program_data_loader.ShowDialog();
106     if (result != DialogResult.OK) return;
107     try
108     {
109     using (Stream stream = File.Open(xmltv_program_data_loader.FileName, FileMode.Open))
110     {
111     try
112     {
113     BinaryFormatter bin = new BinaryFormatter();
114     Programs = (List<IXMLTVProgram>)bin.Deserialize(stream);
115     }
116 william 33 catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
117 william 31 }
118     }
119 william 33 catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
120     MessageBox.Show("Successfully loaded data", "Successfully loaded data", MessageBoxButtons.OK, MessageBoxIcon.Information);
121 william 31 CreateControls();
122 william 30 }
123    
124     private void mnuItemSaveData_Click(object sender, EventArgs e)
125     {
126 william 31 var result = xmltv_program_data_saver.ShowDialog();
127     if (result != DialogResult.OK) return;
128     try
129     {
130     using (Stream stream = File.Open(xmltv_program_data_saver.FileName, FileMode.Create))
131     {
132     try
133     {
134     BinaryFormatter bin = new BinaryFormatter();
135     bin.Serialize(stream, Programs);
136     }
137 william 33 catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
138 william 31 }
139     }
140 william 33 catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
141     MessageBox.Show("Successfully saved data", "Successfully saved data", MessageBoxButtons.OK, MessageBoxIcon.Information);
142 william 30 }
143 william 2 }
144     }
145 william 29

  ViewVC Help
Powered by ViewVC 1.1.22