/[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/15 16:57:50	164
+++ trunk/GBPVRProgramDatabaseFixer/Program.cs	2013/03/15 17:33:15	165
@@ -170,29 +170,42 @@
         static void SQLLITE_OnInstanceCreated(object sender, EventArgs e) { SQLLIST_INSTANCE_CREATED = true; }
 
 
-        static List<SQLLITE.IPROGRAMME> gbpvr_programs;
+        static List<SQLLITE.IPROGRAMME> gbpvr_invalid_programs;
+        static List<SQLLITE.IPROGRAMME> gbpvr_valid_programs;
         static List<SQLLITE.ICHANNEL> gbpvr_channels;
         static List<SQLLITE.IRECORDING_SCHEDULE> gbpvr_recordings;
         static List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs;
         static void PerformDatabaseProcessing()
         {
-            gbpvr_channels = sqlite.Channels;
-            gbpvr_programs = sqlite.Programs;
+           gbpvr_channels = sqlite.Channels;
+            //gbpvr_programs = sqlite.Programs;
+            gbpvr_invalid_programs = new List<SQLLITE.IPROGRAMME>();
+            gbpvr_valid_programs = new List<SQLLITE.IPROGRAMME>();
             gbpvr_recordings = sqlite.Recordings;            
             Type datatype;
             var xmlt_raw_program_data = (IProgramDefinitionList)XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out datatype);
             //xmltv_programs = xmlt_raw_program_data.ToList().OrderBy(p => p.ChannelNumber).ThenBy(p => DateTime.Parse(p.Start)).ToList();
             //xmltv_programs = xmltv_programs.FindAll(p => p.Title == "Law & Order: Criminal Intent").ToList();
             xmltv_programs = xmlt_raw_program_data.ToList().OrderBy(p => DateTime.Parse(p.Start)).ToList();
-
-
-            var gbpvr_programs_startdate_range = sqlite.GetProgramsDateRange(gbpvr_programs);
+            var gbpvr_programs_startdate_range = sqlite.GetProgramsDateRange(sqlite.Programs);
             var xmltv_programs_startdate_range = GetXMLTVProgramStartDateRange(xmltv_programs);
-            List<SQLLITE.IPROGRAMME> gbpvr_removed_programs = new List<SQLLITE.IPROGRAMME>();
-            gbpvr_programs = sqlite.FilterProgramsByDateRange(gbpvr_programs, xmltv_programs_startdate_range, out gbpvr_removed_programs);
+
+            gbpvr_valid_programs = sqlite.FilterProgramsByDateRange(sqlite.Programs, xmltv_programs_startdate_range, out gbpvr_invalid_programs);
             xmltv_programs = xmltv_programs.OrderBy(s => s.ChannelNumber).ThenBy(s => DateTime.Parse(s.Start)).ToList();
-            CheckScheduledRecordingsForDiscrepancies();
-            CheckProgramsForDiscrepancies();
+
+            gbpvr_channels.TrimExcess();
+            gbpvr_invalid_programs.TrimExcess();
+            gbpvr_valid_programs.TrimExcess();
+            gbpvr_recordings.TrimExcess();
+            xmltv_programs.TrimExcess();
+
+            
+            
+
+
+            CheckScheduledRecordingsForDiscrepancies(gbpvr_recordings);
+            
+            CheckProgramsForDiscrepancies(gbpvr_valid_programs.ToArray(), xmltv_programs.ToArray());
         }
 
         static IDateTimeRange GetXMLTVProgramStartDateRange(List<libxmltv.Interfaces.IProgramDefinition> programs)
@@ -209,10 +222,10 @@
             return range;
         }
 
-        static void CheckScheduledRecordingsForDiscrepancies()
+        static void CheckScheduledRecordingsForDiscrepancies(List<SQLLITE.IRECORDING_SCHEDULE> gbpvr)
         {
             //gLog.Warn.WriteLine("CheckScheduledRecordingsForDiscrepancies() has not been implemented");
-            var manual_gbpvr_recordings = gbpvr_recordings.FindAll(p => p.recording_type == 0).ToList();
+            var manual_gbpvr_recordings = gbpvr.FindAll(p => p.recording_type == 0).ToList();
 
             foreach (var manual_recording in manual_gbpvr_recordings)
             {
@@ -253,9 +266,22 @@
             }
         }
 
-        static void CheckProgramsForDiscrepancies()
+        static void CheckProgramsForDiscrepancies(SQLLITE.IPROGRAMME[] gbpvr, libxmltv.Interfaces.IProgramDefinition[] xmltv)
         {
-            gLog.Warn.WriteLine("CheckProgramsForDiscrepancies() has not been implemented");
+            //gLog.Warn.WriteLine("CheckProgramsForDiscrepancies() has not been implemented");
+            if (gbpvr.Count() != xmltv.Count())
+            {
+                throw new ArgumentOutOfRangeException("gbpvr.Count/xmltv.Count", string.Format("gbpvr.Count: '0x{0:x8}' != xmltv.Count: '0x{1:x8}'", gbpvr.Count(),xmltv.Count()));
+            }
+            for (int i = 0; i < gbpvr.Count(); i++)
+            {
+                var gbpvr_entry = gbpvr[i];
+                var xmltv_entry = gbpvr_entry.AsXMLTVProgramDefinition(sqlite);
+                if (!xmltv[i].Equals(xmltv_entry))
+                {
+                    gLog.Warn.WriteLine("Warning GBPVR Program oid: {0} might be invalid", gbpvr_entry.oid);
+                }
+            }
         }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22