Exemplo n.º 1
0
        /// <summary>
        /// Method which returns if the card is idle or not
        /// </summary>
        /// <param name="cardId">id of card</param>
        /// <returns>true if card is idle, otherwise false</returns>
        private bool IsCardIdle(int cardId)
        {
            if (_isRunning == false)
            {
                return(false);
            }
            if (cardId < 0)
            {
                return(false);
            }
            IUser user = new User();

            user.CardId = cardId;
            if (RemoteControl.Instance.IsRecording(ref user))
            {
                return(false);
            }
            if (RemoteControl.Instance.IsTimeShifting(ref user))
            {
                return(false);
            }
            if (RemoteControl.Instance.IsScanning(user.CardId))
            {
                return(false);
            }
            IUser cardUser;

            if (_tvController.IsCardInUse(cardId, out cardUser))
            {
                return(false);
            }
            if (_tvController.IsCardInUse(user.CardId, out cardUser))
            {
                if (cardUser != null)
                {
                    return(cardUser.Name == _user.Name);
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method will try to start the epg grabber for the channel and tuning details specified
        /// Epg grabbing can only be started if there is a card idle which can receive the channel specified
        /// </summary>
        /// <param name="channel">channel to grab/param>
        /// <param name="tuning">tuning information</param>
        /// <param name="card">card to use for grabbing</param>
        /// <returns>true if grabbing has started else false</returns>
        private bool GrabEpgForChannel(Channel channel, IChannel tuning, Card card)
        {
            if (channel == null)
            {
                Log.Error("Epg: invalid channel");
                return(false);
            }
            if (tuning == null)
            {
                Log.Error("Epg: invalid tuning");
                return(false);
            }
            if (card == null)
            {
                Log.Error("Epg: invalid card");
                return(false);
            }
            if (_tvController == null)
            {
                Log.Error("Epg: invalid tvcontroller");
                return(false);
            }
            if (_user == null)
            {
                Log.Error("Epg: invalid user");
                return(false);
            }
            //remove following check to enable multi-card epg grabbing (still beta)
            if (_tvController.AllCardsIdle == false)
            {
                Log.Epg("Epg: card:{0} cards are not idle", card.IdCard);
                return(false);
            }

            TvResult result;
            //handle ATSC
            ATSCChannel atscChannel = tuning as ATSCChannel;

            if (atscChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.Atsc)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} atsc card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        IUser cardUser;
                        if (_tvController.IsCardInUse(card.IdCard, out cardUser) == false)
                        {
                            _user.CardId = card.IdCard;
                            result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                            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 atsc epg grabbing", card.IdCard);
                                    return(false);
                                }
                                _user.CardId = card.IdCard;
                                return(true);
                            }
                            _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;
                    }
                    return(false);
                }
                Log.Epg("Epg: card:{0} could not tune to atsc channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBC
            DVBCChannel dvbcChannel = tuning as DVBCChannel;

            if (dvbcChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbC)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbc card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        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 dvbc epg grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        _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;
                    }
                    //unreachable return false;
                }
                Log.Epg("Epg: card:{0} could not tune to dvbc channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBS
            DVBSChannel dvbsChannel = tuning as DVBSChannel;

            if (dvbsChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbS)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbs card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        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 dvbs epg grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        _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;
                    }
                    //unreachable return false;
                }
                Log.Epg("Epg: card:{0} could not tune to dvbs channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBT
            DVBTChannel dvbtChannel = tuning as DVBTChannel;

            if (dvbtChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbT)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbt card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        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);
                        }
                        _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;
                    }
                    //unreachable return false;
                }
                Log.Epg("Epg: card:{0} could not tune to dvbt channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBIP
            DVBIPChannel dvbipChannel = tuning as DVBIPChannel;

            if (dvbipChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbIP)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbip card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        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 dvbip grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        else
                        {
                            _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 ex;
                    }
                    //unreachable return false;
                }
                else
                {
                    Log.Epg("Epg: card:{0} could not tune to dvbip channel:{1}", card.IdCard, tuning.ToString());
                }
                return(false);
            }
            Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, tuning.ToString());
            return(false);
        }