/
Schedule.cs
1464 lines (1310 loc) · 50.5 KB
/
Schedule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region Copyright (C) 2005-2011 Team MediaPortal
// Copyright (C) 2005-2011 Team MediaPortal
// http://www.team-mediaportal.com
//
// MediaPortal is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// MediaPortal is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MediaPortal. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Collections.Generic;
using Gentle.Framework;
using TvLibrary.Interfaces;
using TvLibrary.Log;
namespace TvDatabase
{
public enum KeepMethodType
{
UntilSpaceNeeded,
UntilWatched,
TillDate,
Always
}
public enum ScheduleRecordingType
{
Once,
Daily,
Weekly,
EveryTimeOnThisChannel,
EveryTimeOnEveryChannel,
Weekends,
WorkingDays,
WeeklyEveryTimeOnThisChannel
}
/// <summary>
/// Instances of this class represent the properties and methods of a row in the table <b>Schedule</b>.
/// </summary>
[TableName("Schedule")]
public class Schedule : Persistent
{
public static DateTime MinSchedule = new DateTime(2000, 1, 1);
public static readonly int HighestPriority = Int32.MaxValue;
//public static readonly int LowestPriority;
#region Members
private bool isChanged;
[TableColumn("id_Schedule", NotNull = true), PrimaryKey(AutoGenerated = true)] private int idSchedule;
[TableColumn("idChannel", NotNull = true), ForeignKey("Channel", "idChannel")] private int idChannel;
[TableColumn("idParentSchedule", NotNull = true), ForeignKey("Channel", "idParentSchedule")] private int
idParentSchedule;
[TableColumn("scheduleType", NotNull = true)] private int scheduleType;
[TableColumn("programName", NotNull = true)] private string programName;
[TableColumn("startTime", NotNull = true)] private DateTime startTime;
[TableColumn("endTime", NotNull = true)] private DateTime endTime;
[TableColumn("maxAirings", NotNull = true)] private int maxAirings;
[TableColumn("priority", NotNull = true)] private int priority;
[TableColumn("directory", NotNull = true)] private string directory;
[TableColumn("quality", NotNull = true)] private int quality;
[TableColumn("keepMethod", NotNull = true)] private int keepMethod;
[TableColumn("keepDate", NotNull = true)] private DateTime keepDate;
[TableColumn("preRecordInterval", NotNull = true)] private int preRecordInterval;
[TableColumn("postRecordInterval", NotNull = true)] private int postRecordInterval;
[TableColumn("canceled", NotNull = true)] private DateTime canceled;
[TableColumn("recommendedCard", NotNull = true)] private int recommendedCard;
[TableColumn("series", NotNull = true)] private bool series;
#endregion
#region Constructors
public Schedule(int idChannel, string programName, DateTime startTime, DateTime endTime)
{
isChanged = true;
this.idChannel = idChannel;
this.idParentSchedule = -1;
ProgramName = programName;
Canceled = MinSchedule;
Directory = "";
EndTime = endTime;
KeepDate = MinSchedule;
KeepMethod = (int)KeepMethodType.UntilSpaceNeeded;
MaxAirings = Int32.MaxValue; //BAV: changed due to mantis bug 1162 - old value 5;
PostRecordInterval = 0;
PreRecordInterval = 0;
Priority = 0;
quality = 0;
BitRateMode = VIDEOENCODER_BITRATE_MODE.NotSet;
QualityType = QualityType.NotSet;
ScheduleType = (int)ScheduleRecordingType.Once;
Series = (scheduleType > 0);
StartTime = startTime;
recommendedCard = -1;
}
/// <summary>
/// Create a new object by specifying all fields (except the auto-generated primary key field).
/// </summary>
public Schedule(int idChannel, int idParentSchedule, int scheduleType, string programName, DateTime startTime,
DateTime endTime,
int maxAirings, int priority, string directory, int quality, int keepMethod, DateTime keepDate,
int preRecordInterval, int postRecordInterval, DateTime canceled)
{
isChanged = true;
this.idChannel = idChannel;
this.idParentSchedule = idParentSchedule;
this.scheduleType = scheduleType;
this.programName = programName;
this.startTime = startTime;
this.endTime = endTime;
this.maxAirings = maxAirings;
this.priority = priority;
this.directory = directory;
this.quality = quality;
this.keepMethod = keepMethod;
this.keepDate = keepDate;
this.preRecordInterval = preRecordInterval;
this.postRecordInterval = postRecordInterval;
this.canceled = canceled;
this.series = (scheduleType > 0);
recommendedCard = -1;
}
/// <summary>
/// Create a new schedule from an existing one (except the auto-generated primary key field).
/// </summary>
public Schedule(Schedule schedule)
{
isChanged = true;
idChannel = schedule.idChannel;
idParentSchedule = schedule.idParentSchedule;
scheduleType = schedule.scheduleType;
programName = schedule.programName;
startTime = schedule.startTime;
endTime = schedule.endTime;
maxAirings = schedule.maxAirings;
priority = schedule.priority;
directory = schedule.directory;
quality = schedule.quality;
keepMethod = schedule.keepMethod;
keepDate = schedule.keepDate;
preRecordInterval = schedule.preRecordInterval;
postRecordInterval = schedule.postRecordInterval;
canceled = schedule.canceled;
series = schedule.Series;
recommendedCard = -1;
}
/// <summary>
/// Create an object from an existing row of data. This will be used by Gentle to
/// construct objects from retrieved rows.
/// </summary>
public Schedule(int idSchedule, int idParentSchedule, int idChannel, int scheduleType, string programName,
DateTime startTime,
DateTime endTime, int maxAirings, int priority, string directory, int quality, int keepMethod,
DateTime keepDate, int preRecordInterval, int postRecordInterval, DateTime canceled)
{
this.idSchedule = idSchedule;
this.idParentSchedule = idParentSchedule;
this.idChannel = idChannel;
this.scheduleType = scheduleType;
this.programName = programName;
this.startTime = startTime;
this.endTime = endTime;
this.maxAirings = maxAirings;
this.priority = priority;
this.directory = directory;
this.quality = quality;
this.keepMethod = keepMethod;
this.keepDate = keepDate;
this.preRecordInterval = preRecordInterval;
this.postRecordInterval = postRecordInterval;
this.canceled = canceled;
this.series = (scheduleType > 0);
recommendedCard = -1;
}
#endregion
#region Public Properties
/// <summary>
/// Indicates whether the entity is changed and requires saving or not.
/// </summary>
public bool IsChanged
{
get { return isChanged; }
}
/// <summary>
/// Property relating to database column id_Schedule
/// </summary>
public int IdSchedule
{
get { return idSchedule; }
}
/// <summary>
/// Property to get/set the card id recommended by ConflictsManager plugin
/// </summary>
public int RecommendedCard
{
get { return recommendedCard; }
set
{
isChanged |= recommendedCard != value;
recommendedCard = value;
}
}
/// <summary>
/// Property relating to database column idChannel
/// </summary>
public int IdChannel
{
get { return idChannel; }
set
{
isChanged |= idChannel != value;
idChannel = value;
}
}
public int IdParentSchedule
{
get { return idParentSchedule; }
set
{
isChanged |= idParentSchedule != value;
idParentSchedule = value;
}
}
/// <summary>
/// Property relating to database column scheduleType
/// </summary>
public int ScheduleType
{
get { return scheduleType; }
set
{
isChanged |= scheduleType != value;
scheduleType = value;
}
}
/// <summary>
/// Is schedule a manual one
/// </summary>
public bool IsManual
{
get
{
if (scheduleType != (int)ScheduleRecordingType.Once)
{
return false;
}
TimeSpan ts = (endTime - startTime);
return ((int)ts.TotalHours == 24);
}
}
/// <summary>
/// Property relating to database column programName
/// </summary>
public string ProgramName
{
get { return programName; }
set
{
isChanged |= programName != value;
programName = value;
}
}
/// <summary>
/// Property relating to database column startTime
/// </summary>
public DateTime StartTime
{
get { return startTime; }
set
{
isChanged |= startTime != value;
startTime = value;
}
}
/// <summary>
/// Property relating to database column endTime
/// </summary>
public DateTime EndTime
{
get { return endTime; }
set
{
isChanged |= endTime != value;
endTime = value;
}
}
/// <summary>
/// Property relating to database column maxAirings
/// </summary>
public int MaxAirings
{
get { return maxAirings; }
set
{
isChanged |= maxAirings != value;
maxAirings = value;
}
}
/// <summary>
/// Property relating to database column priority
/// </summary>
public int Priority
{
get { return priority; }
set
{
isChanged |= priority != value;
priority = value;
}
}
/// <summary>
/// Property relating to database column directory
/// </summary>
public string Directory
{
get { return directory; }
set
{
isChanged |= directory != value;
directory = value;
}
}
/// <summary>
/// Property relating to database column quality
/// </summary>
public int Quality
{
get { return quality; }
set
{
isChanged |= quality != value;
quality = value;
}
}
/// <summary>
/// Property relating to database column keepMethod
/// </summary>
public int KeepMethod
{
get { return keepMethod; }
set
{
isChanged |= keepMethod != value;
keepMethod = value;
}
}
/// <summary>
/// Property relating to database column keepDate
/// </summary>
public DateTime KeepDate
{
get { return keepDate; }
set
{
isChanged |= keepDate != value;
keepDate = value;
}
}
/// <summary>
/// Property relating to database column preRecordInterval
/// </summary>
public int PreRecordInterval
{
get { return preRecordInterval; }
set
{
isChanged |= preRecordInterval != value;
preRecordInterval = value;
}
}
/// <summary>
/// Property relating to database column postRecordInterval
/// </summary>
public int PostRecordInterval
{
get { return postRecordInterval; }
set
{
isChanged |= postRecordInterval != value;
postRecordInterval = value;
}
}
/// <summary>
/// Property relating to database column canceled
/// </summary>
public DateTime Canceled
{
get { return canceled; }
set
{
isChanged |= canceled != value;
canceled = value;
}
}
#endregion
#region Storage and Retrieval
/// <summary>
/// Static method to retrieve all instances that are stored in the database in one call
/// </summary>
public static IList<Schedule> ListAll()
{
return Broker.RetrieveList<Schedule>();
}
public static IList<Schedule> FindOrphanedOnceSchedules()
{
SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule));
//
DateTime now = DateTime.Now;
sb.AddConstraint(Operator.Equals, "scheduleType", 0);
sb.AddConstraint(Operator.LessThan, "endtime", now);
// passing true indicates that we'd like a list of elements, i.e. that no primary key
// constraints from the type being retrieved should be added to the statement
SqlStatement stmt = sb.GetStatement(true);
// execute the statement/query and create a collection of User instances from the result set
IList<Schedule> getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute());
IList<Schedule> newList = new List<Schedule>();
if (getList.Count > 0)
{
foreach (Schedule schedule in getList)
{
DateTime endPostTime = schedule.endTime.AddMinutes(schedule.postRecordInterval);
if (endPostTime < now)
{
newList.Add(schedule);
}
}
}
return newList;
}
public static Schedule FindNoEPGSchedule(Channel channel)
{
int idChannel = channel.IdChannel;
//select * from 'foreigntable'
SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule));
//
sb.AddConstraint(Operator.Equals, "scheduleType", 0);
sb.AddConstraint(Operator.Equals, "idChannel", idChannel);
sb.AddConstraint(Operator.Equals, "idParentSchedule", -1);
sb.AddConstraint(Operator.Equals, "series", false);
// passing true indicates that we'd like a list of elements, i.e. that no primary key
// constraints from the type being retrieved should be added to the statement
SqlStatement stmt = sb.GetStatement(true);
// execute the statement/query and create a collection of User instances from the result set
IList<Schedule> getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute());
if (getList.Count != 0)
{
return getList[0];
}
return null;
}
public static bool IsScheduleRecording(int id, Program prg)
{ // this is not about the schedule at all... is asking whether program is recording right now
bool isScheduleRecording = false;
Schedule schedule = Schedule.Retrieve(id);
prg.Refresh();
if (schedule != null)
{
Schedule spawnedSchedule = Schedule.RetrieveSpawnedSchedule(id, prg.StartTime);
if (spawnedSchedule != null)
{
schedule = spawnedSchedule;
}
if (prg != null && prg.IsRecording)
{
isScheduleRecording = (Recording.ActiveRecording(schedule.idSchedule) != null);
}
}
return isScheduleRecording;
}
public static bool IsScheduleRecording(int id)
{
bool isScheduleRecording = false;
Schedule schedule = Schedule.Retrieve(id);
if (schedule != null)
{
Schedule spawnedSchedule = Schedule.RetrieveSpawnedSchedule(id, schedule.startTime);
if (spawnedSchedule != null)
{
schedule = spawnedSchedule;
}
isScheduleRecording = (Recording.ActiveRecording(schedule.idSchedule) != null);
}
return isScheduleRecording;
}
/// <summary>
/// Retrieves an entity given it's id.
/// </summary>
public static Schedule Retrieve(int id)
{
// Return null if id is smaller than seed and/or increment for autokey
if (id < 1)
{
return null;
}
Key key = new Key(typeof (Schedule), true, "id_Schedule", id);
return Broker.TryRetrieveInstance<Schedule>(key);
}
/// <summary>
/// Retrieves an entity given it's id, using Gentle.Framework.Key class.
/// This allows retrieval based on multi-column keys.
/// </summary>
public static Schedule Retrieve(Key key)
{
return Broker.TryRetrieveInstance<Schedule>(key);
}
public static void SynchProgramStatesForAll()
{
Log.Info("schedule.SynchProgramStatesForAll");
IList<Schedule> allSchedules = Schedule.ListAll();
if (allSchedules != null && allSchedules.Count > 0)
{
foreach (Schedule schedule in allSchedules)
{
Schedule.SynchProgramStates(schedule.idSchedule);
}
}
}
public static void ResetProgramStates(int idSchedule)
{
Schedule schedule = Schedule.Retrieve(idSchedule);
if (schedule == null)
{
return;
}
var progs = GetProgramsForSchedule(schedule);
foreach (var prog in progs)
{
Program.ResetPendingState(prog.IdProgram);
prog.Persist();
}
}
public static void SynchProgramStates(int idSchedule)
{
Schedule schedule = Schedule.Retrieve(idSchedule);
if (schedule == null)
{
return;
}
var progs = GetProgramsForSchedule(schedule);
foreach (var prog in progs)
{
if(schedule.IsSerieIsCanceled(schedule.GetSchedStartTimeForProg(prog)))
{
// program has been cancelled so reset any pending recording flags
Program.ResetPendingState(prog.IdProgram);
prog.Persist();
}
else
{
bool isPartialRecording = Schedule.IsPartialRecording(schedule, prog);
if (schedule.ScheduleType == (int)ScheduleRecordingType.Once)
{
// is one off recording that is still active so set pending flags accordingly
prog.IsRecordingOncePending = true;
prog.IsRecordingSeriesPending = false;
prog.IsPartialRecordingSeriesPending = false;
prog.Persist();
}
else if (isPartialRecording)
{
// is part of a series recording but is a time based schedule and program times do not
// match up with schedule times so flag as partial recording
prog.IsRecordingOncePending = false;
prog.IsRecordingSeriesPending = false;
prog.IsPartialRecordingSeriesPending = true;
prog.Persist();
}
else
{
// is part of a series recording but is not a partial recording
prog.IsRecordingOncePending = false;
prog.IsRecordingSeriesPending = true;
prog.IsPartialRecordingSeriesPending = false;
prog.Persist();
}
}
}
}
public static IList<Program> GetProgramsForSchedule(Schedule schedule)
{
IList<Program> progs = null;
switch (schedule.scheduleType)
{
case (int)ScheduleRecordingType.Once:
var prgOnce = Program.RetrieveOnce(schedule.programName, schedule.startTime, schedule.endTime,
schedule.ReferencedChannel().IdChannel);
progs = new List<Program>();
if (prgOnce != null)
{
progs.Add(prgOnce);
}
break;
case (int)ScheduleRecordingType.Daily:
progs = Program.RetrieveDaily(schedule.startTime, schedule.endTime,schedule.ReferencedChannel().IdChannel);
break;
case (int)ScheduleRecordingType.EveryTimeOnEveryChannel:
progs = Program.RetrieveEveryTimeOnEveryChannel(schedule.programName);
break;
case (int)ScheduleRecordingType.EveryTimeOnThisChannel:
progs = Program.RetrieveEveryTimeOnThisChannel(schedule.programName, schedule.ReferencedChannel().IdChannel);
break;
case (int)ScheduleRecordingType.WeeklyEveryTimeOnThisChannel:
progs = Program.RetrieveWeeklyEveryTimeOnThisChannel(schedule.startTime, schedule.endTime, schedule.programName, schedule.ReferencedChannel().IdChannel);
break;
case (int)ScheduleRecordingType.Weekends:
progs = Program.RetrieveWeekends(schedule.startTime, schedule.endTime, schedule.ReferencedChannel().IdChannel);
break;
case (int)ScheduleRecordingType.Weekly:
progs = Program.RetrieveWeekly(schedule.startTime, schedule.endTime, schedule.ReferencedChannel().IdChannel);
break;
case (int)ScheduleRecordingType.WorkingDays:
progs = Program.RetrieveWorkingDays(schedule.startTime, schedule.endTime, schedule.ReferencedChannel().IdChannel);
break;
}
return progs;
}
public static bool IsPartialRecording(Schedule schedule, Program prg)
{
if (schedule.ScheduleType == (int)ScheduleRecordingType.EveryTimeOnEveryChannel ||
schedule.ScheduleType == (int)ScheduleRecordingType.EveryTimeOnThisChannel ||
schedule.ScheduleType == (int)ScheduleRecordingType.WeeklyEveryTimeOnThisChannel)
{
return false;
}
DateTime schStart;
DateTime schEnd;
if (schedule.GetAdjustedScheduleTimeRange(prg, out schStart, out schEnd))
{
return (prg.StartTime < schStart || prg.EndTime > schEnd);
}
else
{
Log.Info(
"IsPartialRecording: program ({0} {1} - {2} is not (at least partially) included in the schedule {3:hh:mm} - {4:hh:mm}",
prg.Title, prg.StartTime, prg.EndTime, schedule.startTime, schedule.endTime);
return false;
}
}
/// <summary>
/// Persists the entity if it was never persisted or was changed.
/// </summary>
public override void Persist()
{
if (IsChanged || !IsPersisted)
{
try
{
base.Persist();
//WE HAVE TO HANDLE CANCELLED SCHEDULES AND SKIP THOSE - WE DO NOT WANT TO MARK CANCLLED AS recpending.
SynchProgramStates(this.idSchedule);
}
catch (Exception ex)
{
Log.Error("Exception in Schedule.Persist() with Message {0}", ex.Message);
return;
}
isChanged = false;
}
}
/// <summary>
/// Retreives the first found instance of a 'Series' typed schedule given its Channel,Title
/// </summary>
/// <param name="idChannel">Channel id to look for</param>
/// <param name="programName">Title we wanna look for</param>
/// <returns>schedule instance or null</returns>
public static Schedule RetrieveSeries(int idChannel, string programName)
{
//select * from 'foreigntable'
SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule));
//
sb.AddConstraint(Operator.NotEquals, "scheduleType", 0);
sb.AddConstraint(Operator.Equals, "idChannel", idChannel);
sb.AddConstraint(Operator.Equals, "programName", programName);
// passing true indicates that we'd like a list of elements, i.e. that no primary key
// constraints from the type being retrieved should be added to the statement
SqlStatement stmt = sb.GetStatement(true);
// execute the statement/query and create a collection of User instances from the result set
IList<Schedule> getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute());
if (getList.Count != 0)
{
return getList[0];
}
return null;
// TODO In the end, a GentleList should be returned instead of an arraylist
//return new GentleList( typeof(ChannelMap), this );
}
/// <summary>
/// Retreives the first found instance of a 'Series' typed schedule given its Channel,Title,Start and End Times
/// </summary>
/// <param name="idChannel">Channel id to look for</param>
/// <param name="programName">Title we wanna look for</param>
/// <param name="startTime">StartTime</param>
/// <param name="endTime">EndTime</param>
/// <returns>schedule instance or null</returns>
public static Schedule RetrieveSeries(int idChannel, string programName, DateTime startTime, DateTime endTime)
{
//select * from 'foreigntable'
SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule));
//
sb.AddConstraint(Operator.NotEquals, "scheduleType", 0);
sb.AddConstraint(Operator.Equals, "idChannel", idChannel);
sb.AddConstraint(Operator.Equals, "programName", programName);
sb.AddConstraint(Operator.Equals, "startTime", startTime);
sb.AddConstraint(Operator.Equals, "endTime", endTime);
// passing true indicates that we'd like a list of elements, i.e. that no primary key
// constraints from the type being retrieved should be added to the statement
SqlStatement stmt = sb.GetStatement(true);
// execute the statement/query and create a collection of User instances from the result set
IList<Schedule> getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute());
if (getList.Count != 0)
{
return getList[0];
}
return null;
// TODO In the end, a GentleList should be returned instead of an arraylist
//return new GentleList( typeof(ChannelMap), this );
}
/// <summary>
/// Retreives the first found instance of a 'Series' typed schedule given its Channel,Title,Start and End Times
/// </summary>
/// <param name="idChannel">Channel id to look for</param>
/// <param name="startTime">StartTime</param>
/// <param name="endTime">EndTime</param>
/// <returns>schedule instance or null</returns>
public static Schedule RetrieveSeries(int idChannel, DateTime startTime, DateTime endTime)
{
//select * from 'foreigntable'
SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule));
//
sb.AddConstraint(Operator.NotEquals, "scheduleType", 0);
sb.AddConstraint(Operator.Equals, "idChannel", idChannel);
sb.AddConstraint(Operator.Equals, "startTime", startTime);
sb.AddConstraint(Operator.Equals, "endTime", endTime);
// passing true indicates that we'd like a list of elements, i.e. that no primary key
// constraints from the type being retrieved should be added to the statement
SqlStatement stmt = sb.GetStatement(true);
// execute the statement/query and create a collection of User instances from the result set
IList<Schedule> getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute());
if (getList.Count != 0)
{
return getList[0];
}
return null;
// TODO In the end, a GentleList should be returned instead of an arraylist
//return new GentleList( typeof(ChannelMap), this );
}
/// <summary>
/// Retreives the first found instance of a 'Once' typed schedule given its Channel,Title,Start and End Times
/// </summary>
/// <param name="idChannel">Channel id to look for</param>
/// <param name="programName">Title we wanna look for</param>
/// <param name="startTime">StartTime</param>
/// <param name="endTime">EndTime</param>
/// <returns>schedule instance or null</returns>
public static Schedule RetrieveOnce(int idChannel, string programName, DateTime startTime, DateTime endTime)
{
//select * from 'foreigntable'
SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule));
//
sb.AddConstraint(Operator.Equals, "scheduleType", 0);
sb.AddConstraint(Operator.Equals, "idChannel", idChannel);
sb.AddConstraint(Operator.Equals, "programName", programName);
sb.AddConstraint(Operator.Equals, "startTime", startTime);
sb.AddConstraint(Operator.Equals, "endTime", endTime);
// passing true indicates that we'd like a list of elements, i.e. that no primary key
// constraints from the type being retrieved should be added to the statement
SqlStatement stmt = sb.GetStatement(true);
// execute the statement/query and create a collection of User instances from the result set
IList<Schedule> getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute());
if (getList.Count != 0)
{
return getList[0];
}
return null;
// TODO In the end, a GentleList should be returned instead of an arraylist
//return new GentleList( typeof(ChannelMap), this );
}
#endregion
#region Relations
/// <summary>
/// Get a list of CanceledSchedule referring to the current entity.
/// </summary>
public IList<CanceledSchedule> ReferringCanceledSchedule()
{
//select * from 'foreigntable'
SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (CanceledSchedule));
// where foreigntable.foreignkey = ourprimarykey
sb.AddConstraint(Operator.Equals, "idSchedule", idSchedule);
// passing true indicates that we'd like a list of elements, i.e. that no primary key
// constraints from the type being retrieved should be added to the statement
SqlStatement stmt = sb.GetStatement(true);
// execute the statement/query and create a collection of User instances from the result set
return ObjectFactory.GetCollection<CanceledSchedule>(stmt.Execute());
// TODO In the end, a GentleList should be returned instead of an arraylist
//return new GentleList( typeof(CanceledSchedule), this );
}
/// <summary>
/// Get a list of Conflicts referring to the current entity.
/// </summary>
public IList<Conflict> ReferringConflicts()
{
//select * from 'foreigntable'
SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Conflict));
// where foreigntable.foreignkey = ourprimarykey
sb.AddConstraint(Operator.Equals, "idSchedule", idSchedule);
// passing true indicates that we'd like a list of elements, i.e. that no primary key
// constraints from the type being retrieved should be added to the statement
SqlStatement stmt = sb.GetStatement(true);
// execute the statement/query and create a collection of User instances from the result set
return ObjectFactory.GetCollection<Conflict>(stmt.Execute());
// TODO In the end, a GentleList should be returned instead of an arraylist
//return new GentleList( typeof(CanceledSchedule), this );
}
/// <summary>
/// Get a list of Conflicts referring to the current entity.
/// </summary>
public IList<Conflict> ConflictingSchedules()
{
//select * from 'foreigntable'
SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Conflict));
// where foreigntable.foreignkey = ourprimarykey
sb.AddConstraint(Operator.Equals, "idConflictingSchedule", idSchedule);
// passing true indicates that we'd like a list of elements, i.e. that no primary key
// constraints from the type being retrieved should be added to the statement
SqlStatement stmt = sb.GetStatement(true);
// execute the statement/query and create a collection of User instances from the result set
return ObjectFactory.GetCollection<Conflict>(stmt.Execute());
// TODO In the end, a GentleList should be returned instead of an arraylist
//return new GentleList( typeof(CanceledSchedule), this );
}
/// <summary>
///
/// </summary>
public Channel ReferencedChannel()
{
return Channel.Retrieve(IdChannel);
}
/// <summary>
///
/// </summary>
public Schedule ReferencedSchedule()
{
return Schedule.Retrieve(idParentSchedule);
}
#endregion
public bool IsSerieIsCanceled(DateTime startTimeParam)
{
foreach (CanceledSchedule schedule in ReferringCanceledSchedule())
{
if (schedule.CancelDateTime == startTimeParam)
{
return true;
}
}
return false;
}
public bool IsSerieIsCanceled(DateTime startTimeParam, int idChannel)
{
foreach (CanceledSchedule schedule in ReferringCanceledSchedule())
{
if (schedule.CancelDateTime == startTimeParam && schedule.IdChannel == idChannel)
{
return true;
}
}
return false;
}
public void UnCancelSerie()
{
foreach (CanceledSchedule schedule in ReferringCanceledSchedule())
{
schedule.Remove();
Program.SetSingleStateSeriesPending(schedule.CancelDateTime,
schedule.IdChannel,
schedule.ReferencedSchedule().ProgramName);
}
return;