Exemplo n.º 1
0
        private bool TuneEPGgrabber(Channel channel, IChannel tuning, Card card, TvResult result)
        {
            try
            {
                _user.CardId = Card.IdCard;
                ITvCardHandler cardHandler;
                if (_tvController.CardCollection.TryGetValue(Card.IdCard, out cardHandler))
                {
                    ICardTuneReservationTicket ticket = null;
                    try
                    {
                        ICardReservation cardReservationImpl = new CardReservationTimeshifting(_tvController);
                        ticket = cardReservationImpl.RequestCardTuneReservation(cardHandler, tuning, _user, channel.IdChannel);

                        if (ticket != null)
                        {
                            result = _tvController.Tune(ref _user, tuning, channel.IdChannel, ticket);
                            if (result == TvResult.Succeeded)
                            {
                                if (!_isRunning || false == _tvController.GrabEpg(this, Card.IdCard))
                                {
                                    if (!_isRunning)
                                    {
                                        Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                    }
                                    _tvController.StopGrabbingEpg(_user);
                                    _user.CardId = -1;
                                    Log.Epg("Epg: card:{0} could not start dvbt grabbing", Card.IdCard);
                                    return(false);
                                }
                                _user.CardId = Card.IdCard;
                                return(true);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        CardReservationHelper.CancelCardReservation(cardHandler, ticket);
                        throw;
                    }
                }
                _user.CardId = -1;
                Log.Epg("Epg: card:{0} could not tune to channel:{1}", Card.IdCard, result.ToString());
                return(false);
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                throw;
            }
        }