/[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/10 17:43:20	119
+++ trunk/xmltv_parser/main.cs	2013/03/13 12:00:01	127
@@ -26,7 +26,7 @@
         {
             InitializeComponent();
             ListViewSorter Sorter = new ListViewSorter();
-            lstPrograms.ListViewItemSorter = Sorter;
+            //lstPrograms.ListViewItemSorter = Sorter;
             string log_path = Application.StartupPath;
             string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);
             gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
@@ -54,193 +54,21 @@
 
             gLog.ReportProgressEvent += new EventHandler<ReportProgressEventArgs>(gLog_ReportProgress);
         }
-
-        private void ReportProgress(int progress)
-        {
-            if (this.InvokeRequired)
-            {
-                try
-                {
-                    this.Invoke((Action)(delegate { ReportProgress(progress); }));
-                }
-                catch { }
-                return;
-            }
-            if (progress_status != null && !this.IsDisposed)
-                progress_status.Value = progress;
-        }
-        private void gLog_ReportProgress(object sender, ReportProgressEventArgs e) { ReportProgress(e.Progress); }
-
-        StringBuilder log_flusher = new StringBuilder();
-
-        void Log_OnFlush(object sender, LoggerOnFlushEventArgs e)
-        {
-            OnLogFlush(e.Buffer);
-        }
-        //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; }
-            UpdateStatus(logmessage);
-            UpdateLogOutput(logmessage);
-            Application.DoEvents();
-        }
-
-        void UpdateStatus(string logmessage)
-        {
-            if (this.InvokeRequired)
-            {
-                try
-                {
-                    this.Invoke((Action)(delegate { UpdateStatus(logmessage); }));
-                }
-                catch { }
-                return;
-            }
-            txtStatus.Text = logmessage.Replace(System.Environment.NewLine, "");
-        }
-        void UpdateLogOutput(string logmessage)
-        {
-            if (this.InvokeRequired)
-            {
-                try
-                {
-                    this.Invoke((Action)(delegate { UpdateLogOutput(logmessage); }));
-                }
-                catch { }
-                return;
-            }
-            txtLog.AppendText(logmessage);
-            txtLog.SelectionStart = txtLog.Text.Length; //Set the current caret position to the end
-            txtLog.ScrollToCaret(); //Now scroll it automatically
-        }
-
-        //List<IXMLTVChannel> Channels;
-        //List<IXMLTVProgram> Programs;
-
-        private void main_Load(object sender, EventArgs e)
-        {
-
-        }
-        private void main_Shown(object sender, EventArgs e)
-        {
-
-        }
-
-
-        void LoadXMLTVShcedule(string schedule_xml)
-        {
-            XMLTV.Create(schedule_xml, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
-        }
-
-        void XMLTV_OnInstanceCreated(object sender, EventArgs e)
-        {
-            //ReportProgress(0);
-            //var instance = XMLTV.GetInstance();
-            //if (instance != null)
-            //{
-            //    var program_count = instance.Programs.Count;
-            //    var program_list = instance.Programs.ToList().OrderBy(s => s.MetaData[XMLTVConstants.Programs.ProgramStart].ToString());
-            //    //Programs = program_list(0, program_count).ToList();
-            //    Programs = new List<IXMLTVProgram>(program_list.ToArray());
-            //}
-            //CreateControls();
-
-            CreateControls();
-        }
-
-
-        //void xmltv_cancelevent(object sender, CancelEventArgs e)
-        //{
-        //    if (form_closing)
-        //    {
-        //        e.Cancel = true;
-        //    }
-        //}
-
-        void CreateControls()
-        {
-            if (this.InvokeRequired)
-            {
-                this.Invoke((Action)(delegate { CreateControls(); }));
-                return;
-            }
-            //List<ListViewItem> items = new List<ListViewItem>();
-            //foreach (var program in Programs)
-            //{
-            //    IXMLTVChannel Channel = null;
-            //    var instance = XMLTV.GetInstance();
-            //    var id = program.MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString();
-            //    Channel = instance.Channels.Find(m => m.Id == id);
-            //    //ListViewItem li = new ListViewItem(string.Format("{0} {1}", Channel.Number, Channel.CallSign));
-            //    if (Channel == null)
-            //    {
-            //        throw new NullReferenceException(string.Format("Could not find any channel with an id of '{0}'", id));
-            //    }
-            //    if (Channel.MetaData.Count() == 0) { throw new ArgumentOutOfRangeException(string.Format("No metadata available for channel id '{0}'", Channel.Id)); }
-            //    var channel_names = Channel.MetaData[XMLTVConstants.Channels.ChannelDisplayName];
-            //    string channel_name = string.Empty;
-            //    if (channel_names.Count() == 0) { throw new ArgumentOutOfRangeException(string.Format("No properties named '{0}' found for channel id '{1}'", XMLTVConstants.Channels.ChannelDisplayName, Channel.Id)); }
-            //    else
-            //    {
-            //        var channame = channel_names.FirstOrDefault();
-            //        if (channame == null) { throw new ArgumentNullException("channame", string.Format("Unable to get channel display name for channel id '{0}'", Channel.Id)); }
-            //        else
-            //        {
-            //            if (channame.Value == null) { throw new ArgumentNullException("channame.Value", string.Format("Unable to get channel display name for channel id '{0}'", Channel.Id)); }
-            //            else { channel_name = channame.Value.ToString(); }
-            //        }
-            //    }
-            //    ListViewItem li = new ListViewItem(string.Format("{0}", channel_name));
-            //    li.Tag = program;
-            //    li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.MetaData[XMLTVConstants.Programs.ProgramTitle].ToString()));
-            //    li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.MetaData[XMLTVConstants.Programs.ProgramSubTitle].ToString()));
-            //    li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.MetaData[XMLTVConstants.Programs.ProgramDescription].ToString()));
-            //    li.SubItems.Add(new ListViewItem.ListViewSubItem(li, ((DateTime)program.MetaData[XMLTVConstants.Programs.ProgramStart]).ToString("yyyy/MM/dd hh:mm tt")));
-            //    li.SubItems.Add(new ListViewItem.ListViewSubItem(li, ((DateTime)program.MetaData[XMLTVConstants.Programs.ProgramStop]).ToString("yyyy/MM/dd hh:mm tt")));
-            //    //lstPrograms.Items.Add(li);
-            //    items.Add(li);
-            //}
-
-            //lstPrograms.Items.AddRange(items.ToArray());
-
-            
-
-        }
-
+        #region main form events
+        private void mnuItemExit_Click(object sender, EventArgs e) { this.Close(); }
+        private void main_Load(object sender, EventArgs e) { }
+        private void main_Shown(object sender, EventArgs e) { }
         private void mnuItemOpenXMLTVFile_Click(object sender, EventArgs e)
         {
             try
             {
-                lstPrograms.Items.Clear();
-                //LoadXMLTVShcedule("20130307_continuum_schedule.xml");
                 var result = xmltv_file_chooser.ShowDialog();
                 if (result != DialogResult.OK) return;
                 ClearLocalLog();
                 LoadXMLTVShcedule(xmltv_file_chooser.FileName);
-                //CreateControls();
-            }
-            catch (Exception ex)
-            {
-                gLog.Error.WriteLine(ex.ToString());
             }
+            catch (Exception ex) { gLog.Error.WriteLine(ex.ToString()); }
         }
-
-        private void DeserializeDataFromFile(object filename)
-        {
-            if (filename == null) { throw new ArgumentNullException("filename", "cannot be null"); }
-            XMLTV.Load(filename.ToString(), new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
-        }
-
         private void mnuItemOpenSavedData_Click(object sender, EventArgs e)
         {
             try
@@ -250,15 +78,7 @@
                 string filename = xmltv_program_data_loader.FileName;
                 Thread worker = new Thread(new ParameterizedThreadStart(DeserializeDataFromFile)); worker.Start(filename);
             }
-            catch (Exception ex)
-            {
-                gLog.Error.WriteLine(ex.ToString());
-            }
-        }
-        private void DeserializeDataToFile(object filename)
-        {
-            if (filename == null) { throw new ArgumentNullException("filename", "cannot be null"); }
-            XMLTV.Save(filename.ToString());
+            catch (Exception ex) { gLog.Error.WriteLine(ex.ToString()); }
         }
         private void mnuItemSaveData_Click(object sender, EventArgs e)
         {
@@ -269,67 +89,114 @@
                 string filename = xmltv_program_data_saver.FileName;
                 Thread worker = new Thread(new ParameterizedThreadStart(DeserializeDataToFile)); worker.Start(filename);
             }
-            catch (Exception ex)
-            {
-                gLog.Error.WriteLine(ex.ToString());
-            }
+            catch (Exception ex) { gLog.Error.WriteLine(ex.ToString()); }
         }
