/[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:56:05	154
+++ trunk/GBPVRProgramDatabaseFixer/Program.cs	2013/03/14 19:41:32	158
@@ -12,14 +12,21 @@
 {
     class Program
     {
+        static SQLLITE sqlite;
         static string XMLTV_FILE = "";
         static string GBPVR_DATABASE = "";
+
+        static bool LOADING_XMLTV_FILE = false;
         static bool XMLTV_INSTANCE_CREATED = false;
+        static int LAST_REPORTED_XMLTV_PROGRESS = 0;
 
-        static int LAST_REPORTED_XMLTV_PROGRESS =0;
 
-        static FileInfo fi_XMLTVFILE;
+        static bool LOADING_GBPVR_DATABASE = false;
+        static bool SQLLIST_INSTANCE_CREATED = false;
+        static int LAST_REPORTED_SQLLITE_PROGRESS = 0;
 
+        static FileInfo fi_XMLTVFILE;
+        static FileInfo fi_GBPVRDATABASE;
         static void CreateLog()
         {
             string log_path = Application.StartupPath;
@@ -78,34 +85,109 @@
             }
 
             LoadXMLTVFile();
+            LoadGBPVRDatabase();
+            PerformDatabaseProcessing();       
+        }
+
+        static void ConsoleOverwritePreviosLine(string format, params object[] args)
+        {
+            Console.WriteLine(format,args);
+            Console.SetCursorPosition(0, Console.CursorTop - 1);
         }
 
         static void gLog_ReportProgress(object sender, ReportProgressEventArgs e) 
         {
-            if (LAST_REPORTED_XMLTV_PROGRESS != e.Progress)
+            if (!XMLTV_INSTANCE_CREATED && LOADING_XMLTV_FILE)
+            {
+                if (LAST_REPORTED_XMLTV_PROGRESS != e.Progress)
+                {
+                    ConsoleOverwritePreviosLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
+                    LAST_REPORTED_XMLTV_PROGRESS = e.Progress;
+                    if (e.Progress == 100)
+                    {
+                        Console.WriteLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
+                    }
+                }
+            }
+            if (!SQLLIST_INSTANCE_CREATED && LOADING_GBPVR_DATABASE)
             {
-                Console.WriteLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
-                LAST_REPORTED_XMLTV_PROGRESS = e.Progress;
+                if (LAST_REPORTED_SQLLITE_PROGRESS != e.Progress)
+                {
+                    ConsoleOverwritePreviosLine("SQLLITE: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
+                    LAST_REPORTED_SQLLITE_PROGRESS = e.Progress;
+                    if (e.Progress == 100)
+                    {
+                        Console.WriteLine("SQLLITE: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
+                    }
+                }
             }
         }
         static void LoadXMLTVFile()
         {
+            LOADING_XMLTV_FILE = true;
             if (string.IsNullOrEmpty(XMLTV_FILE))
             {
                 gLog.Error.WriteLine("XMLTV File is either a null or empty string.");
+                LOADING_XMLTV_FILE = false;
                 return;
             }
             fi_XMLTVFILE = new FileInfo(XMLTV_FILE);
             if (!fi_XMLTVFILE.Exists)
             {
                 gLog.Error.WriteLine("Could not find XMLTV File: {0}", fi_XMLTVFILE.FullName);
+                LOADING_XMLTV_FILE = false;
                 return;
             }
 
             XMLTV.Create(fi_XMLTVFILE.FullName, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
             while (!XMLTV_INSTANCE_CREATED) { Application.DoEvents(); }
+            LOADING_XMLTV_FILE = false;
         }
-
         static void XMLTV_OnInstanceCreated(object sender, EventArgs e) { XMLTV_INSTANCE_CREATED = true; }
+
+        static void LoadGBPVRDatabase()
+        {
+            LOADING_GBPVR_DATABASE = true;
+            if (string.IsNullOrEmpty(GBPVR_DATABASE))
+            {
+                gLog.Error.WriteLine("GBPVR Datbase is either a null or empty string.");
+                LOADING_GBPVR_DATABASE = false;
+                return;
+            }
+            fi_GBPVRDATABASE = new FileInfo(GBPVR_DATABASE);
+            if (!fi_GBPVRDATABASE.Exists)
+            {
+                gLog.Error.WriteLine("Could not find GBPVR Database: {0}", fi_GBPVRDATABASE.FullName);
+                LOADING_GBPVR_DATABASE = false;
+                return;
+            }
+
+            sqlite = new SQLLITE(fi_GBPVRDATABASE.FullName, new EventHandler<EventArgs>(SQLLITE_OnInstanceCreated));
+            while (!SQLLIST_INSTANCE_CREATED) { Application.DoEvents(); }
+            LOADING_GBPVR_DATABASE = false;
+        }
+        static void SQLLITE_OnInstanceCreated(object sender, EventArgs e) { SQLLIST_INSTANCE_CREATED = true; }
+
+
+        static List<SQLLITE.IPROGRAMME> gbpvr_programs;
+        static List<SQLLITE.IRECORDING_SCHEDULE> gbpvr_recordings;
+        static List<libxmltv.Interfaces.IXMLTVProgram> xmltv_programs;
+        static void PerformDatabaseProcessing()
+        {
+            gbpvr_programs = sqlite.Programs;
+            gbpvr_recordings = sqlite.Recordings;
+            xmltv_programs = XMLTV.GetPrograms();
+            CheckScheduledRecordingsForDiscrepancies();
+            CheckProgramsForDiscrepancies();
+        }
+
+        static void CheckScheduledRecordingsForDiscrepancies()
+        {
+            gLog.Warn.WriteLine("CheckScheduledRecordingsForDiscrepancies() has not been implemented");
+        }
+        static void CheckProgramsForDiscrepancies()
+        {
+            gLog.Warn.WriteLine("CheckProgramsForDiscrepancies() has not been implemented");
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22