/[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:20:09	47
+++ trunk/xmltv_parser/main.cs	2013/03/08 05:20:12	49
@@ -103,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();
@@ -156,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();
         }
@@ -177,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); 
         }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22