コード例 #1
0
    private void StartRecordOnCard(
      RecordingDetail recDetail, 
		  ref IUser user,      
      ICollection<CardDetail> cardsForReservation)
    {
      var cardRes = new CardReservationRec(_tvController);                

      if (cardsForReservation.Count == 0)
      {
        //no free cards available
        Log.Write("scheduler: no free cards found for recording during initial card allocation.");
      }
      else
      {
        IterateCardsUntilRecording(recDetail, user, cardsForReservation, cardRes);
      }
    }
コード例 #2
0
    private void IterateCardsUntilRecording(RecordingDetail recDetail, IUser user,
                                            ICollection<CardDetail> cardsForReservation,
                                            CardReservationRec cardRes)
    {
      IDictionary<CardDetail, ICardTuneReservationTicket> tickets = null;
      try
      {
        ICollection<CardDetail> cardsIterated = new HashSet<CardDetail>();

        int cardIterations = 0;
        bool moreCardsAvailable = true;
        bool recSucceded = false;
        while (moreCardsAvailable && !recSucceded)
        {
          tickets = CardReservationHelper.RequestCardReservations(user, cardsForReservation, _tvController, cardRes, cardsIterated, recDetail.Channel.IdChannel);
          if (tickets.Count == 0)
          {
            //no free cards available
            Log.Write("scheduler: no free card reservation(s) could be made.");
            break;
          }
          TvResult tvResult;
          ICollection<ICardTuneReservationTicket> ticketsList = tickets.Values;
          var cardAllocationTicket = new AdvancedCardAllocationTicket(_layer, _tvController, ticketsList);
          ICollection<CardDetail> cards = cardAllocationTicket.UpdateFreeCardsForChannelBasedOnTicket(
                                                                              cardsForReservation,
                                                                              user, out tvResult);          
          CardReservationHelper.CancelCardReservationsExceedingMaxConcurrentTickets(tickets, cards, _tvController.CardCollection);
          CardReservationHelper.CancelCardReservationsNotFoundInFreeCards(cardsForReservation, tickets, cards, _tvController.CardCollection);

          int maxCards = GetMaxCards(cards);
          CardReservationHelper.CancelCardReservationsBasedOnMaxCardsLimit(tickets, cards, maxCards, _tvController.CardCollection);
          UpdateCardsIterated(cardsIterated, cards); //keep track of what cards have been iterated here.

          if (cards != null && cards.Count > 0)
          {
            cardIterations += cards.Count;
            recSucceded = IterateTicketsUntilRecording(recDetail, user, cards, cardRes, maxCards, tickets, cardsIterated);
            moreCardsAvailable = _maxRecordFreeCardsToTry == 0 || _maxRecordFreeCardsToTry > cardIterations;
          }
          else
          {
            Log.Write("scheduler: no free cards found for recording.");
            break;
          }
        } // end of while
      }
      finally
      {
        CardReservationHelper.CancelAllCardReservations(tickets, _tvController.CardCollection);
      }
    }
コード例 #3
0
    private bool StartRecordingOnDisc(RecordingDetail recDetail, ref IUser user, CardDetail cardInfo, ICardTuneReservationTicket ticket, CardReservationRec cardResImpl)
    {
      bool startRecordingOnDisc = false;
      _tvController.EpgGrabberEnabled = false;
      Log.Write("Scheduler : record, first tune to channel");
      
      cardResImpl.CardInfo = cardInfo;
      cardResImpl.RecDetail = recDetail;      
      
      TvResult tuneResult = _tvController.Tune(ref user, cardInfo.TuningDetail, recDetail.Channel.IdChannel, ticket, cardResImpl);      
      startRecordingOnDisc = (tuneResult == TvResult.Succeeded);

      return startRecordingOnDisc;
    }    
コード例 #4
0
    private bool SetupAndStartRecord(RecordingDetail recDetail, ref IUser user, CardDetail cardInfo, ICardTuneReservationTicket ticket, CardReservationRec cardResImpl)
    {
      bool result = false;
      if (cardInfo != null)
      {
        user.CardId = cardInfo.Id;
        StartRecordingNotification(recDetail);
        SetupRecordingFolder(cardInfo);
        if (StartRecordingOnDisc(recDetail, ref user, cardInfo, ticket, cardResImpl))
        {
          CreateRecording(recDetail);
          try
          {
            recDetail.User.CardId = user.CardId;
            SetRecordingProgramState(recDetail);
            _recordingsInProgressList.Add(recDetail);
            RecordingStartedNotification(recDetail);
            SetupQualityControl(recDetail);
            WriteMatroskaFile(recDetail);
          }
          catch (Exception ex)
          {
            //consume exception, since it isn't catastrophic
            Log.Write(ex);
          }

          Log.Write("Scheduler: recList: count: {0} add scheduleid: {1} card: {2}",
                    _recordingsInProgressList.Count,
                    recDetail.Schedule.IdSchedule, recDetail.CardInfo.Card.Name);
          result = true;
        }
      }
      else
      {
        Log.Write("scheduler: no card found to record on.");
      }
      return result;
    }
