/[xmltv_parser]/trunk/GBPVRProgramDatabaseFixer/Program.cs
ViewVC logotype

Diff of /trunk/GBPVRProgramDatabaseFixer/Program.cs

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

--- trunk/GBPVRProgramDatabaseFixer/Program.cs	2013/03/14 16:24:37	150
+++ trunk/GBPVRProgramDatabaseFixer/Program.cs	2013/03/14 16:56:05	154
@@ -1,13 +1,111 @@
-´╗┐using System;
+´╗┐#define OVERRIDE_COMMANDLINE_ARGUMENTS // when defined will override supplied commandline args
+using System;
 using System.Collections.Generic;
 using System.Text;
+using Enterprise.Logging;
+using System.Windows.Forms;
+using System.Diagnostics;
+using System.IO;
+using libxmltv.Core;
 
 namespace GBPVRProgramDatabaseFixer
 {
     class Program
     {
+        static string XMLTV_FILE = "";
+        static string GBPVR_DATABASE = "";
+        static bool XMLTV_INSTANCE_CREATED = false;
+
+        static int LAST_REPORTED_XMLTV_PROGRESS =0;
+
+        static FileInfo fi_XMLTVFILE;
+
+        static void CreateLog()
+        {
+            string log_path = Application.StartupPath;
+            string log_filename = string.Format("{0}.log", typeof(Program).Assembly.GetName().Name);
+            gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All);
+#if DEBUG
+            LogLevel gLevel = gLog.LogLevel;
+            gLevel |= LogLevel.kLogLevel_VerboseDebug;
+            gLevel |= LogLevel.kLogLevel_Debug;
+            gLog.SetLogLevel(gLevel);
+#else
+            LogLevel gLevel = LogLevel.kLogLevel_Default; // set the default log level: Info, Warn, Error, Debug
+            // it is OK for kLogLevel_Debug to be set in Release mode ... must of the chatty messages are from kLogLevel_VerboseDebug
+            gLevel &= ~LogLevel.kLogLevel_Debug; // ensure this is not set, ever in release mode         
+            gLevel &= ~LogLevel.kLogLevel_VerboseDebug; // ensure this is not set, ever in release mode         
+            gLog.SetLogLevel(gLevel);
+#endif
+            gLog.ReportProgressEvent += new EventHandler<ReportProgressEventArgs>(gLog_ReportProgress);
+        }
+
+        [Conditional("OVERRIDE_COMMANDLINE_ARGUMENTS")]
+        static void CreateDebugCommandlineArgs(ref List<string> cargs)
+        {
+           cargs = new List<string>();
+            cargs.Add(string.Format("--xmltv_file=\"{0}\"", @"c:\EPG Guide\Guide\tvguide.xml"));
+            cargs.Add(string.Format("--gbprv_db=\"{0}\"", @"c:\Program Files (x86)\Devnz\GBPVR\gbpvr.db3"));
+        }
+
+        static List<string> CreateCommandlineArgs(string[] args)
+        {
+            List<string> cargs = new List<string>(args);
+            CreateDebugCommandlineArgs(ref cargs);
+            return cargs;
+        }
+
         static void Main(string[] args)
         {
+            CreateLog();
+            var cargs = CreateCommandlineArgs(args);
+            foreach (var carg in cargs)
+            {
+                if (carg.ToLower().Contains("--xmltv_file="))
+                {
+                    XMLTV_FILE = carg.Replace("--xmltv_file=", "").Replace("\"","");
+                    gLog.Info.WriteLine("XMLTV FILE: '{0}'", XMLTV_FILE);
+                }
+                else if (carg.ToLower().Contains("--gbprv_db="))
+                {
+                    GBPVR_DATABASE = carg.Replace("--gbprv_db=", "").Replace("\"", "");
+                    gLog.Info.WriteLine("GBPVR DATABASE: '{0}'", GBPVR_DATABASE);
+                }
+                else
+                {
+                    gLog.Warn.WriteLine("Unknown commandline option: {0}", carg);
+                }
+            }
+
+            LoadXMLTVFile();
+        }
+
+        static void gLog_ReportProgress(object sender, ReportProgressEventArgs e) 
+        {
+            if (LAST_REPORTED_XMLTV_PROGRESS != e.Progress)
+            {
+                Console.WriteLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
+                LAST_REPORTED_XMLTV_PROGRESS = e.Progress;
+            }
         }
+        static void LoadXMLTVFile()
+        {
+            if (string.IsNullOrEmpty(XMLTV_FILE))
+            {
+                gLog.Error.WriteLine("XMLTV File is either a null or empty string.");
+                return;
+            }
+            fi_XMLTVFILE = new FileInfo(XMLTV_FILE);
+            if (!fi_XMLTVFILE.Exists)
+            {
+                gLog.Error.WriteLine("Could not find XMLTV File: {0}", fi_XMLTVFILE.FullName);
+                return;
+            }
+
+            XMLTV.Create(fi_XMLTVFILE.FullName, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
+            while (!XMLTV_INSTANCE_CREATED) { Application.DoEvents(); }
+        }
+
+        static void XMLTV_OnInstanceCreated(object sender, EventArgs e) { XMLTV_INSTANCE_CREATED = true; }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22