/[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 55 - (show annotations) (download)
Fri Mar 8 10:19:32 2013 UTC (6 years, 9 months ago) by william
File size: 7870 byte(s)
+ upate for: Enterprise.Logging: 1.2.5.1

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

  ViewVC Help
Powered by ViewVC 1.1.22