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

revision 174 by william, Sat Mar 16 16:03:19 2013 UTC revision 233 by william, Sun Mar 17 06:53:55 2013 UTC
# Line 10  using System.IO; Line 10  using System.IO;
10  using libxmltv.Core;  using libxmltv.Core;
11  using libxmltv.Interfaces;  using libxmltv.Interfaces;
12  using libxmltv;  using libxmltv;
13    using GBPVR.Public;
14    using GBPVR.Backend.Common;
15  namespace GBPVRProgramDatabaseFixer  namespace GBPVRProgramDatabaseFixer
16  {  {
17      class Program      class Program
# Line 27  namespace GBPVRProgramDatabaseFixer Line 29  namespace GBPVRProgramDatabaseFixer
29          static bool SQLLIST_INSTANCE_CREATED = false;          static bool SQLLIST_INSTANCE_CREATED = false;
30          //static int LAST_REPORTED_SQLLITE_PROGRESS = 0;          //static int LAST_REPORTED_SQLLITE_PROGRESS = 0;
31    
32          static int LAST_REPORTED_PROGRESS = 0;          //static int LAST_REPORTED_PROGRESS = 0;
33    
34          static FileInfo fi_XMLTVFILE;          static FileInfo fi_XMLTVFILE;
35          static FileInfo fi_GBPVRDATABASE;          static FileInfo fi_GBPVRDATABASE;
# Line 99  namespace GBPVRProgramDatabaseFixer Line 101  namespace GBPVRProgramDatabaseFixer
101              Console.SetCursorPosition(0, Console.CursorTop - 1);              Console.SetCursorPosition(0, Console.CursorTop - 1);
102          }          }
103    
104          static void gLog_ReportProgress(object sender, ReportProgressEventArgs e)          static void gLog_ReportProgress(object sender, ReportProgressEventArgs e)
105          {          {
106              //if (!XMLTV_INSTANCE_CREATED && LOADING_XMLTV_FILE)              object k = e.UserState; // we will assum that is a status message
107              //{              if (k == null) // assume we do not have a user status message (ie: is only a progress message)
             //    if (LAST_REPORTED_XMLTV_PROGRESS != e.Progress)  
             //    {  
             //        ConsoleOverwritePreviosLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);  
             //        LAST_REPORTED_XMLTV_PROGRESS = e.Progress;  
             //        if (e.Progress == 100)  
             //        {  
             //            Console.WriteLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);  
             //        }  
             //    }  
             //}  
             //if (!SQLLIST_INSTANCE_CREATED && LOADING_GBPVR_DATABASE)  
             //{  
             //    if (LAST_REPORTED_SQLLITE_PROGRESS != e.Progress)  
             //    {  
             //        ConsoleOverwritePreviosLine("SQLLITE: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);  
             //        LAST_REPORTED_SQLLITE_PROGRESS = e.Progress;  
             //        if (e.Progress == 100)  
             //        {  
             //            Console.WriteLine("SQLLITE: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);  
             //        }  
             //    }  
             //}  
   
             object k = e.UserState;  
             if (k == null)  
108              {              {
109                  if (sender == null)                  if (sender == null) { ConsoleOverwritePreviosLine("Progress: {0} ", e.Progress); }
110                  {                  else { ConsoleOverwritePreviosLine("{0}: Progress: {1:00}%", sender.GetType().Name, e.Progress); }
                     if (LAST_REPORTED_PROGRESS != e.Progress)  
                     {  
                         ConsoleOverwritePreviosLine("Progress: {0} ", e.Progress);  
                         LAST_REPORTED_PROGRESS = e.Progress;  
                         if (e.Progress == 100)  
                         {  
                             Console.WriteLine("Progress: {0} ", e.Progress);  
                         }  
                     }  
                 }  
                 else  
                 {  
                     if (LAST_REPORTED_PROGRESS != e.Progress)  
                     {  
                         ConsoleOverwritePreviosLine("{0}: Progress: {1:00}%", sender.GetType().Name, e.Progress);  
                         LAST_REPORTED_PROGRESS = e.Progress;  
                         if (e.Progress == 100)  
                         {  
                             Console.WriteLine("{0}: Progress: {1:00}%", sender.GetType().Name, e.Progress);  
                         }  
                     }  
                 }  
111              }              }
112              else              else // assume we have a user status message
113              {              {
114                  if (sender == null)                  if (sender == null) { ConsoleOverwritePreviosLine("{0} ", k.ToString()); }
115                  {                  else { ConsoleOverwritePreviosLine("{0}: {1}", sender.GetType().Name, k.ToString()); }
                     if (LAST_REPORTED_PROGRESS != e.Progress)  
                     {  
                         ConsoleOverwritePreviosLine("Progress: {0} ", k.ToString());  
                         LAST_REPORTED_PROGRESS = e.Progress;  
                         if (e.Progress == 100)  
                         {  
                             Console.WriteLine("Progress: {0} ", k.ToString());  
                         }  
                     }  
                 }  
                 else  
                 {  
                     if (LAST_REPORTED_PROGRESS != e.Progress)  
                     {  
                         ConsoleOverwritePreviosLine("{0}: {1}", sender.GetType().Name, k.ToString());  
                         LAST_REPORTED_PROGRESS = e.Progress;  
                         if (e.Progress == 100)  
                         {  
                             Console.WriteLine("{0}: {1}", sender.GetType().Name, k.ToString());  
                         }  
                     }  
                 }  
116              }              }
117          }          }
118          static void LoadXMLTVFile()          static void LoadXMLTVFile()
# Line 227  namespace GBPVRProgramDatabaseFixer Line 160  namespace GBPVRProgramDatabaseFixer
160          }          }
161          static void SQLLITE_OnInstanceCreated(object sender, EventArgs e) { SQLLIST_INSTANCE_CREATED = true; }          static void SQLLITE_OnInstanceCreated(object sender, EventArgs e) { SQLLIST_INSTANCE_CREATED = true; }
162    
   
         //static List<SQLLITE.IPROGRAMME> gbpvr_invalid_programs;  
         //static List<SQLLITE.IPROGRAMME> gbpvr_valid_programs;  
         //static List<SQLLITE.ICHANNEL> gbpvr_channels;  
         //static List<SQLLITE.IRECORDING_SCHEDULE> gbpvr_recordings;  
         //static List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs;  
