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

Diff of /trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs

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

--- trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/17 01:01:10	213
+++ trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/17 01:31:28	218
@@ -22,17 +22,18 @@
         List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }
         List<SQLLITE.ICHANNEL> Channels { get; }
         IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);
-        List<SQLLITE.IPROGRAMME> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> removed_programs);
+        List<IOldNewProgram> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> removed_programs);
 
         void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);
-        void UpdateGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);
+        void UpdateGBPVRPrograms(List<IOldNewProgram> programs);
 
     }
     public class SQLLITE : ISQLLITE
     {
         private class OldNewProgram : IOldNewProgram
         {
-            public OldNewProgram() : this(new PROGRAMME(), new PROGRAMME()) { }
+            public OldNewProgram() : this(new PROGRAMME()) { }
+            public OldNewProgram(IPROGRAMME _old) : this(_old,_old) {  }
             public OldNewProgram(IPROGRAMME _old, IPROGRAMME _new) { OldProgram = _old; NewProgram = _new; }
 
             public IPROGRAMME OldProgram { get; private set; }
@@ -347,10 +348,10 @@
             return range;
         }
 
-        public List<SQLLITE.IPROGRAMME> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> source_invalid)
+        public List<IOldNewProgram> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> source_invalid)
         {
             source_invalid = new List<IPROGRAMME>();
-            List<IPROGRAMME> source_valid = new List<IPROGRAMME>();
+            List<IOldNewProgram> source_valid = new List<IOldNewProgram>();
             gbpvr_programs = gbpvr_programs.OrderBy(s => s.start_time).ToList();
             xmltv_programs = xmltv_programs.OrderBy(s => DateTime.Parse(s.Start)).ToList();
             gbpvr_programs.TrimExcess();
@@ -411,13 +412,13 @@
                             throw new Exception(string.Format("Program oid '{0}' was not properly updated.", updated_program.oid));
                         }
                         //source_valid.Add(new OldNewProgram(program, updated_program));
-                        source_valid.Add(updated_program);
+                        source_valid.Add(new OldNewProgram(program, updated_program));
                     }
                     else
                     {
                         // data is the same
                         //source_valid.Add(new OldNewProgram(program, program));
-                        source_valid.Add(program);
+                        source_valid.Add(new OldNewProgram(program));
                     }
                 }
                 index++;
@@ -823,34 +824,9 @@
 
         public void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs)
         {            
-            //gLog.Info.WriteLine("Removing {0} gbpvr programs.", programs.Count);
-            //double total = programs.Count;
-            //double index = 0;
-            //double progress = 0;
-            //Stopwatch st = new Stopwatch();
-            //st.Start();
-            //foreach (var program in programs)
-            //{
-            //    progress = 100.0 * (index / total);
-            //    gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Removing GBPVR Program ({0:00}%) oid='{1}'", (int)progress, program.oid)));
-            //    if (!RemoveProgramDatabaseEntry(program))
-            //    {
-            //        gLog.Error.WriteLine("Failed to remove program with oid: {0}", program.oid);
-            //    }
-            //    index++;
-            //}
-            ////Stopwatch st = new Stopwatch();
-            ////st.Start();
-            ////if (!RemoveAllProgramDatabaseEntries())
-            ////{
-            ////    gLog.Error.WriteLine("Failed to remove one or more program(s)");
-            ////}
-            //st.Stop();
-            //gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds", st.Elapsed.TotalSeconds);
-
-            int ChunkSize = 1024;
+            gLog.Info.WriteLine("Removing {0} gbpvr programs.", programs.Count);
+            int ChunkSize = 1;
             var ChunkList = programs.Chunk<IPROGRAMME>(ChunkSize);
-
             double total = programs.Count;
             double index = 0;
             double progress = 0;
@@ -863,16 +839,17 @@
                 {
                     gLog.Error.WriteLine("Failed to remove one or more program(s)");
                 }
-                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Removing {0} gbpvr programs ({1} of {2}) {3:00}%", p.Count(), index, total, (int)progress)));
+                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Removing old gbpvr programs ({0} of {1}) {2:00}%", index, total, (int)progress)));
                 index += (double)p.Count(); 
             }
             st1.Stop();
             gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds overall", st1.Elapsed.TotalSeconds);
         }
-        public void UpdateGBPVRPrograms(List<IPROGRAMME> programs)
+        public void UpdateGBPVRPrograms(List<IOldNewProgram> programs)
         {
-            int ChunkSize = 1024;
-            var ChunkList = programs.Chunk<IPROGRAMME>(ChunkSize);
+            gLog.Info.WriteLine("Updating {0} gbpvr programs.", programs.Count);
+            int ChunkSize = 1;
+            var ChunkList = programs.Chunk<IOldNewProgram>(ChunkSize);
 
             double total = programs.Count;
             double index = 0;
@@ -881,18 +858,12 @@
             st1.Start();
             foreach (var p in ChunkList)
             {
-                //Stopwatch st2 = new Stopwatch();
-                //st2.Start();
                 progress = 100.0 * (index / total);
-                //gLog.Warn.WriteLine("Inserting {0} gbpvr programs ({1} of {2})", p.Count(), index, total);   
                 if (!UpdateProgramEntryDatabase(p))
                 {
                     gLog.Error.WriteLine("Failed to update one or more program(s)");
                 }
-                //st2.Stop();
-                //gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds", st2.Elapsed.TotalSeconds);
-                //gLog.Warn.WriteLine(System.Environment.NewLine);
-                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Updating {0} gbpvr programs ({1} of {2}) {3:00}%", p.Count(), index, total, (int)progress)));
+                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Updating gbpvr programs ({0} of {1}) {2:00}%", index, total, (int)progress)));
                 index += (double)p.Count();                
             }
             st1.Stop();
@@ -979,7 +950,7 @@
             }
             return result;
         }
-        private bool UpdateProgramEntryDatabase(IEnumerable<IPROGRAMME> list)
+        private bool UpdateProgramEntryDatabase(IEnumerable<IOldNewProgram> list)
         {
             bool result = false;
             try
@@ -1088,7 +1059,7 @@
         }
         #endregion
         #region Multi-Update Command Support
-        private string BuildGBPVRMultiUpdateCommand(IEnumerable<IPROGRAMME> list)
+        private string BuildGBPVRMultiUpdateCommand(IEnumerable<IOldNewProgram> list)
         {
             StringBuilder builder = new StringBuilder();
             /*
@@ -1100,7 +1071,11 @@
             builder.AppendLine("begin transaction;");
             foreach (var t in list)
             {
-                builder.AppendLine(BuildGBPVRSingleInsertCommand(t));
+                if (!t.OldProgram.Equals(t.NewProgram))
+                {
+                    // only update the entry if it is different
+                    builder.AppendLine(BuildGBPVRSingleUpdateCommand(t.NewProgram));
+                }                
             }
             builder.AppendLine("end transaction;");
             return builder.ToString();

 

  ViewVC Help
Powered by ViewVC 1.1.22