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

  ViewVC Help
Powered by ViewVC 1.1.22