/[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

revision 213 by william, Sun Mar 17 01:01:10 2013 UTC revision 217 by william, Sun Mar 17 01:23:45 2013 UTC
# Line 22  namespace GBPVRProgramDatabaseFixer Line 22  namespace GBPVRProgramDatabaseFixer
22          List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }          List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }
23          List<SQLLITE.ICHANNEL> Channels { get; }          List<SQLLITE.ICHANNEL> Channels { get; }
24          IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);          IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);
25          List<SQLLITE.IPROGRAMME> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> removed_programs);          List<IOldNewProgram> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> removed_programs);
26    
27          void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);          void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);
28          void UpdateGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs);          void UpdateGBPVRPrograms(List<IOldNewProgram> programs);
29    
30      }      }
31      public class SQLLITE : ISQLLITE      public class SQLLITE : ISQLLITE
32      {      {
33          private class OldNewProgram : IOldNewProgram          private class OldNewProgram : IOldNewProgram
34          {          {
35              public OldNewProgram() : this(new PROGRAMME(), new PROGRAMME()) { }              public OldNewProgram() : this(new PROGRAMME()) { }
36                public OldNewProgram(IPROGRAMME _old) : this(_old,_old) {  }
37              public OldNewProgram(IPROGRAMME _old, IPROGRAMME _new) { OldProgram = _old; NewProgram = _new; }              public OldNewProgram(IPROGRAMME _old, IPROGRAMME _new) { OldProgram = _old; NewProgram = _new; }
38    
39              public IPROGRAMME OldProgram { get; private set; }              public IPROGRAMME OldProgram { get; private set; }
# Line 347  namespace GBPVRProgramDatabaseFixer Line 348  namespace GBPVRProgramDatabaseFixer
348              return range;              return range;
349          }          }
350    
351          public List<SQLLITE.IPROGRAMME> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> source_invalid)          public List<IOldNewProgram> FixGBPVRProgramsDatabase(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> source_invalid)
352          {          {
353              source_invalid = new List<IPROGRAMME>();              source_invalid = new List<IPROGRAMME>();
354              List<IPROGRAMME> source_valid = new List<IPROGRAMME>();              List<IOldNewProgram> source_valid = new List<IOldNewProgram>();
355              gbpvr_programs = gbpvr_programs.OrderBy(s => s.start_time).ToList();              gbpvr_programs = gbpvr_programs.OrderBy(s => s.start_time).ToList();
356              xmltv_programs = xmltv_programs.OrderBy(s => DateTime.Parse(s.Start)).ToList();              xmltv_programs = xmltv_programs.OrderBy(s => DateTime.Parse(s.Start)).ToList();
357              gbpvr_programs.TrimExcess();              gbpvr_programs.TrimExcess();
# Line 411  namespace GBPVRProgramDatabaseFixer Line 412  namespace GBPVRProgramDatabaseFixer
412                              throw new Exception(string.Format("Program oid '{0}' was not properly updated.", updated_program.oid));                              throw new Exception(string.Format("Program oid '{0}' was not properly updated.", updated_program.oid));
413                          }                          }
414                          //source_valid.Add(new OldNewProgram(program, updated_program));                          //source_valid.Add(new OldNewProgram(program, updated_program));
415                          source_valid.Add(updated_program);                          source_valid.Add(new OldNewProgram(program, updated_program));
416                      }                      }
417                      else                      else
418                      {                      {
419                          // data is the same                          // data is the same
420                          //source_valid.Add(new OldNewProgram(program, program));                          //source_valid.Add(new OldNewProgram(program, program));
421                          source_valid.Add(program);                          source_valid.Add(new OldNewProgram(program));
422                      }                      }
423                  }                  }
424                  index++;                  index++;
# Line 823  namespace GBPVRProgramDatabaseFixer Line 824  namespace GBPVRProgramDatabaseFixer
824    
825          public void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs)          public void RemoveOldGBPVRPrograms(List<SQLLITE.IPROGRAMME> programs)
826          {                      {            
827              //gLog.Info.WriteLine("Removing {0} gbpvr programs.", programs.Count);              gLog.Info.WriteLine("Removing {0} gbpvr programs.", programs.Count);
828              //double total = programs.Count;              int ChunkSize = 1;
             //double index = 0;  
             //double progress = 0;  
             //Stopwatch st = new Stopwatch();  
             //st.Start();  
             //foreach (var program in programs)  
             //{  
             //    progress = 100.0 * (index / total);  
             //    gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Removing GBPVR Program ({0:00}%) oid='{1}'", (int)progress, program.oid)));  
             //    if (!RemoveProgramDatabaseEntry(program))  
             //    {  
             //        gLog.Error.WriteLine("Failed to remove program with oid: {0}", program.oid);  
             //    }  
             //    index++;  
             //}  
             ////Stopwatch st = new Stopwatch();  
             ////st.Start();  
             ////if (!RemoveAllProgramDatabaseEntries())  
             ////{  
             ////    gLog.Error.WriteLine("Failed to remove one or more program(s)");  
             ////}  
             //st.Stop();  
             //gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds", st.Elapsed.TotalSeconds);  
   
             int ChunkSize = 1024;  
829              var ChunkList = programs.Chunk<IPROGRAMME>(ChunkSize);              var ChunkList = programs.Chunk<IPROGRAMME>(ChunkSize);
   
830              double total = programs.Count;              double total = programs.Count;
831              double index = 0;              double index = 0;
832              double progress = 0;              double progress = 0;
# Line 869  namespace GBPVRProgramDatabaseFixer Line 845  namespace GBPVRProgramDatabaseFixer
845              st1.Stop();              st1.Stop();
846              gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds overall", st1.Elapsed.TotalSeconds);              gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds overall", st1.Elapsed.TotalSeconds);
847          }          }
848          public void UpdateGBPVRPrograms(List<IPROGRAMME> programs)          public void UpdateGBPVRPrograms(List<IOldNewProgram> programs)
849          {          {
850              int ChunkSize = 1024;              gLog.Info.WriteLine("Updating {0} gbpvr programs.", programs.Count);
851              var ChunkList = programs.Chunk<IPROGRAMME>(ChunkSize);              int ChunkSize = 1;
852                var ChunkList = programs.Chunk<IOldNewProgram>(ChunkSize);
853    
854              double total = programs.Count;              double total = programs.Count;
855              double index = 0;              double index = 0;
# Line 881  namespace GBPVRProgramDatabaseFixer Line 858  namespace GBPVRProgramDatabaseFixer
858              st1.Start();              st1.Start();
859              foreach (var p in ChunkList)              foreach (var p in ChunkList)
860              {              {
                 //Stopwatch st2 = new Stopwatch();  
                 //st2.Start();  
861                  progress = 100.0 * (index / total);                  progress = 100.0 * (index / total);
                 //gLog.Warn.WriteLine("Inserting {0} gbpvr programs ({1} of {2})", p.Count(), index, total);    
862                  if (!UpdateProgramEntryDatabase(p))                  if (!UpdateProgramEntryDatabase(p))
863                  {                  {
864                      gLog.Error.WriteLine("Failed to update one or more program(s)");                      gLog.Error.WriteLine("Failed to update one or more program(s)");
865                  }                  }
                 //st2.Stop();  
                 //gLog.Warn.WriteLine("    operation took: {0:0.00000} seconds", st2.Elapsed.TotalSeconds);  
                 //gLog.Warn.WriteLine(System.Environment.NewLine);  
866                  gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Updating {0} gbpvr programs ({1} of {2}) {3:00}%", p.Count(), index, total, (int)progress)));                  gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Updating {0} gbpvr programs ({1} of {2}) {3:00}%", p.Count(), index, total, (int)progress)));
867                  index += (double)p.Count();                                  index += (double)p.Count();                
868              }              }
# Line 979  namespace GBPVRProgramDatabaseFixer Line 950  namespace GBPVRProgramDatabaseFixer
950              }              }
951              return result;              return result;
952          }          }
953          private bool UpdateProgramEntryDatabase(IEnumerable<IPROGRAMME> list)          private bool UpdateProgramEntryDatabase(IEnumerable<IOldNewProgram> list)
954          {          {
955              bool result = false;              bool result = false;
956              try              try
# Line 1088  namespace GBPVRProgramDatabaseFixer Line 1059  namespace GBPVRProgramDatabaseFixer
1059          }          }
1060          #endregion          #endregion
1061          #region Multi-Update Command Support          #region Multi-Update Command Support
1062          private string BuildGBPVRMultiUpdateCommand(IEnumerable<IPROGRAMME> list)          private string BuildGBPVRMultiUpdateCommand(IEnumerable<IOldNewProgram> list)
1063          {          {
1064              StringBuilder builder = new StringBuilder();              StringBuilder builder = new StringBuilder();
1065              /*              /*
# Line 1100  namespace GBPVRProgramDatabaseFixer Line 1071  namespace GBPVRProgramDatabaseFixer
1071              builder.AppendLine("begin transaction;");              builder.AppendLine("begin transaction;");
1072              foreach (var t in list)              foreach (var t in list)
1073              {              {
1074                  builder.AppendLine(BuildGBPVRSingleInsertCommand(t));                  if (!t.OldProgram.Equals(t.NewProgram))
1075                    {
1076                        // only update the entry if it is different
1077                        builder.AppendLine(BuildGBPVRSingleUpdateCommand(t.NewProgram));
1078                    }                
1079              }              }
1080              builder.AppendLine("end transaction;");              builder.AppendLine("end transaction;");
1081              return builder.ToString();              return builder.ToString();

Legend:
Removed from v.213  
changed lines
  Added in v.217

  ViewVC Help
Powered by ViewVC 1.1.22