/[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:30:41	183
+++ trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/16 18:50:06	184
@@ -56,9 +56,9 @@
         }
         private class CHANNEL : ICHANNEL
         {
-            public CHANNEL() 
+            public CHANNEL()
             {
-                BaseDatabaseDefinition<CHANNEL>.CreateDefault(this); 
+                BaseDatabaseDefinition<CHANNEL>.CreateDefault(this);
             }
             //public RECORDING_SCHEDULE(SQLiteDataReader r, int index) { BaseDatabaseDefinition<RECORDING_SCHEDULE>.Create(this, r, index); }
 
@@ -89,7 +89,7 @@
             Int64 manual_channel_oid { get; }
             Int64 quality_level { get; }
             Int64 pre_pad_minutes { get; }
-            Int64 post_pad_minutes { get;}
+            Int64 post_pad_minutes { get; }
             Int32 priority { get; }
             String conversion_profile { get; }
         }
@@ -130,7 +130,7 @@
                 }
             }
             public static void Create(ref T instance, SQLiteDataReader r, int index)
-            {                
+            {
                 string field_name = r.GetName(index);
                 Type field_type = r.GetFieldType(index);
                 object field_value = r.GetValue(index);
@@ -155,9 +155,9 @@
                                 {
                                     prop.SetValue(instance, field_value, null);
                                 }
-                                
+
                             }
-                            catch (Exception ex) 
+                            catch (Exception ex)
                             {
                                 throw ex;
                             }
@@ -175,26 +175,26 @@
 
         private class RECORDING_SCHEDULE : IRECORDING_SCHEDULE
         {
-            public RECORDING_SCHEDULE() 
+            public RECORDING_SCHEDULE()
             {
-                BaseDatabaseDefinition<RECORDING_SCHEDULE>.CreateDefault(this); 
+                BaseDatabaseDefinition<RECORDING_SCHEDULE>.CreateDefault(this);
             }
             //public RECORDING_SCHEDULE(SQLiteDataReader r, int index) { BaseDatabaseDefinition<RECORDING_SCHEDULE>.Create(this, r, index); }
 
             public static void Create(ref RECORDING_SCHEDULE instance, SQLiteDataReader r, int index)
             {
-                BaseDatabaseDefinition<RECORDING_SCHEDULE>.Create(ref instance, r, index); 
+                BaseDatabaseDefinition<RECORDING_SCHEDULE>.Create(ref instance, r, index);
             }
 
             #region IRECORDING_SCHEDULE members
-            public Int64 oid { get; set;}
-            public Int64 programme_oid { get; set;}
-            public Int64 capture_source_oid { get; set;}
+            public Int64 oid { get; set; }
+            public Int64 programme_oid { get; set; }
+            public Int64 capture_source_oid { get; set; }
             public Int16 status { get; set; }
             public String filename { get; set; }
-            public Int64 recording_type { get;set; }
-            public Int64 recording_group { get; set;}
-            public DateTime manual_start_time { get; set;}
+            public Int64 recording_type { get; set; }
+            public Int64 recording_group { get; set; }
+            public DateTime manual_start_time { get; set; }
             public DateTime manual_end_time { get; set; }
             public Int64 manual_channel_oid { get; set; }
             public Int64 quality_level { get; set; }
@@ -206,7 +206,7 @@
         }
 
         public interface IPROGRAMME : IEquatable<IPROGRAMME>
-            {
+        {
             Int64 oid { get; set; }
             String name { get; set; }
             String sub_title { get; set; }
@@ -222,9 +222,9 @@
         }
         private class PROGRAMME : IPROGRAMME
         {
-            public PROGRAMME() 
+            public PROGRAMME()
             {
-                BaseDatabaseDefinition<PROGRAMME>.CreateDefault(this); 
+                BaseDatabaseDefinition<PROGRAMME>.CreateDefault(this);
             }
             //public PROGRAMME(SQLiteDataReader r, int index) : base(r, index) { }
             public static void Create(ref PROGRAMME instance, SQLiteDataReader r, int index)
@@ -302,7 +302,7 @@
         }
 
         //public SQLLite() { }
-        protected SQLLITE(string database, EventHandler<EventArgs> OnInstanceCreated) 
+        protected SQLLITE(string database, EventHandler<EventArgs> OnInstanceCreated)
         {
             this.OnInstanceCreated = OnInstanceCreated;
             //CreateConnection(database);
@@ -322,14 +322,14 @@
         [NonSerialized]
         private EventHandler<EventArgs> _OnInstanceCreated;
         private EventHandler<EventArgs> OnInstanceCreated { get { return _OnInstanceCreated; } set { _OnInstanceCreated = value; } }
-        
+
         private void OnCreatedInstance(object sender, EventArgs e)
         {
             if (OnInstanceCreated != null) { OnInstanceCreated.Invoke(sender, e); }
         }
 
         private string Database;
-        #region ISQLLITE members        
+        #region ISQLLITE members
         public List<IPROGRAMME> Programs { get; private set; }
         public List<IRECORDING_SCHEDULE> Recordings { get; private set; }
         public List<ICHANNEL> Channels { get; private set; }
@@ -339,7 +339,7 @@
             var list = new List<IPROGRAMME>(programs.ToArray());
             DateTime first = new DateTime();
             DateTime last = new DateTime();
-            first = list.OrderBy(s => s.start_time).ToList().First().start_time;            
+            first = list.OrderBy(s => s.start_time).ToList().First().start_time;
             last = list.OrderBy(s => s.start_time).ToList().Last().start_time;
             gLog.Verbose.Debug.WriteLine("\tFirst: {0} = ({1})", first.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), first.ToDateTimeString());
             gLog.Verbose.Debug.WriteLine("\tLast: {0} = ({1})", last.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), last.ToDateTimeString());
@@ -362,7 +362,7 @@
             foreach (var program in gbpvr_programs)
             {
                 progress = 100.0 * (index / total);
-                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Filtering GBPVR Programs: {0:00}%", (int)progress)));                
+                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Filtering GBPVR Programs: {0:00}%", (int)progress)));
                 // find an entry in xmltv_programs by Channel Number & StartDate                
                 var program_xmltv_entry = program.AsXMLTVProgramDefinition(this);
                 var xmltv_entry = xmltv_programs.Find(s => s.ChannelNumber == program_xmltv_entry.ChannelNumber && s.Start == program_xmltv_entry.Start);
@@ -374,7 +374,7 @@
                 else
                 {
                     // check if the xmltv entry has different data from the current program
-                    if(!xmltv_entry.Equals(program_xmltv_entry))
+                    if (!xmltv_entry.Equals(program_xmltv_entry))
                     {
                         // data is different
                         var updated_program = program;
@@ -668,32 +668,42 @@
                 List<ICHANNEL> channels = new List<ICHANNEL>();
                 using (SQLiteConnection con = CreateConnection())
                 {
-                    con.Open();
-                    string command_text = string.Format("select * from {0};", TABLES.CHANNEL);
-                    gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
-                    using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
+                    try
                     {
-                        using (SQLiteDataReader r = cmd.ExecuteReader())
+                        con.Open();
+                        string command_text = string.Format("select * from {0};", TABLES.CHANNEL);
+                        gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
+                        using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
                         {
-                            if (!r.HasRows)
+                            using (SQLiteDataReader r = cmd.ExecuteReader())
                             {
-                                gLog.Warn.WriteLine("Query: '{0}' returned no rows.", cmd.CommandText);
-                            }
-                            else
-                            {
-                                while (r.Read())
+                                if (!r.HasRows)
                                 {
-                                    CHANNEL channel = new CHANNEL();
-                                    for (int i = 0; i < r.FieldCount; i++)
+                                    gLog.Warn.WriteLine("Query: '{0}' returned no rows.", cmd.CommandText);
+                                }
+                                else
+                                {
+                                    while (r.Read())
                                     {
-                                        CHANNEL.Create(ref channel, r, i);
+                                        CHANNEL channel = new CHANNEL();
+                                        for (int i = 0; i < r.FieldCount; i++)
+                                        {
+                                            CHANNEL.Create(ref channel, r, i);
+                                        }
+                                        channels.Add(channel);
                                     }
-                                    channels.Add(channel);
                                 }
                             }
                         }
                     }
-                    con.Clone();
+                    catch (SQLiteException ex)
+                    {
+                        gLog.Error.WriteLine(ex.ToString());
+                    }
+                    finally
+                    {
+                        con.Close();
+                    }
                 }
                 this.Channels = channels;
             }
@@ -709,32 +719,42 @@
                 List<IPROGRAMME> programs = new List<IPROGRAMME>();
                 using (SQLiteConnection con = CreateConnection())
                 {
-                    con.Open();
-                    string command_text = string.Format("select * from {0};", TABLES.PROGRAMME);
-                    gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
-                    using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
+                    try
                     {
-                        using (SQLiteDataReader r = cmd.ExecuteReader())
+                        con.Open();
+                        string command_text = string.Format("select * from {0};", TABLES.PROGRAMME);
+                        gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
+                        using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
                         {
-                            if (!r.HasRows)
+                            using (SQLiteDataReader r = cmd.ExecuteReader())
                             {
-                                gLog.Warn.WriteLine("Query: '{0}' returned no rows.", cmd.CommandText);
-                            }
-                            else
-                            {
-                                while (r.Read())
+                                if (!r.HasRows)
                                 {
-                                    PROGRAMME program = new PROGRAMME();
-                                    for (int i = 0; i < r.FieldCount; i++)
+                                    gLog.Warn.WriteLine("Query: '{0}' returned no rows.", cmd.CommandText);
+                                }
+                                else
+                                {
+                                    while (r.Read())
                                     {
-                                        PROGRAMME.Create(ref program, r, i);
+                                        PROGRAMME program = new PROGRAMME();
+                                        for (int i = 0; i < r.FieldCount; i++)
+                                        {
+                                            PROGRAMME.Create(ref program, r, i);
+                                        }
+                                        programs.Add(program);
                                     }
-                                    programs.Add(program);
                                 }
                             }
                         }
                     }
-                    con.Clone();
+                    catch (SQLiteException ex)
+                    {
+                        gLog.Error.WriteLine(ex.ToString());
+                    }
+                    finally
+                    {
+                        con.Close();
+                    }
                 }
                 this.Programs = programs;
             }
@@ -750,32 +770,42 @@
                 List<IRECORDING_SCHEDULE> recordings = new List<IRECORDING_SCHEDULE>();
                 using (SQLiteConnection con = CreateConnection())
                 {
-                    con.Open();
-                    string command_text = string.Format("select * from {0};", TABLES.RECORDING_SCHEDULE);
-                    gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
-                    using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
+                    try
                     {
-                        using (SQLiteDataReader r = cmd.ExecuteReader())
+                        con.Open();
+                        string command_text = string.Format("select * from {0};", TABLES.RECORDING_SCHEDULE);
+                        gLog.Verbose.Debug.WriteLine("Executing Command: '{0}'", command_text);
+                        using (SQLiteCommand cmd = new SQLiteCommand(command_text, con))
                         {
-                            if (!r.HasRows)
+                            using (SQLiteDataReader r = cmd.ExecuteReader())
                             {
-                                gLog.Warn.WriteLine("Query: '{0}' returned no rows.", cmd.CommandText);
-                            }
-                            else
-                            {
-                                while (r.Read())
+                                if (!r.HasRows)
                                 {
-                                    RECORDING_SCHEDULE recording = new RECORDING_SCHEDULE();
-                                    for (int i = 0; i < r.FieldCount; i++)
+                                    gLog.Warn.WriteLine("Query: '{0}' returned no rows.", cmd.CommandText);
+                                }
+                                else
+                                {
+                                    while (r.Read())
                                     {
-                                        RECORDING_SCHEDULE.Create(ref recording, r, i);
+                                        RECORDING_SCHEDULE recording = new RECORDING_SCHEDULE();
+                                        for (int i = 0; i < r.FieldCount; i++)
+                                        {
+                                            RECORDING_SCHEDULE.Create(ref recording, r, i);
+                                        }
+                                        recordings.Add(recording);
                                     }
-                                    recordings.Add(recording);
                                 }
                             }
                         }
                     }
-                    con.Clone();
+                    catch (SQLiteException ex)
+                    {
+                        gLog.Error.WriteLine(ex.ToString());
+                    }
+                    finally
+                    {
+                        con.Close();
+                    }
                 }
                 this.Recordings = recordings;
             }
@@ -794,7 +824,7 @@
             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)));                
+                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);
@@ -811,7 +841,7 @@
             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)));                
+                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
@@ -847,7 +877,6 @@
                             int rowsupdated = cmd.ExecuteNonQuery();
                             gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
                         }
-                        con.Clone();
                         result = true;
                     }
                     catch (SQLiteException ex)
@@ -855,6 +884,10 @@
                         gLog.Error.WriteLine(ex.ToString());
                         result = false;
                     }
+                    finally
+                    {
+                        con.Close();
+                    }
                 }
             }
             catch (Exception ex)
@@ -905,7 +938,7 @@
                             int rowsupdated = cmd.ExecuteNonQuery();
                             gLog.Verbose.Info.WriteLine("Updated '{0}' rows", rowsupdated);
                         }
-                        con.Clone();
+
                         result = true;
                     }
                     catch (SQLiteException ex)
@@ -913,6 +946,10 @@
                         gLog.Error.WriteLine(ex.ToString());
                         result = false;
                     }
+                    finally
+                    {
+                        con.Close();
+                    }
                 }
             }
             catch (Exception ex)

 

  ViewVC Help
Powered by ViewVC 1.1.22