예제 #1
0
 private static bool AssignSchedulesToCard(Schedule schedule, List<Schedule>[] cardSchedules, out IList<Schedule> overlappingSchedules, out List<Schedule> notViewabledSchedules)
 {
   overlappingSchedules = new List<Schedule>();
   notViewabledSchedules = new List<Schedule>();
   Log.Info("AssignSchedulesToCard: schedule = " + schedule);
   Log.Debug("assigning schedule " + schedule.ProgramName + " s=" + schedule.StartTime.ToString() + " id=" + schedule.IdChannel.ToString());
   //IEnumerable<Card> cards = CardManagement.ListAllCards(CardIncludeRelationEnum.None); //SEB
   IList<Card> cards = CardManagement.ListAllCards(); //huha
     
     bool assigned = false;
   bool canView = false;
   int count = 0;
   foreach (Card card in cards)
   {
     Log.Debug("checking card="+card.Name+" enabled="+card.Enabled.ToString());
     Log.Debug("CardManagement.CanViewTvChannel(card, schedule.IdChannel)=" + CardManagement.CanViewTvChannel(card, schedule.IdChannel).ToString());
     ScheduleBLL scheduleBll = new ScheduleBLL(schedule);
     if (card.Enabled && CardManagement.CanViewTvChannel(card, schedule.IdChannel))
     {
       canView = true;
       Log.Debug("can view =true");
       // checks if any schedule assigned to this cards overlaps current parsed schedule
       bool free = true;
       foreach (Schedule assignedSchedule in cardSchedules[count])
       {
         Log.Info("AssignSchedulesToCard: card {0}, ID = {1} has schedule = " + assignedSchedule, count, card.IdCard);
         bool hasOverlappingSchedule = scheduleBll.IsOverlapping(assignedSchedule);
         if (hasOverlappingSchedule)
         {
           bool isSameTransponder = (scheduleBll.IsSameTransponder(assignedSchedule));
           Log.Debug("isSameTransponder=" + isSameTransponder.ToString());
           if (!isSameTransponder)
           {
             overlappingSchedules.Add(assignedSchedule);
             Log.Info("AssignSchedulesToCard: overlapping with " + assignedSchedule + " on card {0}, ID = {1}", count,
                      card.IdCard);
             free = false;
             break;
           }
         }
       }
       if (free)
       {
         Log.Info("AssignSchedulesToCard: free on card {0}, ID = {1}", count, card.IdCard);
         cardSchedules[count].Add(schedule);
         assigned = true;
         break;
       }
     }
     count++;
   }
   if (!canView)
   {
       Log.Debug("notViewabledSchedules.Add(schedule)");
     notViewabledSchedules.Add(schedule);
   }
   Log.Debug("canView=" + canView.ToString() + "  assigned=" + assigned.ToString());
   return (canView && assigned);
 }