/[xmltv_parser]/trunk/xmltv_parser/main.cs
ViewVC logotype

Diff of /trunk/xmltv_parser/main.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/xmltv_parser/main.cs	2013/03/08 04:01:25	46
+++ trunk/xmltv_parser/main.cs	2013/03/08 05:20:12	49
@@ -61,12 +61,30 @@
             }
             
         }
+        //bool txtLog_EnterMouse = false;
 
+        private void txtLog_MouseLeave(object sender, EventArgs e)
+        {
+            //txtLog_EnterMouse = false;
+        }
+        private void txtLog_MouseEnter(object sender, EventArgs e)
+        {
+            //txtLog_EnterMouse = true;
+        }
         void OnLogFlush(string logmessage)
         {
+            if (this.IsDisposed) { return; }
             Console.Write(logmessage);        
             txtStatus.Text = logmessage.Replace(System.Environment.NewLine, "");
-            Thread.Sleep(100);
+            txtLog.AppendText(logmessage);
+
+            //if (!txtLog_EnterMouse)
+            //{
+            txtLog.SelectionStart = txtLog.Text.Length; //Set the current caret position to the end
+            txtLog.ScrollToCaret(); //Now scroll it automatically
+            //}
+            //Thread.Sleep(100);
+            Application.DoEvents();
         }
 
         //List<IXMLTVChannel> Channels;
@@ -85,17 +103,8 @@
 
         void LoadXMLTVShcedule(string schedule_xml)
         {
-            //var xmltv_loader = XMLTV.CreateLoader(schedule_xml);
-            //var xmltv_parser = XMLTV.CreateParser(xmltv_loader);
-            //var p = XMLTV.GetParser(xmltv_parser);
-
-            ////var channel_count = p.Channels.Values.Count;
-            ////Channels = p.Channels.Values.ToList().GetRange(0, channel_count).ToList();
-            //var program_count = p.Programs.Values.Count;
-            //var program_list = p.Programs.Values.ToList().OrderBy(s => s.Start);
-            ////Programs = program_list(0, program_count).ToList();
-            //Programs = new List<IXMLTVProgram>(program_list.ToArray());            
-            xmltv = XMLTV.CreateInstance(schedule_xml, new EventHandler<CancelEventArgs>(xmltv_cancelevent));
+            XMLTV.CreateInstance(schedule_xml, new EventHandler<CancelEventArgs>(xmltv_cancelevent));
+            xmltv = XMLTV.GetInstance();
             var program_count = xmltv.Programs.Values.Count;
             var program_list = xmltv.Programs.Values.ToList().OrderBy(s => s.Start);
             //Programs = program_list(0, program_count).ToList();
@@ -126,6 +135,7 @@
 
         private void mnuItemOpenXMLTVFile_Click(object sender, EventArgs e)
         {
+            ClearLocalLog();
             //LoadXMLTVShcedule("20130307_continuum_schedule.xml");
             var result = xmltv_file_chooser.ShowDialog();
             if (result != DialogResult.OK) return;
@@ -137,19 +147,12 @@
         {
             var result = xmltv_program_data_loader.ShowDialog();
             if (result != DialogResult.OK) return;
-            try
+            string filename = xmltv_program_data_loader.FileName;
+            if (!XMLTV.GetSerializer().DeSerialize(filename, out xmltv))
             {
-                using (Stream stream = File.Open(xmltv_program_data_loader.FileName, FileMode.Open))
-                {
-                    try
-                    {
-                        BinaryFormatter bin = new BinaryFormatter();
-                        Programs = (List<IXMLTVProgram>)bin.Deserialize(stream);
-                    }
-                    catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
-                }
+                MessageBox.Show("Failed to load data - check log", "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                return;
             }
-            catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to load data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
             MessageBox.Show("Successfully loaded data", "Successfully loaded data", MessageBoxButtons.OK, MessageBoxIcon.Information); 
             CreateControls();
         }
@@ -158,19 +161,12 @@
         {
             var result = xmltv_program_data_saver.ShowDialog();
             if (result != DialogResult.OK) return;
-            try
+            string filename = xmltv_program_data_saver.FileName;
+            if (!XMLTV.GetSerializer().Serialize(filename))
             {
-                using (Stream stream = File.Open(xmltv_program_data_saver.FileName, FileMode.Create))
-                {
-                    try
-                    {
-                        BinaryFormatter bin = new BinaryFormatter();
-                        bin.Serialize(stream, Programs);
-                    }
-                    catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
-                }
+                MessageBox.Show("Failed to save data - check log", "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                return;
             }
-            catch (Exception ex) { gLog.Log.Error.WriteLine(ex.ToString()); MessageBox.Show(ex.Message, "Failed to save data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
             MessageBox.Show("Successfully saved data", "Successfully saved data", MessageBoxButtons.OK, MessageBoxIcon.Information); 
         }
 
@@ -178,6 +174,21 @@
         {
             form_closing = true;
         }
+
+        private void mnuItemClearLocalLog_Click(object sender, EventArgs e)
+        {
+            ClearLocalLog();
+        }
+        private void ClearLocalLog()
+        {
+            var log_top_entry = txtLog.Lines.FirstOrDefault();
+            txtLog.Clear();
+            if (!string.IsNullOrEmpty(log_top_entry))
+            {
+                txtLog.AppendText(log_top_entry);
+            }
+        }
+
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22