/[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 18:23:11	182
+++ trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/16 18:30:41	183
@@ -24,6 +24,9 @@
         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);
 
+        void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);
+        void UpdateGBPVRPrograms(List<IOldNewProgram> programs);
+
     }
     public class SQLLITE : ISQLLITE
     {
@@ -782,100 +785,141 @@
             }
         }
 
-
+        public void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs)
+        {
+            gLog.Info.WriteLine("Removing {0} old gbpvr programs.", programs.Count);
+            double total = programs.Count;
+            double index = 0;
+            double progress = 0;
+            foreach (var program in programs)
+            {
+                progress = 100.0 * (index / total);
+                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Removing GBPVR Programs: {0:00}%", (int)progress)));                
+                if (!RemoveProgramDatabaseEntry(program))
+                {
+                    gLog.Error.WriteLine("Failed to remove program with oid: {0}", program.oid);
+                }
+                index++;
+            }
+        }
+        public void UpdateGBPVRPrograms(List<IOldNewProgram> programs)
+        {
+            gLog.Info.WriteLine("Updating {0} gbpvr programs.", programs.Count);
+            double total = programs.Count;
+            double index = 0;
+            double progress = 0;
+            foreach (var program in programs)
+            {
+                progress = 100.0 * (index / total);
+                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Updating GBPVR Programs: {0:00}%", (int)progress)));                
+                if (program.NewProgram.Equals(program.OldProgram))
+                {
+                    // program does not need to be updated
+                    continue;
+                }
+                else
+                {
+                    if (!UpdateProgramDatabaseEntry(program.NewProgram))
+                    {
+                        gLog.Error.WriteLine("Failed to update program with oid: {0}", program.NewProgram.oid);
+                    }
+                }
+                index++;
+            }
+        }
 
         private bool RemoveProgramDatabaseEntry(IPROGRAMME old_program)
         {
             bool result = false;
-            //try
-            //{                
-            //    using (SQLiteConnection con = CreateConnection())
-            //    {
-            //        try
-            //        {
-            //            gLog.Verbose.Info.WriteLine("Removing old program with oid: '{0}'", old_program.oid);
-            //            con.Open();
-            //            string command_text = string.Format(@"DELETE FROM [{0}] WHERE [oid] = @oid;", TABLES.PROGRAMME);
-            //            gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
-            //            using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
-            //            {
-            //                cmd.Parameters.Add(new SQLiteParameter("oid", old_program.oid));
-            //                int rowsupdated = cmd.ExecuteNonQuery();
-            //                gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
-            //            }
-            //            con.Clone();
-            //            result = true;
-            //        }
-            //        catch (SQLiteException ex)
-            //        {
-            //            gLog.Error.WriteLine(ex.ToString());
-            //            result = false;
-            //        }
-            //    }
-            //}
-            //catch (Exception ex)
-            //{
-            //    gLog.Error.WriteLine(ex.ToString());
-            //    result = false;
-            //}
+            try
+            {
+                using (SQLiteConnection con = CreateConnection())
+                {
+                    try
+                    {
+                        gLog.Verbose.Info.WriteLine("Removing old program with oid: '{0}'", old_program.oid);
+                        con.Open();
+                        string command_text = string.Format(@"DELETE FROM [{0}] WHERE [oid] = @oid;", TABLES.PROGRAMME);
+                        gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
+                        using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
+                        {
+                            cmd.Parameters.Add(new SQLiteParameter("oid", old_program.oid));
+                            int rowsupdated = cmd.ExecuteNonQuery();
+                            gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
+                        }
+                        con.Clone();
+                        result = true;
+                    }
+                    catch (SQLiteException ex)
+                    {
+                        gLog.Error.WriteLine(ex.ToString());
+                        result = false;
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                gLog.Error.WriteLine(ex.ToString());
+                result = false;
+            }
             return result;
         }
-        private bool UpdateProgramDatabaseEntry(IPROGRAMME old_program, IPROGRAMME new_program)
+        private bool UpdateProgramDatabaseEntry(IPROGRAMME new_program)
         {
             bool result = false;
-            //try
-            //{
-            //    using (SQLiteConnection con = CreateConnection())
-            //    {
-            //        try
-            //        {
-            //            gLog.Verbose.Info.WriteLine("Updating old program with oid: '{0}'", old_program.oid);
-            //            con.Open();
-            //            //string command_text = string.Format(@"UPDATE [{0}] SET [name]=@name,[sub_title]=@subtitle, WHERE [OID] = @oid", TABLES.PROGRAMME);
-            //            string command_text = string.Empty;
-            //            StringBuilder builder = new StringBuilder();
-            //            builder.AppendLine(string.Format("UPDATE [{0}]", TABLES.PROGRAMME));
-            //            builder.Append("SET ");
-            //            builder.AppendFormat("[name]=@name,");
-            //            builder.AppendFormat("[sub_title]=@sub_title,");
-            //            builder.AppendFormat("[description]=@description,");
-            //            builder.AppendFormat("[start_time]=@start_time,");
-            //            builder.AppendFormat("[end_time]=@end_time,");
-            //            builder.AppendFormat("[channel_oid]=@channel_oid,");
-            //            builder.AppendFormat("[unique_identifier]=@unique_identifier,");
-            //            builder.AppendFormat("[rating]=@rating");
-            //            builder.AppendLine(" WHERE [oid] = @oid");
-            //            command_text = builder.ToString();
-            //            gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
-            //            using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
-            //            {
-            //                cmd.Parameters.Add(new SQLiteParameter("oid", old_program.oid));
-            //                cmd.Parameters.Add(new SQLiteParameter("name", new_program.name));
-            //                cmd.Parameters.Add(new SQLiteParameter("sub_title", new_program.sub_title));
-            //                cmd.Parameters.Add(new SQLiteParameter("description", new_program.description));
-            //                cmd.Parameters.Add(new SQLiteParameter("start_time", new_program.start_time));
-            //                cmd.Parameters.Add(new SQLiteParameter("end_time", new_program.end_time));
-            //                cmd.Parameters.Add(new SQLiteParameter("channel_oid", new_program.channel_oid));
-            //                cmd.Parameters.Add(new SQLiteParameter("unique_identifier", new_program.unique_identifier));
-            //                cmd.Parameters.Add(new SQLiteParameter("rating", new_program.rating));
-            //                int rowsupdated = cmd.ExecuteNonQuery();
-            //                gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
-            //            }
-            //            con.Clone();
-            //            result = true;
-            //        }
-            //        catch (SQLiteException ex)
-            //        {
-            //            gLog.Error.WriteLine(ex.ToString());
-            //            result = false;
-            //        }
-            //    }
-            //}
-            //catch (Exception ex)
-            //{
-            //    gLog.Error.WriteLine(ex.ToString());
-            //    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);
+                        string command_text = string.Empty;
+                        StringBuilder builder = new StringBuilder();
+                        builder.AppendLine(string.Format("UPDATE [{0}]", TABLES.PROGRAMME));
+                        builder.Append("SET ");
+                        builder.AppendFormat("[name]=@name,");
+                        builder.AppendFormat("[sub_title]=@sub_title,");
+                        builder.AppendFormat("[description]=@description,");
+                        builder.AppendFormat("[start_time]=@start_time,");
+                        builder.AppendFormat("[end_time]=@end_time,");
+                        builder.AppendFormat("[channel_oid]=@channel_oid,");
+                        builder.AppendFormat("[unique_identifier]=@unique_identifier,");
+                        builder.AppendFormat("[rating]=@rating");
+                        builder.AppendLine(" WHERE [oid] = @oid");
+                        command_text = builder.ToString();
+                        gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
+                        using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
+                        {
+                            cmd.Parameters.Add(new SQLiteParameter("oid", new_program.oid));
+                            cmd.Parameters.Add(new SQLiteParameter("name", new_program.name));
+                            cmd.Parameters.Add(new SQLiteParameter("sub_title", new_program.sub_title));
+                            cmd.Parameters.Add(new SQLiteParameter("description", new_program.description));
+                            cmd.Parameters.Add(new SQLiteParameter("start_time", new_program.start_time));
+                            cmd.Parameters.Add(new SQLiteParameter("end_time", new_program.end_time));
+                            cmd.Parameters.Add(new SQLiteParameter("channel_oid", new_program.channel_oid));
+                            cmd.Parameters.Add(new SQLiteParameter("unique_identifier", new_program.unique_identifier));
+                            cmd.Parameters.Add(new SQLiteParameter("rating", new_program.rating));
+                            int rowsupdated = cmd.ExecuteNonQuery();
+                            gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
+                        }
+                        con.Clone();
+                        result = true;
+                    }
+                    catch (SQLiteException ex)
+                    {
+                        gLog.Error.WriteLine(ex.ToString());
+                        result = false;
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                gLog.Error.WriteLine(ex.ToString());
+                result = false;
+            }
             return result;
         }
     }

 

  ViewVC Help
Powered by ViewVC 1.1.22