+        private void main_FormClosing(object sender, FormClosingEventArgs e) { try { XMLTV.Destroy(); } catch { } }
+        private void mnuItemClearLocalLog_Click(object sender, EventArgs e) { ClearLocalLog(); }
+        #endregion
 
-        private void main_FormClosing(object sender, FormClosingEventArgs e)
+        private void ReportProgress(int progress)
         {
-            try
+            if (this.InvokeRequired)
             {
-                XMLTV.Destroy();
+                try { this.Invoke((Action)(delegate { ReportProgress(progress); })); }
+                catch { }
+                return;
             }
-            catch { }
+            if (progress_status != null && !this.IsDisposed)
+                progress_status.Value = progress;
         }
 
-        private void mnuItemClearLocalLog_Click(object sender, EventArgs e)
+        #region gLog Events
+        private void gLog_ReportProgress(object sender, ReportProgressEventArgs e) { ReportProgress(e.Progress); }
+        #endregion
+        #region XMLT Events
+        void XMLTV_OnInstanceCreated(object sender, EventArgs e) { ReportProgress(0); CreateControls(); }
+        void LoadXMLTVShcedule(string schedule_xml) { XMLTV.Create(schedule_xml, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated)); }
+        #endregion
+
+
+        #region Logging Events
+        StringBuilder log_flusher = new StringBuilder();
+        void Log_OnFlush(object sender, LoggerOnFlushEventArgs e) { OnLogFlush(e.Buffer); }
+        void OnLogFlush(string logmessage)
         {
-            ClearLocalLog();
+            if (this.IsDisposed) { return; }
+            UpdateStatus(logmessage);
+            UpdateLogOutput(logmessage);
+            Application.DoEvents();
         }
         private void ClearLocalLog()
         {
             var log_top_entry = txtLog.Lines.FirstOrDefault();
             txtLog.Clear();
-            if (!string.IsNullOrEmpty(log_top_entry))
+            if (!string.IsNullOrEmpty(log_top_entry)) { txtLog.AppendText(log_top_entry); }
+        }
+        void UpdateStatus(string logmessage)
+        {
+            try
             {
-                txtLog.AppendText(log_top_entry);
+                if (this.InvokeRequired)
+                {
+                    try { this.Invoke((Action)(delegate { UpdateStatus(logmessage); })); }
+                    catch { }
+                    return;
+                }
+                txtStatus.Text = logmessage.Replace(System.Environment.NewLine, "");
             }
+            catch (Exception ex) { gLog.Error.WriteLine(ex.ToString()); }
         }
