/[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/14 21:40:19	162
+++ trunk/GBPVRProgramDatabaseFixer/Program.cs	2013/03/15 16:53:40	163
@@ -14,7 +14,7 @@
 {
     class Program
     {
-        static SQLLITE sqlite;
+        static ISQLLITE sqlite;
         static string XMLTV_FILE = "";
         static string GBPVR_DATABASE = "";
 
@@ -88,7 +88,7 @@
 
             LoadXMLTVFile();
             LoadGBPVRDatabase();
-            PerformDatabaseProcessing();       
+            PerformDatabaseProcessing();
         }
 
         static void ConsoleOverwritePreviosLine(string format, params object[] args)
@@ -163,8 +163,7 @@
                 LOADING_GBPVR_DATABASE = false;
                 return;
             }
-
-            sqlite = new SQLLITE(fi_GBPVRDATABASE.FullName, new EventHandler<EventArgs>(SQLLITE_OnInstanceCreated));
+            sqlite = SQLLITE.Create(fi_GBPVRDATABASE.FullName, new EventHandler<EventArgs>(SQLLITE_OnInstanceCreated));
             while (!SQLLIST_INSTANCE_CREATED) { Application.DoEvents(); }
             LOADING_GBPVR_DATABASE = false;
         }
@@ -182,21 +181,33 @@
             gbpvr_recordings = sqlite.Recordings;            
             Type datatype;
             var xmlt_raw_program_data = (IProgramDefinitionList)XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out datatype);
-            xmltv_programs = xmlt_raw_program_data.ToList().OrderBy(p => p.ChannelNumber).ThenBy(p => DateTime.Parse(p.Start)).ToList();
-
-
-            xmltv_programs = xmltv_programs.FindAll(p => p.Title == "Law & Order: Criminal Intent").ToList();
-
+            //xmltv_programs = xmlt_raw_program_data.ToList().OrderBy(p => p.ChannelNumber).ThenBy(p => DateTime.Parse(p.Start)).ToList();
+            //xmltv_programs = xmltv_programs.FindAll(p => p.Title == "Law & Order: Criminal Intent").ToList();
+            xmltv_programs = xmlt_raw_program_data.ToList().OrderBy(p => DateTime.Parse(p.Start)).ToList();
 
 
-            //var data = xmltv_programs[0];
-            //DateTime p = DateTime.Parse(data.Start);
-            //string strP = p.ToString("yyyy/MM/dd HH:mm:ss.fffffff");
-            
+            var gbpvr_programs_startdate_range = sqlite.GetProgramsDateRange(gbpvr_programs);
+            var xmltv_programs_startdate_range = GetXMLTVProgramStartDateRange(xmltv_programs);
+            gbpvr_programs = sqlite.FilterProgramsByDateRange(gbpvr_programs, xmltv_programs_startdate_range);
+            xmltv_programs = xmltv_programs.OrderBy(s => s.ChannelNumber).ThenBy(s => DateTime.Parse(s.Start)).ToList();
             CheckScheduledRecordingsForDiscrepancies();
             CheckProgramsForDiscrepancies();
         }
 
+        static IDateTimeRange GetXMLTVProgramStartDateRange(List<libxmltv.Interfaces.IProgramDefinition> programs)
+        {
+            IDateTimeRange range = DateTimeRange.Create();
+            var list = new List<libxmltv.Interfaces.IProgramDefinition>(programs.ToArray());
+            DateTime first = new DateTime();
+            DateTime last = new DateTime();
+            first = DateTime.Parse(list.OrderBy(s => DateTime.Parse(s.Start)).ToList().First().Start);
+            last = DateTime.Parse(list.OrderBy(s => DateTime.Parse(s.Start)).ToList().Last().Start);
+            gLog.Info.WriteLine("\tFirst: {0} = ({1})", first.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), first.ToDateTimeString());
+            gLog.Info.WriteLine("\tLast: {0} = ({1})", last.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), last.ToDateTimeString());
+            range = DateTimeRange.Create(first, last);
+            return range;
+        }
+
         static void CheckScheduledRecordingsForDiscrepancies()
         {
             //gLog.Warn.WriteLine("CheckScheduledRecordingsForDiscrepancies() has not been implemented");

 

  ViewVC Help
Powered by ViewVC 1.1.22