163          static void PerformDatabaseProcessing()          static void PerformDatabaseProcessing()
164          {          {
165              var sqllite_channels = sqlite.Channels;              var sqllite_channels = sqlite.Channels;
# Line 244  namespace GBPVRProgramDatabaseFixer Line 171  namespace GBPVRProgramDatabaseFixer
171              var sqllite_programs_startdate_range = sqlite.GetProgramsDateRange(sqllite_programs);              var sqllite_programs_startdate_range = sqlite.GetProgramsDateRange(sqllite_programs);
172              var xmltv_programs_startdate_range = GetXMLTVProgramStartDateRange(xmltv_programs);              var xmltv_programs_startdate_range = GetXMLTVProgramStartDateRange(xmltv_programs);
173              var gbpvr_invalid_programs = new List<SQLLITE.IPROGRAMME>();              var gbpvr_invalid_programs = new List<SQLLITE.IPROGRAMME>();
174              var gbpvr_valid_programs = sqlite.FixGBPVRProgramsDatabase(sqllite_programs, xmltv_programs, out gbpvr_invalid_programs);              var gbpvr_valid_programs = sqlite.FixGBPVRProgramsDatabase(sqllite_programs, xmltv_programs, out gbpvr_invalid_programs);    
175              //xmltv_programs = xmltv_programs.OrderBy(s => s.ChannelNumber).ThenBy(s => DateTime.Parse(s.Start)).ToList();              sqlite.RemoveOldGBPVRPrograms(gbpvr_invalid_programs);
176              //sqllite_channels.TrimExcess();              sqlite.UpdateGBPVRPrograms(gbpvr_valid_programs);
177              //gbpvr_invalid_programs.TrimExcess();  
178              //gbpvr_valid_programs.TrimExcess();              sqllite_programs.Clear();
179              //sqllite_programs.TrimExcess();              gbpvr_valid_programs.ForEach(s=>sqllite_programs.Add(s.NewProgram));
180              //xmltv_programs.TrimExcess();  
181              //CheckScheduledRecordingsForDiscrepancies(sqllite_recordings);              CheckScheduledRecordingsForDiscrepancies(sqllite_recordings,sqllite_programs);
             //CheckProgramsForDiscrepancies(gbpvr_valid_programs, xmltv_programs);  
182          }          }
183    
184          static IDateTimeRange GetXMLTVProgramStartDateRange(List<libxmltv.Interfaces.IProgramDefinition> programs)          static IDateTimeRange GetXMLTVProgramStartDateRange(List<libxmltv.Interfaces.IProgramDefinition> programs)
# Line 269  namespace GBPVRProgramDatabaseFixer Line 195  namespace GBPVRProgramDatabaseFixer
195              return range;              return range;
196          }          }
197    
198          static void CheckScheduledRecordingsForDiscrepancies(List<SQLLITE.IRECORDING_SCHEDULE> gbpvr)          static void CheckScheduledRecordingsForDiscrepancies(List<SQLLITE.IRECORDING_SCHEDULE> recordings, List<SQLLITE.IPROGRAMME> programs)
199          {          {
200              ////gLog.Warn.WriteLine("CheckScheduledRecordingsForDiscrepancies() has not been implemented");              List<SQLLITE.IRECORDING_SCHEDULE> recordings_to_delete = new List<SQLLITE.IRECORDING_SCHEDULE>();
201              //var manual_gbpvr_recordings = gbpvr.FindAll(p => p.recording_type == 0).ToList();              //List<SQLLITE.IRECORDING_SCHEDULE> deleted_recordings = new List<SQLLITE.IRECORDING_SCHEDULE>();
202                //List<SQLLITE.IRECORDING_SCHEDULE> reocurring_recordings = new List<SQLLITE.IRECORDING_SCHEDULE>();
203    
204    
205              //foreach (var manual_recording in manual_gbpvr_recordings)              //reocurring_recordings = recordings.FindAll(s => s.recording_type != (long)RecordingType.TYPE_RECORD_ONCE).ToList();
206              //{  
207              //    string title = manual_recording.filename;              foreach (var recording in recordings)
208              //    DateTime start = manual_recording.manual_start_time;              {
209              //    DateTime end = manual_recording.manual_end_time;                  RecordingStatus status = (RecordingStatus)recording.status;
210              //    long channel_oid = manual_recording.manual_channel_oid;                  RecordingType type = (RecordingType)recording.recording_type;
211              //    var found_channel = gbpvr_channels.Find(p => p.oid == channel_oid);                  if (type == RecordingType.TYPE_RECORD_SEASON)
212              //    var channel_number = found_channel.channel_number;                  {
213              //    var found_program = xmltv_programs.ToList().Find(p =>                      continue; // ignore TYPE_RECORD_SEASON
214              //        p.Title.ToLower() == title.ToLower() &&                  }
215              //        p.Start == start.ToDateTimeString() &&                  if (status != RecordingStatus.STATUS_PENDING)
216              //        p.Stop == end.ToDateTimeString() &&                  {
217              //        p.ChannelNumber == channel_number                      continue; // ignore any status except STATUS_PENDING
218              //        );                  }
219              //    if (found_program != null)                  if (recording.recording_group == 0 && recording.programme_oid == 0)
220              //    {                  {
221              //        gLog.Info.WriteLine("Recording might be valid: oid='{0}' programme_oid='{1}' title='{2}' start='{3}', end='{4}'", manual_recording.oid, manual_recording.programme_oid, title, start.ToDateTimeString(), end.ToDateTimeString());                      continue; // ignore manual recordings
222              //    }                  }
223              //    else                  // verify data for this recording
224              //    {                  var recording_oid = recording.oid;
225              //        gLog.Warn.WriteLine("Recording may not be valid: oid='{0}' programme_oid='{1}' title='{2}' start='{3}', end='{4}'", manual_recording.oid, manual_recording.programme_oid, title, start.ToDateTimeString(), end.ToDateTimeString());                  var programme_oid = recording.programme_oid;
226              //        // find the program on the channel at the start time                  var filename = recording.filename;
227              //        var correct_program = xmltv_programs.ToList().Find(p =>                  var manual_start_time = recording.manual_start_time;
228              //            p.ChannelNumber == channel_number &&                  var manual_end_time = recording.manual_end_time;
229              //            p.Start == start.ToDateTimeString()                  var manual_channel_oid = recording.manual_channel_oid;
230              //            );  
231              //        if (correct_program != null)                  // lookup program by oid
232              //        {                  var entry = programs.Find(s => s.oid == programme_oid);
233              //            gLog.Warn.WriteLine("\tThis will be recorded: {0}", correct_program.ToString());                  if (entry == null)
234              //        }                  {
235              //    }                      gLog.Warn.WriteLine("Unable to find program with oid: '{0}' for recording with oid: '{1}' -- assuming it should be deleted", programme_oid, recording_oid);
236              //}                      //throw new NullReferenceException(string.Format("Unable to find program with oid: '{0}' for recording with oid: '{1}'", programme_oid, recording_oid));
237          }                      //deleted_recordings.Add(recording);
238                    }
239          static void CheckProgramsForDiscrepancies(List<SQLLITE.IPROGRAMME> list_gbpvr, List<libxmltv.Interfaces.IProgramDefinition> list_xmltv)                  else
240          {                  {
241              ////gLog.Warn.WriteLine("CheckProgramsForDiscrepancies() has not been implemented");                      recordings_to_delete.Add(recording);        
242              //var gbpvr = list_gbpvr.ToArray();                  }
243              //var xmltv = list_xmltv.ToArray();              }
244              ////if (gbpvr.Count() != xmltv.Count())              recordings_to_delete.TrimExcess();
245              ////{              if (recordings_to_delete.Count > 0)
246              ////    throw new ArgumentOutOfRangeException("gbpvr.Count/xmltv.Count", string.Format("gbpvr.Count: '0x{0:x8}' != xmltv.Count: '0x{1:x8}'", gbpvr.Count(),xmltv.Count()));              {
247              ////}                  gLog.Info.WriteLine("Found {0} recordings to delete.", recordings_to_delete.Count);
248              ////for (int i = 0; i < gbpvr.Count(); i++)                  sqlite.DeleteGBPVRScheduledRecordings(recordings_to_delete);
249              ////{              }
250              ////    var gbpvr_entry = gbpvr[i];  
251              ////    var xmltv_entry = gbpvr_entry.AsXMLTVProgramDefinition(sqlite);              try
252              ////    if (!xmltv[i].Equals(xmltv_entry))              {
253              ////    {                  IScheduleHelper helper = ScheduleHelper.getInstance();
254              ////        gLog.Warn.WriteLine("Warning GBPVR Program oid: {0} might be invalid", gbpvr_entry.oid);                  helper.ForceRecordingScheduleReload();
255              ////    }              }
256              ////}              catch (Exception ex)
257                {
258                    gLog.Error.WriteLine(ex.ToString());
259                }
260          }          }
261      }      }
262  }  }

Legend:
Removed from v.174  
changed lines
  Added in v.233

  ViewVC Help
Powered by ViewVC 1.1.22