-
-        private void mnuItemExit_Click(object sender, EventArgs e)
+        void UpdateLogOutput(string logmessage)
         {
-            this.Close();
+            try
+            {
+                if (this.InvokeRequired)
+                {
+                    try { this.Invoke((Action)(delegate { UpdateLogOutput(logmessage); })); }
+                    catch { }
+                    return;
+                }
+                txtLog.AppendText(logmessage);
+                txtLog.SelectionStart = txtLog.Text.Length; //Set the current caret position to the end
+                txtLog.ScrollToCaret(); //Now scroll it automatically
+            }
+            catch (Exception ex) { gLog.Error.WriteLine(ex.ToString()); }
         }
+        #endregion
 
-        private void lstPrograms_SelectedIndexChanged(object sender, EventArgs e)
+        #region Binary Data Read/Write support
+        private void DeserializeDataFromFile(object filename)
         {
-            //IXMLTVProgram program = null;
-            //var item = lstPrograms.SelectedItems[0];
-            //int selected_index = lstPrograms.Items.IndexOf(item);
-            //program = (item.Tag as IXMLTVProgram);
-            //gLog.Debug.WriteLine("Selected ListViewItem at index: {0}", selected_index);
-            //if (program == null) { return; }
-            //txtStatus.Text = program.ToString();
-            ////gLog.Debug.WriteLine(program.ToString());
-
+            if (filename == null) { throw new ArgumentNullException("filename", "cannot be null"); }
+            XMLTV.Load(filename.ToString(), new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
+        }
+        private void DeserializeDataToFile(object filename)
+        {
+            if (filename == null) { throw new ArgumentNullException("filename", "cannot be null"); }
+            XMLTV.Save(filename.ToString());
         }
+        #endregion
+
 
-        private void lstPrograms_ColumnClick(object sender, ColumnClickEventArgs e)
+        #region t
+        void CreateControls()
         {
-            //if (!(lstPrograms.ListViewItemSorter is ListViewSorter)) return;
-            //ListViewSorter Sorter = (ListViewSorter)lstPrograms.ListViewItemSorter;
-            //Sorter.LastColumn = Sorter.CurrentColumn;
-            //Sorter.CurrentColumn = e.Column;
-            //if (Sorter.LastColumn == e.Column)
-            //{
-            //    if (lstPrograms.Sorting == SortOrder.Ascending) { lstPrograms.Sorting = SortOrder.Descending; }
-            //    else { lstPrograms.Sorting = SortOrder.Ascending; }
-            //}
-            //else { lstPrograms.Sorting = SortOrder.Descending; }
-            //lstPrograms.Sort();
+            try
+            {
+                if (this.InvokeRequired)
+                {
+                    try { this.Invoke((Action)(delegate { CreateControls(); })); }
+                    catch { }
+                    return;
+                }
+                object datasource = XMLTV.CreateDataSourceFromObject(XMLTV.GetPrograms());
+                XMLTV.CreateSorterFromDataSource(ref datasource, "title");
+                dataGrid.DataSource = datasource;
+            }
+            catch (Exception ex) { gLog.Error.WriteLine(ex.ToString()); }
         }
+        #endregion
+
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22