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 |
175 |
sqlite.RemoveOldGBPVRPrograms(gbpvr_invalid_programs); |
sqlite.RemoveOldGBPVRPrograms(gbpvr_invalid_programs); |
176 |
sqlite.UpdateGBPVRPrograms(gbpvr_valid_programs); |
sqlite.UpdateGBPVRPrograms(gbpvr_valid_programs); |
177 |
|
|
178 |
|
sqllite_programs.Clear(); |
179 |
|
gbpvr_valid_programs.ForEach(s=>sqllite_programs.Add(s.NewProgram)); |
180 |
|
|
181 |
|
CheckScheduledRecordingsForDiscrepancies(sqllite_recordings,sqllite_programs); |
182 |
} |
} |
183 |
|
|
184 |
static IDateTimeRange GetXMLTVProgramStartDateRange(List<libxmltv.Interfaces.IProgramDefinition> programs) |
static IDateTimeRange GetXMLTVProgramStartDateRange(List<libxmltv.Interfaces.IProgramDefinition> programs) |
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 |
} |
List<SQLLITE.IRECORDING_SCHEDULE> recordings_to_delete = new List<SQLLITE.IRECORDING_SCHEDULE>(); |
201 |
|
//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 |
|
//reocurring_recordings = recordings.FindAll(s => s.recording_type != (long)RecordingType.TYPE_RECORD_ONCE).ToList(); |
206 |
|
|
207 |
|
foreach (var recording in recordings) |
208 |
|
{ |
209 |
|
RecordingStatus status = (RecordingStatus)recording.status; |
210 |
|
RecordingType type = (RecordingType)recording.recording_type; |
211 |
|
if (type == RecordingType.TYPE_RECORD_SEASON) |
212 |
|
{ |
213 |
|
continue; // ignore TYPE_RECORD_SEASON |
214 |
|
} |
215 |
|
if (status != RecordingStatus.STATUS_PENDING) |
216 |
|
{ |
217 |
|
continue; // ignore any status except STATUS_PENDING |
218 |
|
} |
219 |
|
if (recording.recording_group == 0 && recording.programme_oid == 0) |
220 |
|
{ |
221 |
|
continue; // ignore manual recordings |
222 |
|
} |
223 |
|
// verify data for this recording |
224 |
|
var recording_oid = recording.oid; |
225 |
|
var programme_oid = recording.programme_oid; |
226 |
|
var filename = recording.filename; |
227 |
|
var manual_start_time = recording.manual_start_time; |
228 |
|
var manual_end_time = recording.manual_end_time; |
229 |
|
var manual_channel_oid = recording.manual_channel_oid; |
230 |
|
|
231 |
|
// lookup program by oid |
232 |
|
var entry = programs.Find(s => s.oid == programme_oid); |
233 |
|
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 |
|
else |
240 |
|
{ |
241 |
|
recordings_to_delete.Add(recording); |
242 |
|
} |
243 |
|
} |
244 |
|
recordings_to_delete.TrimExcess(); |
245 |
|
if (recordings_to_delete.Count > 0) |
246 |
|
{ |
247 |
|
gLog.Info.WriteLine("Found {0} recordings to delete.", recordings_to_delete.Count); |
248 |
|
sqlite.DeleteGBPVRScheduledRecordings(recordings_to_delete); |
249 |
|
} |
250 |
|
|
251 |
|
try |
252 |
|
{ |
253 |
|
IScheduleHelper helper = ScheduleHelper.getInstance(); |
254 |
|
helper.ForceRecordingScheduleReload(); |
255 |
|
} |
256 |
|
catch (Exception ex) |
257 |
|
{ |
258 |
|
gLog.Error.WriteLine(ex.ToString()); |
259 |
|
} |
260 |
|
} |
261 |
} |
} |
262 |
} |
} |