/[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/16 21:44:30	195
+++ trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/16 21:53:19	196
@@ -22,10 +22,10 @@
         List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }
         List<SQLLITE.ICHANNEL> Channels { get; }
         IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);
-        List<IOldNewProgram> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> removed_programs);
+        List<SQLLITE.IPROGRAMME> 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<IOldNewProgram> programs);
+        void UpdateGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);
 
     }
     public class SQLLITE : ISQLLITE
@@ -347,10 +347,10 @@
             return range;
         }
 
-        public List<IOldNewProgram> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> source_invalid)
+        public List<SQLLITE.IPROGRAMME> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> source_invalid)
         {
             source_invalid = new List<IPROGRAMME>();
-            List<IOldNewProgram> source_valid = new List<IOldNewProgram>();
+            List<IPROGRAMME> source_valid = new List<IPROGRAMME>();
             gbpvr_programs = gbpvr_programs.OrderBy(s => s.start_time).ToList();
             xmltv_programs = xmltv_programs.OrderBy(s => DateTime.Parse(s.Start)).ToList();
             gbpvr_programs.TrimExcess();
@@ -410,12 +410,14 @@
                         {
                             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(new OldNewProgram(program, updated_program));
+                        source_valid.Add(updated_program);
                     }
                     else
                     {
                         // data is the same
-                        source_valid.Add(new OldNewProgram(program, program));
+                        //source_valid.Add(new OldNewProgram(program, program));
+                        source_valid.Add(program);
                     }
                 }
                 index++;
@@ -843,42 +845,26 @@
             st.Stop();
             gLog.Warn.WriteLine("    operation took: {0:0.00000} minutes", st.Elapsed.TotalMinutes);
         }
-        public void UpdateGBPVRPrograms(List<IOldNewProgram> programs)
+        public void UpdateGBPVRPrograms(List<IPROGRAMME> programs)
         {
-            int STEP = 500;
-            List<List<IPROGRAMME>> array_list = new List<List<IPROGRAMME>>(); // holds a list of ~STEP programs per index
-            for (int i = 0; i < programs.Count;)
-            {
-                List<IPROGRAMME> tmp = new List<IPROGRAMME>(STEP);
-                for (int j = 0; j < STEP; j++)
-                {
-                    try
-                    {
-                        tmp.Add(programs[i + j].NewProgram);
-                    }
-                    catch { }
-                }
-                tmp.TrimExcess();
-                array_list.Add(tmp);
-                i += STEP;
-            }
-            array_list.TrimExcess();
+            int ChunkSize = 500;
+            var ChunkList = programs.Chunk<IPROGRAMME>(ChunkSize);
 
             int total = programs.Count;
             int index = 0;
             double progress = 0;
             Stopwatch st = new Stopwatch();
             st.Start();
-            foreach (var p in array_list)
+            foreach (var p in ChunkList)
             {
-                progress = 100.0 * (index / total);               
+                progress = 100.0 * (index / total);
                 //gLog.Info.WriteLine("Inserting {0} gbpvr programs.", p.Count);   
-                if (!InsertProgramEntryDatabase(p))
+                if (!InsertProgramEntryDatabase(p.ToList()))
                 {
                     gLog.Error.WriteLine("Failed to insert one or more program(s)");
-                }               
+                }
                 gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Inserting GBPVR Programs: {0:00}%", (int)progress)));
-                index += p.Count;
+                index += p.Count();
             }
             st.Stop();
             gLog.Warn.WriteLine("    operation took: {0:0.00000} minutes", st.Elapsed.TotalMinutes);

 

  ViewVC Help
Powered by ViewVC 1.1.22