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 |
|
|
txtLog.Invoke((Action)(delegate { UpdateLogOutput(logmessage); })); |
69 |
|
|
return; |
70 |
|
|
} |
71 |
william |
47 |
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 |
william |
40 |
} |
75 |
|
|
|
76 |
william |
29 |
//List<IXMLTVChannel> Channels; |
77 |
|
|
List<IXMLTVProgram> Programs; |
78 |
|
|
|
79 |
william |
16 |
private void main_Load(object sender, EventArgs e) |
80 |
william |
11 |
{ |
81 |
|
|
|
82 |
|
|
} |
83 |
william |
16 |
private void main_Shown(object sender, EventArgs e) |
84 |
william |
30 |
{ |
85 |
william |
52 |
|
86 |
william |
29 |
} |
87 |
|
|
|
88 |
|
|
|
89 |
|
|
void LoadXMLTVShcedule(string schedule_xml) |
90 |
william |
11 |
{ |
91 |
william |
54 |
//XMLTV.CreateInstance(schedule_xml, new EventHandler<CancelEventArgs>(xmltv_cancelevent)); |
92 |
|
|
XMLTV.CreateInstance(schedule_xml); |
93 |
|
|
XMLTV.OnInstanceCreated += new EventHandler<EventArgs>(XMLTV_OnInstanceCreated); |
94 |
william |
11 |
} |
95 |
william |
29 |
|
96 |
william |
54 |
void XMLTV_OnInstanceCreated(object sender, EventArgs e) |
97 |
william |
46 |
{ |
98 |
william |
54 |
var instance = XMLTV.GetInstance(); |
99 |
|
|
if (instance != null) |
100 |
william |
46 |
{ |
101 |
william |
54 |
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 |
william |
46 |
} |
106 |
william |
54 |
CreateControls(); |
107 |
william |
46 |
} |
108 |
|
|
|
109 |
william |
54 |
|
110 |
|
|
//void xmltv_cancelevent(object sender, CancelEventArgs e) |
111 |
|
|
//{ |
112 |
|
|
// if (form_closing) |
113 |
|
|
// { |
114 |
|
|
// e.Cancel = true; |
115 |
|
|
// } |
116 |
|
|
//} |
117 |
|
|
|
118 |
william |
29 |
void CreateControls() |
119 |
|
|
{ |
120 |
william |
54 |
if (this.InvokeRequired) |
121 |
|
|
{ |
122 |
|
|
this.Invoke((Action)(delegate { CreateControls(); })); |
123 |
|
|
return; |
124 |
|
|
} |
125 |
william |
29 |
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 |
william |
30 |
|
137 |
|
|
private void mnuItemOpenXMLTVFile_Click(object sender, EventArgs e) |
138 |
william |
52 |
{ |
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 |
william |
54 |
//CreateControls(); |
147 |
william |
52 |
} |
148 |
|
|
catch (Exception ex) |
149 |
|
|
{ |
150 |
william |
55 |
gLog.Error.WriteLine(ex.ToString()); |
151 |
william |
52 |
} |
152 |
william |
30 |
} |
153 |
|
|
|
154 |
|
|
private void mnuItemOpenSavedData_Click(object sender, EventArgs e) |
155 |
|
|
{ |
156 |
william |
52 |
try |
157 |
william |
31 |
{ |
158 |
william |
52 |
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 |
william |
31 |
} |
172 |
william |
52 |
catch (Exception ex) |
173 |
|
|
{ |
174 |
william |
55 |
gLog.Error.WriteLine(ex.ToString()); |
175 |
william |
52 |
} |
176 |
william |
30 |
} |
177 |
|
|
|
178 |
|
|
private void mnuItemSaveData_Click(object sender, EventArgs e) |
179 |
|
|
{ |
180 |
william |
52 |
try |
181 |
william |
31 |
{ |
182 |
william |
52 |
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 |
william |
31 |
} |
192 |
william |
52 |
catch (Exception ex) |
193 |
|
|
{ |
194 |
william |
55 |
gLog.Error.WriteLine(ex.ToString()); |
195 |
william |
52 |
} |
196 |
william |
30 |
} |
197 |
william |
44 |
|
198 |
|
|
private void main_FormClosing(object sender, FormClosingEventArgs e) |
199 |
|
|
{ |
200 |
william |
54 |
try |
201 |
|
|
{ |
202 |
|
|
XMLTV.DestroyInstance(); |
203 |
|
|
} |
204 |
|
|
catch { } |
205 |
william |
44 |
} |
206 |
william |
47 |
|
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 |
william |
2 |
} |
222 |
|
|
} |
223 |
william |
29 |
|