/[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

revision 63 by william, Fri Mar 8 14:26:48 2013 UTC revision 108 by william, Sun Mar 10 12:59:31 2013 UTC
# Line 1  Line 1 
1  ´╗┐using System;  ´╗┐//#define DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG // when defined will turn off kLogLevel_Debug messages, in release mode
2    //#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode
3    using System;
4  using System.Collections.Generic;  using System.Collections.Generic;
5  using System.ComponentModel;  using System.ComponentModel;
6  using System.Data;  using System.Data;
# Line 12  using libxmltv.Interfaces; Line 14  using libxmltv.Interfaces;
14  using System.IO;  using System.IO;
15  using System.Runtime.Serialization.Formatters.Binary;  using System.Runtime.Serialization.Formatters.Binary;
16  using System.Threading;  using System.Threading;
17    using System.Diagnostics;
18    
19  namespace xmltv_parser  namespace xmltv_parser
20  {  {
21    
22      public partial class main : Form      public partial class main : Form
23      {      {
         //bool form_closing = false;  
         //private IXMLTVRuntimeInstance xmltv;  
         private bool IsUnix  
         {  
             get { return System.Environment.OSVersion.Platform == PlatformID.Unix; }  
         }  
   
24          public main()          public main()
25          {          {
26              InitializeComponent();              InitializeComponent();
# Line 33  namespace xmltv_parser Line 29  namespace xmltv_parser
29              string log_path = Application.StartupPath;              string log_path = Application.StartupPath;
30              string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);              string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);
31              gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));              gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
32              gLog.SetLogLevel(gLog.LogLevel & ~LogLevel.kLogLevel_VerboseDebug);  #if DEBUG
33                LogLevel gLevel = gLog.LogLevel;
34    #if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG
35                gLevel &= ~LogLevel.kLogLevel_VerboseDebug;
36    #else
37                gLevel |= LogLevel.kLogLevel_VerboseDebug;
38    #endif
39                gLevel |= LogLevel.kLogLevel_Debug;
40                gLog.SetLogLevel(gLevel);
41    #else
42                LogLevel gLevel = LogLevel.kLogLevel_Default; // set the default log level: Info, Warn, Error, Debug
43                // it is OK for kLogLevel_Debug to be set in Release mode ... must of the chatty messages are from kLogLevel_VerboseDebug
44    #if DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG
45                gLevel &= ~LogLevel.kLogLevel_Debug;
46    #else
47                gLevel |= LogLevel.kLogLevel_Debug;
48    #endif
49                gLevel &= ~LogLevel.kLogLevel_VerboseDebug; // ensure this is not set, ever in release mode        
50                gLog.SetLogLevel(gLevel);
51    #endif
52    
53    
54              gLog.ReportProgressEvent += new EventHandler<ReportProgressEventArgs>(gLog_ReportProgress);              gLog.ReportProgressEvent += new EventHandler<ReportProgressEventArgs>(gLog_ReportProgress);
55          }          }
56    
# Line 48  namespace xmltv_parser Line 65  namespace xmltv_parser
65                  catch { }                  catch { }
66                  return;                  return;
67              }              }
68              progress_status.Value = progress;              if (progress_status != null)
69                    progress_status.Value = progress;
70          }          }
71          private void gLog_ReportProgress(object sender, ReportProgressEventArgs e) { ReportProgress(e.Progress); }          private void gLog_ReportProgress(object sender, ReportProgressEventArgs e) { ReportProgress(e.Progress); }
72    
# Line 78  namespace xmltv_parser Line 96  namespace xmltv_parser
96    
97          void UpdateStatus(string logmessage)          void UpdateStatus(string logmessage)
98          {          {
99                if (this.InvokeRequired)
100                {
101                    try
102                    {
103                        this.Invoke((Action)(delegate { UpdateStatus(logmessage); }));
104                    }
105                    catch { }
106                    return;
107                }
108              txtStatus.Text = logmessage.Replace(System.Environment.NewLine, "");              txtStatus.Text = logmessage.Replace(System.Environment.NewLine, "");
109          }          }
110          void UpdateLogOutput(string logmessage)          void UpdateLogOutput(string logmessage)
111          {          {
112              if (txtLog.InvokeRequired)              if (this.InvokeRequired)
113              {              {
114                  try                  try
115                  {                  {
116                      txtLog.Invoke((Action)(delegate { UpdateLogOutput(logmessage); }));                      this.Invoke((Action)(delegate { UpdateLogOutput(logmessage); }));
117                  }                  }
118                  catch { }                  catch { }
119                  return;                  return;
# Line 111  namespace xmltv_parser Line 138  namespace xmltv_parser
138    
139          void LoadXMLTVShcedule(string schedule_xml)          void LoadXMLTVShcedule(string schedule_xml)
140          {          {
141              //XMLTV.CreateInstance(schedule_xml, new EventHandler<CancelEventArgs>(xmltv_cancelevent));              XMLTV.CreateInstance(schedule_xml, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
             XMLTV.CreateInstance(schedule_xml);  
             XMLTV.OnInstanceCreated += new EventHandler<EventArgs>(XMLTV_OnInstanceCreated);  
142          }          }
143    
144          void XMLTV_OnInstanceCreated(object sender, EventArgs e)          void XMLTV_OnInstanceCreated(object sender, EventArgs e)
# Line 122  namespace xmltv_parser Line 147  namespace xmltv_parser
147              var instance = XMLTV.GetInstance();              var instance = XMLTV.GetInstance();
148              if (instance != null)              if (instance != null)
149              {              {
150                  var program_count = instance.Programs.Values.Count;                  var program_count = instance.Programs.Count;
151                  var program_list = instance.Programs.Values.ToList().OrderBy(s => s.Start);                  var program_list = instance.Programs.ToList().OrderBy(s => s.MetaData[XMLTVConstants.Programs.ProgramStart].ToString());
152                  //Programs = program_list(0, program_count).ToList();                  //Programs = program_list(0, program_count).ToList();
153                  Programs = new List<IXMLTVProgram>(program_list.ToArray());                  Programs = new List<IXMLTVProgram>(program_list.ToArray());
154              }              }
# Line 149  namespace xmltv_parser Line 174  namespace xmltv_parser
174              List<ListViewItem> items = new List<ListViewItem>();              List<ListViewItem> items = new List<ListViewItem>();
175              foreach (var program in Programs)              foreach (var program in Programs)
176              {              {
177                  ListViewItem li = new ListViewItem(string.Format("{0} {1}", program.Channel.Number, program.Channel.CallSign));                  IXMLTVChannel Channel = null;
178                    var instance = XMLTV.GetInstance();
179                    var id = program.MetaData[XMLTVConstants.Programs.ProgramChannelId].ToString();
180                    Channel = instance.Channels.Find(m => m.Id == id);
181                    //ListViewItem li = new ListViewItem(string.Format("{0} {1}", Channel.Number, Channel.CallSign));
182                    if (Channel == null)
183                    {
184                        throw new NullReferenceException(string.Format("Could not find any channel with an id of '{0}'", id));
185                    }
186                    if (Channel.MetaData.Count() == 0) { throw new ArgumentOutOfRangeException(string.Format("No metadata available for channel id '{0}'", Channel.Id)); }
187                    var channel_names = Channel.MetaData[XMLTVConstants.Channels.ChannelDisplayName];
188                    string channel_name = string.Empty;
189                    if (channel_names.Count() == 0) { throw new ArgumentOutOfRangeException(string.Format("No properties named '{0}' found for channel id '{1}'", XMLTVConstants.Channels.ChannelDisplayName, Channel.Id)); }
190                    else
191                    {
192                        var channame = channel_names.FirstOrDefault();
193                        if (channame == null) { throw new ArgumentNullException("channame", string.Format("Unable to get channel display name for channel id '{0}'", Channel.Id)); }
194                        else
195                        {
196                            if (channame.Value == null) { throw new ArgumentNullException("channame.Value", string.Format("Unable to get channel display name for channel id '{0}'", Channel.Id)); }
197                            else { channel_name = channame.Value.ToString(); }
198                        }
199                    }
200                    ListViewItem li = new ListViewItem(string.Format("{0}", channel_name));
201                  li.Tag = program;                  li.Tag = program;
202                  li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Title));                  li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.MetaData[XMLTVConstants.Programs.ProgramTitle].ToString()));
203                  li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.SubTitle));                  li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.MetaData[XMLTVConstants.Programs.ProgramSubTitle].ToString()));
204                  li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Description));                  li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.MetaData[XMLTVConstants.Programs.ProgramDescription].ToString()));
205                  li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Start.ToString("yyyy/MM/dd hh:mm tt")));                  li.SubItems.Add(new ListViewItem.ListViewSubItem(li, ((DateTime)program.MetaData[XMLTVConstants.Programs.ProgramStart]).ToString("yyyy/MM/dd hh:mm tt")));
206                  li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Stop.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")));
207                  //lstPrograms.Items.Add(li);                  //lstPrograms.Items.Add(li);
208                  items.Add(li);                  items.Add(li);
209              }              }

Legend:
Removed from v.63  
changed lines
  Added in v.108

  ViewVC Help
Powered by ViewVC 1.1.22