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

  ViewVC Help
Powered by ViewVC 1.1.22