コード例 #5
0
 private bool FindFreeCardAndStartRecord(RecordingDetail recDetail, IUser user, ICollection<CardDetail> cards, int maxCards, IDictionary<CardDetail, ICardTuneReservationTicket> tickets, CardReservationRec cardResImpl)
 {
   bool result = false;
   //keep tuning each card until we are succesful
   for (int i = 0; i < maxCards; i++)
   {
     CardDetail cardInfo = null;
     try
     {
       cardInfo = GetCardDetailForRecording(cards);
       ITvCardHandler tvCardHandler;
       if (_tvController.CardCollection.TryGetValue(cardInfo.Id, out tvCardHandler))
       {
         ICardTuneReservationTicket ticket = GetTicketByCardDetail(cardInfo, tickets);
         if (ticket == null)
         {
           ticket = CardReservationHelper.RequestCardReservation(user, cardInfo, _tvController, cardResImpl, recDetail.Channel.IdChannel);
           if (ticket != null)
           {
             tickets[cardInfo] = ticket;
           }
         }
         if (ticket != null)
         {
           result = SetupAndStartRecord(recDetail, ref user, cardInfo, ticket, cardResImpl);
           if (result)
           {
             break;
           }
         }
         else
         {
           Log.Write("scheduler: could not find free cardreservation on card:{0}", cardInfo.Id);
         }
       }
     }
     catch (Exception ex)
     {
       Log.Error(ex.ToString());
     }
     Log.Write("scheduler: recording failed, lets try next available card.");
     CardReservationHelper.CancelCardReservationAndRemoveTicket(cardInfo, tickets, _tvController.CardCollection);
     StopFailedRecord(recDetail);
     if (cardInfo != null && cards.Contains(cardInfo))
     {
       cards.Remove(cardInfo);
     }
   }
   return result;
 }
コード例 #6
0
    private bool IterateTicketsUntilRecording(RecordingDetail recDetail, IUser user, ICollection<CardDetail> cards, CardReservationRec cardRes, int maxCards, IDictionary<CardDetail, ICardTuneReservationTicket> tickets, ICollection<CardDetail> cardsIterated)
    {
      bool recSucceded = false;
      while (!recSucceded && tickets.Count > 0)
      {
        List<CardDetail> freeCards =
          cards.Where(t => t.NumberOfOtherUsers == 0 || (t.NumberOfOtherUsers > 0 && t.SameTransponder)).ToList();
        List<CardDetail> availCards = cards.Where(t => t.NumberOfOtherUsers > 0 && !t.SameTransponder).ToList();

        Log.Write("scheduler: try max {0} of {1} free cards for recording", maxCards, cards.Count);
        if (freeCards.Count > 0)
        {          
          recSucceded = FindFreeCardAndStartRecord(recDetail, user, freeCards, maxCards, tickets, cardRes);
        }
        else if (availCards.Count > 0)
        {
          recSucceded = FindAvailCardAndStartRecord(recDetail, user, availCards, maxCards, tickets, cardRes);
        }

        if (!recSucceded)
        {
          CardDetail cardInfo = GetCardDetailForRecording(cards);
          cards.Remove(cardInfo);
        }
      }
      return recSucceded;
    }
コード例 #7
0
ファイル: Scheduler.cs プロジェクト: sekotin/MediaPortal-1
    private bool FindAvailCardAndStartRecord(RecordingDetail recDetail, IUser user, ICollection<CardDetail> cards, int maxCards, ICollection<ICardTuneReservationTicket> tickets, CardReservationRec cardResImpl)
    {
      bool result = false;
      //keep tuning each card until we are succesful                   

      for (int k = 0; k < maxCards; k++)
      {
        ITvCardHandler tvCardHandler;
        CardDetail cardInfo = GetCardInfoForRecording(cards);
        if (_tvController.CardCollection.TryGetValue(cardInfo.Id, out tvCardHandler))
        {
          ICardTuneReservationTicket ticket = GetTicketByCardId(tickets, cardInfo.Id);

          if (ticket != null)
          {
            try
            {
              cardInfo = HijackCardForRecording(cards, ticket);
              result = SetupAndStartRecord(recDetail, ref user, cardInfo, ticket, cardResImpl);
              if (result)
              {
                break;
              }

            }
            catch (Exception ex)
            {
              CardReservationHelper.CancelCardReservationAndRemoveTicket(tvCardHandler, tickets);
              Log.Write(ex);
              StopFailedRecord(recDetail);
            }
          }
          else
          {
            Log.Write("scheduler: could not find available cardreservation on card:{0}", cardInfo.Id);
          }
        }
        Log.Write("scheduler: recording failed, lets try next available card.");
        CardReservationHelper.CancelCardReservationAndRemoveTicket(tvCardHandler, tickets);
        if (cardInfo != null && cards.Contains(cardInfo))
        {
          cards.Remove(cardInfo);
        }
      }
      return result;
    }