/[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/17 05:35:32	232
+++ trunk/GBPVRProgramDatabaseFixer/Program.cs	2013/03/17 06:53:55	233
@@ -10,6 +10,8 @@
 using libxmltv.Core;
 using libxmltv.Interfaces;
 using libxmltv;
+using GBPVR.Public;
+using GBPVR.Backend.Common;
 namespace GBPVRProgramDatabaseFixer
 {
     class Program
@@ -173,6 +175,10 @@
             sqlite.RemoveOldGBPVRPrograms(gbpvr_invalid_programs);
             sqlite.UpdateGBPVRPrograms(gbpvr_valid_programs);
 
+            sqllite_programs.Clear();
+            gbpvr_valid_programs.ForEach(s=>sqllite_programs.Add(s.NewProgram));
+
+            CheckScheduledRecordingsForDiscrepancies(sqllite_recordings,sqllite_programs);
         }
 
         static IDateTimeRange GetXMLTVProgramStartDateRange(List<libxmltv.Interfaces.IProgramDefinition> programs)
@@ -189,9 +195,68 @@
             return range;
         }
 
-        static void CheckScheduledRecordingsForDiscrepancies(List<SQLLITE.IRECORDING_SCHEDULE> gbpvr)
+        static void CheckScheduledRecordingsForDiscrepancies(List<SQLLITE.IRECORDING_SCHEDULE> recordings, List<SQLLITE.IPROGRAMME> programs)
         {
-        }
+            List<SQLLITE.IRECORDING_SCHEDULE> recordings_to_delete = new List<SQLLITE.IRECORDING_SCHEDULE>();
+            //List<SQLLITE.IRECORDING_SCHEDULE> deleted_recordings = new List<SQLLITE.IRECORDING_SCHEDULE>();
+            //List<SQLLITE.IRECORDING_SCHEDULE> reocurring_recordings = new List<SQLLITE.IRECORDING_SCHEDULE>();
+
+
+            //reocurring_recordings = recordings.FindAll(s => s.recording_type != (long)RecordingType.TYPE_RECORD_ONCE).ToList();
 
+            foreach (var recording in recordings)
+            {
+                RecordingStatus status = (RecordingStatus)recording.status;
+                RecordingType type = (RecordingType)recording.recording_type;
+                if (type == RecordingType.TYPE_RECORD_SEASON)
+                {
+                    continue; // ignore TYPE_RECORD_SEASON
+                }
+                if (status != RecordingStatus.STATUS_PENDING)
+                {
+                    continue; // ignore any status except STATUS_PENDING
+                }
+                if (recording.recording_group == 0 && recording.programme_oid == 0)
+                {
+                    continue; // ignore manual recordings
+                }
+                // verify data for this recording
+                var recording_oid = recording.oid;
+                var programme_oid = recording.programme_oid;
+                var filename = recording.filename;
+                var manual_start_time = recording.manual_start_time;
+                var manual_end_time = recording.manual_end_time;
+                var manual_channel_oid = recording.manual_channel_oid;
+
+                // lookup program by oid
+                var entry = programs.Find(s => s.oid == programme_oid);
+                if (entry == null) 
+                {
+                    gLog.Warn.WriteLine("Unable to find program with oid: '{0}' for recording with oid: '{1}' -- assuming it should be deleted", programme_oid, recording_oid);
+                    //throw new NullReferenceException(string.Format("Unable to find program with oid: '{0}' for recording with oid: '{1}'", programme_oid, recording_oid)); 
+                    //deleted_recordings.Add(recording);
+                }
+                else
+                {
+                    recordings_to_delete.Add(recording);        
+                }
+            }
+            recordings_to_delete.TrimExcess();
+            if (recordings_to_delete.Count > 0)
+            {
+                gLog.Info.WriteLine("Found {0} recordings to delete.", recordings_to_delete.Count);
+                sqlite.DeleteGBPVRScheduledRecordings(recordings_to_delete);
+            }
+
+            try
+            {
+                IScheduleHelper helper = ScheduleHelper.getInstance();
+                helper.ForceRecordingScheduleReload();
+            }
+            catch (Exception ex)
+            {
+                gLog.Error.WriteLine(ex.ToString());
+            }
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22