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

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

  ViewVC Help
Powered by ViewVC 1.1.22