/[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 05:35:32	232
+++ trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/17 06:53:55	233
@@ -30,6 +30,7 @@
 
         void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);
         void UpdateGBPVRPrograms(List<IOldNewProgram> programs);
+        void DeleteGBPVRScheduledRecordings(List<SQLLITE.IRECORDING_SCHEDULE> recordings);
 
     }
     public class SQLLITE : ISQLLITE
@@ -189,21 +190,21 @@
         }
         public interface IRECORDING_SCHEDULE : ICloneable<IRECORDING_SCHEDULE>
         {
-            Int64 oid { get; }
-            Int64 programme_oid { get; }
-            Int64 capture_source_oid { get; }
-            Int16 status { get; }
-            String filename { get; }
-            Int64 recording_type { get; }
-            Int64 recording_group { get; }
-            DateTime manual_start_time { get; }
-            DateTime manual_end_time { get; }
-            Int64 manual_channel_oid { get; }
-            Int64 quality_level { get; }
-            Int64 pre_pad_minutes { get; }
-            Int64 post_pad_minutes { get; }
-            Int32 priority { get; }
-            String conversion_profile { get; }
+            Int64 oid { get; set; }
+            Int64 programme_oid { get; set; }
+            Int64 capture_source_oid { get; set; }
+            Int16 status { get; set; }
+            String filename { get; set; }
+            Int64 recording_type { get; set; }
+            Int64 recording_group { get; set; }
+            DateTime manual_start_time { get; set; }
+            DateTime manual_end_time { get; set; }
+            Int64 manual_channel_oid { get; set; }
+            Int64 quality_level { get; set; }
+            Int64 pre_pad_minutes { get; set; }
+            Int64 post_pad_minutes { get; set; }
+            Int32 priority { get; set; }
+            String conversion_profile { get; set; }
         }
         private class RECORDING_SCHEDULE : IRECORDING_SCHEDULE, ICloneable<RECORDING_SCHEDULE>
         {
@@ -676,6 +677,7 @@
         #endregion
 
 
+       
         private string CreateConnectionString()
         {
             string connection_string = string.Format("Data Source={0}", this.Database);
@@ -902,6 +904,29 @@
             }
         }
 
+        public void DeleteGBPVRScheduledRecordings(List<SQLLITE.IRECORDING_SCHEDULE> recordings)
+        {
+            gLog.Info.WriteLine("Removing {0} gbpvr scheduled recordings.", recordings.Count);
+
+            double total = recordings.Count;
+            double index = 0;
+            double progress = 0;
+            Stopwatch st1 = new Stopwatch();
+            foreach (var recording in recordings)
+            {
+                progress = 100.0 * (index / total);
+                if (!RemoveScheduledRecordingEntry(recording))
+                {
+                    gLog.Error.WriteLine("Failed to remove one or more recordings(s)");
+                }
+                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Removing scheduled recordings ({0:00}%) oid='{1}'", (int)progress, recording.oid)));
+                index++;
+            }
+            gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Removing scheduled recordings ({0:00}%)", (int)progress)));
+            st1.Stop();
+            gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds overall", st1.Elapsed.TotalSeconds);
+
+        }
         public void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs)
         {            
             gLog.Info.WriteLine("Removing {0} gbpvr programs.", programs.Count);
@@ -991,6 +1016,49 @@
             }
             return result;
         }
+        private bool RemoveScheduledRecordingEntry(IRECORDING_SCHEDULE recording)
+        {
+            bool result = false;
+            try
+            {
+                using (SQLiteConnection con = CreateConnection())
+                {
+                    try
+                    {
+                        //gLog.Verbose.Info.WriteLine("Updating old program with oid: '{0}'", new_program.oid);
+                        con.Open();
+                        //string command_text = string.Format(@"UPDATE [{0}] SET [name]=@name,[sub_title]=@subtitle, WHERE [OID] = @oid", TABLES.PROGRAMME);
+                        StringBuilder builder = new StringBuilder();                        
+                        builder.AppendLine("begin transaction;");
+                        builder.AppendFormat("delete from {0} where oid={1};", TABLES.RECORDING_SCHEDULE, recording.oid);
+                        builder.AppendLine("end transaction;");
+                        //gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
+                        using (SQLiteCommand cmd = new SQLiteCommand(builder.ToString(), con))
+                        {
+                            int rowsupdated = cmd.ExecuteNonQuery();
+                            //gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
+                        }
+
+                        result = true;
+                    }
+                    catch (SQLiteException ex)
+                    {
+                        gLog.Error.WriteLine(ex.ToString());
+                        result = false;
+                    }
+                    finally
+                    {
+                        con.Close();
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                gLog.Error.WriteLine(ex.ToString());
+                result = false;
+            }
+            return result;
+        }
         private bool RemoveProgramDatabaseEntry(IEnumerable<IPROGRAMME> list)
         {
             bool result = false;
@@ -1115,6 +1183,7 @@
             return result;
         }
 
+
         #region Multi-Delete Command Support
         private string BuildGBPVRMultiDeleteCommand(IEnumerable<IPROGRAMME> list)
         {
@@ -1205,8 +1274,8 @@
             builder.AppendFormat("\"{0}\",", program.name);
             builder.AppendFormat("\"{0}\",", program.sub_title);
             builder.AppendFormat("\"{0}\",", program.description);
-            builder.AppendFormat("'{0}',", program.start_time.ToString("yyyy/MM/dd HH:mm:ss.fffffff"));
-            builder.AppendFormat("'{0}',", program.end_time.ToString("yyyy/MM/dd HH:mm:ss.fffffff"));
+            builder.AppendFormat("'{0}',", program.start_time.ToString("yyyy-MM-dd HH:mm:ss.fffffff"));
+            builder.AppendFormat("'{0}',", program.end_time.ToString("yyyy-MM-dd HH:mm:ss.fffffff"));
             builder.AppendFormat("{0},", program.channel_oid);
             builder.AppendFormat("\"{0}\",", program.unique_identifier);
             builder.AppendFormat("\"{0}\");", program.rating);

 

  ViewVC Help
Powered by ViewVC 1.1.22