/[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 56 - (hide annotations) (download)
Fri Mar 8 12:05:33 2013 UTC (6 years, 7 months ago) by william
File size: 8148 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 50
19 william 13 public partial class main : Form
20 william 2 {
21 william 54 //bool form_closing = false;
22 william 50 //private IXMLTVRuntimeInstance xmltv;
23 william 42 private bool IsUnix
24     {
25     get { return System.Environment.OSVersion.Platform == PlatformID.Unix; }
26     }
27    
28 william 13 public main()
29 william 2 {
30     InitializeComponent();
31 william 13 string log_path = Application.StartupPath;
32     string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);
33 william 41 gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
34 william 2 }
35 william 11
36 william 40 StringBuilder log_flusher = new StringBuilder();
37 william 54
38 william 41 void Log_OnFlush(object sender, LoggerOnFlushEventArgs e)
39 william 40 {
40 william 54 OnLogFlush(e.Buffer);
41 william 40 }
42 william 47 //bool txtLog_EnterMouse = false;
43 william 40
44 william 47 private void txtLog_MouseLeave(object sender, EventArgs e)
45     {
46     //txtLog_EnterMouse = false;
47     }
48     private void txtLog_MouseEnter(object sender, EventArgs e)
49     {
50     //txtLog_EnterMouse = true;
51     }
52 william 40 void OnLogFlush(string logmessage)
53     {
54 william 47 if (this.IsDisposed) { return; }
55 william 54 UpdateStatus(logmessage);
56     UpdateLogOutput(logmessage);
57     Application.DoEvents();
58     }
59    
60     void UpdateStatus(string logmessage)
61     {
62 william 42 txtStatus.Text = logmessage.Replace(System.Environment.NewLine, "");
63 william 54 }
64     void UpdateLogOutput(string logmessage)
65     {
66     if (txtLog.InvokeRequired)
67     {
68 william 56 try
69     {
70     txtLog.Invoke((Action)(delegate { UpdateLogOutput(logmessage); }));
71     }
72     catch { }
73 william 54 return;
74     }
75 william 47 txtLog.AppendText(logmessage);
76     txtLog.SelectionStart = txtLog.Text.Length; //Set the current caret position to the end
77     txtLog.ScrollToCaret(); //Now scroll it automatically
78 william 40 }
79    
80 william 29 //List<IXMLTVChannel> Channels;
81     List<IXMLTVProgram> Programs;
82    
83 william 16 private void main_Load(object sender, EventArgs e)
84 william 11 {
85    
86     }
87 william 16 private void main_Shown(object sender, EventArgs e)
88 william 30 {
89 william 52
90 william 29 }
91    
92    
93     void LoadXMLTVShcedule(string schedule_xml)
94 william 11 {
95 william 54 //XMLTV.CreateInstance(schedule_xml, new EventHandler<CancelEventArgs>(xmltv_cancelevent));
96     XMLTV.CreateInstance(schedule_xml);
97     XMLTV.OnInstanceCreated += new EventHandler<EventArgs>(XMLTV_OnInstanceCreated);
98 william 11 }
99 william 29
100 william 54 void XMLTV_OnInstanceCreated(object sender, EventArgs e)
101 william 46 {
102 william 54 var instance = XMLTV.GetInstance();
103     if (instance != null)
104 william 46 {
105 william 54 var program_count = instance.Programs.Values.Count;
106     var program_list = instance.Programs.Values.ToList().OrderBy(s => s.Start);
107     //Programs = program_list(0, program_count).ToList();
108     Programs = new List<IXMLTVProgram>(program_list.ToArray());
109 william 46 }
110 william 54 CreateControls();
111 william 46 }
112    
113 william 54
114     //void xmltv_cancelevent(object sender, CancelEventArgs e)
115     //{
116     // if (form_closing)
117     // {
118     // e.Cancel = true;
119     // }
120     //}
121    
122 william 29 void CreateControls()
123     {
124 william 54 if (this.InvokeRequired)
125     {
126     this.Invoke((Action)(delegate { CreateControls(); }));
127     return;
128     }
129 william 29 foreach (var program in Programs)
130     {
131     ListViewItem li = new ListViewItem(string.Format("{0} {1}", program.Channel.Number, program.Channel.CallSign));
132     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Title));
133     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.SubTitle));
134     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Description));
135     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Start.ToString("yyyy/MM/dd hh:mm tt")));
136     li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Stop.ToString("yyyy/MM/dd hh:mm tt")));
137     lstPrograms.Items.Add(li);
138     }
139     }
140 william 30
141     private void mnuItemOpenXMLTVFile_Click(object sender, EventArgs e)
142 william 52 {
143     try
144     {
145     //LoadXMLTVShcedule("20130307_continuum_schedule.xml");
146     var result = xmltv_file_chooser.ShowDialog();
147     if (result != DialogResult.OK) return;
148     ClearLocalLog();
149     LoadXMLTVShcedule(xmltv_file_chooser.FileName);
150 william 54 //CreateControls();
151 william 52 }
152     catch (Exception ex)
153     {
154 william 55 gLog.Error.WriteLine(ex.ToString());
155 william 52 }
156 william 30 }
157    
158     private void mnuItemOpenSavedData_Click(object sender, EventArgs e)
159     {
160 william 52 try
161 william 31 {
162 william 52 var result = xmltv_program_data_loader.ShowDialog();
163     if (result != DialogResult.OK) return;
164     string filename = xmltv_program_data_loader.FileName;
165     IXMLTVRuntimeInstance xmltv = null;
166     bool status = false;
167     xmltv = XMLTV.DeSerialize(filename, out status);
168 william 56 XMLTV.CreateFromInstance(xmltv, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
169 william 52 if (!status)
170     {
171     MessageBox.Show("Failed to load data - check log", "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error);
172     return;
173     }
174     MessageBox.Show("Successfully loaded data", "Successfully loaded data", MessageBoxButtons.OK, MessageBoxIcon.Information);
175 william 31 }
176 william 52 catch (Exception ex)
177     {
178 william 55 gLog.Error.WriteLine(ex.ToString());
179 william 52 }
180 william 30 }
181    
182     private void mnuItemSaveData_Click(object sender, EventArgs e)
183     {
184 william 52 try
185 william 31 {
186 william 52 var result = xmltv_program_data_saver.ShowDialog();
187     if (result != DialogResult.OK) return;
188     string filename = xmltv_program_data_saver.FileName;
189     if (!XMLTV.Serialize(filename))
190     {
191     MessageBox.Show("Failed to save data - check log", "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error);
192     return;
193     }
194     MessageBox.Show("Successfully saved data", "Successfully saved data", MessageBoxButtons.OK, MessageBoxIcon.Information);
195 william 31 }
196 william 52 catch (Exception ex)
197     {
198 william 55 gLog.Error.WriteLine(ex.ToString());
199 william 52 }
200 william 30 }
201 william 44
202     private void main_FormClosing(object sender, FormClosingEventArgs e)
203     {
204 william 54 try
205     {
206     XMLTV.DestroyInstance();
207     }
208     catch { }
209 william 44 }
210 william 47
211     private void mnuItemClearLocalLog_Click(object sender, EventArgs e)
212     {
213     ClearLocalLog();
214     }
215     private void ClearLocalLog()
216     {
217     var log_top_entry = txtLog.Lines.FirstOrDefault();
218     txtLog.Clear();
219     if (!string.IsNullOrEmpty(log_top_entry))
220     {
221     txtLog.AppendText(log_top_entry);
222     }
223     }
224    
225 william 56 private void mnuItemExit_Click(object sender, EventArgs e)
226     {
227     this.Close();
228     }
229    
230 william 2 }
231     }
232 william 29

  ViewVC Help
Powered by ViewVC 1.1.22